@sigx/router 0.1.6

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 ADDED
@@ -0,0 +1,682 @@
1
+ import { component, defineInjectable, defineProvide, getCurrentInstance, signal } from "sigx";
2
+ import { jsx } from "sigx/jsx-runtime";
3
+ function parseSegments(path) {
4
+ return path.replace(/^\/|\/$/g, "").split("/").filter(Boolean).map((part) => {
5
+ if (part.startsWith(":")) {
6
+ const isOptional = part.endsWith("?");
7
+ return {
8
+ isParam: true,
9
+ isWildcard: false,
10
+ value: isOptional ? part.slice(1, -1) : part.slice(1),
11
+ isOptional
12
+ };
13
+ }
14
+ if (part.startsWith("*")) return {
15
+ isParam: false,
16
+ isWildcard: true,
17
+ value: part.slice(1) || "pathMatch",
18
+ isOptional: false
19
+ };
20
+ return {
21
+ isParam: false,
22
+ isWildcard: false,
23
+ value: part,
24
+ isOptional: false
25
+ };
26
+ });
27
+ }
28
+ function calculateScore(segments) {
29
+ let score = 0;
30
+ for (const segment of segments) if (segment.isWildcard) score += 1;
31
+ else if (segment.isParam) score += segment.isOptional ? 2 : 3;
32
+ else score += 4;
33
+ return score;
34
+ }
35
+ function buildRegex(segments) {
36
+ const parts = segments.map((segment) => {
37
+ if (segment.isWildcard) return "(?:\\/(.*))?";
38
+ if (segment.isParam) return segment.isOptional ? "(?:\\/([^\\/]+))?" : "\\/([^\\/]+)";
39
+ return `\\/${escapeRegex(segment.value)}`;
40
+ });
41
+ return new RegExp(`^${parts.join("")}\\/?$`);
42
+ }
43
+ function escapeRegex(str) {
44
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
45
+ }
46
+ function compileRoute(record, parent = null) {
47
+ const segments = parseSegments(record.path);
48
+ return {
49
+ record,
50
+ segments,
51
+ regex: buildRegex(segments),
52
+ paramNames: segments.filter((s) => s.isParam || s.isWildcard).map((s) => s.value),
53
+ score: calculateScore(segments),
54
+ parent
55
+ };
56
+ }
57
+ function compileRoutes(routes, parentPath = "", parentRoute = null) {
58
+ const compiled = [];
59
+ for (const route of routes) {
60
+ const fullPath = joinPaths(parentPath, route.path);
61
+ const compiledRoute = compileRoute({
62
+ ...route,
63
+ path: fullPath
64
+ }, parentRoute);
65
+ compiled.push(compiledRoute);
66
+ if (route.children) compiled.push(...compileRoutes(route.children, fullPath, compiledRoute));
67
+ }
68
+ compiled.sort((a, b) => b.score - a.score);
69
+ return compiled;
70
+ }
71
+ function joinPaths(parent, child) {
72
+ if (!parent) return child;
73
+ if (child.startsWith("/")) return child;
74
+ return (parent.endsWith("/") ? parent.slice(0, -1) : parent) + (child.startsWith("/") ? child : "/" + child);
75
+ }
76
+ function matchRoute(path, compiledRoutes) {
77
+ const [pathOnly] = path.split(/[?#]/);
78
+ for (const compiled of compiledRoutes) {
79
+ const match = compiled.regex.exec(pathOnly);
80
+ if (match) {
81
+ const params = {};
82
+ compiled.paramNames.forEach((name, index) => {
83
+ const value = match[index + 1];
84
+ if (value !== void 0) params[name] = decodeURIComponent(value);
85
+ });
86
+ return {
87
+ route: compiled,
88
+ params
89
+ };
90
+ }
91
+ }
92
+ return null;
93
+ }
94
+ function parseQuery(queryString) {
95
+ const query = {};
96
+ if (!queryString || queryString === "?") return query;
97
+ const qs = queryString.startsWith("?") ? queryString.slice(1) : queryString;
98
+ for (const pair of qs.split("&")) {
99
+ if (!pair) continue;
100
+ const [key, value] = pair.split("=");
101
+ const decodedKey = decodeURIComponent(key);
102
+ const decodedValue = value !== void 0 ? decodeURIComponent(value) : "";
103
+ const existing = query[decodedKey];
104
+ if (existing !== void 0) if (Array.isArray(existing)) existing.push(decodedValue);
105
+ else query[decodedKey] = [existing, decodedValue];
106
+ else query[decodedKey] = decodedValue;
107
+ }
108
+ return query;
109
+ }
110
+ function stringifyQuery(query) {
111
+ const parts = [];
112
+ for (const key in query) {
113
+ const value = query[key];
114
+ if (value === void 0) continue;
115
+ if (Array.isArray(value)) for (const v of value) parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(v)}`);
116
+ else parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
117
+ }
118
+ return parts.length ? "?" + parts.join("&") : "";
119
+ }
120
+ function parseURL(url) {
121
+ let path = url;
122
+ let queryString = "";
123
+ let hash = "";
124
+ const hashIndex = path.indexOf("#");
125
+ if (hashIndex !== -1) {
126
+ hash = path.slice(hashIndex);
127
+ path = path.slice(0, hashIndex);
128
+ }
129
+ const queryIndex = path.indexOf("?");
130
+ if (queryIndex !== -1) {
131
+ queryString = path.slice(queryIndex);
132
+ path = path.slice(0, queryIndex);
133
+ }
134
+ return {
135
+ path: path || "/",
136
+ query: parseQuery(queryString),
137
+ hash
138
+ };
139
+ }
140
+ function buildPath(path, query, hash) {
141
+ let result = path;
142
+ if (query && Object.keys(query).length > 0) result += stringifyQuery(query);
143
+ if (hash) result += hash.startsWith("#") ? hash : "#" + hash;
144
+ return result;
145
+ }
146
+ function createRouteLocation(fullPath, matched, params) {
147
+ const { path, query, hash } = parseURL(fullPath);
148
+ const matchedRecords = [];
149
+ if (matched) {
150
+ let current = matched;
151
+ const routeChain = [];
152
+ while (current) {
153
+ routeChain.unshift(current);
154
+ current = current.parent;
155
+ }
156
+ for (const route of routeChain) matchedRecords.push({
157
+ path: route.record.path,
158
+ name: route.record.name,
159
+ component: route.record.component,
160
+ meta: route.record.meta || {},
161
+ props: route.record.props
162
+ });
163
+ }
164
+ return {
165
+ fullPath,
166
+ path,
167
+ name: matched?.record.name,
168
+ params,
169
+ query,
170
+ hash,
171
+ matched: matchedRecords,
172
+ meta: matched?.record.meta || {}
173
+ };
174
+ }
175
+ const useRouter = defineInjectable(() => {
176
+ throw new Error("useRouter() is called but no router is installed. Make sure to install the router with app.use(router).");
177
+ });
178
+ const useRoute = defineInjectable(() => {
179
+ throw new Error("useRoute() is called but no router is installed. Make sure to install the router with app.use(router).");
180
+ });
181
+ function createRouter(options) {
182
+ const { history, routes } = options;
183
+ options.base;
184
+ let compiledRoutes = compileRoutes(routes);
185
+ const routeRecords = [...routes];
186
+ const beforeGuards = [];
187
+ const beforeResolveGuards = [];
188
+ const afterHooks = [];
189
+ let readyPromise = null;
190
+ let readyResolve = null;
191
+ const initialLocation = history.location;
192
+ const initialMatch = matchRoute(initialLocation, compiledRoutes);
193
+ const currentRouteState = signal(createRouteLocation(initialLocation, initialMatch?.route || null, initialMatch?.params || {}));
194
+ function resolve(to) {
195
+ if (typeof to === "string") {
196
+ const match = matchRoute(to, compiledRoutes);
197
+ return createRouteLocation(to, match?.route || null, match?.params || {});
198
+ }
199
+ const { path, name, params = {}, query = {}, hash = "" } = to;
200
+ if (name) {
201
+ const route = compiledRoutes.find((r) => r.record.name === name);
202
+ if (!route) {
203
+ console.warn(`Route with name "${name}" not found`);
204
+ return createRouteLocation("/", null, {});
205
+ }
206
+ return createRouteLocation(buildPath(buildPathFromParams(route.record.path, params), query, hash), route, params);
207
+ }
208
+ if (path) {
209
+ const fullPath = buildPath(path, query, hash);
210
+ const match = matchRoute(path, compiledRoutes);
211
+ return createRouteLocation(fullPath, match?.route || null, match?.params || {});
212
+ }
213
+ return getCurrentRoute();
214
+ }
215
+ function buildPathFromParams(pattern, params) {
216
+ let path = pattern;
217
+ for (const key in params) path = path.replace(`:${key}`, encodeURIComponent(params[key]));
218
+ path = path.replace(/\/:[^/]+\?/g, "");
219
+ return path;
220
+ }
221
+ function getCurrentRoute() {
222
+ const state = currentRouteState;
223
+ return {
224
+ fullPath: state.fullPath,
225
+ path: state.path,
226
+ name: state.name,
227
+ params: state.params,
228
+ query: state.query,
229
+ hash: state.hash,
230
+ matched: state.matched,
231
+ meta: state.meta,
232
+ redirectedFrom: state.redirectedFrom
233
+ };
234
+ }
235
+ async function runGuards(to, from, guards) {
236
+ for (const guard of guards) {
237
+ const result = await guard(to, from);
238
+ if (result === false) return false;
239
+ if (typeof result === "string") return resolve(result);
240
+ if (result && typeof result === "object") return resolve(result);
241
+ }
242
+ return true;
243
+ }
244
+ function finalizeNavigation(to, from) {
245
+ currentRouteState.$set(to);
246
+ for (const hook of afterHooks) hook(to, from);
247
+ }
248
+ async function navigate(to, replace = false) {
249
+ const from = getCurrentRoute();
250
+ const resolved = resolve(to);
251
+ const matched = resolved.matched[resolved.matched.length - 1];
252
+ if (matched) {
253
+ const routeRecord = compiledRoutes.find((r) => r.record.path === matched.path)?.record;
254
+ if (routeRecord?.redirect) return navigate(typeof routeRecord.redirect === "function" ? routeRecord.redirect(resolved) : routeRecord.redirect, replace);
255
+ }
256
+ const beforeResult = await runGuards(resolved, from, beforeGuards);
257
+ if (beforeResult === false) return;
258
+ if (beforeResult && typeof beforeResult === "object") return navigate(beforeResult, replace);
259
+ for (const record of resolved.matched) {
260
+ const routeRecord = compiledRoutes.find((r) => r.record.path === record.path)?.record;
261
+ if (routeRecord?.beforeEnter) {
262
+ const result = await runGuards(resolved, from, Array.isArray(routeRecord.beforeEnter) ? routeRecord.beforeEnter : [routeRecord.beforeEnter]);
263
+ if (result === false) return;
264
+ if (result && typeof result === "object") return navigate(result, replace);
265
+ }
266
+ }
267
+ const resolveResult = await runGuards(resolved, from, beforeResolveGuards);
268
+ if (resolveResult === false) return;
269
+ if (resolveResult && typeof resolveResult === "object") return navigate(resolveResult, replace);
270
+ if (replace) history.replace(resolved.fullPath);
271
+ else history.push(resolved.fullPath);
272
+ finalizeNavigation(resolved, from);
273
+ return resolved;
274
+ }
275
+ history.listen((to, from, state) => {
276
+ const match = matchRoute(to, compiledRoutes);
277
+ finalizeNavigation(createRouteLocation(to, match?.route || null, match?.params || {}), getCurrentRoute());
278
+ });
279
+ const router = {
280
+ get currentRoute() {
281
+ return getCurrentRoute();
282
+ },
283
+ get options() {
284
+ return options;
285
+ },
286
+ push(to) {
287
+ return navigate(to, false);
288
+ },
289
+ replace(to) {
290
+ return navigate(to, true);
291
+ },
292
+ back() {
293
+ history.go(-1);
294
+ },
295
+ forward() {
296
+ history.go(1);
297
+ },
298
+ go(delta) {
299
+ history.go(delta);
300
+ },
301
+ beforeEach(guard) {
302
+ beforeGuards.push(guard);
303
+ return () => {
304
+ const index = beforeGuards.indexOf(guard);
305
+ if (index !== -1) beforeGuards.splice(index, 1);
306
+ };
307
+ },
308
+ beforeResolve(guard) {
309
+ beforeResolveGuards.push(guard);
310
+ return () => {
311
+ const index = beforeResolveGuards.indexOf(guard);
312
+ if (index !== -1) beforeResolveGuards.splice(index, 1);
313
+ };
314
+ },
315
+ afterEach(hook) {
316
+ afterHooks.push(hook);
317
+ return () => {
318
+ const index = afterHooks.indexOf(hook);
319
+ if (index !== -1) afterHooks.splice(index, 1);
320
+ };
321
+ },
322
+ hasRoute(name) {
323
+ return routeRecords.some((r) => r.name === name);
324
+ },
325
+ getRoutes() {
326
+ return [...routeRecords];
327
+ },
328
+ addRoute(route, parentName) {
329
+ if (parentName) {
330
+ const parent = routeRecords.find((r) => r.name === parentName);
331
+ if (parent) {
332
+ parent.children = parent.children || [];
333
+ parent.children.push(route);
334
+ }
335
+ } else routeRecords.push(route);
336
+ compiledRoutes = compileRoutes(routeRecords);
337
+ const routeRef = route;
338
+ return () => {
339
+ if (routeRef.name) router.removeRoute(routeRef.name);
340
+ else {
341
+ const index = routeRecords.indexOf(routeRef);
342
+ if (index !== -1) {
343
+ routeRecords.splice(index, 1);
344
+ compiledRoutes = compileRoutes(routeRecords);
345
+ }
346
+ }
347
+ };
348
+ },
349
+ removeRoute(name) {
350
+ const index = routeRecords.findIndex((r) => r.name === name);
351
+ if (index !== -1) {
352
+ routeRecords.splice(index, 1);
353
+ compiledRoutes = compileRoutes(routeRecords);
354
+ }
355
+ },
356
+ resolve,
357
+ match(patterns) {
358
+ const route = getCurrentRoute();
359
+ const routeName = route.name;
360
+ if (routeName && routeName in patterns) {
361
+ const pattern = patterns[routeName];
362
+ if (typeof pattern === "function") return pattern(route.params);
363
+ return pattern;
364
+ }
365
+ if ("_" in patterns) {
366
+ const fallback = patterns._;
367
+ if (typeof fallback === "function") return fallback(route.params);
368
+ return fallback;
369
+ }
370
+ },
371
+ install(app) {
372
+ app.defineProvide(useRouter, () => router);
373
+ app.defineProvide(useRoute, () => currentRouteState);
374
+ if (readyResolve) readyResolve();
375
+ },
376
+ isReady() {
377
+ if (!readyPromise) readyPromise = new Promise((resolve) => {
378
+ readyResolve = resolve;
379
+ });
380
+ return readyPromise;
381
+ }
382
+ };
383
+ return router;
384
+ }
385
+ function createWebHistory(options = {}) {
386
+ const base = normalizeBase(options.base);
387
+ const listeners = /* @__PURE__ */ new Set();
388
+ let currentLocation = getCurrentLocation(base);
389
+ let currentState = typeof window !== "undefined" ? window.history.state : null;
390
+ const handlePopState = (event) => {
391
+ const from = currentLocation;
392
+ currentLocation = getCurrentLocation(base);
393
+ currentState = event.state;
394
+ listeners.forEach((callback) => {
395
+ callback(currentLocation, from, currentState);
396
+ });
397
+ };
398
+ if (typeof window !== "undefined") window.addEventListener("popstate", handlePopState);
399
+ return {
400
+ get location() {
401
+ return currentLocation;
402
+ },
403
+ get state() {
404
+ return currentState;
405
+ },
406
+ get base() {
407
+ return base;
408
+ },
409
+ push(to, state) {
410
+ const from = currentLocation;
411
+ const fullPath = base === "/" ? to : base + to;
412
+ const historyState = {
413
+ ...state,
414
+ path: to,
415
+ position: (currentState?.position ?? 0) + 1
416
+ };
417
+ if (typeof window !== "undefined") window.history.pushState(historyState, "", fullPath);
418
+ currentLocation = to;
419
+ currentState = historyState;
420
+ listeners.forEach((callback) => {
421
+ callback(to, from, historyState);
422
+ });
423
+ },
424
+ replace(to, state) {
425
+ const from = currentLocation;
426
+ const fullPath = base === "/" ? to : base + to;
427
+ const historyState = {
428
+ ...state,
429
+ path: to,
430
+ position: currentState?.position ?? 0
431
+ };
432
+ if (typeof window !== "undefined") window.history.replaceState(historyState, "", fullPath);
433
+ currentLocation = to;
434
+ currentState = historyState;
435
+ listeners.forEach((callback) => {
436
+ callback(to, from, historyState);
437
+ });
438
+ },
439
+ go(delta) {
440
+ if (typeof window !== "undefined") window.history.go(delta);
441
+ },
442
+ listen(callback) {
443
+ listeners.add(callback);
444
+ return () => {
445
+ listeners.delete(callback);
446
+ };
447
+ },
448
+ createHref(path) {
449
+ return base === "/" ? path : base + path;
450
+ },
451
+ destroy() {
452
+ if (typeof window !== "undefined") window.removeEventListener("popstate", handlePopState);
453
+ listeners.clear();
454
+ }
455
+ };
456
+ }
457
+ function normalizeBase(base) {
458
+ if (!base) {
459
+ if (typeof document !== "undefined") {
460
+ const baseTag = document.querySelector("base");
461
+ if (baseTag) base = baseTag.getAttribute("href") || "/";
462
+ }
463
+ base = base || "/";
464
+ }
465
+ if (!base.startsWith("/")) base = "/" + base;
466
+ if (base !== "/" && base.endsWith("/")) base = base.slice(0, -1);
467
+ return base;
468
+ }
469
+ function getCurrentLocation(base) {
470
+ if (typeof window === "undefined") return "/";
471
+ const { pathname, search, hash } = window.location;
472
+ let path = pathname;
473
+ if (base !== "/" && pathname.startsWith(base)) path = pathname.slice(base.length) || "/";
474
+ return path + search + hash;
475
+ }
476
+ function createMemoryHistory(options = {}) {
477
+ const base = options.base || "";
478
+ const initialLocation = options.initialLocation || "/";
479
+ const listeners = /* @__PURE__ */ new Set();
480
+ const entries = [{
481
+ location: initialLocation,
482
+ state: {
483
+ path: initialLocation,
484
+ position: 0
485
+ }
486
+ }];
487
+ let currentIndex = 0;
488
+ return {
489
+ get location() {
490
+ return entries[currentIndex].location;
491
+ },
492
+ get state() {
493
+ return entries[currentIndex].state;
494
+ },
495
+ get base() {
496
+ return base;
497
+ },
498
+ push(to, state) {
499
+ const from = entries[currentIndex].location;
500
+ const historyState = {
501
+ ...state,
502
+ path: to,
503
+ position: currentIndex + 1
504
+ };
505
+ entries.splice(currentIndex + 1);
506
+ entries.push({
507
+ location: to,
508
+ state: historyState
509
+ });
510
+ currentIndex = entries.length - 1;
511
+ listeners.forEach((callback) => {
512
+ callback(to, from, historyState);
513
+ });
514
+ },
515
+ replace(to, state) {
516
+ const from = entries[currentIndex].location;
517
+ const historyState = {
518
+ ...state,
519
+ path: to,
520
+ position: currentIndex
521
+ };
522
+ entries[currentIndex] = {
523
+ location: to,
524
+ state: historyState
525
+ };
526
+ listeners.forEach((callback) => {
527
+ callback(to, from, historyState);
528
+ });
529
+ },
530
+ go(delta) {
531
+ const newIndex = currentIndex + delta;
532
+ if (newIndex < 0 || newIndex >= entries.length) return;
533
+ const from = entries[currentIndex].location;
534
+ currentIndex = newIndex;
535
+ const to = entries[currentIndex].location;
536
+ const state = entries[currentIndex].state;
537
+ listeners.forEach((callback) => {
538
+ callback(to, from, state);
539
+ });
540
+ },
541
+ listen(callback) {
542
+ listeners.add(callback);
543
+ return () => {
544
+ listeners.delete(callback);
545
+ };
546
+ },
547
+ createHref(path) {
548
+ return base + path;
549
+ },
550
+ destroy() {
551
+ listeners.clear();
552
+ }
553
+ };
554
+ }
555
+ function useParams() {
556
+ return useRoute().params;
557
+ }
558
+ function useQuery() {
559
+ return useRoute().query;
560
+ }
561
+ function useNavigate() {
562
+ const router = useRouter();
563
+ return router.push.bind(router);
564
+ }
565
+ function onBeforeRouteLeave(guard) {
566
+ const ctx = getCurrentInstance();
567
+ if (!ctx) {
568
+ console.warn("onBeforeRouteLeave() is called outside of component setup");
569
+ return;
570
+ }
571
+ const unregister = useRouter().beforeEach((to, from) => {
572
+ if (!from) return;
573
+ const currentRoute = useRoute();
574
+ if (from.path !== currentRoute.path) return;
575
+ return new Promise((resolve) => {
576
+ guard(to, from, (result) => {
577
+ if (result === false) resolve(false);
578
+ else if (typeof result === "string") resolve(result);
579
+ else if (result && typeof result === "object") resolve(result);
580
+ else resolve();
581
+ });
582
+ });
583
+ });
584
+ ctx.onUnmounted(() => {
585
+ unregister();
586
+ });
587
+ }
588
+ function onBeforeRouteUpdate(guard) {
589
+ const ctx = getCurrentInstance();
590
+ if (!ctx) {
591
+ console.warn("onBeforeRouteUpdate() is called outside of component setup");
592
+ return;
593
+ }
594
+ const router = useRouter();
595
+ const currentRoute = useRoute();
596
+ const unregister = router.beforeEach((to, from) => {
597
+ if (to.path !== currentRoute.path) return;
598
+ return new Promise((resolve) => {
599
+ guard(to, from, (result) => {
600
+ if (result === false) resolve(false);
601
+ else if (typeof result === "string") resolve(result);
602
+ else if (result && typeof result === "object") resolve(result);
603
+ else resolve();
604
+ });
605
+ });
606
+ });
607
+ ctx.onUnmounted(() => {
608
+ unregister();
609
+ });
610
+ }
611
+ var useRouterViewDepth = defineInjectable(() => 0);
612
+ function isComponentFactory(component) {
613
+ return typeof component === "function" && "__setup" in component;
614
+ }
615
+ const RouterView = component((ctx) => {
616
+ const route = useRoute();
617
+ const depth = useRouterViewDepth();
618
+ defineProvide(useRouterViewDepth, () => depth + 1);
619
+ return () => {
620
+ const { name = "default", pageProps = {} } = ctx.props;
621
+ const matched = route.matched;
622
+ if (matched.length === 0 || depth >= matched.length) return null;
623
+ const match = matched[depth];
624
+ const Component = match.component;
625
+ if (!Component) return null;
626
+ if (!isComponentFactory(Component)) return null;
627
+ let componentProps = {};
628
+ if (match.props === true) componentProps = { ...route.params };
629
+ else if (typeof match.props === "function") componentProps = match.props(route);
630
+ else if (match.props && typeof match.props === "object") componentProps = { ...match.props };
631
+ if (pageProps && Object.keys(pageProps).length > 0) componentProps = {
632
+ ...componentProps,
633
+ ...pageProps
634
+ };
635
+ return /* @__PURE__ */ jsx(Component, { ...componentProps });
636
+ };
637
+ }, { name: "RouterView" });
638
+ const Link = component(({ props, slots, emit }) => {
639
+ const router = useRouter();
640
+ const currentRoute = useRoute();
641
+ const replace = () => props.replace ?? false;
642
+ const activeClass = () => props.activeClass ?? "router-link-active";
643
+ const exactActiveClass = () => props.exactActiveClass ?? "router-link-exact-active";
644
+ const ariaCurrentValue = () => props.ariaCurrentValue ?? "page";
645
+ const handleClick = (event) => {
646
+ emit("click", event);
647
+ if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.shiftKey || event.button !== 0) return;
648
+ event.preventDefault();
649
+ if (replace()) router.replace(props.to);
650
+ else router.push(props.to);
651
+ };
652
+ return () => {
653
+ const resolved = router.resolve(props.to);
654
+ const href = resolved.fullPath;
655
+ const isExactActive = currentRoute.path === resolved.path;
656
+ const isActive = currentRoute.path.startsWith(resolved.path);
657
+ const classes = [];
658
+ if (isActive && activeClass()) classes.push(activeClass());
659
+ if (isExactActive && exactActiveClass()) classes.push(exactActiveClass());
660
+ return /* @__PURE__ */ jsx("a", {
661
+ href,
662
+ onClick: handleClick,
663
+ class: classes.length > 0 ? classes.join(" ") : void 0,
664
+ "aria-current": isExactActive ? ariaCurrentValue() : void 0,
665
+ children: slots.default()
666
+ });
667
+ };
668
+ }, { name: "Link" });
669
+ const RouterLink = Link;
670
+ function createRouterPlugin(options) {
671
+ const router = createRouter(options);
672
+ return {
673
+ name: "@sigx/router",
674
+ router,
675
+ install(app) {
676
+ router.install(app);
677
+ }
678
+ };
679
+ }
680
+ export { Link, RouterLink, RouterView, buildPath, createMemoryHistory, createRouter, createRouterPlugin, createWebHistory, onBeforeRouteLeave, onBeforeRouteUpdate, parseQuery, parseURL, stringifyQuery, useNavigate, useParams, useQuery, useRoute, useRouter };
681
+
682
+ //# sourceMappingURL=index.js.map