@ktjs/router 0.32.5 → 0.33.1
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/README.md +35 -3
- package/dist/index.mjs +165 -286
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,11 +12,14 @@
|
|
|
12
12
|
|
|
13
13
|
<p align="center"><strong>Visit KT.js: <a href="https://baendlorel.github.io/kt.js/">https://baendlorel.github.io/kt.js/</a></strong></p>
|
|
14
14
|
|
|
15
|
+
> kt.js is still under development, so there might be some breaking changes. Note the Update Log below
|
|
16
|
+
|
|
15
17
|
## Recent Updates
|
|
16
18
|
|
|
17
|
-
1.
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
1. `ref.value` remains the standard read API, and it can also replace the whole outer value with `ref.value = nextValue`.
|
|
20
|
+
2. `ref.draft` is the deep-mutation entry for nested objects, arrays, `Map` / `Set`, and custom mutable objects.
|
|
21
|
+
3. `ref.draft` itself is not assignable; mutate nested fields or call mutating methods on the returned object instead.
|
|
22
|
+
4. `addOnChange((newValue, oldValue) => ...)` keeps `oldValue` as the previous reference, not a deep snapshot.
|
|
20
23
|
|
|
21
24
|
## Community
|
|
22
25
|
|
|
@@ -29,6 +32,35 @@ kt.js is a simple framework with a tiny runtime that renders real DOM directly (
|
|
|
29
32
|
|
|
30
33
|
KT.js focuses on one principle: keep direct control of the DOM and avoid unnecessary repainting.
|
|
31
34
|
|
|
35
|
+
## Reactive Contract
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
const user = ref({ profile: { name: 'John' }, tags: ['new'] });
|
|
39
|
+
|
|
40
|
+
console.log(user.value.profile.name); // read
|
|
41
|
+
|
|
42
|
+
user.value = {
|
|
43
|
+
...user.value,
|
|
44
|
+
profile: { ...user.value.profile, name: 'Jane' },
|
|
45
|
+
tags: [...user.value.tags],
|
|
46
|
+
}; // replace the whole outer value
|
|
47
|
+
|
|
48
|
+
user.draft.profile.name = 'Jane'; // deep write
|
|
49
|
+
user.draft.tags.push('active'); // array / map / set / custom-object style mutation
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Rules:
|
|
53
|
+
|
|
54
|
+
- Read with `.value`.
|
|
55
|
+
- Replace the whole outer value with `.value = nextValue`.
|
|
56
|
+
- Use `.draft` for deep mutations on nested objects, arrays, `Map` / `Set`, or other mutable instances.
|
|
57
|
+
- Do not assign to `.draft` itself; mutate inside it.
|
|
58
|
+
- `computed` stays read-only and is consumed through `.value`.
|
|
59
|
+
- `oldValue` in change listeners is the previous reference only, not a deep-cloned snapshot.
|
|
60
|
+
- Correctness is expected to come from the transformer and TypeScript checks; runtime hot paths stay minimal on purpose.
|
|
61
|
+
|
|
62
|
+
This is an explicit contract, closer to a Rust-style model than permissive runtime magic: unclear code should fail early.
|
|
63
|
+
|
|
32
64
|
## Quick Start
|
|
33
65
|
|
|
34
66
|
```bash
|
package/dist/index.mjs
CHANGED
|
@@ -1,315 +1,155 @@
|
|
|
1
|
-
import { normalizePath, extractParams, $emptyFn, parseQuery, emplaceParams, buildQuery } from
|
|
1
|
+
import { normalizePath, extractParams, $emptyFn, parseQuery, emplaceParams, buildQuery } from "@ktjs/shared";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const createMatcher = (routes) => {
|
|
7
|
-
const nameMap = {};
|
|
8
|
-
for (let i = 0; i < routes.length; i++) {
|
|
9
|
-
const route = routes[i];
|
|
10
|
-
if (route.name !== undefined) {
|
|
11
|
-
if (route.name in nameMap) {
|
|
12
|
-
throw new Error(`[@ktjs/router error] Duplicate route name detected: '${route.name}'`);
|
|
13
|
-
}
|
|
14
|
-
nameMap[route.name] = route;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Find route by name
|
|
19
|
-
*/
|
|
20
|
-
const findByName = (name) => {
|
|
21
|
-
return nameMap[name] ?? null;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Match path against all routes
|
|
25
|
-
*/
|
|
26
|
-
const match = (path) => {
|
|
27
|
-
const normalizedPath = normalizePath(path);
|
|
28
|
-
// Try exact match first
|
|
29
|
-
for (const route of routes) {
|
|
30
|
-
if (route.path === normalizedPath) {
|
|
31
|
-
return {
|
|
32
|
-
route,
|
|
33
|
-
params: {},
|
|
34
|
-
result: getMatchedChain(route),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
// Try dynamic routes
|
|
39
|
-
for (const route of routes) {
|
|
40
|
-
if (route.path.includes(':')) {
|
|
41
|
-
const params = extractParams(route.path, normalizedPath);
|
|
42
|
-
if (params) {
|
|
43
|
-
return {
|
|
44
|
-
route,
|
|
45
|
-
params,
|
|
46
|
-
result: getMatchedChain(route),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Get chain of matched routes (for nested routes)
|
|
55
|
-
* - parent roots ahead
|
|
56
|
-
*/
|
|
57
|
-
const getMatchedChain = (route) => {
|
|
58
|
-
const matched = [route];
|
|
59
|
-
const path = route.path;
|
|
60
|
-
// Find parent routes by path prefix matching
|
|
61
|
-
for (let i = 0; i < routes.length; i++) {
|
|
62
|
-
const r = routes[i];
|
|
63
|
-
if (r !== route && path.startsWith(r.path) && path !== r.path) {
|
|
64
|
-
matched.push(r);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return matched.reverse();
|
|
68
|
-
};
|
|
69
|
-
return {
|
|
70
|
-
findByName,
|
|
71
|
-
match,
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Create a router view container that automatically renders route components
|
|
77
|
-
*/
|
|
78
|
-
function KTRouter({ router }) {
|
|
79
|
-
const view = document.createElement('kt-router-view');
|
|
80
|
-
router.setRouterView(view);
|
|
81
|
-
return view;
|
|
3
|
+
function KTRouter({router: router}) {
|
|
4
|
+
const view = document.createElement("kt-router-view");
|
|
5
|
+
return router.setRouterView(view), view;
|
|
82
6
|
}
|
|
83
7
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
const routes = [];
|
|
90
|
-
const history = [];
|
|
91
|
-
let routerView = null;
|
|
92
|
-
let current = null;
|
|
93
|
-
// # methods
|
|
94
|
-
const normalize = (rawRoutes, parentPath) => rawRoutes.map((route) => {
|
|
95
|
-
const path = normalizePath(parentPath, route.path);
|
|
96
|
-
const normalized = {
|
|
8
|
+
const createRouter = ({beforeEach: beforeEach = $emptyFn, afterEach: afterEach = $emptyFn, onNotFound: onNotFound = $emptyFn, onError: onError = $emptyFn, prefix: prefix = "", routes: rawRoutes}) => {
|
|
9
|
+
const routes = [], history = [];
|
|
10
|
+
let routerView = null, current = null;
|
|
11
|
+
const normalize = (rawRoutes, parentPath) => rawRoutes.map(route => {
|
|
12
|
+
const path = normalizePath(parentPath, route.path), normalized = {
|
|
97
13
|
path: prefix + path,
|
|
98
|
-
name: route.name ??
|
|
14
|
+
name: route.name ?? "",
|
|
99
15
|
meta: route.meta ?? {},
|
|
100
16
|
beforeEnter: route.beforeEnter ?? $emptyFn,
|
|
101
17
|
after: route.after ?? $emptyFn,
|
|
102
18
|
children: route.children ? normalize(route.children, path) : [],
|
|
103
|
-
component: route.component
|
|
104
|
-
};
|
|
105
|
-
// directly push the normalized route to the list
|
|
106
|
-
// avoid flatten them again
|
|
107
|
-
routes.push(normalized);
|
|
108
|
-
return normalized;
|
|
109
|
-
});
|
|
110
|
-
const guard = async (to, from, guardLevel) => {
|
|
111
|
-
try {
|
|
112
|
-
if (guardLevel === 0 /* GuardLevel.None */) {
|
|
113
|
-
return { continue: true };
|
|
114
|
-
}
|
|
115
|
-
if (guardLevel & 1 /* GuardLevel.Global */) {
|
|
116
|
-
const result = await beforeEach(to, from);
|
|
117
|
-
if (result === false) {
|
|
118
|
-
return { continue: false };
|
|
119
|
-
}
|
|
120
|
-
if (typeof result === 'string') {
|
|
121
|
-
return { continue: false, redirectTo: { path: result } };
|
|
122
|
-
}
|
|
123
|
-
if (result && typeof result === 'object') {
|
|
124
|
-
return { continue: false, redirectTo: result };
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
if (guardLevel & 2 /* GuardLevel.Route */) {
|
|
128
|
-
const targetRoute = to.matched[to.matched.length - 1];
|
|
129
|
-
const result = await targetRoute.beforeEnter(to);
|
|
130
|
-
if (result === false) {
|
|
131
|
-
return { continue: false };
|
|
132
|
-
}
|
|
133
|
-
if (typeof result === 'string') {
|
|
134
|
-
return { continue: false, redirectTo: { path: result } };
|
|
135
|
-
}
|
|
136
|
-
if (result && typeof result === 'object') {
|
|
137
|
-
return { continue: false, redirectTo: result };
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return { continue: true };
|
|
141
|
-
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
onError(error);
|
|
144
|
-
return { continue: false };
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
const navigatePrepare = (options) => {
|
|
148
|
-
// Resolve target route
|
|
149
|
-
let targetPath;
|
|
150
|
-
let targetRoute;
|
|
151
|
-
if (options.name) {
|
|
152
|
-
targetRoute = findByName(options.name);
|
|
153
|
-
if (!targetRoute) {
|
|
154
|
-
throw new Error(`[@ktjs/router error] Route not found: ${options.name}`);
|
|
155
|
-
}
|
|
156
|
-
targetPath = targetRoute.path;
|
|
157
|
-
}
|
|
158
|
-
else if (options.path) {
|
|
159
|
-
targetPath = normalizePath(options.path);
|
|
160
|
-
targetRoute = match(targetPath)?.route;
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
throw new Error(`[@ktjs/router error] Either path or name must be provided`);
|
|
164
|
-
}
|
|
165
|
-
// Substitute params
|
|
166
|
-
if (options.params) {
|
|
167
|
-
targetPath = emplaceParams(targetPath, options.params);
|
|
168
|
-
}
|
|
169
|
-
// Match final path
|
|
170
|
-
const matched = match(targetPath);
|
|
171
|
-
if (!matched) {
|
|
172
|
-
onNotFound(targetPath);
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
// Build route context
|
|
176
|
-
const queryString = options.query ? buildQuery(options.query) : '';
|
|
177
|
-
const fullPath = targetPath + queryString;
|
|
178
|
-
const to = {
|
|
179
|
-
path: targetPath,
|
|
180
|
-
name: matched.route.name,
|
|
181
|
-
params: { ...matched.params, ...(options.params ?? {}) },
|
|
182
|
-
query: options.query ?? {},
|
|
183
|
-
meta: matched.route.meta ?? {},
|
|
184
|
-
matched: matched.result,
|
|
185
|
-
};
|
|
186
|
-
return {
|
|
187
|
-
guardLevel: options.guardLevel ?? 15 /* GuardLevel.Default */,
|
|
188
|
-
replace: options.replace ?? false,
|
|
189
|
-
to,
|
|
190
|
-
fullPath,
|
|
19
|
+
component: route.component
|
|
191
20
|
};
|
|
192
|
-
|
|
193
|
-
|
|
21
|
+
return routes.push(normalized), normalized;
|
|
22
|
+
}), navigate = async (options, redirectCount = 0) => {
|
|
194
23
|
try {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const guardResult = await guard(to, current, guardLevel);
|
|
206
|
-
if (!guardResult.continue) {
|
|
207
|
-
// Check if there's a redirect
|
|
208
|
-
if (guardResult.redirectTo) {
|
|
209
|
-
return await navigate(guardResult.redirectTo, redirectCount + 1);
|
|
210
|
-
}
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
// ---- Guards passed ----
|
|
214
|
-
const hashUrl = '#' + fullPath;
|
|
215
|
-
if (replace) {
|
|
216
|
-
window.location.replace(hashUrl);
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
window.location.hash = fullPath;
|
|
220
|
-
}
|
|
221
|
-
current = to;
|
|
222
|
-
if (replace) {
|
|
223
|
-
if (history.length > 0) {
|
|
224
|
-
history[history.length - 1] = to;
|
|
24
|
+
if (redirectCount > 10) return onError(new Error("Maximum redirect count exceeded")),
|
|
25
|
+
!1;
|
|
26
|
+
const prep = (options => {
|
|
27
|
+
let targetPath, targetRoute;
|
|
28
|
+
if (options.name) {
|
|
29
|
+
if (targetRoute = findByName(options.name), !targetRoute) throw new Error(`[@ktjs/router error] Route not found: ${options.name}`);
|
|
30
|
+
targetPath = targetRoute.path;
|
|
31
|
+
} else {
|
|
32
|
+
if (!options.path) throw new Error("[@ktjs/router error] Either path or name must be provided");
|
|
33
|
+
targetPath = normalizePath(options.path), targetRoute = match(targetPath)?.route;
|
|
225
34
|
}
|
|
226
|
-
|
|
227
|
-
|
|
35
|
+
options.params && (targetPath = emplaceParams(targetPath, options.params));
|
|
36
|
+
const matched = match(targetPath);
|
|
37
|
+
if (!matched) return onNotFound(targetPath), null;
|
|
38
|
+
const fullPath = targetPath + (options.query ? buildQuery(options.query) : ""), to = {
|
|
39
|
+
path: targetPath,
|
|
40
|
+
name: matched.route.name,
|
|
41
|
+
params: {
|
|
42
|
+
...matched.params,
|
|
43
|
+
...options.params ?? {}
|
|
44
|
+
},
|
|
45
|
+
query: options.query ?? {},
|
|
46
|
+
meta: matched.route.meta ?? {},
|
|
47
|
+
matched: matched.result
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
guardLevel: options.guardLevel ?? 15,
|
|
51
|
+
replace: options.replace ?? !1,
|
|
52
|
+
to: to,
|
|
53
|
+
fullPath: fullPath
|
|
54
|
+
};
|
|
55
|
+
})(options);
|
|
56
|
+
if (!prep) return !1;
|
|
57
|
+
const {guardLevel: guardLevel, replace: replace, to: to, fullPath: fullPath} = prep, guardResult = await (async (to, from, guardLevel) => {
|
|
58
|
+
try {
|
|
59
|
+
if (0 === guardLevel) return {
|
|
60
|
+
continue: !0
|
|
61
|
+
};
|
|
62
|
+
if (1 & guardLevel) {
|
|
63
|
+
const result = await beforeEach(to, from);
|
|
64
|
+
if (!1 === result) return {
|
|
65
|
+
continue: !1
|
|
66
|
+
};
|
|
67
|
+
if ("string" == typeof result) return {
|
|
68
|
+
continue: !1,
|
|
69
|
+
redirectTo: {
|
|
70
|
+
path: result
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
if (result && "object" == typeof result) return {
|
|
74
|
+
continue: !1,
|
|
75
|
+
redirectTo: result
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (2 & guardLevel) {
|
|
79
|
+
const targetRoute = to.matched[to.matched.length - 1], result = await targetRoute.beforeEnter(to);
|
|
80
|
+
if (!1 === result) return {
|
|
81
|
+
continue: !1
|
|
82
|
+
};
|
|
83
|
+
if ("string" == typeof result) return {
|
|
84
|
+
continue: !1,
|
|
85
|
+
redirectTo: {
|
|
86
|
+
path: result
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
if (result && "object" == typeof result) return {
|
|
90
|
+
continue: !1,
|
|
91
|
+
redirectTo: result
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
continue: !0
|
|
96
|
+
};
|
|
97
|
+
} catch (error) {
|
|
98
|
+
return onError(error), {
|
|
99
|
+
continue: !1
|
|
100
|
+
};
|
|
228
101
|
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
102
|
+
})(to, current, guardLevel);
|
|
103
|
+
if (!guardResult.continue) return !!guardResult.redirectTo && await navigate(guardResult.redirectTo, redirectCount + 1);
|
|
104
|
+
const hashUrl = "#" + fullPath;
|
|
105
|
+
if (replace ? window.location.replace(hashUrl) : window.location.hash = fullPath,
|
|
106
|
+
current = to, replace && history.length > 0 ? history[history.length - 1] = to : history.push(to),
|
|
107
|
+
routerView && to.matched.length > 0) {
|
|
235
108
|
const route = to.matched[to.matched.length - 1];
|
|
236
109
|
if (route.component) {
|
|
237
110
|
const element = await route.component();
|
|
238
|
-
routerView.innerHTML =
|
|
239
|
-
routerView.appendChild(element);
|
|
111
|
+
routerView.innerHTML = "", routerView.appendChild(element);
|
|
240
112
|
}
|
|
241
113
|
}
|
|
242
|
-
executeAfterHooks(to, history[history.length - 2] ?? null);
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
catch (error) {
|
|
246
|
-
onError(error);
|
|
247
|
-
return false;
|
|
114
|
+
return executeAfterHooks(to, history[history.length - 2] ?? null), !0;
|
|
115
|
+
} catch (error) {
|
|
116
|
+
return onError(error), !1;
|
|
248
117
|
}
|
|
249
|
-
}
|
|
250
|
-
const executeAfterHooks = async (to, from) => {
|
|
118
|
+
}, executeAfterHooks = async (to, from) => {
|
|
251
119
|
const targetRoute = to.matched[to.matched.length - 1];
|
|
252
|
-
await targetRoute.after(to);
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
* Normalize navigation argument
|
|
257
|
-
*/
|
|
258
|
-
const normalizeLocation = (loc) => {
|
|
259
|
-
if (typeof loc !== 'string') {
|
|
260
|
-
return loc;
|
|
261
|
-
}
|
|
262
|
-
const [path, queryString] = loc.split('?');
|
|
120
|
+
await targetRoute.after(to), await afterEach(to, from);
|
|
121
|
+
}, normalizeLocation = loc => {
|
|
122
|
+
if ("string" != typeof loc) return loc;
|
|
123
|
+
const [path, queryString] = loc.split("?");
|
|
263
124
|
return {
|
|
264
|
-
path,
|
|
265
|
-
query: queryString ? parseQuery(queryString) :
|
|
125
|
+
path: path,
|
|
126
|
+
query: queryString ? parseQuery(queryString) : void 0
|
|
266
127
|
};
|
|
267
128
|
};
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const [path] = hash.split('?');
|
|
272
|
-
const normalizedPath = normalizePath(path);
|
|
273
|
-
if (current && current.path === normalizedPath) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
// render route for new hash without adding extra history entry
|
|
129
|
+
window.addEventListener("hashchange", () => {
|
|
130
|
+
const hash = window.location.hash.slice(1), [path] = hash.split("?"), normalizedPath = normalizePath(path);
|
|
131
|
+
if (current && current.path === normalizedPath) return;
|
|
277
132
|
const matched = match(normalizedPath);
|
|
278
|
-
if (!matched)
|
|
279
|
-
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
const queryString = window.location.hash.slice(1).split('?')[1];
|
|
283
|
-
const to = {
|
|
133
|
+
if (!matched) return void onNotFound(normalizedPath);
|
|
134
|
+
const queryString = window.location.hash.slice(1).split("?")[1], to = {
|
|
284
135
|
path: normalizedPath,
|
|
285
136
|
name: matched.route.name,
|
|
286
137
|
params: matched.params,
|
|
287
138
|
query: queryString ? parseQuery(queryString) : {},
|
|
288
139
|
meta: matched.route.meta ?? {},
|
|
289
|
-
matched: matched.result
|
|
140
|
+
matched: matched.result
|
|
290
141
|
};
|
|
291
|
-
|
|
292
|
-
current = to;
|
|
293
|
-
history.push(to);
|
|
294
|
-
if (routerView && to.matched.length > 0) {
|
|
142
|
+
if (current = to, history.push(to), routerView && to.matched.length > 0) {
|
|
295
143
|
const route = to.matched[to.matched.length - 1];
|
|
296
144
|
if (route.component) {
|
|
297
145
|
const element = route.component();
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
routerView.appendChild(el);
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
routerView.innerHTML = '';
|
|
306
|
-
routerView.appendChild(element);
|
|
307
|
-
}
|
|
146
|
+
element instanceof Promise ? element.then(el => {
|
|
147
|
+
routerView.innerHTML = "", routerView.appendChild(el);
|
|
148
|
+
}) : (routerView.innerHTML = "", routerView.appendChild(element));
|
|
308
149
|
}
|
|
309
150
|
}
|
|
310
151
|
executeAfterHooks(to, history[history.length - 2] ?? null);
|
|
311
152
|
});
|
|
312
|
-
// # initialize
|
|
313
153
|
const instance = {
|
|
314
154
|
get current() {
|
|
315
155
|
return current;
|
|
@@ -326,26 +166,65 @@ const createRouter = ({ beforeEach = $emptyFn, afterEach = $emptyFn, onNotFound
|
|
|
326
166
|
},
|
|
327
167
|
silentPush(location) {
|
|
328
168
|
const options = normalizeLocation(location);
|
|
329
|
-
return navigate({
|
|
169
|
+
return navigate({
|
|
170
|
+
...options,
|
|
171
|
+
guardLevel: 2
|
|
172
|
+
});
|
|
330
173
|
},
|
|
331
174
|
replace(location) {
|
|
332
175
|
const options = normalizeLocation(location);
|
|
333
|
-
return navigate({
|
|
176
|
+
return navigate({
|
|
177
|
+
...options,
|
|
178
|
+
replace: !0
|
|
179
|
+
});
|
|
334
180
|
},
|
|
335
181
|
back() {
|
|
336
182
|
window.history.back();
|
|
337
183
|
},
|
|
338
184
|
forward() {
|
|
339
185
|
window.history.forward();
|
|
340
|
-
}
|
|
186
|
+
}
|
|
341
187
|
};
|
|
342
|
-
normalize(rawRoutes,
|
|
343
|
-
const { findByName, match } =
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
188
|
+
normalize(rawRoutes, "/");
|
|
189
|
+
const {findByName: findByName, match: match} = (routes => {
|
|
190
|
+
const nameMap = {};
|
|
191
|
+
for (let i = 0; i < routes.length; i++) {
|
|
192
|
+
const route = routes[i];
|
|
193
|
+
if (void 0 !== route.name) {
|
|
194
|
+
if (route.name in nameMap) throw new Error(`[@ktjs/router error] Duplicate route name detected: '${route.name}'`);
|
|
195
|
+
nameMap[route.name] = route;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const getMatchedChain = route => {
|
|
199
|
+
const matched = [ route ], path = route.path;
|
|
200
|
+
for (let i = 0; i < routes.length; i++) {
|
|
201
|
+
const r = routes[i];
|
|
202
|
+
r !== route && path.startsWith(r.path) && path !== r.path && matched.push(r);
|
|
203
|
+
}
|
|
204
|
+
return matched.reverse();
|
|
205
|
+
};
|
|
206
|
+
return {
|
|
207
|
+
findByName: name => nameMap[name] ?? null,
|
|
208
|
+
match: path => {
|
|
209
|
+
const normalizedPath = normalizePath(path);
|
|
210
|
+
for (const route of routes) if (route.path === normalizedPath) return {
|
|
211
|
+
route: route,
|
|
212
|
+
params: {},
|
|
213
|
+
result: getMatchedChain(route)
|
|
214
|
+
};
|
|
215
|
+
for (const route of routes) if (route.path.includes(":")) {
|
|
216
|
+
const params = extractParams(route.path, normalizedPath);
|
|
217
|
+
if (params) return {
|
|
218
|
+
route: route,
|
|
219
|
+
params: params,
|
|
220
|
+
result: getMatchedChain(route)
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
})(routes), currentHash = window.location.hash.slice(1);
|
|
227
|
+
return currentHash && instance.push(currentHash), instance;
|
|
349
228
|
};
|
|
350
229
|
|
|
351
230
|
export { KTRouter, createRouter };
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/core/matcher.ts","../src/core/kt-router.ts","../src/core/index.ts"],"sourcesContent":["import type { RouteConfig, RouteMatch } from '../types/router.js';\nimport { extractParams, normalizePath } from '@ktjs/shared';\n\n/**\n * Route matcher for finding matching routes and extracting params\n */\nexport const createMatcher = (routes: RouteConfig[]) => {\n const nameMap: Record<string, RouteConfig> = {};\n\n for (let i = 0; i < routes.length; i++) {\n const route = routes[i];\n if (route.name !== undefined) {\n if (route.name in nameMap) {\n $throw(`Duplicate route name detected: '${route.name}'`);\n }\n nameMap[route.name] = route;\n }\n }\n\n /**\n * Find route by name\n */\n const findByName = (name: string): RouteConfig | null => {\n return nameMap[name] ?? null;\n };\n\n /**\n * Match path against all routes\n */\n const match = (path: string): RouteMatch | null => {\n const normalizedPath = normalizePath(path);\n\n // Try exact match first\n for (const route of routes) {\n if (route.path === normalizedPath) {\n return {\n route,\n params: {},\n result: getMatchedChain(route),\n };\n }\n }\n\n // Try dynamic routes\n for (const route of routes) {\n if (route.path.includes(':')) {\n const params = extractParams(route.path, normalizedPath);\n if (params) {\n return {\n route,\n params,\n result: getMatchedChain(route),\n };\n }\n }\n }\n\n return null;\n };\n\n /**\n * Get chain of matched routes (for nested routes)\n * - parent roots ahead\n */\n const getMatchedChain = (route: RouteConfig): RouteConfig[] => {\n const matched: RouteConfig[] = [route];\n const path = route.path;\n\n // Find parent routes by path prefix matching\n for (let i = 0; i < routes.length; i++) {\n const r = routes[i];\n if (r !== route && path.startsWith(r.path) && path !== r.path) {\n matched.push(r);\n }\n }\n\n return matched.reverse();\n };\n\n return {\n findByName,\n match,\n };\n};\n","import { JSX } from '@ktjs/core/jsx-runtime';\nimport type { Router } from '../types/router.js';\n\n/**\n * Create a router view container that automatically renders route components\n */\nexport function KTRouter({ router }: { router: Router }): JSX.Element {\n const view = document.createElement('kt-router-view');\n router.setRouterView(view);\n return view as JSX.Element;\n}\n","import { $emptyFn, buildQuery, normalizePath, parseQuery, emplaceParams } from '@ktjs/shared';\n\nimport type { Router, RouterConfig, RouteContext, NavOptions, RawRouteConfig, RouteConfig } from '../types/router.js';\nimport { GuardLevel } from './consts.js';\nimport { createMatcher } from './matcher.js';\n\n/**\n * Create a new router instance\n */\nexport const createRouter = ({\n beforeEach = $emptyFn,\n afterEach = $emptyFn,\n onNotFound = $emptyFn,\n onError = $emptyFn,\n prefix = '',\n routes: rawRoutes,\n}: RouterConfig): Router => {\n // # private values\n const routes: RouteConfig[] = [];\n const history: RouteContext[] = [];\n let routerView: HTMLElement | null = null;\n let current: RouteContext | null = null;\n\n // # methods\n const normalize = (rawRoutes: RawRouteConfig[], parentPath: string): RouteConfig[] =>\n rawRoutes.map((route) => {\n const path = normalizePath(parentPath, route.path);\n const normalized = {\n path: prefix + path,\n name: route.name ?? '',\n meta: route.meta ?? {},\n beforeEnter: route.beforeEnter ?? $emptyFn,\n after: route.after ?? $emptyFn,\n children: route.children ? normalize(route.children, path) : [],\n component: route.component,\n };\n\n // directly push the normalized route to the list\n // avoid flatten them again\n routes.push(normalized);\n return normalized;\n });\n\n const guard = async (\n to: RouteContext,\n from: RouteContext | null,\n guardLevel: GuardLevel,\n ): Promise<{ continue: boolean; redirectTo?: NavOptions }> => {\n try {\n if (guardLevel === GuardLevel.None) {\n return { continue: true };\n }\n\n if (guardLevel & GuardLevel.Global) {\n const result = await beforeEach(to, from);\n if (result === false) {\n return { continue: false };\n }\n if (typeof result === 'string') {\n return { continue: false, redirectTo: { path: result } };\n }\n if (result && typeof result === 'object') {\n return { continue: false, redirectTo: result };\n }\n }\n\n if (guardLevel & GuardLevel.Route) {\n const targetRoute = to.matched[to.matched.length - 1];\n const result = await targetRoute.beforeEnter(to);\n if (result === false) {\n return { continue: false };\n }\n if (typeof result === 'string') {\n return { continue: false, redirectTo: { path: result } };\n }\n if (result && typeof result === 'object') {\n return { continue: false, redirectTo: result };\n }\n }\n\n return { continue: true };\n } catch (error) {\n onError(error as Error);\n return { continue: false };\n }\n };\n\n const navigatePrepare = (options: NavOptions) => {\n // Resolve target route\n let targetPath: string;\n let targetRoute;\n\n if (options.name) {\n targetRoute = findByName(options.name);\n if (!targetRoute) {\n $throw(`Route not found: ${options.name}`);\n }\n targetPath = targetRoute.path;\n } else if (options.path) {\n targetPath = normalizePath(options.path);\n targetRoute = match(targetPath)?.route;\n } else {\n $throw(`Either path or name must be provided`);\n }\n\n // Substitute params\n if (options.params) {\n targetPath = emplaceParams(targetPath, options.params);\n }\n\n // Match final path\n const matched = match(targetPath);\n if (!matched) {\n onNotFound(targetPath);\n return null;\n }\n\n // Build route context\n const queryString = options.query ? buildQuery(options.query) : '';\n const fullPath = targetPath + queryString;\n\n const to: RouteContext = {\n path: targetPath,\n name: matched.route.name,\n params: { ...matched.params, ...(options.params ?? {}) },\n query: options.query ?? {},\n meta: matched.route.meta ?? {},\n matched: matched.result,\n };\n\n return {\n guardLevel: options.guardLevel ?? GuardLevel.Default,\n replace: options.replace ?? false,\n to,\n fullPath,\n };\n };\n\n const navigate = async (options: NavOptions, redirectCount = 0): Promise<boolean> => {\n try {\n // Prevent infinite redirect loop\n if (redirectCount > 10) {\n onError(new Error('Maximum redirect count exceeded'));\n return false;\n }\n\n const prep = navigatePrepare(options);\n if (!prep) {\n return false;\n }\n\n const { guardLevel, replace, to, fullPath } = prep;\n\n const guardResult = await guard(to, current, guardLevel);\n if (!guardResult.continue) {\n // Check if there's a redirect\n if (guardResult.redirectTo) {\n return await navigate(guardResult.redirectTo, redirectCount + 1);\n }\n return false;\n }\n\n // ---- Guards passed ----\n\n const hashUrl = '#' + fullPath;\n if (replace) {\n window.location.replace(hashUrl);\n } else {\n window.location.hash = fullPath;\n }\n\n current = to;\n if (replace) {\n if (history.length > 0) {\n history[history.length - 1] = to;\n } else {\n history.push(to);\n }\n } else {\n history.push(to);\n }\n\n // Render component if routerView exists\n if (routerView && to.matched.length > 0) {\n const route = to.matched[to.matched.length - 1];\n if (route.component) {\n const element = await route.component();\n routerView.innerHTML = '';\n routerView.appendChild(element);\n }\n }\n\n executeAfterHooks(to, history[history.length - 2] ?? null);\n return true;\n } catch (error) {\n onError(error as Error);\n return false;\n }\n };\n\n const executeAfterHooks = async (to: RouteContext, from: RouteContext | null): Promise<void> => {\n const targetRoute = to.matched[to.matched.length - 1];\n await targetRoute.after(to);\n await afterEach(to, from);\n };\n\n /**\n * Normalize navigation argument\n */\n const normalizeLocation = (loc: string | NavOptions): NavOptions => {\n if (typeof loc !== 'string') {\n return loc;\n }\n\n const [path, queryString] = loc.split('?');\n return {\n path,\n query: queryString ? parseQuery(queryString) : undefined,\n };\n };\n\n // # register events\n window.addEventListener('hashchange', () => {\n const hash = window.location.hash.slice(1);\n const [path] = hash.split('?');\n const normalizedPath = normalizePath(path);\n if (current && current.path === normalizedPath) {\n return;\n }\n // render route for new hash without adding extra history entry\n const matched = match(normalizedPath);\n if (!matched) {\n onNotFound(normalizedPath);\n return;\n }\n const queryString = window.location.hash.slice(1).split('?')[1];\n const to: RouteContext = {\n path: normalizedPath,\n name: matched.route.name,\n params: matched.params,\n query: queryString ? parseQuery(queryString) : {},\n meta: matched.route.meta ?? {},\n matched: matched.result,\n };\n\n // apply without modifying browser history\n current = to;\n history.push(to);\n\n if (routerView && to.matched.length > 0) {\n const route = to.matched[to.matched.length - 1];\n if (route.component) {\n const element = route.component();\n if (element instanceof Promise) {\n element.then((el) => {\n routerView!.innerHTML = '';\n routerView!.appendChild(el);\n });\n } else {\n routerView.innerHTML = '';\n routerView.appendChild(element);\n }\n }\n }\n\n executeAfterHooks(to, history[history.length - 2] ?? null);\n });\n\n // # initialize\n const instance: Router = {\n get current() {\n return current;\n },\n\n get history() {\n return history.concat();\n },\n\n setRouterView(view: HTMLElement) {\n routerView = view;\n },\n\n push(location: string | NavOptions): boolean | Promise<boolean> {\n const options = normalizeLocation(location);\n return navigate(options);\n },\n\n silentPush(location: string | NavOptions): boolean | Promise<boolean> {\n const options = normalizeLocation(location);\n return navigate({ ...options, guardLevel: GuardLevel.Route });\n },\n\n replace(location: string | NavOptions): boolean | Promise<boolean> {\n const options = normalizeLocation(location);\n return navigate({ ...options, replace: true });\n },\n\n back() {\n window.history.back();\n },\n\n forward() {\n window.history.forward();\n },\n };\n normalize(rawRoutes, '/');\n const { findByName, match } = createMatcher(routes);\n const currentHash = window.location.hash.slice(1);\n if (currentHash) {\n instance.push(currentHash);\n }\n\n return instance;\n};\n\nexport { GuardLevel };\nexport { KTRouter } from './kt-router.js';\n"],"names":[],"mappings":";;AAGA;;AAEG;AACI,MAAM,aAAa,GAAG,CAAC,MAAqB,KAAI;IACrD,MAAM,OAAO,GAAgC,EAAE;AAE/C,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACtC,QAAA,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC;AACvB,QAAA,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE;AAC5B,YAAA,IAAI,KAAK,CAAC,IAAI,IAAI,OAAO,EAAE;AACzB,gBAAA,MAAA,IAAA,KAAA,CAAA,CAAA,qDAAO,EAAmC,KAAK,CAAC,IAAI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AAC,SAAS,EAAE,GAAG,CAAC;IACzB,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC;AACnD,IAAA,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACjD,IAAI,WAAW,EAAE;AACf,QAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC;IAC5B;AAEA,IAAA,OAAO,QAAQ;AACjB;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/core/kt-router.ts","../src/core/index.ts","../src/core/matcher.ts"],"sourcesContent":["import type { JSX } from '@ktjs/core/jsx-runtime';\nimport type { Router } from '../types/router.js';\n\n/**\n * Create a router view container that automatically renders route components\n */\nexport function KTRouter({ router }: { router: Router }): JSX.Element {\n const view = document.createElement('kt-router-view');\n router.setRouterView(view);\n return view as JSX.Element;\n}\n","import { $emptyFn, buildQuery, normalizePath, parseQuery, emplaceParams } from '@ktjs/shared';\n\nimport type { Router, RouterConfig, RouteContext, NavOptions, RawRouteConfig, RouteConfig } from '../types/router.js';\nimport { GuardLevel } from './consts.js';\nimport { createMatcher } from './matcher.js';\n\n/**\n * Create a new router instance\n */\nexport const createRouter = ({\n beforeEach = $emptyFn,\n afterEach = $emptyFn,\n onNotFound = $emptyFn,\n onError = $emptyFn,\n prefix = '',\n routes: rawRoutes,\n}: RouterConfig): Router => {\n // # private values\n const routes: RouteConfig[] = [];\n const history: RouteContext[] = [];\n let routerView: HTMLElement | null = null;\n let current: RouteContext | null = null;\n\n // # methods\n const normalize = (rawRoutes: RawRouteConfig[], parentPath: string): RouteConfig[] =>\n rawRoutes.map((route) => {\n const path = normalizePath(parentPath, route.path);\n const normalized = {\n path: prefix + path,\n name: route.name ?? '',\n meta: route.meta ?? {},\n beforeEnter: route.beforeEnter ?? $emptyFn,\n after: route.after ?? $emptyFn,\n children: route.children ? normalize(route.children, path) : [],\n component: route.component,\n };\n\n // directly push the normalized route to the list\n // avoid flatten them again\n routes.push(normalized);\n return normalized;\n });\n\n const guard = async (\n to: RouteContext,\n from: RouteContext | null,\n guardLevel: GuardLevel,\n ): Promise<{ continue: boolean; redirectTo?: NavOptions }> => {\n try {\n if (guardLevel === GuardLevel.None) {\n return { continue: true };\n }\n\n if (guardLevel & GuardLevel.Global) {\n const result = await beforeEach(to, from);\n if (result === false) {\n return { continue: false };\n }\n if (typeof result === 'string') {\n return { continue: false, redirectTo: { path: result } };\n }\n if (result && typeof result === 'object') {\n return { continue: false, redirectTo: result };\n }\n }\n\n if (guardLevel & GuardLevel.Route) {\n const targetRoute = to.matched[to.matched.length - 1];\n const result = await targetRoute.beforeEnter(to);\n if (result === false) {\n return { continue: false };\n }\n if (typeof result === 'string') {\n return { continue: false, redirectTo: { path: result } };\n }\n if (result && typeof result === 'object') {\n return { continue: false, redirectTo: result };\n }\n }\n\n return { continue: true };\n } catch (error) {\n onError(error as Error);\n return { continue: false };\n }\n };\n\n const navigatePrepare = (options: NavOptions) => {\n // Resolve target route\n let targetPath: string;\n let targetRoute;\n\n if (options.name) {\n targetRoute = findByName(options.name);\n if (!targetRoute) {\n $throw(`Route not found: ${options.name}`);\n }\n targetPath = targetRoute.path;\n } else if (options.path) {\n targetPath = normalizePath(options.path);\n targetRoute = match(targetPath)?.route;\n } else {\n $throw(`Either path or name must be provided`);\n }\n\n // Substitute params\n if (options.params) {\n targetPath = emplaceParams(targetPath, options.params);\n }\n\n // Match final path\n const matched = match(targetPath);\n if (!matched) {\n onNotFound(targetPath);\n return null;\n }\n\n // Build route context\n const queryString = options.query ? buildQuery(options.query) : '';\n const fullPath = targetPath + queryString;\n\n const to: RouteContext = {\n path: targetPath,\n name: matched.route.name,\n params: { ...matched.params, ...(options.params ?? {}) },\n query: options.query ?? {},\n meta: matched.route.meta ?? {},\n matched: matched.result,\n };\n\n return {\n guardLevel: options.guardLevel ?? GuardLevel.Default,\n replace: options.replace ?? false,\n to,\n fullPath,\n };\n };\n\n const navigate = async (options: NavOptions, redirectCount = 0): Promise<boolean> => {\n try {\n // Prevent infinite redirect loop\n if (redirectCount > 10) {\n onError(new Error('Maximum redirect count exceeded'));\n return false;\n }\n\n const prep = navigatePrepare(options);\n if (!prep) {\n return false;\n }\n\n const { guardLevel, replace, to, fullPath } = prep;\n\n const guardResult = await guard(to, current, guardLevel);\n if (!guardResult.continue) {\n // Check if there's a redirect\n if (guardResult.redirectTo) {\n return await navigate(guardResult.redirectTo, redirectCount + 1);\n }\n return false;\n }\n\n // ---- Guards passed ----\n\n const hashUrl = '#' + fullPath;\n if (replace) {\n window.location.replace(hashUrl);\n } else {\n window.location.hash = fullPath;\n }\n\n current = to;\n if (replace) {\n if (history.length > 0) {\n history[history.length - 1] = to;\n } else {\n history.push(to);\n }\n } else {\n history.push(to);\n }\n\n // Render component if routerView exists\n if (routerView && to.matched.length > 0) {\n const route = to.matched[to.matched.length - 1];\n if (route.component) {\n const element = await route.component();\n routerView.innerHTML = '';\n routerView.appendChild(element);\n }\n }\n\n executeAfterHooks(to, history[history.length - 2] ?? null);\n return true;\n } catch (error) {\n onError(error as Error);\n return false;\n }\n };\n\n const executeAfterHooks = async (to: RouteContext, from: RouteContext | null): Promise<void> => {\n const targetRoute = to.matched[to.matched.length - 1];\n await targetRoute.after(to);\n await afterEach(to, from);\n };\n\n /**\n * Normalize navigation argument\n */\n const normalizeLocation = (loc: string | NavOptions): NavOptions => {\n if (typeof loc !== 'string') {\n return loc;\n }\n\n const [path, queryString] = loc.split('?');\n return {\n path,\n query: queryString ? parseQuery(queryString) : undefined,\n };\n };\n\n // # register events\n window.addEventListener('hashchange', () => {\n const hash = window.location.hash.slice(1);\n const [path] = hash.split('?');\n const normalizedPath = normalizePath(path);\n if (current && current.path === normalizedPath) {\n return;\n }\n // render route for new hash without adding extra history entry\n const matched = match(normalizedPath);\n if (!matched) {\n onNotFound(normalizedPath);\n return;\n }\n const queryString = window.location.hash.slice(1).split('?')[1];\n const to: RouteContext = {\n path: normalizedPath,\n name: matched.route.name,\n params: matched.params,\n query: queryString ? parseQuery(queryString) : {},\n meta: matched.route.meta ?? {},\n matched: matched.result,\n };\n\n // apply without modifying browser history\n current = to;\n history.push(to);\n\n if (routerView && to.matched.length > 0) {\n const route = to.matched[to.matched.length - 1];\n if (route.component) {\n const element = route.component();\n if (element instanceof Promise) {\n element.then((el) => {\n routerView!.innerHTML = '';\n routerView!.appendChild(el);\n });\n } else {\n routerView.innerHTML = '';\n routerView.appendChild(element);\n }\n }\n }\n\n executeAfterHooks(to, history[history.length - 2] ?? null);\n });\n\n // # initialize\n const instance: Router = {\n get current() {\n return current;\n },\n\n get history() {\n return history.concat();\n },\n\n setRouterView(view: HTMLElement) {\n routerView = view;\n },\n\n push(location: string | NavOptions): boolean | Promise<boolean> {\n const options = normalizeLocation(location);\n return navigate(options);\n },\n\n silentPush(location: string | NavOptions): boolean | Promise<boolean> {\n const options = normalizeLocation(location);\n return navigate({ ...options, guardLevel: GuardLevel.Route });\n },\n\n replace(location: string | NavOptions): boolean | Promise<boolean> {\n const options = normalizeLocation(location);\n return navigate({ ...options, replace: true });\n },\n\n back() {\n window.history.back();\n },\n\n forward() {\n window.history.forward();\n },\n };\n normalize(rawRoutes, '/');\n const { findByName, match } = createMatcher(routes);\n const currentHash = window.location.hash.slice(1);\n if (currentHash) {\n instance.push(currentHash);\n }\n\n return instance;\n};\n\nexport { GuardLevel };\nexport { KTRouter } from './kt-router.js';\n","import type { RouteConfig, RouteMatch } from '../types/router.js';\nimport { extractParams, normalizePath } from '@ktjs/shared';\n\n/**\n * Route matcher for finding matching routes and extracting params\n */\nexport const createMatcher = (routes: RouteConfig[]) => {\n const nameMap: Record<string, RouteConfig> = {};\n\n for (let i = 0; i < routes.length; i++) {\n const route = routes[i];\n if (route.name !== undefined) {\n if (route.name in nameMap) {\n $throw(`Duplicate route name detected: '${route.name}'`);\n }\n nameMap[route.name] = route;\n }\n }\n\n /**\n * Find route by name\n */\n const findByName = (name: string): RouteConfig | null => {\n return nameMap[name] ?? null;\n };\n\n /**\n * Match path against all routes\n */\n const match = (path: string): RouteMatch | null => {\n const normalizedPath = normalizePath(path);\n\n // Try exact match first\n for (const route of routes) {\n if (route.path === normalizedPath) {\n return {\n route,\n params: {},\n result: getMatchedChain(route),\n };\n }\n }\n\n // Try dynamic routes\n for (const route of routes) {\n if (route.path.includes(':')) {\n const params = extractParams(route.path, normalizedPath);\n if (params) {\n return {\n route,\n params,\n result: getMatchedChain(route),\n };\n }\n }\n }\n\n return null;\n };\n\n /**\n * Get chain of matched routes (for nested routes)\n * - parent roots ahead\n */\n const getMatchedChain = (route: RouteConfig): RouteConfig[] => {\n const matched: RouteConfig[] = [route];\n const path = route.path;\n\n // Find parent routes by path prefix matching\n for (let i = 0; i < routes.length; i++) {\n const r = routes[i];\n if (r !== route && path.startsWith(r.path) && path !== r.path) {\n matched.push(r);\n }\n }\n\n return matched.reverse();\n };\n\n return {\n findByName,\n match,\n };\n};\n"],"names":["KTRouter","router","view","document","createElement","setRouterView","createRouter","beforeEach","$emptyFn","afterEach","onNotFound","onError","prefix","routes","rawRoutes","history","routerView","current","normalize","parentPath","map","route","path","normalizePath","normalized","name","meta","beforeEnter","after","children","component","push","navigate","async","options","redirectCount","Error","prep","targetPath","targetRoute","findByName","match","params","emplaceParams","matched","fullPath","query","buildQuery","to","result","guardLevel","replace","navigatePrepare","guardResult","from","continue","redirectTo","length","error","guard","hashUrl","window","location","hash","element","innerHTML","appendChild","executeAfterHooks","normalizeLocation","loc","queryString","split","parseQuery","undefined","addEventListener","slice","normalizedPath","Promise","then","el","instance","concat","silentPush","back","forward","nameMap","i","getMatchedChain","r","startsWith","reverse","includes","extractParams","createMatcher","currentHash"],"mappings":";;AAMM,SAAUA,UAASC,QAAEA;IACzB,MAAMC,OAAOC,SAASC,cAAc;IAEpC,OADAH,OAAOI,cAAcH,OACdA;AACT;;ACDO,MAAMI,eAAe,EAC1BC,yBAAaC,UACbC,uBAAYD,UACZE,yBAAaF,UACbG,m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