@useavalon/avalon 0.1.22 → 0.1.24

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.
Files changed (115) hide show
  1. package/dist/mod.d.ts +50 -0
  2. package/dist/src/build/integration-bundler-plugin.d.ts +25 -0
  3. package/dist/src/build/integration-config.d.ts +44 -0
  4. package/dist/src/build/integration-detection-plugin.d.ts +20 -0
  5. package/dist/src/build/integration-resolver-plugin.d.ts +10 -0
  6. package/dist/src/build/island-manifest.d.ts +57 -0
  7. package/dist/src/build/island-types-generator.d.ts +49 -0
  8. package/dist/src/build/mdx-island-transform.d.ts +23 -0
  9. package/dist/src/build/mdx-plugin.d.ts +36 -0
  10. package/dist/src/build/page-island-transform.d.ts +41 -0
  11. package/dist/src/build/prop-extractors/index.d.ts +8 -0
  12. package/dist/src/build/prop-extractors/lit.d.ts +11 -0
  13. package/dist/src/build/prop-extractors/qwik.d.ts +9 -0
  14. package/dist/src/build/prop-extractors/solid.d.ts +12 -0
  15. package/dist/src/build/prop-extractors/svelte.d.ts +13 -0
  16. package/dist/src/build/prop-extractors/vue.d.ts +19 -0
  17. package/dist/src/build/sidecar-file-manager.d.ts +23 -0
  18. package/dist/src/build/sidecar-renderer.d.ts +22 -0
  19. package/dist/src/client/adapters/index.d.ts +15 -0
  20. package/dist/src/client/components.d.ts +21 -0
  21. package/dist/src/client/css-hmr-handler.d.ts +94 -0
  22. package/dist/src/client/framework-adapter.d.ts +225 -0
  23. package/dist/src/client/hmr-coordinator.d.ts +88 -0
  24. package/dist/src/components/Image.d.ts +61 -0
  25. package/dist/src/components/IslandErrorBoundary.d.ts +37 -0
  26. package/dist/src/components/IslandErrorBoundary.js +1 -1
  27. package/dist/src/components/LayoutDataErrorBoundary.d.ts +34 -0
  28. package/dist/src/components/LayoutDataErrorBoundary.js +1 -1
  29. package/dist/src/components/LayoutErrorBoundary.d.ts +25 -0
  30. package/dist/src/components/LayoutErrorBoundary.js +1 -1
  31. package/dist/src/components/PersistentIsland.d.ts +36 -0
  32. package/dist/src/components/StreamingErrorBoundary.d.ts +42 -0
  33. package/dist/src/components/StreamingErrorBoundary.js +1 -1
  34. package/dist/src/components/StreamingLayout.d.ts +83 -0
  35. package/dist/src/components/StreamingLayout.js +1 -1
  36. package/dist/src/core/components/component-analyzer.d.ts +48 -0
  37. package/dist/src/core/components/component-detection.d.ts +72 -0
  38. package/dist/src/core/components/enhanced-framework-detector.d.ts +78 -0
  39. package/dist/src/core/components/framework-registry.d.ts +114 -0
  40. package/dist/src/core/content/mdx-processor.d.ts +14 -0
  41. package/dist/src/core/integrations/index.d.ts +6 -0
  42. package/dist/src/core/integrations/loader.d.ts +35 -0
  43. package/dist/src/core/integrations/registry.d.ts +51 -0
  44. package/dist/src/core/islands/island-persistence.d.ts +74 -0
  45. package/dist/src/core/islands/island-state-serializer.d.ts +53 -0
  46. package/dist/src/core/islands/persistent-island-context.d.ts +36 -0
  47. package/dist/src/core/islands/use-persistent-state.d.ts +17 -0
  48. package/dist/src/core/layout/enhanced-layout-resolver.d.ts +73 -0
  49. package/dist/src/core/layout/layout-cache-manager.d.ts +66 -0
  50. package/dist/src/core/layout/layout-composer.d.ts +63 -0
  51. package/dist/src/core/layout/layout-data-loader.d.ts +146 -0
  52. package/dist/src/core/layout/layout-discovery.d.ts +51 -0
  53. package/dist/src/core/layout/layout-matcher.d.ts +77 -0
  54. package/dist/src/core/layout/layout-types.d.ts +94 -0
  55. package/dist/src/core/modules/framework-module-resolver.d.ts +85 -0
  56. package/dist/src/islands/component-analysis.d.ts +38 -0
  57. package/dist/src/islands/css-utils.d.ts +81 -0
  58. package/dist/src/islands/discovery/index.d.ts +16 -0
  59. package/dist/src/islands/discovery/registry.d.ts +141 -0
  60. package/dist/src/islands/discovery/resolver.d.ts +190 -0
  61. package/dist/src/islands/discovery/scanner.d.ts +55 -0
  62. package/dist/src/islands/discovery/types.d.ts +92 -0
  63. package/dist/src/islands/discovery/validator.d.ts +89 -0
  64. package/dist/src/islands/discovery/watcher.d.ts +95 -0
  65. package/dist/src/islands/framework-detection.d.ts +53 -0
  66. package/dist/src/islands/integration-loader.d.ts +139 -0
  67. package/dist/src/islands/island.d.ts +55 -0
  68. package/dist/src/islands/render-cache.d.ts +203 -0
  69. package/dist/src/islands/types.d.ts +63 -0
  70. package/dist/src/islands/universal-css-collector.d.ts +41 -0
  71. package/dist/src/islands/universal-head-collector.d.ts +42 -0
  72. package/dist/src/layout-system.d.ts +92 -592
  73. package/dist/src/middleware/discovery.d.ts +70 -0
  74. package/dist/src/middleware/executor.d.ts +52 -0
  75. package/dist/src/middleware/index.d.ts +43 -0
  76. package/dist/src/middleware/types.d.ts +89 -0
  77. package/dist/src/nitro/build-config.d.ts +163 -0
  78. package/dist/src/nitro/config.d.ts +268 -0
  79. package/dist/src/nitro/error-handler.d.ts +151 -0
  80. package/dist/src/nitro/index.d.ts +15 -0
  81. package/dist/src/nitro/island-manifest.d.ts +191 -0
  82. package/dist/src/nitro/middleware-adapter.d.ts +151 -0
  83. package/dist/src/nitro/renderer.d.ts +342 -0
  84. package/dist/src/nitro/route-discovery.d.ts +142 -0
  85. package/dist/src/nitro/types.d.ts +278 -0
  86. package/dist/src/render/collect-css.d.ts +28 -0
  87. package/dist/src/render/error-pages.d.ts +14 -0
  88. package/dist/src/render/isolated-ssr-renderer.d.ts +127 -0
  89. package/dist/src/render/ssr.d.ts +56 -0
  90. package/dist/src/schemas/api.d.ts +27 -0
  91. package/dist/src/schemas/core.d.ts +75 -0
  92. package/dist/src/schemas/index.d.ts +79 -0
  93. package/dist/src/schemas/index.js +1 -1
  94. package/dist/src/schemas/layout.d.ts +282 -0
  95. package/dist/src/schemas/routing/index.d.ts +181 -0
  96. package/dist/src/schemas/routing.d.ts +388 -0
  97. package/dist/src/types/as-island.d.ts +17 -0
  98. package/dist/src/types/layout.d.ts +177 -0
  99. package/dist/src/types/routing.d.ts +297 -0
  100. package/dist/src/types/types.d.ts +6 -0
  101. package/dist/src/utils/dev-logger.d.ts +84 -0
  102. package/dist/src/utils/fs.d.ts +41 -0
  103. package/dist/src/vite-plugin/auto-discover.d.ts +72 -0
  104. package/dist/src/vite-plugin/config.d.ts +82 -0
  105. package/dist/src/vite-plugin/errors.d.ts +62 -0
  106. package/dist/src/vite-plugin/image-optimization.d.ts +36 -0
  107. package/dist/src/vite-plugin/integration-activator.d.ts +48 -0
  108. package/dist/src/vite-plugin/island-sidecar-plugin.d.ts +17 -0
  109. package/dist/src/vite-plugin/module-discovery.d.ts +66 -0
  110. package/dist/src/vite-plugin/nitro-integration.d.ts +56 -0
  111. package/dist/src/vite-plugin/nitro-integration.js +1 -1
  112. package/dist/src/vite-plugin/plugin.d.ts +51 -0
  113. package/dist/src/vite-plugin/types.d.ts +281 -0
  114. package/dist/src/vite-plugin/validation.d.ts +93 -0
  115. package/package.json +33 -9
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Hook for persistent island state — like useState but survives navigations.
3
+ *
4
+ * State is serialized to sessionStorage (supports Date, Map, Set, RegExp).
5
+ * On the server or when storage is unavailable, falls back to in-memory state.
6
+ *
7
+ * ```tsx
8
+ * const [count, setCount, clearCount] = usePersistentState('my-counter', 0);
9
+ * ```
10
+ *
11
+ * @param id - Unique storage key for this piece of state
12
+ * @param initialValue - Default value when no persisted state exists
13
+ * @param options - Optional: `storage` ('session' | 'local'), defaults to 'session'
14
+ */
15
+ export declare function usePersistentState<T>(id: string, initialValue: T, options?: {
16
+ storage?: 'session' | 'local';
17
+ }): [T, (value: T | ((prev: T) => T)) => void, () => void];
@@ -0,0 +1,73 @@
1
+ import { LayoutDiscovery } from './layout-discovery.ts';
2
+ import { LayoutMatcher } from './layout-matcher.ts';
3
+ import { LayoutComposer } from './layout-composer.ts';
4
+ import { LayoutDataLoader } from './layout-data-loader.ts';
5
+ import { LayoutCacheManager } from './layout-cache-manager.ts';
6
+ import type { LayoutContext, LayoutDiscoveryOptions, ResolvedLayout, PageModule } from './layout-types.ts';
7
+ interface IEnhancedLayoutResolver {
8
+ resolveAndRender(routePath: string, pageModule: PageModule, context: LayoutContext): Promise<ResolvedLayout>;
9
+ getCachedResolution(routePath: string): ResolvedLayout | null;
10
+ clearCache(): void;
11
+ setCaching(enabled: boolean): void;
12
+ }
13
+ /**
14
+ * Enhanced Layout Resolver Options
15
+ */
16
+ export interface EnhancedLayoutResolverOptions extends LayoutDiscoveryOptions {
17
+ enableCaching?: boolean;
18
+ cacheTTL?: number;
19
+ maxCacheSize?: number;
20
+ enableMetrics?: boolean;
21
+ enableDebugInfo?: boolean;
22
+ }
23
+ /**
24
+ * Simplified Enhanced Layout Resolver
25
+ * Handles: discovery → conditional filtering → composition → data loading → rendering
26
+ */
27
+ export declare class EnhancedLayoutResolver implements IEnhancedLayoutResolver {
28
+ private readonly layoutDiscovery;
29
+ private readonly layoutMatcher;
30
+ private readonly layoutComposer;
31
+ private readonly layoutDataLoader;
32
+ private readonly cache;
33
+ private readonly cacheManager;
34
+ private readonly options;
35
+ constructor(options: EnhancedLayoutResolverOptions);
36
+ /**
37
+ * Resolve layout chain for a route
38
+ */
39
+ resolveLayouts(routePath: string, pageModule: PageModule, context: LayoutContext): Promise<ResolvedLayout>;
40
+ /**
41
+ * Resolve and render complete layout chain
42
+ */
43
+ resolveAndRender(routePath: string, pageModule: PageModule, context: LayoutContext): Promise<ResolvedLayout>;
44
+ private renderLayoutsToString;
45
+ getCachedResolution(cacheKey: string): ResolvedLayout | null;
46
+ invalidateCacheByFilePath(filePath: string): number;
47
+ clearCache(): void;
48
+ setCaching(enabled: boolean): void;
49
+ private generateCacheKey;
50
+ getResolverStats(): {
51
+ cacheSize: number;
52
+ cacheHitRate: number;
53
+ totalResolutions: number;
54
+ averageResolutionTime: number;
55
+ errorCount: number;
56
+ cacheStats: ReturnType<LayoutCacheManager['getStats']>;
57
+ discoveryStats: ReturnType<LayoutDiscovery['getCacheStats']>;
58
+ };
59
+ updateOptions(options: Partial<EnhancedLayoutResolverOptions>): void;
60
+ getOptions(): Required<EnhancedLayoutResolverOptions>;
61
+ getLayoutDiscovery(): LayoutDiscovery;
62
+ getLayoutMatcher(): LayoutMatcher;
63
+ getLayoutComposer(): LayoutComposer;
64
+ getLayoutDataLoader(): LayoutDataLoader;
65
+ getCacheManager(): LayoutCacheManager;
66
+ destroy(): void;
67
+ }
68
+ export declare function createEnhancedLayoutResolver(options: EnhancedLayoutResolverOptions): EnhancedLayoutResolver;
69
+ export declare const EnhancedLayoutResolverUtils: {
70
+ createBasicConfig(baseDirectory: string, developmentMode?: boolean): EnhancedLayoutResolverOptions;
71
+ createProductionConfig(baseDirectory: string): EnhancedLayoutResolverOptions;
72
+ };
73
+ export {};
@@ -0,0 +1,66 @@
1
+ import type { LayoutHandler, ResolvedLayout, LayoutData } from './layout-types.ts';
2
+ export interface CacheEntry<T> {
3
+ value: T;
4
+ timestamp: number;
5
+ ttl: number;
6
+ accessCount: number;
7
+ lastAccessed: number;
8
+ }
9
+ export interface CacheStats {
10
+ hits: number;
11
+ misses: number;
12
+ evictions: number;
13
+ totalEntries: number;
14
+ memoryUsage: number;
15
+ }
16
+ export interface CacheConfig {
17
+ defaultTtl: number;
18
+ maxEntries: number;
19
+ cleanupInterval: number;
20
+ enableStats: boolean;
21
+ enableCompression?: boolean;
22
+ intelligentInvalidation?: boolean;
23
+ preloadThreshold?: number;
24
+ }
25
+ export declare class LayoutCacheManager {
26
+ private readonly config;
27
+ private readonly resolvedLayouts;
28
+ private readonly layoutHandlers;
29
+ private readonly layoutData;
30
+ private readonly dependencyGraph;
31
+ private readonly accessOrder;
32
+ private accessCounter;
33
+ private stats;
34
+ private cleanupTimer?;
35
+ constructor(config: CacheConfig);
36
+ setResolvedLayout(key: string, layout: ResolvedLayout, ttl?: number): void;
37
+ getResolvedLayout(key: string): ResolvedLayout | null;
38
+ setLayoutHandler(key: string, handler: LayoutHandler, ttl?: number): void;
39
+ getLayoutHandler(key: string): LayoutHandler | null;
40
+ setLayoutData(key: string, data: LayoutData, ttl?: number): void;
41
+ getLayoutData(key: string): LayoutData | null;
42
+ invalidateResolvedLayout(key: string): boolean;
43
+ invalidateLayoutHandler(key: string): boolean;
44
+ invalidateLayoutData(key: string): boolean;
45
+ invalidateByFilePath(filePath: string): number;
46
+ addDependency(key: string, dependsOn: string): void;
47
+ removeDependency(key: string, dependsOn: string): void;
48
+ invalidateByPattern(pattern: RegExp): number;
49
+ clear(): void;
50
+ getStats(): CacheStats;
51
+ getHitRate(): number;
52
+ private isExpired;
53
+ private invalidateDependents;
54
+ private normalizePath;
55
+ private isKeyAffectedByPath;
56
+ private updateAccessOrder;
57
+ private updateStats;
58
+ private estimateMemoryUsage;
59
+ private enforceMaxEntries;
60
+ private startCleanupTimer;
61
+ private cleanup;
62
+ private resetStats;
63
+ destroy(): void;
64
+ }
65
+ export declare const defaultCacheConfig: CacheConfig;
66
+ export declare const layoutCache: LayoutCacheManager;
@@ -0,0 +1,63 @@
1
+ import { LayoutDiscovery } from './layout-discovery.ts';
2
+ import type { LayoutHandler, LayoutConfig, LayoutDiscoveryOptions, PageModule } from './layout-types.ts';
3
+ /**
4
+ * Layout composition control system that handles page-level layout customization.
5
+ * Provides support for skipLayouts, replaceLayout, onlyLayouts, and customLayout configurations.
6
+ *
7
+ * Requirements: 5.1, 5.2, 5.3, 5.4, 5.5
8
+ */
9
+ export declare class LayoutComposer {
10
+ private readonly layoutDiscovery;
11
+ private readonly customLayoutCache;
12
+ private developmentMode;
13
+ constructor(options: LayoutDiscoveryOptions);
14
+ /**
15
+ * Resolves layouts for a route with page-level configuration applied
16
+ * Requirements: 5.1, 5.2, 5.3, 5.4, 5.5
17
+ */
18
+ resolveLayouts(routePath: string, pageModule: PageModule): Promise<LayoutHandler[]>;
19
+ /**
20
+ * Applies layout configuration to a layout chain
21
+ * Requirements: 5.2, 5.3, 5.4, 5.5
22
+ */
23
+ applyConfiguration(layouts: LayoutHandler[], config: LayoutConfig): Promise<LayoutHandler[]>;
24
+ /** Handles replaceLayout: returns only custom layout or empty array */
25
+ private handleReplaceLayout;
26
+ /** Checks if a layout matches a glob or exact path pattern */
27
+ private matchesLayoutPattern;
28
+ /** Removes layouts matching skipLayouts patterns */
29
+ private applySkipLayouts;
30
+ /** Keeps only layouts matching onlyLayouts patterns */
31
+ private applyOnlyLayouts;
32
+ /** Adds a custom layout to the layout chain */
33
+ private addCustomLayout;
34
+ /**
35
+ * Resolves a layout path to an absolute path, trying multiple resolution strategies.
36
+ */
37
+ private resolveLayoutPath;
38
+ /** Loads a custom layout from a file path */
39
+ private loadCustomLayout;
40
+ /** Validates layout configuration */
41
+ validateLayoutConfig(config: LayoutConfig): {
42
+ valid: boolean;
43
+ errors: string[];
44
+ };
45
+ /** Gets composition statistics for debugging */
46
+ getCompositionStats(): {
47
+ customLayoutCacheSize: number;
48
+ discoveryStats: {
49
+ layoutCount: number;
50
+ routeCacheCount: number;
51
+ };
52
+ };
53
+ /** Clears all caches */
54
+ clearCache(): void;
55
+ /** Clears custom layout cache */
56
+ clearCustomLayoutCache(): void;
57
+ /** Gets the underlying layout discovery instance */
58
+ getLayoutDiscovery(): LayoutDiscovery;
59
+ /** Sets development mode */
60
+ setDevelopmentMode(enabled: boolean): void;
61
+ /** Gets development mode status */
62
+ isDevelopmentMode(): boolean;
63
+ }
@@ -0,0 +1,146 @@
1
+ import type { LayoutContext, LayoutData, LayoutHandler, LayoutErrorInfo } from './layout-types.ts';
2
+ /**
3
+ * Layout data loading error with context information
4
+ */
5
+ export declare class LayoutDataLoadingError extends Error {
6
+ readonly layoutPath: string;
7
+ readonly originalError?: Error;
8
+ constructor(message: string, layoutPath: string, originalError?: Error);
9
+ }
10
+ /**
11
+ * Result of a layout data loading operation
12
+ */
13
+ export interface LayoutDataLoadingResult {
14
+ success: boolean;
15
+ data: LayoutData;
16
+ error?: LayoutDataLoadingError;
17
+ loadingTime: number;
18
+ layoutPath: string;
19
+ }
20
+ /**
21
+ * Options for layout data loading
22
+ */
23
+ export interface LayoutDataLoadingOptions {
24
+ /**
25
+ * Maximum time to wait for data loading (in milliseconds)
26
+ */
27
+ timeout?: number;
28
+ /**
29
+ * Whether to enable parallel loading of multiple loaders
30
+ */
31
+ enableParallelLoading?: boolean;
32
+ /**
33
+ * Whether to continue loading other loaders if one fails
34
+ */
35
+ continueOnError?: boolean;
36
+ /**
37
+ * Development mode flag for enhanced error reporting
38
+ */
39
+ developmentMode?: boolean;
40
+ /**
41
+ * Maximum number of retry attempts for failed loaders
42
+ */
43
+ maxRetries?: number;
44
+ /**
45
+ * Delay between retry attempts (in milliseconds)
46
+ */
47
+ retryDelay?: number;
48
+ }
49
+ /**
50
+ * Layout data loader execution system
51
+ * Handles parallel data loading for multiple layout loaders in the chain
52
+ *
53
+ * Requirements: 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
54
+ */
55
+ export declare class LayoutDataLoader {
56
+ private readonly options;
57
+ constructor(options?: LayoutDataLoadingOptions);
58
+ /**
59
+ * Loads data for all layout handlers in the chain
60
+ * Requirements: 2.1, 2.2, 2.3, 2.4
61
+ */
62
+ loadLayoutData(layoutHandlers: LayoutHandler[], context: LayoutContext): Promise<LayoutDataLoadingResult[]>;
63
+ /**
64
+ * Loads data for multiple loaders in parallel with optimized batching
65
+ * Requirements: 2.2, 2.3, 2.4
66
+ */
67
+ private loadDataInParallel;
68
+ /**
69
+ * Loads data for multiple loaders sequentially
70
+ * Requirements: 2.2, 2.3, 2.4
71
+ */
72
+ private loadDataSequentially;
73
+ /**
74
+ * Loads data for a single layout handler with retry logic
75
+ * Requirements: 2.1, 2.2, 2.5, 2.6
76
+ */
77
+ private loadSingleLayoutData;
78
+ /**
79
+ * Executes a layout loader with timeout protection
80
+ * Requirements: 2.1, 2.5
81
+ */
82
+ private executeLoaderWithTimeout;
83
+ /**
84
+ * Creates enhanced layout context with parent data
85
+ * Requirements: 2.4, 2.6
86
+ */
87
+ createEnhancedContext(baseContext: LayoutContext, parentData: LayoutData[]): LayoutContext;
88
+ /**
89
+ * Processes layout data loading results and creates data array for components
90
+ * Requirements: 2.3, 2.4, 2.6
91
+ */
92
+ processLoadingResults(results: LayoutDataLoadingResult[], layoutHandlers: LayoutHandler[]): {
93
+ data: LayoutData[];
94
+ errors: LayoutErrorInfo[];
95
+ };
96
+ /**
97
+ * Creates fallback data for failed loaders
98
+ * Requirements: 2.5, 2.6
99
+ */
100
+ createFallbackData(layoutPath: string, error: LayoutDataLoadingError): LayoutData;
101
+ /**
102
+ * Validates layout data structure
103
+ * Requirements: 2.1, 2.3
104
+ */
105
+ validateLayoutData(data: unknown, layoutPath: string): LayoutData;
106
+ /**
107
+ * Utility method to create a delay
108
+ */
109
+ private delay;
110
+ /**
111
+ * Preload data for layouts that are likely to be needed soon
112
+ * Requirements: 2.1, 2.2
113
+ */
114
+ preloadLayoutData(layoutHandlers: LayoutHandler[], context: LayoutContext, priority?: 'high' | 'medium' | 'low'): Promise<void>;
115
+ /**
116
+ * Gets current loading options
117
+ */
118
+ getOptions(): Required<LayoutDataLoadingOptions>;
119
+ /**
120
+ * Updates loading options
121
+ */
122
+ updateOptions(options: Partial<LayoutDataLoadingOptions>): void;
123
+ }
124
+ /**
125
+ * Default layout data loader instance
126
+ */
127
+ export declare const defaultLayoutDataLoader: LayoutDataLoader;
128
+ /**
129
+ * Utility function to create a layout data loader with specific options
130
+ */
131
+ export declare function createLayoutDataLoader(options?: LayoutDataLoadingOptions): LayoutDataLoader;
132
+ /**
133
+ * Utility function to load data for a single layout
134
+ * Requirements: 2.1, 2.2
135
+ */
136
+ export declare function loadSingleLayoutData(handler: LayoutHandler, context: LayoutContext, options?: LayoutDataLoadingOptions): Promise<LayoutDataLoadingResult>;
137
+ /**
138
+ * Utility function to merge layout data from multiple sources
139
+ * Requirements: 2.4, 2.6
140
+ */
141
+ export declare function mergeLayoutData(...dataSources: LayoutData[]): LayoutData;
142
+ /**
143
+ * Utility function to extract parent data from context
144
+ * Requirements: 2.4, 2.6
145
+ */
146
+ export declare function getParentLayoutData(context: LayoutContext): LayoutData[];
@@ -0,0 +1,51 @@
1
+ import type { LayoutRoute, LayoutHandler, LayoutDiscoveryOptions, LayoutContext, LayoutData, LayoutErrorInfo } from './layout-types.ts';
2
+ export type { LayoutDiscoveryOptions } from './layout-types.ts';
3
+ /**
4
+ * Simplified Layout Discovery System
5
+ *
6
+ * Looks for _layout.tsx files in the path hierarchy from root to the current route.
7
+ *
8
+ * For route /admin/users/123:
9
+ * - Check src/layouts/_layout.tsx (root layout)
10
+ * - Check src/layouts/admin/_layout.tsx
11
+ * - Check src/layouts/admin/users/_layout.tsx
12
+ */
13
+ export declare class LayoutDiscovery {
14
+ private readonly layoutCache;
15
+ private readonly routeCache;
16
+ private readonly baseDirectory;
17
+ private readonly filePattern;
18
+ private readonly developmentMode;
19
+ constructor(options: LayoutDiscoveryOptions);
20
+ /**
21
+ * Discovers all layout files for a given route path by walking up the path hierarchy
22
+ */
23
+ discoverLayouts(routePath: string): Promise<LayoutRoute[]>;
24
+ /**
25
+ * Builds a complete layout chain for a URL
26
+ */
27
+ buildLayoutChain(url: URL): Promise<LayoutHandler[]>;
28
+ /**
29
+ * Builds layout chain with data loading
30
+ */
31
+ buildLayoutChainWithData(url: URL, context: LayoutContext): Promise<{
32
+ handlers: LayoutHandler[];
33
+ data: LayoutData[];
34
+ errors: LayoutErrorInfo[];
35
+ }>;
36
+ /**
37
+ * Loads layout handler from file
38
+ */
39
+ private loadLayout;
40
+ /** Clears all caches */
41
+ clearCache(): void;
42
+ /** Clears cache for a specific layout file */
43
+ clearLayoutCache(filePath: string): void;
44
+ /** Gets cache statistics (for debugging) */
45
+ getCacheStats(): {
46
+ layoutCount: number;
47
+ routeCacheCount: number;
48
+ };
49
+ /** Gets the current discovery options */
50
+ getOptions(): LayoutDiscoveryOptions;
51
+ }
@@ -0,0 +1,77 @@
1
+ import type { LayoutRule, RouteInfo } from './layout-types.ts';
2
+ /**
3
+ * Built-in layout rules for common scenarios
4
+ */
5
+ export declare class BuiltInLayoutRules {
6
+ /**
7
+ * Rule to skip HTML layouts for API routes
8
+ * Requirements: 4.1
9
+ */
10
+ static readonly API_ROUTES_SKIP_LAYOUTS: LayoutRule;
11
+ /**
12
+ * Rule to apply mobile-specific layouts for mobile user agents
13
+ * Requirements: 4.2
14
+ */
15
+ static readonly MOBILE_LAYOUT_DETECTION: LayoutRule;
16
+ /**
17
+ * Rule to skip layouts based on specific headers
18
+ * Requirements: 4.3
19
+ */
20
+ static readonly HEADER_BASED_SKIP: LayoutRule;
21
+ /**
22
+ * Rule to apply admin layouts only for admin routes
23
+ * Requirements: 4.3
24
+ */
25
+ static readonly ADMIN_LAYOUT_RESTRICTION: LayoutRule;
26
+ static getAllRules(): LayoutRule[];
27
+ }
28
+ /**
29
+ * Layout matcher class that handles conditional layout rendering based on rules
30
+ * Requirements: 4.1, 4.2, 4.3, 4.4, 4.5
31
+ */
32
+ export declare class LayoutMatcher {
33
+ private rules;
34
+ private readonly developmentMode;
35
+ constructor(options?: {
36
+ developmentMode?: boolean;
37
+ });
38
+ /**
39
+ * Add a new layout rule
40
+ * Requirements: 4.3
41
+ */
42
+ addRule(rule: LayoutRule): void;
43
+ /**
44
+ * Remove a layout rule
45
+ * Requirements: 4.3
46
+ */
47
+ removeRule(rule: LayoutRule): void;
48
+ /**
49
+ * Check if a layout should be applied based on all rules
50
+ * Requirements: 4.1, 4.2, 4.3, 4.4, 4.5
51
+ */
52
+ shouldApplyLayout(layoutPath: string, route: RouteInfo): boolean;
53
+ getRules(): LayoutRule[];
54
+ clearRules(): void;
55
+ private addBuiltInRules;
56
+ private sortRulesByPriority;
57
+ private getMatchingRules;
58
+ private resolveRuleConflicts;
59
+ private resolveEqualPriorityConflicts;
60
+ /**
61
+ * Create a custom rule
62
+ * Requirements: 4.3
63
+ */
64
+ static createCustomRule(matcher: (route: RouteInfo) => boolean, apply: boolean, priority?: number): LayoutRule;
65
+ static createPathRule(pathPattern: string | RegExp, apply: boolean, priority?: number): LayoutRule;
66
+ static createHeaderRule(headerName: string, headerValue: string | RegExp, apply: boolean, priority?: number): LayoutRule;
67
+ static createMethodRule(methods: string | string[], apply: boolean, priority?: number): LayoutRule;
68
+ getDebugInfo(layoutPath: string, route: RouteInfo): {
69
+ totalRules: number;
70
+ matchingRules: Array<{
71
+ priority: number;
72
+ apply: boolean;
73
+ }>;
74
+ finalDecision: boolean;
75
+ conflictResolution?: string;
76
+ };
77
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Shared layout type definitions for the core/layout module.
3
+ *
4
+ * These are pure TypeScript interfaces with NO zod dependency,
5
+ * intentionally kept separate from schemas/layout.ts to avoid
6
+ * importing zod at cold start time.
7
+ */
8
+ export type ComponentType<P = any> = ((props: P) => any) | (new (props: P) => any);
9
+ export interface LayoutContext {
10
+ request: Request;
11
+ params: Record<string, string>;
12
+ query: URLSearchParams;
13
+ state: Map<string, unknown>;
14
+ middlewareContext?: unknown;
15
+ }
16
+ export type LayoutData = Record<string, unknown>;
17
+ export type LayoutLoader = (ctx: LayoutContext) => Promise<LayoutData>;
18
+ export interface LayoutProps {
19
+ children: import('preact').ComponentChildren;
20
+ data: LayoutData;
21
+ frontmatter?: Record<string, unknown>;
22
+ route: {
23
+ path: string;
24
+ params: Record<string, string>;
25
+ query: URLSearchParams;
26
+ };
27
+ }
28
+ export interface LayoutHandler {
29
+ component: ComponentType<LayoutProps>;
30
+ loader?: LayoutLoader;
31
+ path: string;
32
+ priority: number;
33
+ }
34
+ export interface LayoutRoute {
35
+ pattern: URLPattern;
36
+ layoutPath: string;
37
+ priority: number;
38
+ type: 'root' | 'nested';
39
+ depth: number;
40
+ }
41
+ export interface LayoutDiscoveryOptions {
42
+ baseDirectory: string;
43
+ filePattern?: string;
44
+ excludeDirectories?: string[];
45
+ enableWatching?: boolean;
46
+ developmentMode?: boolean;
47
+ }
48
+ export interface LayoutConfig {
49
+ skipLayouts?: string[];
50
+ replaceLayout?: boolean;
51
+ onlyLayouts?: string[];
52
+ customLayout?: string;
53
+ }
54
+ export interface RouteInfo {
55
+ path: string;
56
+ params: Record<string, string>;
57
+ method: string;
58
+ headers: Headers;
59
+ }
60
+ export interface LayoutRule {
61
+ matches: (route: RouteInfo, layoutPath?: string) => boolean;
62
+ apply: boolean;
63
+ priority: number;
64
+ }
65
+ export interface LayoutErrorInfo {
66
+ layoutPath: string;
67
+ errorType: 'component' | 'loader' | 'rendering' | 'island';
68
+ timestamp: number;
69
+ componentStack?: string;
70
+ errorBoundary?: string;
71
+ }
72
+ export interface ResolvedLayout {
73
+ handlers: LayoutHandler[];
74
+ dataLoaders: LayoutLoader[];
75
+ errorBoundaries: unknown[];
76
+ streamingComponents: unknown[];
77
+ metadata: {
78
+ totalLayouts: number;
79
+ resolutionTime: number;
80
+ cacheHit: boolean;
81
+ };
82
+ }
83
+ export interface LayoutCache {
84
+ resolved: Map<string, ResolvedLayout>;
85
+ handlers: Map<string, LayoutHandler>;
86
+ data: Map<string, LayoutData>;
87
+ ttl: Map<string, number>;
88
+ }
89
+ export interface PageModule {
90
+ default: ComponentType<Record<string, unknown>>;
91
+ layoutConfig?: LayoutConfig;
92
+ loader?: LayoutLoader;
93
+ frontmatter?: Record<string, unknown>;
94
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Framework-aware module resolver for handling framework-specific path transformations
3
+ * and MIME type resolution during hydration and module serving.
4
+ */
5
+ export interface ModuleResolutionConfig {
6
+ framework: string;
7
+ baseUrl: string;
8
+ extensions: string[];
9
+ transformPath: (path: string) => string;
10
+ mimeType: string;
11
+ }
12
+ export interface ResolvedModule {
13
+ originalPath: string;
14
+ resolvedPath: string;
15
+ framework: string;
16
+ shouldTransform: boolean;
17
+ mimeType: string;
18
+ url: string;
19
+ }
20
+ export interface FrameworkModuleConfig {
21
+ extensions: string[];
22
+ hydrationExtension: string;
23
+ mimeType: string;
24
+ transformPath: (path: string, mode: 'development' | 'production') => string;
25
+ }
26
+ export declare class FrameworkModuleResolver {
27
+ private mode;
28
+ private baseUrl;
29
+ constructor(mode?: 'development' | 'production', baseUrl?: string);
30
+ /**
31
+ * Resolve a module path for a specific framework
32
+ */
33
+ resolveModule(originalPath: string, framework: string, options?: {
34
+ forHydration?: boolean;
35
+ baseUrl?: string;
36
+ }): ResolvedModule;
37
+ /**
38
+ * Check if a path needs transformation for the given framework
39
+ */
40
+ needsTransformation(path: string, framework: string): boolean;
41
+ /**
42
+ * Get the appropriate MIME type for a file path
43
+ */
44
+ getMimeType(path: string): string;
45
+ /**
46
+ * Generate a module URL for the given path
47
+ */
48
+ generateModuleUrl(path: string, baseUrl?: string): string;
49
+ /**
50
+ * Get supported frameworks
51
+ */
52
+ getSupportedFrameworks(): string[];
53
+ /**
54
+ * Get framework configuration
55
+ */
56
+ getFrameworkConfig(framework: string): FrameworkModuleConfig | undefined;
57
+ /**
58
+ * Check if a framework is supported
59
+ */
60
+ isFrameworkSupported(framework: string): boolean;
61
+ /**
62
+ * Get file extension from path
63
+ */
64
+ private getFileExtension;
65
+ /**
66
+ * Set the resolver mode (development/production)
67
+ */
68
+ setMode(mode: 'development' | 'production'): void;
69
+ /**
70
+ * Get current mode
71
+ */
72
+ getMode(): 'development' | 'production';
73
+ /**
74
+ * Set base URL for module resolution
75
+ */
76
+ setBaseUrl(baseUrl: string): void;
77
+ /**
78
+ * Get current base URL
79
+ */
80
+ getBaseUrl(): string;
81
+ }
82
+ /**
83
+ * Default instance for common usage
84
+ */
85
+ export declare const frameworkModuleResolver: FrameworkModuleResolver;