@zenithbuild/router 0.6.5 → 0.6.7

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.
@@ -1,373 +0,0 @@
1
- /**
2
- * Navigation & Prefetch Runtime
3
- *
4
- * Phase 7: Prefetch compiled output, safe SPA navigation, route caching
5
- *
6
- * This runtime handles:
7
- * - Prefetching compiled HTML + JS for routes
8
- * - Caching prefetched routes
9
- * - Safe DOM mounting and hydration
10
- * - Browser history management
11
- * - Explicit data exposure for navigation
12
- */
13
- /**
14
- * Route cache - stores prefetched compiled output
15
- */
16
- const routeCache = new Map();
17
- /**
18
- * Current navigation state
19
- */
20
- let currentRoute = '';
21
- let navigationInProgress = false;
22
- /**
23
- * Prefetch a route's compiled output
24
- *
25
- * @param routePath - The route path to prefetch (e.g., "/dashboard")
26
- * @returns Promise that resolves when prefetch is complete
27
- */
28
- export async function prefetchRoute(routePath) {
29
- // Normalize route path
30
- const normalizedPath = routePath === '' ? '/' : routePath;
31
- // Check if already cached
32
- if (routeCache.has(normalizedPath)) {
33
- return Promise.resolve();
34
- }
35
- // In a real implementation, this would fetch from the build output
36
- // For Phase 7, we'll generate a placeholder that indicates the route needs to be built
37
- try {
38
- // Fetch compiled HTML + JS
39
- // In production, this would be:
40
- // const htmlResponse = await fetch(`${normalizedPath}.html`)
41
- // const jsResponse = await fetch(`${normalizedPath}.js`)
42
- // For now, return a placeholder that indicates prefetch structure
43
- const cacheEntry = {
44
- html: `<!-- Prefetched route: ${normalizedPath} -->`,
45
- js: `// Prefetched route runtime: ${normalizedPath}`,
46
- styles: [],
47
- routePath: normalizedPath,
48
- compiledAt: Date.now()
49
- };
50
- routeCache.set(normalizedPath, cacheEntry);
51
- }
52
- catch (error) {
53
- console.warn(`[Zenith] Failed to prefetch route ${normalizedPath}:`, error);
54
- throw error;
55
- }
56
- }
57
- /**
58
- * Get cached route entry
59
- */
60
- export function getCachedRoute(routePath) {
61
- const normalizedPath = routePath === '' ? '/' : routePath;
62
- return routeCache.get(normalizedPath) || null;
63
- }
64
- /**
65
- * Navigate to a route with explicit data
66
- *
67
- * @param routePath - The route path to navigate to
68
- * @param options - Navigation options with loaderData, props, stores
69
- */
70
- export async function navigate(routePath, options = {}) {
71
- if (navigationInProgress) {
72
- console.warn('[Zenith] Navigation already in progress, skipping');
73
- return;
74
- }
75
- navigationInProgress = true;
76
- try {
77
- const normalizedPath = routePath === '' ? '/' : routePath;
78
- // Check if route is cached, otherwise prefetch
79
- let cacheEntry = getCachedRoute(normalizedPath);
80
- if (!cacheEntry && options.prefetch !== false) {
81
- await prefetchRoute(normalizedPath);
82
- cacheEntry = getCachedRoute(normalizedPath);
83
- }
84
- if (!cacheEntry) {
85
- throw new Error(`Route ${normalizedPath} not found. Ensure the route is compiled.`);
86
- }
87
- // Cleanup previous route
88
- cleanupPreviousRoute();
89
- // Get router outlet
90
- const outlet = getRouterOutlet();
91
- if (!outlet) {
92
- throw new Error('Router outlet not found. Ensure <div id="zenith-outlet"></div> exists.');
93
- }
94
- // Mount compiled HTML
95
- outlet.innerHTML = cacheEntry.html;
96
- // Inject styles
97
- injectStyles(cacheEntry.styles);
98
- // Execute JS runtime (compiled expressions + hydration)
99
- await executeRouteRuntime(cacheEntry.js, {
100
- loaderData: options.loaderData || {},
101
- props: options.props || {},
102
- stores: options.stores || {}
103
- });
104
- // Update browser history
105
- if (typeof window !== 'undefined') {
106
- const url = normalizedPath + (window.location.search || '');
107
- if (options.replace) {
108
- window.history.replaceState({ route: normalizedPath }, '', url);
109
- }
110
- else {
111
- window.history.pushState({ route: normalizedPath }, '', url);
112
- }
113
- }
114
- currentRoute = normalizedPath;
115
- // Dispatch navigation event
116
- dispatchNavigationEvent(normalizedPath, options);
117
- }
118
- catch (error) {
119
- console.error('[Zenith] Navigation error:', error);
120
- throw error;
121
- }
122
- finally {
123
- navigationInProgress = false;
124
- }
125
- }
126
- /**
127
- * Cleanup previous route
128
- */
129
- function cleanupPreviousRoute() {
130
- if (typeof window === 'undefined')
131
- return;
132
- // Cleanup hydration runtime
133
- if (window.zenithCleanup) {
134
- ;
135
- window.zenithCleanup();
136
- }
137
- // Remove previous page styles
138
- document.querySelectorAll('style[data-zen-route-style]').forEach(style => {
139
- style.remove();
140
- });
141
- // Clear window state (if needed)
142
- // State is managed per-route, so we don't clear it here
143
- }
144
- /**
145
- * Get router outlet element
146
- */
147
- function getRouterOutlet() {
148
- if (typeof window === 'undefined')
149
- return null;
150
- return document.querySelector('#zenith-outlet') || document.querySelector('[data-zen-outlet]');
151
- }
152
- /**
153
- * Inject route styles
154
- */
155
- function injectStyles(styles) {
156
- if (typeof window === 'undefined')
157
- return;
158
- styles.forEach((styleContent, index) => {
159
- const style = document.createElement('style');
160
- style.setAttribute('data-zen-route-style', String(index));
161
- style.textContent = styleContent;
162
- document.head.appendChild(style);
163
- });
164
- }
165
- /**
166
- * Execute route runtime JS
167
- *
168
- * This executes the compiled JS bundle for the route, which includes:
169
- * - Expression wrappers
170
- * - Hydration runtime
171
- * - Event bindings
172
- */
173
- async function executeRouteRuntime(jsCode, data) {
174
- if (typeof window === 'undefined')
175
- return;
176
- try {
177
- // Execute the compiled JS (which registers expressions and hydration functions)
178
- // In a real implementation, this would use a script tag or eval (secure context)
179
- const script = document.createElement('script');
180
- script.textContent = jsCode;
181
- document.head.appendChild(script);
182
- document.head.removeChild(script);
183
- // After JS executes, call hydrate with explicit data
184
- if (window.zenithHydrate) {
185
- const state = window.__ZENITH_STATE__ || {};
186
- window.zenithHydrate(state, data.loaderData, data.props, data.stores, getRouterOutlet());
187
- }
188
- }
189
- catch (error) {
190
- console.error('[Zenith] Error executing route runtime:', error);
191
- throw error;
192
- }
193
- }
194
- /**
195
- * Dispatch navigation event
196
- */
197
- function dispatchNavigationEvent(routePath, options) {
198
- if (typeof window === 'undefined')
199
- return;
200
- const event = new CustomEvent('zenith:navigate', {
201
- detail: {
202
- route: routePath,
203
- loaderData: options.loaderData,
204
- props: options.props,
205
- stores: options.stores
206
- }
207
- });
208
- window.dispatchEvent(event);
209
- }
210
- /**
211
- * Handle browser back/forward navigation
212
- */
213
- export function setupHistoryHandling() {
214
- if (typeof window === 'undefined')
215
- return;
216
- window.addEventListener('popstate', (event) => {
217
- const state = event.state;
218
- const routePath = state?.route || window.location.pathname;
219
- // Navigate without pushing to history (browser already changed it)
220
- navigate(routePath, { replace: true, prefetch: false }).catch((error) => {
221
- console.error('[Zenith] History navigation error:', error);
222
- });
223
- });
224
- }
225
- /**
226
- * Generate navigation runtime code (to be included in bundle)
227
- */
228
- export function generateNavigationRuntime() {
229
- return `
230
- // Zenith Navigation Runtime (Phase 7)
231
- (function() {
232
- 'use strict';
233
-
234
- // Route cache
235
- const __zen_routeCache = new Map();
236
-
237
- // Current route state
238
- let __zen_currentRoute = '';
239
- let __zen_navigationInProgress = false;
240
-
241
- /**
242
- * Prefetch a route
243
- */
244
- async function prefetchRoute(routePath) {
245
- const normalizedPath = routePath === '' ? '/' : routePath;
246
-
247
- if (__zen_routeCache.has(normalizedPath)) {
248
- return Promise.resolve();
249
- }
250
-
251
- try {
252
- // Fetch compiled HTML + JS
253
- // This is a placeholder - in production, fetch from build output
254
- const cacheEntry = {
255
- html: '<!-- Prefetched: ' + normalizedPath + ' -->',
256
- js: '// Prefetched runtime: ' + normalizedPath,
257
- styles: [],
258
- routePath: normalizedPath,
259
- compiledAt: Date.now()
260
- };
261
-
262
- __zen_routeCache.set(normalizedPath, cacheEntry);
263
- } catch (error) {
264
- console.warn('[Zenith] Prefetch failed:', routePath, error);
265
- throw error;
266
- }
267
- }
268
-
269
- /**
270
- * Navigate to route with explicit data
271
- */
272
- async function navigate(routePath, options) {
273
- options = options || {};
274
-
275
- if (__zen_navigationInProgress) {
276
- console.warn('[Zenith] Navigation in progress');
277
- return;
278
- }
279
-
280
- __zen_navigationInProgress = true;
281
-
282
- try {
283
- const normalizedPath = routePath === '' ? '/' : routePath;
284
-
285
- // Get cached route or prefetch
286
- let cacheEntry = __zen_routeCache.get(normalizedPath);
287
- if (!cacheEntry && options.prefetch !== false) {
288
- await prefetchRoute(normalizedPath);
289
- cacheEntry = __zen_routeCache.get(normalizedPath);
290
- }
291
-
292
- if (!cacheEntry) {
293
- throw new Error('Route not found: ' + normalizedPath);
294
- }
295
-
296
- // Get outlet
297
- const outlet = document.querySelector('#zenith-outlet') || document.querySelector('[data-zen-outlet]');
298
- if (!outlet) {
299
- throw new Error('Router outlet not found');
300
- }
301
-
302
- // Mount HTML
303
- outlet.innerHTML = cacheEntry.html;
304
-
305
- // Execute runtime JS
306
- if (cacheEntry.js) {
307
- const script = document.createElement('script');
308
- script.textContent = cacheEntry.js;
309
- document.head.appendChild(script);
310
- document.head.removeChild(script);
311
- }
312
-
313
- // Hydrate with explicit data
314
- if (window.zenithHydrate) {
315
- const state = window.__ZENITH_STATE__ || {};
316
- window.zenithHydrate(
317
- state,
318
- options.loaderData || {},
319
- options.props || {},
320
- options.stores || {},
321
- outlet
322
- );
323
- }
324
-
325
- // Update history
326
- const url = normalizedPath + (window.location.search || '');
327
- if (options.replace) {
328
- window.history.replaceState({ route: normalizedPath }, '', url);
329
- } else {
330
- window.history.pushState({ route: normalizedPath }, '', url);
331
- }
332
-
333
- __zen_currentRoute = normalizedPath;
334
-
335
- // Dispatch event
336
- window.dispatchEvent(new CustomEvent('zenith:navigate', {
337
- detail: { route: normalizedPath, options: options }
338
- }));
339
- } catch (error) {
340
- console.error('[Zenith] Navigation error:', error);
341
- throw error;
342
- } finally {
343
- __zen_navigationInProgress = false;
344
- }
345
- }
346
-
347
- /**
348
- * Handle browser history
349
- */
350
- function setupHistoryHandling() {
351
- window.addEventListener('popstate', function(event) {
352
- const state = event.state;
353
- const routePath = state && state.route ? state.route : window.location.pathname;
354
-
355
- navigate(routePath, { replace: true, prefetch: false }).catch(function(error) {
356
- console.error('[Zenith] History navigation error:', error);
357
- });
358
- });
359
- }
360
-
361
- // Initialize history handling
362
- setupHistoryHandling();
363
-
364
- // Expose API
365
- if (typeof window !== 'undefined') {
366
- window.__zenith_navigate = navigate;
367
- window.__zenith_prefetch = prefetchRoute;
368
- window.navigate = navigate; // Global convenience
369
- }
370
- })();
371
- `;
372
- }
373
- //# sourceMappingURL=client-router.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client-router.js","sourceRoot":"","sources":["../../src/navigation/client-router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAwBH;;GAEG;AACH,MAAM,UAAU,GAAG,IAAI,GAAG,EAA2B,CAAA;AAErD;;GAEG;AACH,IAAI,YAAY,GAAW,EAAE,CAAA;AAC7B,IAAI,oBAAoB,GAAY,KAAK,CAAA;AAEzC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,SAAiB;IACjD,uBAAuB;IACvB,MAAM,cAAc,GAAG,SAAS,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAA;IAEzD,0BAA0B;IAC1B,IAAI,UAAU,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;QACjC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;IAC5B,CAAC;IAED,mEAAmE;IACnE,uFAAuF;IACvF,IAAI,CAAC;QACD,2BAA2B;QAC3B,gCAAgC;QAChC,6DAA6D;QAC7D,yDAAyD;QAEzD,kEAAkE;QAClE,MAAM,UAAU,GAAoB;YAChC,IAAI,EAAE,0BAA0B,cAAc,MAAM;YACpD,EAAE,EAAE,gCAAgC,cAAc,EAAE;YACpD,MAAM,EAAE,EAAE;YACV,SAAS,EAAE,cAAc;YACzB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;SACzB,CAAA;QAED,UAAU,CAAC,GAAG,CAAC,cAAc,EAAE,UAAU,CAAC,CAAA;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,qCAAqC,cAAc,GAAG,EAAE,KAAK,CAAC,CAAA;QAC3E,MAAM,KAAK,CAAA;IACf,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AC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACpE,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAA;QAC9D,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB;IACrC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8IV,CAAA;AACD,CAAC"}
@@ -1,30 +0,0 @@
1
- /**
2
- * Zenith Navigation System
3
- *
4
- * Provides SPA navigation utilities and the ZenLink API.
5
- *
6
- * @package @zenithbuild/router
7
- *
8
- * @example
9
- * ```ts
10
- * import { navigate, isActive, prefetch, zenLink } from '@zenithbuild/router/navigation'
11
- *
12
- * // Programmatic navigation
13
- * navigate('/about')
14
- *
15
- * // Check active state
16
- * if (isActive('/blog')) {
17
- * console.log('On blog section')
18
- * }
19
- *
20
- * // Prefetch for faster navigation
21
- * prefetch('/dashboard')
22
- *
23
- * // Create link programmatically
24
- * const link = zenLink({ href: '/contact', children: 'Contact' })
25
- * ```
26
- */
27
- export { zenNavigate, navigate, zenBack, back, zenForward, forward, zenGo, go, zenIsActive, isActive, zenPrefetch, prefetch, zenIsPrefetched, isPrefetched, setGlobalTransition, getGlobalTransition, createTransitionContext, zenGetRoute, getRoute, zenGetParam, getParam, zenGetQuery, getQuery, createZenLink, zenLink, isExternalUrl, shouldUseSPANavigation, normalizePath } from './zen-link';
28
- export * from './client-router';
29
- export type { ZenLinkProps, TransitionContext, TransitionHandler, NavigateOptions } from './zen-link';
30
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/navigation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,EAEH,WAAW,EACX,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,UAAU,EACV,OAAO,EACP,KAAK,EACL,EAAE,EAGF,WAAW,EACX,QAAQ,EAGR,WAAW,EACX,QAAQ,EACR,eAAe,EACf,YAAY,EAGZ,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EAGvB,WAAW,EACX,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,WAAW,EACX,QAAQ,EAGR,aAAa,EACb,OAAO,EAGP,aAAa,EACb,sBAAsB,EACtB,aAAa,EAChB,MAAM,YAAY,CAAA;AAEnB,cAAc,iBAAiB,CAAA;AAG/B,YAAY,EACR,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EAClB,MAAM,YAAY,CAAA"}
@@ -1,44 +0,0 @@
1
- /**
2
- * Zenith Navigation System
3
- *
4
- * Provides SPA navigation utilities and the ZenLink API.
5
- *
6
- * @package @zenithbuild/router
7
- *
8
- * @example
9
- * ```ts
10
- * import { navigate, isActive, prefetch, zenLink } from '@zenithbuild/router/navigation'
11
- *
12
- * // Programmatic navigation
13
- * navigate('/about')
14
- *
15
- * // Check active state
16
- * if (isActive('/blog')) {
17
- * console.log('On blog section')
18
- * }
19
- *
20
- * // Prefetch for faster navigation
21
- * prefetch('/dashboard')
22
- *
23
- * // Create link programmatically
24
- * const link = zenLink({ href: '/contact', children: 'Contact' })
25
- * ```
26
- */
27
- // Export all navigation utilities
28
- export {
29
- // Navigation API
30
- zenNavigate, navigate, zenBack, back, zenForward, forward, zenGo, go,
31
- // Active state
32
- zenIsActive, isActive,
33
- // Prefetching
34
- zenPrefetch, prefetch, zenIsPrefetched, isPrefetched,
35
- // Transitions API
36
- setGlobalTransition, getGlobalTransition, createTransitionContext,
37
- // Route state
38
- zenGetRoute, getRoute, zenGetParam, getParam, zenGetQuery, getQuery,
39
- // ZenLink factory
40
- createZenLink, zenLink,
41
- // Utilities
42
- isExternalUrl, shouldUseSPANavigation, normalizePath } from './zen-link';
43
- export * from './client-router';
44
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/navigation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,kCAAkC;AAClC,OAAO;AACH,iBAAiB;AACjB,WAAW,EACX,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,UAAU,EACV,OAAO,EACP,KAAK,EACL,EAAE;AAEF,eAAe;AACf,WAAW,EACX,QAAQ;AAER,cAAc;AACd,WAAW,EACX,QAAQ,EACR,eAAe,EACf,YAAY;AAEZ,kBAAkB;AAClB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB;AAEvB,cAAc;AACd,WAAW,EACX,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,WAAW,EACX,QAAQ;AAER,kBAAkB;AAClB,aAAa,EACb,OAAO;AAEP,YAAY;AACZ,aAAa,EACb,sBAAsB,EACtB,aAAa,EAChB,MAAM,YAAY,CAAA;AAEnB,cAAc,iBAAiB,CAAA"}
@@ -1,234 +0,0 @@
1
- /**
2
- * ZenLink Runtime Module
3
- *
4
- * Provides programmatic navigation and ZenLink utilities.
5
- * This module can be imported in `.zen` files or TypeScript.
6
- *
7
- * @package @zenithbuild/router
8
- *
9
- * @example
10
- * ```ts
11
- * import { navigate, zenLink, isActive } from '@zenithbuild/router'
12
- *
13
- * // Programmatic navigation
14
- * navigate('/about')
15
- *
16
- * // Check active state
17
- * if (isActive('/blog')) {
18
- * console.log('On blog section')
19
- * }
20
- * ```
21
- */
22
- /**
23
- * Props for ZenLink component
24
- */
25
- export interface ZenLinkProps {
26
- /** Target URL path */
27
- href: string;
28
- /** Optional CSS class(es) */
29
- class?: string;
30
- /** Link target (_blank, _self, etc.) */
31
- target?: '_blank' | '_self' | '_parent' | '_top';
32
- /** Click handler (called before navigation) */
33
- onClick?: (event: MouseEvent) => void | boolean;
34
- /** Preload the linked page on hover */
35
- preload?: boolean;
36
- /** Future: Transition configuration */
37
- onTransition?: TransitionHandler;
38
- /** Future: Disable page transition animation */
39
- noTransition?: boolean;
40
- /** Match exact path for active state */
41
- exact?: boolean;
42
- /** Additional aria attributes */
43
- ariaLabel?: string;
44
- /** Replace history instead of push */
45
- replace?: boolean;
46
- /** Link content (children) */
47
- children?: string | HTMLElement | HTMLElement[];
48
- }
49
- /**
50
- * Transition context for Transitions API
51
- */
52
- export interface TransitionContext {
53
- /** Current page element */
54
- currentPage: HTMLElement | null;
55
- /** Next page element (after load) */
56
- nextPage: HTMLElement | null;
57
- /** Between/loading page element */
58
- betweenPage: HTMLElement | null;
59
- /** Navigation direction */
60
- direction: 'forward' | 'back';
61
- /** Origin path */
62
- fromPath: string;
63
- /** Destination path */
64
- toPath: string;
65
- /** Route params */
66
- params: Record<string, string>;
67
- /** Query params */
68
- query: Record<string, string>;
69
- }
70
- /**
71
- * Transition handler function
72
- */
73
- export type TransitionHandler = (context: TransitionContext) => void | Promise<void>;
74
- /**
75
- * Navigation options
76
- */
77
- export interface NavigateOptions {
78
- /** Replace current history entry instead of pushing */
79
- replace?: boolean;
80
- /** Scroll to top after navigation */
81
- scrollToTop?: boolean;
82
- /** Transition handler for this navigation */
83
- onTransition?: TransitionHandler;
84
- /** Skip transition animation */
85
- noTransition?: boolean;
86
- /** State to pass to the next page */
87
- state?: Record<string, unknown>;
88
- }
89
- /**
90
- * Check if URL is external (different origin)
91
- */
92
- export declare function isExternalUrl(url: string): boolean;
93
- /**
94
- * Check if link should use SPA navigation
95
- */
96
- export declare function shouldUseSPANavigation(href: string, target?: string): boolean;
97
- /**
98
- * Normalize a path
99
- */
100
- export declare function normalizePath(path: string): string;
101
- /**
102
- * Navigate to a new URL (SPA navigation)
103
- *
104
- * This is the primary API for programmatic navigation.
105
- *
106
- * @example
107
- * ```ts
108
- * // Simple navigation
109
- * navigate('/about')
110
- *
111
- * // With options
112
- * navigate('/dashboard', { replace: true })
113
- *
114
- * // With transition
115
- * navigate('/gallery', {
116
- * onTransition: async (ctx) => {
117
- * await animateOut(ctx.currentPage)
118
- * await animateIn(ctx.nextPage)
119
- * }
120
- * })
121
- * ```
122
- */
123
- export declare function zenNavigate(to: string, options?: NavigateOptions): Promise<void>;
124
- export declare const navigate: typeof zenNavigate;
125
- /**
126
- * Navigate back in history
127
- */
128
- export declare function zenBack(): void;
129
- export declare const back: typeof zenBack;
130
- /**
131
- * Navigate forward in history
132
- */
133
- export declare function zenForward(): void;
134
- export declare const forward: typeof zenForward;
135
- /**
136
- * Navigate to a specific history index
137
- */
138
- export declare function zenGo(delta: number): void;
139
- export declare const go: typeof zenGo;
140
- /**
141
- * Check if a path is currently active
142
- *
143
- * @example
144
- * ```ts
145
- * // Check if on blog section
146
- * if (isActive('/blog')) {
147
- * addClass(link, 'active')
148
- * }
149
- *
150
- * // Exact match only
151
- * if (isActive('/blog', true)) {
152
- * addClass(link, 'active-exact')
153
- * }
154
- * ```
155
- */
156
- export declare function zenIsActive(path: string, exact?: boolean): boolean;
157
- export declare const isActive: typeof zenIsActive;
158
- /**
159
- * Prefetch a route for faster navigation
160
- *
161
- * @example
162
- * ```ts
163
- * // Prefetch on hover
164
- * element.addEventListener('mouseenter', () => {
165
- * prefetch('/about')
166
- * })
167
- * ```
168
- */
169
- export declare function zenPrefetch(path: string): Promise<void>;
170
- export declare const prefetch: typeof zenPrefetch;
171
- /**
172
- * Check if a route has been prefetched
173
- */
174
- export declare function zenIsPrefetched(path: string): boolean;
175
- export declare const isPrefetched: typeof zenIsPrefetched;
176
- /**
177
- * Set global transition handler
178
- *
179
- * This allows setting a layout-level transition that applies to all navigations.
180
- *
181
- * @example
182
- * ```ts
183
- * // In layout component
184
- * setGlobalTransition(async (ctx) => {
185
- * ctx.currentPage?.classList.add('fade-out')
186
- * await delay(300)
187
- * ctx.nextPage?.classList.add('fade-in')
188
- * })
189
- * ```
190
- */
191
- export declare function setGlobalTransition(handler: TransitionHandler | null): void;
192
- /**
193
- * Get current global transition handler
194
- */
195
- export declare function getGlobalTransition(): TransitionHandler | null;
196
- /**
197
- * Create a transition context
198
- */
199
- export declare function createTransitionContext(fromPath: string, toPath: string, direction?: 'forward' | 'back'): TransitionContext;
200
- /**
201
- * Get current route state
202
- */
203
- export declare function zenGetRoute(): {
204
- path: string;
205
- params: Record<string, string>;
206
- query: Record<string, string>;
207
- };
208
- export declare const getRoute: typeof zenGetRoute;
209
- /**
210
- * Get a route parameter
211
- */
212
- export declare function zenGetParam(name: string): string | undefined;
213
- export declare const getParam: typeof zenGetParam;
214
- /**
215
- * Get a query parameter
216
- */
217
- export declare function zenGetQuery(name: string): string | undefined;
218
- export declare const getQuery: typeof zenGetQuery;
219
- /**
220
- * Create a ZenLink element programmatically
221
- *
222
- * @example
223
- * ```ts
224
- * const link = createZenLink({
225
- * href: '/about',
226
- * class: 'nav-link',
227
- * children: 'About Us'
228
- * })
229
- * container.appendChild(link)
230
- * ```
231
- */
232
- export declare function createZenLink(props: ZenLinkProps): HTMLAnchorElement;
233
- export declare const zenLink: typeof createZenLink;
234
- //# sourceMappingURL=zen-link.d.ts.map