@lytjs/router 6.4.0 → 6.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,284 @@
1
+ import * as _lytjs_reactivity from '@lytjs/reactivity';
2
+ import { Signal } from '@lytjs/reactivity';
3
+
4
+ /**
5
+ * @lytjs/router - Core type definitions
6
+ */
7
+
8
+ type App = {
9
+ provide?: unknown;
10
+ config?: {
11
+ globalProperties?: Record<string, unknown>;
12
+ };
13
+ };
14
+ type Component = unknown;
15
+ type RouteRecordName = string | symbol;
16
+ type RouteParams = Record<string, string | string[]>;
17
+ type LocationQuery = Record<string, string | string[] | null>;
18
+ type RouteMeta = Record<string | number | symbol, unknown>;
19
+ interface RouteRecordRaw {
20
+ path: string;
21
+ name?: RouteRecordName;
22
+ component?: Component | (() => Promise<Component>);
23
+ children?: RouteRecordRaw[];
24
+ redirect?: string | RouteLocationRaw | ((to: RouteLocationNormalized) => RouteLocationRaw);
25
+ alias?: string | string[];
26
+ meta?: RouteMeta;
27
+ beforeEnter?: NavigationGuard;
28
+ props?: boolean | Record<string, unknown> | ((to: RouteLocationNormalized) => Record<string, unknown>);
29
+ }
30
+ interface RouteRecordNormalized {
31
+ path: string;
32
+ name: RouteRecordName | null;
33
+ meta: RouteMeta;
34
+ children: RouteRecordNormalized[];
35
+ aliasOf?: RouteRecordNormalized;
36
+ beforeEnter?: NavigationGuard | undefined;
37
+ props: boolean | Record<string, unknown> | ((to: RouteLocationNormalized) => Record<string, unknown>);
38
+ component?: Component | (() => Promise<Component>);
39
+ components?: Record<string, Component | (() => Promise<Component>)>;
40
+ }
41
+ interface RouteLocationNormalized {
42
+ name: RouteRecordName | null;
43
+ path: string;
44
+ fullPath: string;
45
+ query: LocationQuery;
46
+ hash: string;
47
+ params: RouteParams;
48
+ matched: RouteRecordNormalized[];
49
+ meta: RouteMeta;
50
+ redirectedFrom?: RouteLocationNormalized;
51
+ }
52
+ type RouteLocationRaw = string | {
53
+ path?: string;
54
+ name?: RouteRecordName | null;
55
+ params?: RouteParams;
56
+ query?: LocationQuery;
57
+ hash?: string;
58
+ };
59
+ interface NavigationGuardNext {
60
+ (): void;
61
+ (error: Error): void;
62
+ (location: RouteLocationRaw): void;
63
+ (valid: boolean): void;
64
+ }
65
+ type NavigationGuardReturn = void | Error | RouteLocationRaw | boolean | undefined;
66
+ type NavigationGuard = (to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) => NavigationGuardReturn;
67
+ interface NavigationFailure {
68
+ type: NavigationFailureType;
69
+ from: RouteLocationNormalized;
70
+ to: RouteLocationNormalized;
71
+ }
72
+ declare enum NavigationFailureType {
73
+ aborted = 1,
74
+ cancelled = 2,
75
+ duplicated = 4
76
+ }
77
+ type RouterScrollBehavior = (to: RouteLocationNormalized, from: RouteLocationNormalized, savedPosition: {
78
+ left: number;
79
+ top: number;
80
+ } | null) => {
81
+ left: number;
82
+ top: number;
83
+ } | void | false;
84
+ interface RouterOptions {
85
+ history: RouterHistory;
86
+ routes: RouteRecordRaw[];
87
+ scrollBehavior?: RouterScrollBehavior;
88
+ strict?: boolean;
89
+ }
90
+ interface Router {
91
+ readonly currentRoute: Signal<RouteLocationNormalized>;
92
+ readonly options: RouterOptions;
93
+ push(to: RouteLocationRaw): Promise<NavigationFailure | void>;
94
+ replace(to: RouteLocationRaw): Promise<NavigationFailure | void>;
95
+ go(delta: number): void;
96
+ back(): void;
97
+ forward(): void;
98
+ beforeEach(guard: NavigationGuard): () => void;
99
+ afterEach(hook: (to: RouteLocationNormalized, from: RouteLocationNormalized, failure?: NavigationFailure) => void): () => void;
100
+ beforeResolve(guard: NavigationGuard): () => void;
101
+ install(app: App): void;
102
+ isReady(): Promise<void>;
103
+ resolveName(name: string | symbol, params?: RouteParams): {
104
+ path: string;
105
+ } | null;
106
+ }
107
+ type HistoryState = Record<string, unknown>;
108
+ interface NavigationInfo {
109
+ type: 'push' | 'replace' | 'pop';
110
+ direction: 'back' | 'forward' | 'unknown';
111
+ delta: number;
112
+ }
113
+ interface RouterHistory {
114
+ readonly location: RouteLocationNormalized;
115
+ readonly state: HistoryState | null;
116
+ base: string;
117
+ push(to: RouteLocationRaw): Promise<NavigationFailure | void>;
118
+ replace(to: RouteLocationRaw): Promise<NavigationFailure | void>;
119
+ go(delta: number): void;
120
+ listen(callback: (to: RouteLocationNormalized, from: RouteLocationNormalized, info: NavigationInfo) => void): () => void;
121
+ destroy(): void;
122
+ }
123
+
124
+ /**
125
+ * @lytjs/router - createRouter implementation
126
+ *
127
+ * Core router with navigation, guard pipeline, and route matching.
128
+ */
129
+
130
+ /**
131
+ * Create a router instance
132
+ */
133
+ declare function createRouter(options: RouterOptions): Router;
134
+
135
+ /**
136
+ * @lytjs/router - History implementations
137
+ *
138
+ * Provides three history modes:
139
+ * - createWebHistory: HTML5 History API
140
+ * - createWebHashHistory: hash-based routing
141
+ * - createMemoryHistory: in-memory (SSR/testing)
142
+ */
143
+
144
+ /**
145
+ * Create a Web History implementation using the HTML5 History API
146
+ */
147
+ declare function createWebHistory(base?: string): RouterHistory;
148
+ /**
149
+ * Create a Hash History implementation using hashchange events
150
+ */
151
+ declare function createWebHashHistory(base?: string): RouterHistory;
152
+ /**
153
+ * Create an in-memory history implementation for SSR and testing
154
+ */
155
+ declare function createMemoryHistory(initial?: string): RouterHistory;
156
+
157
+ /**
158
+ * @lytjs/router - useRouter composable
159
+ */
160
+
161
+ /**
162
+ * Set the active router instance (called during install)
163
+ */
164
+ declare function setCurrentRouter(router: Router): void;
165
+ /**
166
+ * Get the current router instance
167
+ */
168
+ declare function useRouter(): Router;
169
+
170
+ /**
171
+ * @lytjs/router - useRoute composable
172
+ */
173
+
174
+ /**
175
+ * Get the current route location (reactive)
176
+ * Returns a Signal that can be called to get the current route value
177
+ */
178
+ declare function useRoute(): Signal<RouteLocationNormalized>;
179
+
180
+ interface UseLinkOptions {
181
+ to: RouteLocationRaw;
182
+ replace?: boolean;
183
+ activeClass?: string;
184
+ exactActiveClass?: string;
185
+ }
186
+ declare function useLink(options: UseLinkOptions): {
187
+ route: _lytjs_reactivity.ComputedSignal<{
188
+ path: string;
189
+ query: LocationQuery;
190
+ hash: string;
191
+ params?: RouteParams;
192
+ }>;
193
+ href: _lytjs_reactivity.ComputedSignal<string>;
194
+ isActive: _lytjs_reactivity.ComputedSignal<boolean>;
195
+ isExactActive: _lytjs_reactivity.ComputedSignal<boolean>;
196
+ navigate: (e?: MouseEvent) => void;
197
+ };
198
+
199
+ /**
200
+ * @lytjs/router - RouterView component
201
+ *
202
+ * Renders the matched component for the current route.
203
+ * Supports nested routes by rendering child RouterView.
204
+ */
205
+
206
+ interface RouterViewProps {
207
+ name?: string;
208
+ route?: RouteLocationNormalized;
209
+ }
210
+ /**
211
+ * RouterView component
212
+ * Renders the matched component for the current route.
213
+ * Supports named views via the `name` prop and props passing from route records.
214
+ */
215
+ declare const RouterView: {
216
+ name: string;
217
+ props: {
218
+ name: {
219
+ type: StringConstructor;
220
+ default: string;
221
+ };
222
+ };
223
+ setup(props: RouterViewProps): () => any;
224
+ };
225
+
226
+ /**
227
+ * @lytjs/router - RouterLink component
228
+ *
229
+ * Renders an anchor tag that navigates to the target route.
230
+ */
231
+ interface RouterLinkProps {
232
+ to: string;
233
+ replace?: boolean;
234
+ activeClass?: string;
235
+ exactActiveClass?: string;
236
+ ariaCurrentValue?: string;
237
+ }
238
+ /**
239
+ * RouterLink component
240
+ * Renders an anchor tag that navigates to the target route.
241
+ * Supports active state detection and aria-current attribute.
242
+ */
243
+ declare const RouterLink: {
244
+ name: string;
245
+ props: {
246
+ to: {
247
+ type: StringConstructor;
248
+ required: boolean;
249
+ };
250
+ replace: {
251
+ type: BooleanConstructor;
252
+ default: boolean;
253
+ };
254
+ activeClass: {
255
+ type: StringConstructor;
256
+ default: string;
257
+ };
258
+ exactActiveClass: {
259
+ type: StringConstructor;
260
+ default: string;
261
+ };
262
+ ariaCurrentValue: {
263
+ type: StringConstructor;
264
+ default: string;
265
+ };
266
+ };
267
+ setup(props: RouterLinkProps, { slots, }: {
268
+ slots?: {
269
+ default?: (props?: unknown) => unknown;
270
+ [key: string]: ((props?: unknown) => unknown) | undefined;
271
+ };
272
+ }): () => {
273
+ tag: string;
274
+ props: {
275
+ href: string;
276
+ class: string;
277
+ 'aria-current': string | undefined;
278
+ onClick: (event: MouseEvent) => void;
279
+ };
280
+ children: unknown;
281
+ };
282
+ };
283
+
284
+ export { type LocationQuery, type NavigationFailure, NavigationFailureType, type NavigationGuard, type NavigationGuardNext, type NavigationGuardReturn, type NavigationInfo, type RouteLocationNormalized, type RouteLocationRaw, type RouteMeta, type RouteParams, type RouteRecordName, type RouteRecordNormalized, type RouteRecordRaw, type Router, type RouterHistory, RouterLink, type RouterLinkProps, type RouterOptions, type RouterScrollBehavior, RouterView, type RouterViewProps, type UseLinkOptions, createMemoryHistory, createRouter, createWebHashHistory, createWebHistory, setCurrentRouter, useLink, useRoute, useRouter };