@flight-framework/core 0.2.6 → 0.3.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 +211 -17
- package/dist/{chunk-54HPVE7N.js → chunk-3KRBRSRJ.js} +157 -3
- package/dist/chunk-3KRBRSRJ.js.map +1 -0
- package/dist/{chunk-KWFX6WHG.js → chunk-OYF2OAKS.js} +115 -32
- package/dist/chunk-OYF2OAKS.js.map +1 -0
- package/dist/{chunk-LBYDTULN.js → chunk-ROJFQCGV.js} +3 -3
- package/dist/{chunk-LBYDTULN.js.map → chunk-ROJFQCGV.js.map} +1 -1
- package/dist/file-router/index.d.ts +95 -1
- package/dist/file-router/index.js +1 -1
- package/dist/index.js +3 -3
- package/dist/middleware/index.d.ts +163 -10
- package/dist/middleware/index.js +1 -1
- package/dist/server/index.js +2 -2
- package/package.json +222 -210
- package/dist/chunk-54HPVE7N.js.map +0 -1
- package/dist/chunk-KWFX6WHG.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
# @flight-framework/core
|
|
2
2
|
|
|
3
|
-
Core primitives for Flight Framework
|
|
3
|
+
Core primitives for Flight Framework, including configuration, routing, caching, streaming SSR, and server actions.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
- **Zero Lock-in** - Every component is replaceable
|
|
7
|
+
- Multi-render mode: SSR, SSG, ISR, and streaming
|
|
8
|
+
- Framework support: React, Vue, Svelte, Solid, HTMX
|
|
9
|
+
- File-based routing with automatic route discovery
|
|
10
|
+
- Type-safe server actions with form support
|
|
11
|
+
- Streaming SSR with priority control
|
|
12
|
+
- Islands architecture for partial hydration
|
|
13
|
+
- Pluggable cache adapters with deduplication
|
|
14
|
+
- Structured error handling with type guards
|
|
16
15
|
|
|
17
16
|
## Installation
|
|
18
17
|
|
|
@@ -171,20 +170,153 @@ hydrateIslands({
|
|
|
171
170
|
|
|
172
171
|
### Middleware
|
|
173
172
|
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
Flight provides a composable middleware system for request/response handling.
|
|
174
|
+
|
|
175
|
+
#### Middleware Chain
|
|
176
176
|
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
```typescript
|
|
178
|
+
import {
|
|
179
|
+
createMiddlewareChain,
|
|
180
|
+
cors,
|
|
181
|
+
logger,
|
|
182
|
+
securityHeaders
|
|
183
|
+
} from '@flight-framework/core/middleware';
|
|
184
|
+
|
|
185
|
+
const chain = createMiddlewareChain();
|
|
186
|
+
|
|
187
|
+
chain
|
|
188
|
+
.use(logger())
|
|
189
|
+
.use(cors({ origin: ['https://app.example.com'] }))
|
|
190
|
+
.use(securityHeaders())
|
|
191
|
+
.use(async (ctx, next) => {
|
|
179
192
|
const start = Date.now();
|
|
180
193
|
await next();
|
|
181
194
|
console.log(`Request took ${Date.now() - start}ms`);
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
#### Error Handling
|
|
199
|
+
|
|
200
|
+
Centralized error handling with the `errorHandler` factory:
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import { createMiddlewareChain, errorHandler } from '@flight-framework/core/middleware';
|
|
204
|
+
|
|
205
|
+
const chain = createMiddlewareChain();
|
|
206
|
+
|
|
207
|
+
// Place error handler first in the chain
|
|
208
|
+
chain.use(errorHandler({
|
|
209
|
+
expose: process.env.NODE_ENV === 'development',
|
|
210
|
+
emit: (error, ctx) => {
|
|
211
|
+
logger.error(`[${ctx.method}] ${ctx.url.pathname}:`, error);
|
|
212
|
+
errorTracker.capture(error);
|
|
213
|
+
},
|
|
214
|
+
}));
|
|
215
|
+
|
|
216
|
+
chain.use(authMiddleware);
|
|
217
|
+
chain.use(routeHandler);
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
The error handler catches all downstream errors, sets appropriate status codes, and supports custom error handlers:
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
chain.use(errorHandler({
|
|
224
|
+
onError: async ({ error, status, ctx, timestamp }) => {
|
|
225
|
+
ctx.status = status;
|
|
226
|
+
ctx.responseBody = JSON.stringify({
|
|
227
|
+
error: error.message,
|
|
228
|
+
timestamp,
|
|
229
|
+
requestId: ctx.locals.requestId,
|
|
230
|
+
});
|
|
182
231
|
},
|
|
183
|
-
|
|
184
|
-
loggingMiddleware,
|
|
185
|
-
]);
|
|
232
|
+
}));
|
|
186
233
|
```
|
|
187
234
|
|
|
235
|
+
#### Typed Context
|
|
236
|
+
|
|
237
|
+
Middleware context supports generics for type-safe data sharing:
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
import type { Middleware, MiddlewareContext } from '@flight-framework/core/middleware';
|
|
241
|
+
|
|
242
|
+
interface AppLocals {
|
|
243
|
+
user: { id: string; role: string };
|
|
244
|
+
requestId: string;
|
|
245
|
+
db: DatabaseClient;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const authMiddleware: Middleware<AppLocals> = async (ctx, next) => {
|
|
249
|
+
const token = ctx.headers.get('Authorization');
|
|
250
|
+
const user = await verifyToken(token);
|
|
251
|
+
|
|
252
|
+
ctx.locals.user = user;
|
|
253
|
+
ctx.locals.requestId = crypto.randomUUID();
|
|
254
|
+
|
|
255
|
+
await next();
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// Type-safe access in subsequent middleware
|
|
259
|
+
const roleGuard: Middleware<AppLocals> = async (ctx, next) => {
|
|
260
|
+
if (ctx.locals.user.role !== 'admin') {
|
|
261
|
+
ctx.status = 403;
|
|
262
|
+
ctx.responseBody = 'Forbidden';
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
await next();
|
|
266
|
+
};
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
#### CORS
|
|
270
|
+
|
|
271
|
+
CORS middleware with dynamic origin validation and CDN compatibility:
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
import { cors } from '@flight-framework/core/middleware';
|
|
275
|
+
|
|
276
|
+
// Static origins
|
|
277
|
+
chain.use(cors({
|
|
278
|
+
origin: ['https://app.example.com', 'https://admin.example.com'],
|
|
279
|
+
methods: ['GET', 'POST', 'PUT', 'DELETE'],
|
|
280
|
+
credentials: true,
|
|
281
|
+
}));
|
|
282
|
+
|
|
283
|
+
// Async validation (database lookup)
|
|
284
|
+
chain.use(cors({
|
|
285
|
+
origin: async (requestOrigin) => {
|
|
286
|
+
return await db.allowedOrigins.exists(requestOrigin);
|
|
287
|
+
},
|
|
288
|
+
exposeHeaders: ['X-Request-Id', 'X-RateLimit-Remaining'],
|
|
289
|
+
}));
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Dynamic origins automatically set `Vary: Origin` for CDN/cache compatibility.
|
|
293
|
+
|
|
294
|
+
#### Built-in Middleware
|
|
295
|
+
|
|
296
|
+
| Middleware | Purpose |
|
|
297
|
+
|------------|---------|
|
|
298
|
+
| `cors(options?)` | Cross-origin resource sharing |
|
|
299
|
+
| `logger(options?)` | Request logging with configurable levels |
|
|
300
|
+
| `securityHeaders(options?)` | Security headers (CSP, X-Frame-Options, etc.) |
|
|
301
|
+
| `errorHandler(options?)` | Centralized error handling |
|
|
302
|
+
| `compress()` | Mark responses for compression |
|
|
303
|
+
|
|
304
|
+
#### Logger Configuration
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
import { logger } from '@flight-framework/core/middleware';
|
|
308
|
+
|
|
309
|
+
chain.use(logger({
|
|
310
|
+
level: 'info', // 'debug' | 'info' | 'warn' | 'error' | 'silent'
|
|
311
|
+
format: 'json', // 'pretty' | 'json' | 'combined' | 'common' | 'short'
|
|
312
|
+
skip: (ctx) => ctx.url.pathname === '/health',
|
|
313
|
+
writer: (entry, formatted) => externalLogger.log(entry),
|
|
314
|
+
}));
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
The logger captures errors from downstream middleware before re-throwing, ensuring all requests are logged including failures.
|
|
318
|
+
|
|
319
|
+
|
|
188
320
|
### Error Handling
|
|
189
321
|
|
|
190
322
|
```typescript
|
|
@@ -342,6 +474,68 @@ import type {
|
|
|
342
474
|
} from '@flight-framework/core';
|
|
343
475
|
```
|
|
344
476
|
|
|
477
|
+
## Build Plugins
|
|
478
|
+
|
|
479
|
+
### Critical CSS Extraction
|
|
480
|
+
|
|
481
|
+
Extract and inline critical CSS for improved LCP:
|
|
482
|
+
|
|
483
|
+
```bash
|
|
484
|
+
npm install critters
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
```typescript
|
|
488
|
+
// vite.config.ts
|
|
489
|
+
import { criticalCSS } from '@flight-framework/core/plugins';
|
|
490
|
+
|
|
491
|
+
export default defineConfig({
|
|
492
|
+
plugins: [
|
|
493
|
+
criticalCSS({
|
|
494
|
+
// Strategy for loading non-critical CSS
|
|
495
|
+
preload: 'swap', // 'body' | 'media' | 'swap' | 'swap-high' | 'js' | 'js-lazy'
|
|
496
|
+
|
|
497
|
+
// Remove inlined CSS from source
|
|
498
|
+
pruneSource: false,
|
|
499
|
+
|
|
500
|
+
// Routes to process
|
|
501
|
+
include: ['**/*.html'],
|
|
502
|
+
exclude: ['/api/**'],
|
|
503
|
+
}),
|
|
504
|
+
],
|
|
505
|
+
});
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
#### Preload Strategies
|
|
509
|
+
|
|
510
|
+
| Strategy | Description |
|
|
511
|
+
|----------|-------------|
|
|
512
|
+
| `swap` | Use rel="preload" and swap on load |
|
|
513
|
+
| `swap-high` | Like swap with fetchpriority="high" |
|
|
514
|
+
| `media` | Use media="print" and swap |
|
|
515
|
+
| `js` | Load via JavaScript |
|
|
516
|
+
| `js-lazy` | Load via JavaScript when idle |
|
|
517
|
+
| `body` | Move stylesheets to end of body |
|
|
518
|
+
|
|
519
|
+
#### CSS Utilities
|
|
520
|
+
|
|
521
|
+
```typescript
|
|
522
|
+
import {
|
|
523
|
+
extractInlineStyles,
|
|
524
|
+
mergeCSS,
|
|
525
|
+
generatePreloadLink,
|
|
526
|
+
generateNoscriptFallback,
|
|
527
|
+
} from '@flight-framework/core/plugins/critical-css';
|
|
528
|
+
|
|
529
|
+
// Extract styles from HTML
|
|
530
|
+
const { html, styles } = extractInlineStyles(htmlString);
|
|
531
|
+
|
|
532
|
+
// Generate preload link
|
|
533
|
+
const preload = generatePreloadLink('/styles.css', 'swap');
|
|
534
|
+
|
|
535
|
+
// Generate noscript fallback
|
|
536
|
+
const fallback = generateNoscriptFallback('/styles.css');
|
|
537
|
+
```
|
|
538
|
+
|
|
345
539
|
## License
|
|
346
540
|
|
|
347
541
|
MIT
|
|
@@ -39,6 +39,11 @@ async function scanRoutes(options) {
|
|
|
39
39
|
routes.push(...interceptRoutes);
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
|
+
const groupMatch = entry.name.match(/^\(([^.]+)\)$/);
|
|
43
|
+
if (groupMatch) {
|
|
44
|
+
await scanDir(fullPath, basePath);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
42
47
|
await scanDir(fullPath, `${basePath}/${entry.name}`);
|
|
43
48
|
} else if (entry.isFile()) {
|
|
44
49
|
const ext = extname(entry.name);
|
|
@@ -268,7 +273,156 @@ async function createFileRouter(options) {
|
|
|
268
273
|
refresh
|
|
269
274
|
};
|
|
270
275
|
}
|
|
276
|
+
function resolveParallelSlots(routes, currentPath) {
|
|
277
|
+
const slots = {};
|
|
278
|
+
const normalizedPath = normalizePath(currentPath);
|
|
279
|
+
const slotNames = /* @__PURE__ */ new Set();
|
|
280
|
+
for (const route of routes) {
|
|
281
|
+
if (route.slot) {
|
|
282
|
+
slotNames.add(route.slot);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
for (const slotName of slotNames) {
|
|
286
|
+
const slotRoutes = routes.filter((r) => r.slot === slotName);
|
|
287
|
+
let matchingRoute = slotRoutes.find((r) => {
|
|
288
|
+
const routePath = normalizePath(r.path);
|
|
289
|
+
return pathMatches(routePath, normalizedPath);
|
|
290
|
+
});
|
|
291
|
+
if (!matchingRoute) {
|
|
292
|
+
matchingRoute = slotRoutes.find(
|
|
293
|
+
(r) => r.path.endsWith("/default") || r.filePath.includes("default.page")
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
if (matchingRoute && matchingRoute.component) {
|
|
297
|
+
slots[slotName] = {
|
|
298
|
+
component: matchingRoute.component,
|
|
299
|
+
route: matchingRoute
|
|
300
|
+
};
|
|
301
|
+
} else {
|
|
302
|
+
slots[slotName] = null;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return slots;
|
|
306
|
+
}
|
|
307
|
+
function getSlotDefault(routes, slotName, basePath = "") {
|
|
308
|
+
const normalizedBase = normalizePath(basePath);
|
|
309
|
+
return routes.find(
|
|
310
|
+
(r) => r.slot === slotName && (r.filePath.includes("default.page") || r.path === `${normalizedBase}/default`)
|
|
311
|
+
) || null;
|
|
312
|
+
}
|
|
313
|
+
function getSlotNames(routes) {
|
|
314
|
+
const names = /* @__PURE__ */ new Set();
|
|
315
|
+
for (const route of routes) {
|
|
316
|
+
if (route.slot) {
|
|
317
|
+
names.add(route.slot);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return Array.from(names);
|
|
321
|
+
}
|
|
322
|
+
function findInterceptingRoute(routes, fromPath, toPath) {
|
|
323
|
+
const normalizedFrom = normalizePath(fromPath);
|
|
324
|
+
const normalizedTo = normalizePath(toPath);
|
|
325
|
+
const interceptingRoutes = routes.filter((r) => r.interceptInfo);
|
|
326
|
+
for (const route of interceptingRoutes) {
|
|
327
|
+
const { interceptInfo } = route;
|
|
328
|
+
if (!interceptInfo) continue;
|
|
329
|
+
const interceptPath = normalizePath(interceptInfo.interceptPath);
|
|
330
|
+
if (!pathMatches(interceptPath, normalizedTo)) {
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
let validOrigin = false;
|
|
334
|
+
const routePathStr = normalizePath(route.path);
|
|
335
|
+
const interceptMarkerMatch = routePathStr.match(/\/\(\.+\)/);
|
|
336
|
+
if (interceptInfo.level >= 3) {
|
|
337
|
+
validOrigin = true;
|
|
338
|
+
} else if (interceptMarkerMatch && interceptMarkerMatch.index !== void 0) {
|
|
339
|
+
const routeBase = routePathStr.substring(0, interceptMarkerMatch.index);
|
|
340
|
+
if (interceptInfo.level === 1) {
|
|
341
|
+
validOrigin = normalizedFrom === routeBase || normalizedFrom.startsWith(routeBase + "/") || routeBase === "" && normalizedFrom.startsWith("/");
|
|
342
|
+
} else if (interceptInfo.level === 2) {
|
|
343
|
+
validOrigin = normalizedFrom === routeBase || normalizedFrom.startsWith(routeBase + "/");
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (validOrigin) {
|
|
347
|
+
return route;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
function shouldDismissIntercept(currentRoute, toPath) {
|
|
353
|
+
if (!currentRoute || !currentRoute.interceptInfo) {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
const normalizedTo = normalizePath(toPath);
|
|
357
|
+
const interceptPath = normalizePath(currentRoute.interceptInfo.interceptPath);
|
|
358
|
+
return !pathMatches(interceptPath, normalizedTo);
|
|
359
|
+
}
|
|
360
|
+
function extractRouteParams(routePath, actualPath) {
|
|
361
|
+
const routeParts = routePath.split("/").filter(Boolean);
|
|
362
|
+
const actualParts = actualPath.split("/").filter(Boolean);
|
|
363
|
+
if (routeParts.length !== actualParts.length) {
|
|
364
|
+
const hasCatchAll = routeParts.some((p) => p.endsWith("+") || p.endsWith("*"));
|
|
365
|
+
if (!hasCatchAll) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
const params = {};
|
|
370
|
+
for (let i = 0; i < routeParts.length; i++) {
|
|
371
|
+
const routePart = routeParts[i];
|
|
372
|
+
const actualPart = actualParts[i];
|
|
373
|
+
if (!routePart) continue;
|
|
374
|
+
if (routePart.startsWith(":")) {
|
|
375
|
+
const paramName = routePart.slice(1).replace(/[+*]$/, "");
|
|
376
|
+
if (routePart.endsWith("+") || routePart.endsWith("*")) {
|
|
377
|
+
params[paramName] = actualParts.slice(i).join("/");
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
if (!actualPart) {
|
|
381
|
+
if (routePart.endsWith("*")) {
|
|
382
|
+
params[paramName] = "";
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
params[paramName] = actualPart;
|
|
388
|
+
} else if (routePart !== actualPart) {
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return params;
|
|
393
|
+
}
|
|
394
|
+
function normalizePath(path) {
|
|
395
|
+
let normalized = path.trim();
|
|
396
|
+
if (!normalized.startsWith("/")) {
|
|
397
|
+
normalized = "/" + normalized;
|
|
398
|
+
}
|
|
399
|
+
if (normalized !== "/" && normalized.endsWith("/")) {
|
|
400
|
+
normalized = normalized.slice(0, -1);
|
|
401
|
+
}
|
|
402
|
+
normalized = normalized.replace(/\/+/g, "/");
|
|
403
|
+
return normalized;
|
|
404
|
+
}
|
|
405
|
+
function pathMatches(routePath, actualPath) {
|
|
406
|
+
const routeParts = routePath.split("/").filter(Boolean);
|
|
407
|
+
const actualParts = actualPath.split("/").filter(Boolean);
|
|
408
|
+
for (let i = 0; i < routeParts.length; i++) {
|
|
409
|
+
const routePart = routeParts[i];
|
|
410
|
+
const actualPart = actualParts[i];
|
|
411
|
+
if (!routePart) continue;
|
|
412
|
+
if (routePart.startsWith(":") && (routePart.endsWith("+") || routePart.endsWith("*"))) {
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
if (routePart.startsWith(":")) {
|
|
416
|
+
if (!actualPart) return false;
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
if (routePart !== actualPart) {
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return routeParts.length === actualParts.length;
|
|
424
|
+
}
|
|
271
425
|
|
|
272
|
-
export { createFileRouter, loadRoutes, scanRoutes };
|
|
273
|
-
//# sourceMappingURL=chunk-
|
|
274
|
-
//# sourceMappingURL=chunk-
|
|
426
|
+
export { createFileRouter, extractRouteParams, findInterceptingRoute, getSlotDefault, getSlotNames, loadRoutes, resolveParallelSlots, scanRoutes, shouldDismissIntercept };
|
|
427
|
+
//# sourceMappingURL=chunk-3KRBRSRJ.js.map
|
|
428
|
+
//# sourceMappingURL=chunk-3KRBRSRJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/file-router/index.ts"],"names":[],"mappings":";;;;;AA6EA,eAAsB,WAAW,OAAA,EAAiD;AAC9E,EAAA,MAAM;AAAA,IACF,SAAA;AAAA,IACA,UAAA,GAAa,CAAC,KAAA,EAAO,KAAK;AAAA,GAC9B,GAAI,OAAA;AAEJ,EAAA,MAAM,SAAsB,EAAC;AAC7B,EAAA,MAAM,SAAmB,EAAC;AAE1B,EAAA,eAAe,OAAA,CAAQ,GAAA,EAAa,QAAA,GAAmB,EAAA,EAAmB;AACtE,IAAA,IAAI;AACA,MAAA,MAAM,UAAU,MAAM,OAAA,CAAQ,KAAK,EAAE,aAAA,EAAe,MAAM,CAAA;AAE1D,MAAA,KAAA,MAAW,SAAS,OAAA,EAAS;AACzB,QAAA,MAAM,QAAA,GAAW,IAAA,CAAK,GAAA,EAAK,KAAA,CAAM,IAAI,CAAA;AAErC,QAAA,IAAI,KAAA,CAAM,aAAY,EAAG;AAErB,UAAA,IAAI,MAAM,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,IAAK,KAAA,CAAM,SAAS,cAAA,EAAgB;AAC7D,YAAA;AAAA,UACJ;AAGA,UAAA,IAAI,KAAA,CAAM,IAAA,CAAK,UAAA,CAAW,GAAG,C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9B,IAAA,MAAM,UAAA,GAAa,YAAY,CAAC,CAAA;AAEhC,IAAA,IAAI,CAAC,SAAA,EAAW;AAGhB,IAAA,IAAI,SAAA,CAAU,UAAA,CAAW,GAAG,CAAA,KAAM,SAAA,CAAU,QAAA,CAAS,GAAG,CAAA,IAAK,SAAA,CAAU,QAAA,CAAS,GAAG,CAAA,CAAA,EAAI;AACnF,MAAA,OAAO,IAAA;AAAA,IACX;AAGA,IAAA,IAAI,SAAA,CAAU,UAAA,CAAW,GAAG,CAAA,EAAG;AAC3B,MAAA,IAAI,CAAC,YAAY,OAAO,KAAA;AACxB,MAAA;AAAA,IACJ;AAGA,IAAA,IAAI,cAAc,UAAA,EAAY;AAC1B,MAAA,OAAO,KAAA;AAAA,IACX;AAAA,EACJ;AAGA,EAAA,OAAO,UAAA,CAAW,WAAW,WAAA,CAAY,MAAA;AAC7C","file":"chunk-3KRBRSRJ.js","sourcesContent":["/**\r\n * @flight-framework/core - File Router\r\n * \r\n * Auto-discovery of routes from file system.\r\n * Similar to Next.js App Router and Nuxt server/api patterns.\r\n */\r\n\r\nimport { readdir } from 'node:fs/promises';\r\nimport { join, basename, extname } from 'node:path';\r\nimport { pathToFileURL } from 'node:url';\r\n\r\n// ============================================================================\r\n// Types\r\n// ============================================================================\r\n\r\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';\r\n\r\nexport type Handler = (context: unknown) => Response | Promise<Response>;\r\nexport type Middleware = (context: unknown, next: () => Promise<Response>) => Response | Promise<Response>;\r\n\r\nexport interface FileRoute {\r\n /** HTTP method (GET, POST, etc) or 'ALL' */\r\n method: HttpMethod | 'ALL';\r\n /** Route path with params (e.g., /users/:id) */\r\n path: string;\r\n /** Original file path */\r\n filePath: string;\r\n /** Handler function (for APIs) */\r\n handler?: Handler;\r\n /** Route-specific middleware */\r\n middleware?: Middleware[];\r\n /** Route type: 'page' for SSR pages, 'api' for API endpoints */\r\n type: 'page' | 'api';\r\n /** Component function (for pages) */\r\n component?: () => unknown;\r\n /** Page metadata (title, description, etc) */\r\n meta?: Record<string, unknown>;\r\n /** Parallel route slot name (for @folder convention) */\r\n slot?: string;\r\n /** Intercepting route info (for (.) (..) (...) convention) */\r\n interceptInfo?: {\r\n /** Number of levels to intercept: 1 = same, 2 = parent, 3+ = root */\r\n level: number;\r\n /** Target route segment to intercept */\r\n target: string;\r\n /** Original path that triggers interception */\r\n interceptPath: string;\r\n };\r\n}\r\n\r\nexport interface FileRouterOptions {\r\n /** Root directory to scan (default: src/routes) */\r\n directory: string;\r\n /** File extensions to consider (default: ['.ts', '.js']) */\r\n extensions?: string[];\r\n /** Whether to watch for changes (default: false in prod) */\r\n watch?: boolean;\r\n /** \r\n * Custom module loader for development with Vite.\r\n * Pass vite.ssrLoadModule to load TSX files correctly.\r\n * Falls back to native import() if not provided.\r\n */\r\n moduleLoader?: (filePath: string) => Promise<any>;\r\n}\r\n\r\nexport interface ScanResult {\r\n routes: FileRoute[];\r\n errors: string[];\r\n}\r\n\r\n// ============================================================================\r\n// File Scanner\r\n// ============================================================================\r\n\r\n/**\r\n * Scan a directory for route files\r\n */\r\nexport async function scanRoutes(options: FileRouterOptions): Promise<ScanResult> {\r\n const {\r\n directory,\r\n extensions = ['.ts', '.js'],\r\n } = options;\r\n\r\n const routes: FileRoute[] = [];\r\n const errors: string[] = [];\r\n\r\n async function scanDir(dir: string, basePath: string = ''): Promise<void> {\r\n try {\r\n const entries = await readdir(dir, { withFileTypes: true });\r\n\r\n for (const entry of entries) {\r\n const fullPath = join(dir, entry.name);\r\n\r\n if (entry.isDirectory()) {\r\n // Skip hidden directories and node_modules\r\n if (entry.name.startsWith('.') || entry.name === 'node_modules') {\r\n continue;\r\n }\r\n\r\n // Detect parallel route slots (@folder convention)\r\n if (entry.name.startsWith('@')) {\r\n const slotName = entry.name.slice(1);\r\n // Scan slot directory and mark routes with slot name\r\n const slotRoutes = await scanSlotDir(fullPath, basePath, slotName, extensions);\r\n routes.push(...slotRoutes);\r\n continue;\r\n }\r\n\r\n // Detect intercepting routes ((.) (..) (...) convention)\r\n const interceptMatch = entry.name.match(/^\\((\\.+)\\)(.+)$/);\r\n if (interceptMatch) {\r\n const level = interceptMatch[1].length;\r\n const targetSegment = interceptMatch[2];\r\n // Scan intercept directory and mark routes with interceptInfo\r\n const interceptRoutes = await scanInterceptDir(\r\n fullPath,\r\n basePath,\r\n level,\r\n targetSegment,\r\n extensions\r\n );\r\n routes.push(...interceptRoutes);\r\n continue;\r\n }\r\n\r\n // Detect route groups ((groupName) without dots - organizational only)\r\n // Route groups allow organizing routes without affecting URL structure\r\n // Example: (marketing)/about.page.tsx -> /about (not /marketing/about)\r\n const groupMatch = entry.name.match(/^\\(([^.]+)\\)$/);\r\n if (groupMatch) {\r\n // This is a route group - scan contents but don't add group to path\r\n await scanDir(fullPath, basePath);\r\n continue;\r\n }\r\n\r\n // Recurse into subdirectory\r\n await scanDir(fullPath, `${basePath}/${entry.name}`);\r\n } else if (entry.isFile()) {\r\n const ext = extname(entry.name);\r\n\r\n if (!extensions.includes(ext)) {\r\n continue;\r\n }\r\n\r\n // Parse route from filename\r\n const routeInfo = parseRouteFile(entry.name, basePath);\r\n\r\n if (routeInfo && routeInfo.method && routeInfo.path) {\r\n routes.push({\r\n method: routeInfo.method,\r\n path: routeInfo.path,\r\n filePath: fullPath,\r\n type: routeInfo.type,\r\n });\r\n }\r\n }\r\n }\r\n } catch (error) {\r\n errors.push(`Failed to scan ${dir}: ${error}`);\r\n }\r\n }\r\n\r\n await scanDir(directory);\r\n\r\n return { routes, errors };\r\n}\r\n\r\n/**\r\n * Scan a parallel route slot directory\r\n */\r\nasync function scanSlotDir(\r\n dir: string,\r\n basePath: string,\r\n slotName: string,\r\n extensions: string[] = ['.ts', '.js', '.tsx', '.jsx']\r\n): Promise<FileRoute[]> {\r\n const routes: FileRoute[] = [];\r\n\r\n try {\r\n const entries = await readdir(dir, { withFileTypes: true });\r\n\r\n for (const entry of entries) {\r\n const fullPath = join(dir, entry.name);\r\n\r\n if (entry.isFile()) {\r\n const ext = extname(entry.name);\r\n\r\n if (!extensions.includes(ext)) {\r\n continue;\r\n }\r\n\r\n const routeInfo = parseRouteFile(entry.name, basePath);\r\n\r\n if (routeInfo && routeInfo.method && routeInfo.path) {\r\n routes.push({\r\n method: routeInfo.method,\r\n path: routeInfo.path,\r\n filePath: fullPath,\r\n type: routeInfo.type,\r\n slot: slotName,\r\n });\r\n }\r\n }\r\n }\r\n } catch (error) {\r\n console.error(`[Flight] Failed to scan slot @${slotName}:`, error);\r\n }\r\n\r\n return routes;\r\n}\r\n\r\n/**\r\n * Scan an intercepting route directory\r\n * Uses (.) (..) (...) convention similar to Next.js\r\n * - (.)segment - intercepts from same level\r\n * - (..)segment - intercepts from parent level\r\n * - (...)segment - intercepts from root\r\n */\r\nasync function scanInterceptDir(\r\n dir: string,\r\n basePath: string,\r\n level: number,\r\n targetSegment: string,\r\n extensions: string[] = ['.ts', '.js', '.tsx', '.jsx']\r\n): Promise<FileRoute[]> {\r\n const routes: FileRoute[] = [];\r\n\r\n // Calculate the intercept path based on level\r\n const pathParts = basePath.split('/').filter(Boolean);\r\n let interceptPath: string;\r\n\r\n if (level === 1) {\r\n // (.) - Same level, intercepts sibling route\r\n interceptPath = `${basePath}/${targetSegment}`;\r\n } else if (level === 2) {\r\n // (..) - Parent level\r\n pathParts.pop();\r\n interceptPath = `/${pathParts.join('/')}/${targetSegment}`;\r\n } else {\r\n // (...) - Root level (3 or more dots)\r\n interceptPath = `/${targetSegment}`;\r\n }\r\n\r\n try {\r\n const entries = await readdir(dir, { withFileTypes: true });\r\n\r\n for (const entry of entries) {\r\n const fullPath = join(dir, entry.name);\r\n\r\n if (entry.isFile()) {\r\n const ext = extname(entry.name);\r\n\r\n if (!extensions.includes(ext)) {\r\n continue;\r\n }\r\n\r\n const routeInfo = parseRouteFile(entry.name, basePath);\r\n\r\n if (routeInfo && routeInfo.method && routeInfo.path) {\r\n routes.push({\r\n method: routeInfo.method,\r\n path: routeInfo.path,\r\n filePath: fullPath,\r\n type: routeInfo.type,\r\n interceptInfo: {\r\n level,\r\n target: targetSegment,\r\n interceptPath: interceptPath.replace(/\\/+/g, '/') || '/',\r\n },\r\n });\r\n }\r\n } else if (entry.isDirectory()) {\r\n // Recurse into subdirectories within intercept folder\r\n const subRoutes = await scanInterceptDir(\r\n fullPath,\r\n `${basePath}/${entry.name}`,\r\n level,\r\n targetSegment,\r\n extensions\r\n );\r\n routes.push(...subRoutes);\r\n }\r\n }\r\n } catch (error) {\r\n console.error(`[Flight] Failed to scan intercept (${'.'.repeat(level)})${targetSegment}:`, error);\r\n }\r\n\r\n return routes;\r\n}\r\n\r\n// ============================================================================\r\n// Route Parser\r\n// ============================================================================\r\n\r\ninterface ParsedRoute {\r\n method: HttpMethod | 'ALL';\r\n path: string;\r\n type: 'page' | 'api';\r\n}\r\n\r\n/**\r\n * Parse route information from filename and path\r\n * \r\n * Patterns:\r\n * - index.ts → /\r\n * - users.ts → /users\r\n * - users.get.ts → GET /users (API)\r\n * - users.post.ts → POST /users (API)\r\n * - about.page.tsx → GET /about (Page)\r\n * - blog/[slug].page.tsx → GET /blog/:slug (Page)\r\n * - [id].ts → /:id\r\n * - [...slug].ts → /* (catch-all)\r\n * - [[...slug]].ts → /* (optional catch-all)\r\n */\r\nfunction parseRouteFile(filename: string, basePath: string): ParsedRoute | null {\r\n const ext = extname(filename);\r\n const nameWithoutExt = basename(filename, ext);\r\n\r\n // Skip files starting with underscore (private)\r\n if (nameWithoutExt.startsWith('_')) {\r\n return null;\r\n }\r\n\r\n // Detect route type\r\n let type: 'page' | 'api' = 'api';\r\n let routeName = nameWithoutExt;\r\n let method: HttpMethod | 'ALL' = 'ALL';\r\n\r\n // Check for page suffix (e.g., about.page.tsx, index.page.tsx)\r\n const pageMatch = nameWithoutExt.match(/^(.+)?\\.page$/i);\r\n if (pageMatch) {\r\n type = 'page';\r\n method = 'GET'; // Pages are always GET\r\n routeName = pageMatch[1] || 'index';\r\n } else {\r\n // Check for method suffix (e.g., users.get.ts)\r\n const methodMatch = nameWithoutExt.match(/^(.+)\\.(get|post|put|delete|patch|head|options)$/i);\r\n if (methodMatch) {\r\n routeName = methodMatch[1] || nameWithoutExt;\r\n method = (methodMatch[2] || 'ALL').toUpperCase() as HttpMethod;\r\n }\r\n }\r\n\r\n // Also check if file is in /api/ directory\r\n if (basePath.startsWith('/api') || basePath.includes('/api/')) {\r\n type = 'api';\r\n }\r\n\r\n // Build route path\r\n let path = basePath;\r\n\r\n if (routeName !== 'index') {\r\n path = `${basePath}/${convertToRoutePath(routeName)}`;\r\n }\r\n\r\n // Ensure path starts with /\r\n if (!path.startsWith('/')) {\r\n path = '/' + path;\r\n }\r\n\r\n // Remove trailing slash (except for root)\r\n if (path !== '/' && path.endsWith('/')) {\r\n path = path.slice(0, -1);\r\n }\r\n\r\n return { method, path, type };\r\n}\r\n\r\n/**\r\n * Convert filename segment to route path segment\r\n * \r\n * - [id] → :id\r\n * - [...slug] → *\r\n * - [[...slug]] → *?\r\n */\r\nfunction convertToRoutePath(name: string): string {\r\n // Optional catch-all: [[...slug]]\r\n if (name.startsWith('[[...') && name.endsWith(']]')) {\r\n const paramName = name.slice(5, -2);\r\n return `:${paramName}*`;\r\n }\r\n\r\n // Catch-all: [...slug]\r\n if (name.startsWith('[...') && name.endsWith(']')) {\r\n const paramName = name.slice(4, -1);\r\n return `:${paramName}+`;\r\n }\r\n\r\n // Dynamic param: [id]\r\n if (name.startsWith('[') && name.endsWith(']')) {\r\n const paramName = name.slice(1, -1);\r\n return `:${paramName}`;\r\n }\r\n\r\n return name;\r\n}\r\n\r\n// ============================================================================\r\n// Route Loader\r\n// ============================================================================\r\n\r\n/**\r\n * Load routes with their handlers or components\r\n * @param scanResult - Result from scanRoutes\r\n * @param moduleLoader - Optional custom loader (use vite.ssrLoadModule for dev)\r\n */\r\nexport async function loadRoutes(\r\n scanResult: ScanResult,\r\n moduleLoader?: (filePath: string) => Promise<any>\r\n): Promise<FileRoute[]> {\r\n const loadedRoutes: FileRoute[] = [];\r\n\r\n for (const route of scanResult.routes) {\r\n try {\r\n // Use custom loader if provided (Vite ssrLoadModule for TSX)\r\n // Otherwise fall back to native import() for production\r\n let module: any;\r\n if (moduleLoader) {\r\n module = await moduleLoader(route.filePath);\r\n } else {\r\n // Convert to file:// URL for Windows ESM compatibility\r\n const fileUrl = pathToFileURL(route.filePath).href;\r\n module = await import(fileUrl);\r\n }\r\n\r\n // Handle PAGE routes\r\n if (route.type === 'page') {\r\n // Pages export default component\r\n const component = module.default;\r\n const meta = module.meta || module.metadata || {};\r\n\r\n if (component) {\r\n loadedRoutes.push({\r\n ...route,\r\n component,\r\n meta,\r\n });\r\n }\r\n continue;\r\n }\r\n\r\n // Handle API routes\r\n if (route.method === 'ALL') {\r\n // Look for named exports: GET, POST, PUT, DELETE, etc\r\n const methods: HttpMethod[] = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];\r\n\r\n for (const method of methods) {\r\n if (typeof module[method] === 'function') {\r\n loadedRoutes.push({\r\n ...route,\r\n method,\r\n handler: module[method],\r\n });\r\n }\r\n }\r\n\r\n // Also check for default export as handler\r\n if (typeof module.default === 'function') {\r\n loadedRoutes.push({\r\n ...route,\r\n method: 'ALL',\r\n handler: module.default,\r\n });\r\n }\r\n } else {\r\n // Specific method from filename suffix\r\n const handler = module[route.method] || module.default;\r\n\r\n if (typeof handler === 'function') {\r\n loadedRoutes.push({\r\n ...route,\r\n handler,\r\n });\r\n }\r\n }\r\n } catch (error) {\r\n console.error(`[Flight] Failed to load route ${route.filePath}:`, error);\r\n }\r\n }\r\n\r\n return loadedRoutes;\r\n}\r\n\r\n// ============================================================================\r\n// File Router Factory\r\n// ============================================================================\r\n\r\nexport interface FileRouter {\r\n routes: FileRoute[];\r\n refresh: () => Promise<void>;\r\n}\r\n\r\n/**\r\n * Create a file-based router\r\n * \r\n * @example\r\n * ```typescript\r\n * import { createFileRouter } from '@flight-framework/core/file-router';\r\n * import { createServer } from '@flight-framework/http';\r\n * \r\n * const router = await createFileRouter({ directory: './src/routes' });\r\n * const app = createServer();\r\n * \r\n * // Register all discovered routes\r\n * for (const route of router.routes) {\r\n * app[route.method.toLowerCase()](route.path, route.handler);\r\n * }\r\n * ```\r\n */\r\nexport async function createFileRouter(options: FileRouterOptions): Promise<FileRouter> {\r\n let routes: FileRoute[] = [];\r\n const { moduleLoader } = options;\r\n\r\n async function refresh(): Promise<void> {\r\n const scanResult = await scanRoutes(options);\r\n\r\n if (scanResult.errors.length > 0) {\r\n console.warn('[Flight] Route scan errors:', scanResult.errors);\r\n }\r\n\r\n routes = await loadRoutes(scanResult, moduleLoader);\r\n\r\n console.log(`[Flight] Loaded ${routes.length} routes from ${options.directory}`);\r\n }\r\n\r\n // Initial load\r\n await refresh();\r\n\r\n return {\r\n get routes() {\r\n return routes;\r\n },\r\n refresh,\r\n };\r\n}\r\n\r\n// ============================================================================\r\n// Parallel Routes Resolution\r\n// ============================================================================\r\n\r\n/**\r\n * Resolved parallel route slots for a layout.\r\n * Each slot name maps to its resolved component or null if not matched.\r\n */\r\nexport interface ResolvedSlots {\r\n [slotName: string]: {\r\n /** The component to render */\r\n component: () => unknown;\r\n /** The full route information */\r\n route: FileRoute;\r\n } | null;\r\n}\r\n\r\n/**\r\n * Resolve parallel route slots for a given path.\r\n * \r\n * Parallel routes use the @folder convention to define named slots\r\n * that can render alongside the main content in a layout.\r\n * \r\n * @param routes - All loaded routes from the file router\r\n * @param currentPath - The current URL path to resolve slots for\r\n * @returns Object mapping slot names to their resolved components\r\n * \r\n * @example\r\n * ```typescript\r\n * // Given routes from @modal/ and @sidebar/ directories\r\n * const slots = resolveParallelSlots(router.routes, '/dashboard');\r\n * \r\n * // In layout:\r\n * if (slots.modal) {\r\n * renderModal(slots.modal.component);\r\n * }\r\n * ```\r\n */\r\nexport function resolveParallelSlots(\r\n routes: FileRoute[],\r\n currentPath: string\r\n): ResolvedSlots {\r\n const slots: ResolvedSlots = {};\r\n const normalizedPath = normalizePath(currentPath);\r\n\r\n // Get all unique slot names from routes\r\n const slotNames = new Set<string>();\r\n for (const route of routes) {\r\n if (route.slot) {\r\n slotNames.add(route.slot);\r\n }\r\n }\r\n\r\n // For each slot, find matching route or default\r\n for (const slotName of slotNames) {\r\n const slotRoutes = routes.filter(r => r.slot === slotName);\r\n\r\n // Find exact match for current path\r\n let matchingRoute = slotRoutes.find(r => {\r\n const routePath = normalizePath(r.path);\r\n return pathMatches(routePath, normalizedPath);\r\n });\r\n\r\n // If no match, look for default.page in the slot\r\n if (!matchingRoute) {\r\n matchingRoute = slotRoutes.find(r =>\r\n r.path.endsWith('/default') || r.filePath.includes('default.page')\r\n );\r\n }\r\n\r\n if (matchingRoute && matchingRoute.component) {\r\n slots[slotName] = {\r\n component: matchingRoute.component,\r\n route: matchingRoute,\r\n };\r\n } else {\r\n // Slot has no matching content for this path\r\n slots[slotName] = null;\r\n }\r\n }\r\n\r\n return slots;\r\n}\r\n\r\n/**\r\n * Get the default page for an unmatched slot.\r\n * \r\n * When a parallel route slot doesn't have a matching route for the current path,\r\n * it should render its default.page if one exists, or null.\r\n * \r\n * @param routes - All loaded routes\r\n * @param slotName - Name of the slot (without @)\r\n * @param basePath - Base path to search from\r\n * @returns The default route for the slot, or null\r\n */\r\nexport function getSlotDefault(\r\n routes: FileRoute[],\r\n slotName: string,\r\n basePath: string = ''\r\n): FileRoute | null {\r\n const normalizedBase = normalizePath(basePath);\r\n\r\n return routes.find(r =>\r\n r.slot === slotName &&\r\n (r.filePath.includes('default.page') || r.path === `${normalizedBase}/default`)\r\n ) || null;\r\n}\r\n\r\n/**\r\n * Get all slot names used in the routes.\r\n * \r\n * @param routes - All loaded routes\r\n * @returns Array of unique slot names\r\n */\r\nexport function getSlotNames(routes: FileRoute[]): string[] {\r\n const names = new Set<string>();\r\n for (const route of routes) {\r\n if (route.slot) {\r\n names.add(route.slot);\r\n }\r\n }\r\n return Array.from(names);\r\n}\r\n\r\n// ============================================================================\r\n// Intercepting Routes Resolution\r\n// ============================================================================\r\n\r\n/**\r\n * Check if a navigation should be intercepted by an intercepting route.\r\n * \r\n * Intercepting routes use the (.) (..) (...) convention:\r\n * - (.)segment - intercepts from same level\r\n * - (..)segment - intercepts from parent level \r\n * - (...)segment - intercepts from root\r\n * \r\n * @param routes - All loaded routes\r\n * @param fromPath - Current path where navigation originates\r\n * @param toPath - Target path the user wants to navigate to\r\n * @returns The intercepting route if found, null otherwise\r\n * \r\n * @example\r\n * ```typescript\r\n * // User is on /feed and clicks link to /photo/123\r\n * const intercepted = findInterceptingRoute(routes, '/feed', '/photo/123');\r\n * \r\n * if (intercepted) {\r\n * // Render intercepted.component as modal instead of navigating\r\n * showModal(intercepted);\r\n * }\r\n * ```\r\n */\r\nexport function findInterceptingRoute(\r\n routes: FileRoute[],\r\n fromPath: string,\r\n toPath: string\r\n): FileRoute | null {\r\n const normalizedFrom = normalizePath(fromPath);\r\n const normalizedTo = normalizePath(toPath);\r\n\r\n // Filter to only intercepting routes\r\n const interceptingRoutes = routes.filter(r => r.interceptInfo);\r\n\r\n for (const route of interceptingRoutes) {\r\n const { interceptInfo } = route;\r\n if (!interceptInfo) continue;\r\n\r\n // Check if the interceptPath matches the target path\r\n const interceptPath = normalizePath(interceptInfo.interceptPath);\r\n\r\n if (!pathMatches(interceptPath, normalizedTo)) {\r\n continue;\r\n }\r\n\r\n // Check if we're navigating from a valid origin based on level\r\n // For level 1 (.), the intercept route is at same level as navigation origin\r\n // For level 2 (..), the intercept route is one level up from navigation origin\r\n // For level 3+ (...), intercepts from anywhere\r\n\r\n let validOrigin = false;\r\n\r\n // Find the intercept marker position in route path\r\n // Route path example: /feed/(.)photo/:id -> base is /feed\r\n const routePathStr = normalizePath(route.path);\r\n const interceptMarkerMatch = routePathStr.match(/\\/\\(\\.+\\)/);\r\n\r\n if (interceptInfo.level >= 3) {\r\n // (...) - Root level: intercepts from anywhere\r\n validOrigin = true;\r\n } else if (interceptMarkerMatch && interceptMarkerMatch.index !== undefined) {\r\n // Extract the base path before the intercept marker\r\n const routeBase = routePathStr.substring(0, interceptMarkerMatch.index);\r\n\r\n if (interceptInfo.level === 1) {\r\n // (.) - Same level: origin should be at or under the route base\r\n // Route at /feed/(.)photo, origin should be /feed or /feed/*\r\n validOrigin = normalizedFrom === routeBase ||\r\n normalizedFrom.startsWith(routeBase + '/') ||\r\n (routeBase === '' && normalizedFrom.startsWith('/'));\r\n } else if (interceptInfo.level === 2) {\r\n // (..) - Parent level: origin is one level deeper\r\n // Route at /gallery/albums/(..)photo, origin should be /gallery/albums/*\r\n validOrigin = normalizedFrom === routeBase ||\r\n normalizedFrom.startsWith(routeBase + '/');\r\n }\r\n }\r\n\r\n if (validOrigin) {\r\n return route;\r\n }\r\n }\r\n\r\n return null;\r\n}\r\n\r\n/**\r\n * Check if an intercepting route should be dismissed on this navigation.\r\n * \r\n * @param currentRoute - The currently active intercepting route\r\n * @param toPath - The path being navigated to\r\n * @returns true if the interception should be dismissed\r\n */\r\nexport function shouldDismissIntercept(\r\n currentRoute: FileRoute | null,\r\n toPath: string\r\n): boolean {\r\n if (!currentRoute || !currentRoute.interceptInfo) {\r\n return false;\r\n }\r\n\r\n const normalizedTo = normalizePath(toPath);\r\n const interceptPath = normalizePath(currentRoute.interceptInfo.interceptPath);\r\n\r\n // Dismiss if navigating away from the intercepted path\r\n return !pathMatches(interceptPath, normalizedTo);\r\n}\r\n\r\n/**\r\n * Get route params from a path match.\r\n * \r\n * @param routePath - The route pattern with params (e.g., /photo/:id)\r\n * @param actualPath - The actual URL path (e.g., /photo/123)\r\n * @returns Object with matched params, or null if no match\r\n */\r\nexport function extractRouteParams(\r\n routePath: string,\r\n actualPath: string\r\n): Record<string, string> | null {\r\n const routeParts = routePath.split('/').filter(Boolean);\r\n const actualParts = actualPath.split('/').filter(Boolean);\r\n\r\n if (routeParts.length !== actualParts.length) {\r\n // Check for catch-all\r\n const hasCatchAll = routeParts.some(p => p.endsWith('+') || p.endsWith('*'));\r\n if (!hasCatchAll) {\r\n return null;\r\n }\r\n }\r\n\r\n const params: Record<string, string> = {};\r\n\r\n for (let i = 0; i < routeParts.length; i++) {\r\n const routePart = routeParts[i];\r\n const actualPart = actualParts[i];\r\n\r\n if (!routePart) continue;\r\n\r\n if (routePart.startsWith(':')) {\r\n // Dynamic param\r\n const paramName = routePart.slice(1).replace(/[+*]$/, '');\r\n\r\n if (routePart.endsWith('+') || routePart.endsWith('*')) {\r\n // Catch-all: collect remaining parts\r\n params[paramName] = actualParts.slice(i).join('/');\r\n break;\r\n }\r\n\r\n if (!actualPart) {\r\n if (routePart.endsWith('*')) {\r\n // Optional catch-all, can be empty\r\n params[paramName] = '';\r\n break;\r\n }\r\n return null;\r\n }\r\n\r\n params[paramName] = actualPart;\r\n } else if (routePart !== actualPart) {\r\n return null;\r\n }\r\n }\r\n\r\n return params;\r\n}\r\n\r\n// ============================================================================\r\n// Path Utilities\r\n// ============================================================================\r\n\r\n/**\r\n * Normalize a path for consistent comparison.\r\n */\r\nfunction normalizePath(path: string): string {\r\n let normalized = path.trim();\r\n\r\n // Ensure starts with /\r\n if (!normalized.startsWith('/')) {\r\n normalized = '/' + normalized;\r\n }\r\n\r\n // Remove trailing slash (except for root)\r\n if (normalized !== '/' && normalized.endsWith('/')) {\r\n normalized = normalized.slice(0, -1);\r\n }\r\n\r\n // Remove duplicate slashes\r\n normalized = normalized.replace(/\\/+/g, '/');\r\n\r\n return normalized;\r\n}\r\n\r\n/**\r\n * Check if a route path matches an actual path.\r\n * Handles dynamic segments (:param) and catch-alls.\r\n */\r\nfunction pathMatches(routePath: string, actualPath: string): boolean {\r\n const routeParts = routePath.split('/').filter(Boolean);\r\n const actualParts = actualPath.split('/').filter(Boolean);\r\n\r\n for (let i = 0; i < routeParts.length; i++) {\r\n const routePart = routeParts[i];\r\n const actualPart = actualParts[i];\r\n\r\n if (!routePart) continue;\r\n\r\n // Catch-all segment\r\n if (routePart.startsWith(':') && (routePart.endsWith('+') || routePart.endsWith('*'))) {\r\n return true; // Matches rest of path\r\n }\r\n\r\n // Dynamic segment\r\n if (routePart.startsWith(':')) {\r\n if (!actualPart) return false;\r\n continue; // Any value matches\r\n }\r\n\r\n // Static segment - must match exactly\r\n if (routePart !== actualPart) {\r\n return false;\r\n }\r\n }\r\n\r\n // Check lengths match (unless catch-all was present)\r\n return routeParts.length === actualParts.length;\r\n}\r\n\r\n"]}
|