@coherent.js/client 1.0.0-beta.3 → 1.0.0-beta.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.
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Coherent.js Client Router Types
3
+ * TypeScript definitions for the client-side routing system
4
+ *
5
+ * @version 1.0.0-beta.1
6
+ */
7
+
8
+ import type { CoherentComponent } from '@coherent.js/core';
9
+
10
+ // ============================================================================
11
+ // Route Types
12
+ // ============================================================================
13
+
14
+ /** Route transition configuration */
15
+ export interface RouteTransition {
16
+ enter: string;
17
+ leave: string;
18
+ duration: number;
19
+ }
20
+
21
+ /** Route configuration */
22
+ export interface RouteConfig {
23
+ /** Route path pattern */
24
+ path: string;
25
+ /** Component to render (can be async for code splitting) */
26
+ component: CoherentComponent | (() => Promise<CoherentComponent>);
27
+ /** Route metadata */
28
+ meta?: Record<string, any>;
29
+ /** Before enter guard */
30
+ beforeEnter?: (to: Route, from: Route | null) => boolean | Promise<boolean>;
31
+ /** Before leave guard */
32
+ beforeLeave?: (to: Route, from: Route) => boolean | Promise<boolean>;
33
+ /** Prefetch priority */
34
+ priority?: number;
35
+ /** Custom transition for this route */
36
+ transition?: RouteTransition;
37
+ }
38
+
39
+ /** Current route state */
40
+ export interface Route {
41
+ path: string;
42
+ component?: CoherentComponent;
43
+ meta?: Record<string, any>;
44
+ hash?: string;
45
+ query?: Record<string, string>;
46
+ }
47
+
48
+ // ============================================================================
49
+ // Router Configuration
50
+ // ============================================================================
51
+
52
+ /** Scroll behavior configuration */
53
+ export interface ScrollBehaviorConfig {
54
+ enabled?: boolean;
55
+ behavior?: ScrollBehavior;
56
+ position?: 'top' | 'saved';
57
+ delay?: number;
58
+ savePosition?: boolean;
59
+ custom?: (
60
+ to: Route,
61
+ from: Route | null,
62
+ savedPosition: { x: number; y: number } | null
63
+ ) => { x: number; y: number } | { el: Element };
64
+ }
65
+
66
+ /** Router configuration options */
67
+ export interface RouterConfig {
68
+ mode?: 'history' | 'hash';
69
+ base?: string;
70
+ prefetch?: {
71
+ enabled?: boolean;
72
+ strategy?: 'hover' | 'visible' | 'idle';
73
+ delay?: number;
74
+ maxConcurrent?: number;
75
+ priority?: {
76
+ critical?: number;
77
+ high?: number;
78
+ normal?: number;
79
+ low?: number;
80
+ };
81
+ };
82
+ transitions?: {
83
+ enabled?: boolean;
84
+ default?: RouteTransition;
85
+ routes?: Record<string, RouteTransition>;
86
+ onStart?: (from: string | null, to: string) => void;
87
+ onComplete?: (from: string | null, to: string) => void;
88
+ };
89
+ codeSplitting?: {
90
+ enabled?: boolean;
91
+ strategy?: 'route';
92
+ chunkNaming?: string;
93
+ preload?: string[];
94
+ onLoad?: (path: string, component: any, loadTime: number) => void;
95
+ };
96
+ scrollBehavior?: ScrollBehaviorConfig;
97
+ }
98
+
99
+ // ============================================================================
100
+ // Router Statistics
101
+ // ============================================================================
102
+
103
+ /** Router statistics */
104
+ export interface RouterStats {
105
+ navigations: number;
106
+ prefetches: number;
107
+ transitionsCompleted: number;
108
+ chunksLoaded: number;
109
+ scrollRestores: number;
110
+ routesRegistered: number;
111
+ prefetchQueueSize: number;
112
+ activePrefetches: number;
113
+ loadedChunks: number;
114
+ savedPositions: number;
115
+ historyLength: number;
116
+ }
117
+
118
+ // ============================================================================
119
+ // Router Interface
120
+ // ============================================================================
121
+
122
+ /** Router instance */
123
+ export interface Router {
124
+ /** Add a route to the router */
125
+ addRoute(path: string, config: RouteConfig): void;
126
+ /** Navigate to a path */
127
+ push(path: string, options?: Partial<Route>): Promise<boolean>;
128
+ /** Replace current route */
129
+ replace(path: string, options?: Partial<Route>): Promise<boolean>;
130
+ /** Go back in history */
131
+ back(): void;
132
+ /** Go forward in history */
133
+ forward(): void;
134
+ /** Prefetch a single route */
135
+ prefetchRoute(path: string, priority?: number): Promise<void>;
136
+ /** Prefetch multiple routes */
137
+ prefetchRoutes(paths: string[], priority?: number): void;
138
+ /** Setup prefetch strategy for an element */
139
+ setupPrefetchStrategy(element: HTMLElement, path: string): void;
140
+ /** Get route configuration by path */
141
+ getRoute(path: string): RouteConfig | undefined;
142
+ /** Get all registered routes */
143
+ getRoutes(): RouteConfig[];
144
+ /** Get current route */
145
+ getCurrentRoute(): Route | null;
146
+ /** Get router statistics */
147
+ getStats(): RouterStats;
148
+ /** Clear all caches */
149
+ clearCaches(): void;
150
+ /** Internal state (for testing) */
151
+ _state?: any;
152
+ }
153
+
154
+ // ============================================================================
155
+ // Exports
156
+ // ============================================================================
157
+
158
+ /**
159
+ * Create an enhanced router with advanced features
160
+ *
161
+ * @param options - Router configuration options
162
+ * @returns Router instance
163
+ */
164
+ export declare function createRouter(options?: RouterConfig): Router;
165
+
166
+ /** Default router instance */
167
+ export declare const router: Router;