@useavalon/avalon 0.1.11 → 0.1.12
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 +54 -54
- package/dist/mod.js +1 -0
- package/dist/src/build/integration-bundler-plugin.js +1 -0
- package/dist/src/build/integration-config.js +1 -0
- package/dist/src/build/integration-detection-plugin.js +1 -0
- package/dist/src/build/integration-resolver-plugin.js +1 -0
- package/dist/src/build/island-manifest.js +1 -0
- package/dist/src/build/island-types-generator.js +5 -0
- package/dist/src/build/mdx-island-transform.js +2 -0
- package/dist/src/build/mdx-plugin.js +1 -0
- package/dist/src/build/page-island-transform.js +3 -0
- package/dist/src/build/prop-extractors/index.js +1 -0
- package/dist/src/build/prop-extractors/lit.js +1 -0
- package/dist/src/build/prop-extractors/qwik.js +1 -0
- package/dist/src/build/prop-extractors/solid.js +1 -0
- package/dist/src/build/prop-extractors/svelte.js +1 -0
- package/dist/src/build/prop-extractors/vue.js +1 -0
- package/dist/src/build/sidecar-file-manager.js +1 -0
- package/dist/src/build/sidecar-renderer.js +6 -0
- package/dist/src/client/adapters/index.js +1 -0
- package/dist/src/client/components.js +1 -0
- package/dist/src/client/css-hmr-handler.js +1 -0
- package/dist/src/client/framework-adapter.js +13 -0
- package/dist/src/client/hmr-coordinator.js +1 -0
- package/dist/src/client/hmr-error-overlay.js +214 -0
- package/dist/src/client/main.js +39 -0
- package/{src → dist/src}/client/types/framework-runtime.d.ts +68 -68
- package/{src → dist/src}/client/types/vite-hmr.d.ts +46 -46
- package/dist/src/client/types/vite-virtual-modules.d.ts +70 -0
- package/dist/src/components/Image.js +1 -0
- package/dist/src/components/IslandErrorBoundary.js +1 -0
- package/dist/src/components/LayoutDataErrorBoundary.js +1 -0
- package/dist/src/components/LayoutErrorBoundary.js +1 -0
- package/dist/src/components/PersistentIsland.js +1 -0
- package/dist/src/components/StreamingErrorBoundary.js +1 -0
- package/dist/src/components/StreamingLayout.js +29 -0
- package/dist/src/core/components/component-analyzer.js +1 -0
- package/dist/src/core/components/component-detection.js +5 -0
- package/dist/src/core/components/enhanced-framework-detector.js +1 -0
- package/dist/src/core/components/framework-registry.js +1 -0
- package/dist/src/core/content/mdx-processor.js +1 -0
- package/dist/src/core/integrations/index.js +1 -0
- package/dist/src/core/integrations/loader.js +1 -0
- package/dist/src/core/integrations/registry.js +1 -0
- package/dist/src/core/islands/island-persistence.js +1 -0
- package/dist/src/core/islands/island-state-serializer.js +1 -0
- package/dist/src/core/islands/persistent-island-context.js +1 -0
- package/dist/src/core/islands/use-persistent-state.js +1 -0
- package/dist/src/core/layout/enhanced-layout-resolver.js +1 -0
- package/dist/src/core/layout/layout-cache-manager.js +1 -0
- package/dist/src/core/layout/layout-composer.js +1 -0
- package/dist/src/core/layout/layout-data-loader.js +1 -0
- package/dist/src/core/layout/layout-discovery.js +1 -0
- package/dist/src/core/layout/layout-matcher.js +1 -0
- package/dist/src/core/layout/layout-types.js +1 -0
- package/dist/src/core/modules/framework-module-resolver.js +1 -0
- package/dist/src/islands/component-analysis.js +1 -0
- package/dist/src/islands/css-utils.js +17 -0
- package/dist/src/islands/discovery/index.js +1 -0
- package/dist/src/islands/discovery/registry.js +1 -0
- package/dist/src/islands/discovery/resolver.js +2 -0
- package/dist/src/islands/discovery/scanner.js +1 -0
- package/dist/src/islands/discovery/types.js +1 -0
- package/dist/src/islands/discovery/validator.js +18 -0
- package/dist/src/islands/discovery/watcher.js +1 -0
- package/dist/src/islands/framework-detection.js +1 -0
- package/dist/src/islands/integration-loader.js +1 -0
- package/dist/src/islands/island.js +1 -0
- package/dist/src/islands/render-cache.js +1 -0
- package/dist/src/islands/types.js +1 -0
- package/dist/src/islands/universal-css-collector.js +5 -0
- package/dist/src/islands/universal-head-collector.js +2 -0
- package/{src → dist/src}/layout-system.d.ts +592 -592
- package/dist/src/layout-system.js +1 -0
- package/dist/src/middleware/discovery.js +1 -0
- package/dist/src/middleware/executor.js +1 -0
- package/dist/src/middleware/index.js +1 -0
- package/dist/src/middleware/types.js +1 -0
- package/dist/src/nitro/build-config.js +1 -0
- package/dist/src/nitro/config.js +1 -0
- package/dist/src/nitro/error-handler.js +198 -0
- package/dist/src/nitro/index.js +1 -0
- package/dist/src/nitro/island-manifest.js +2 -0
- package/dist/src/nitro/middleware-adapter.js +1 -0
- package/dist/src/nitro/renderer.js +183 -0
- package/dist/src/nitro/route-discovery.js +1 -0
- package/dist/src/nitro/types.js +1 -0
- package/dist/src/render/collect-css.js +3 -0
- package/{src/render/error-pages.ts → dist/src/render/error-pages.js} +7 -38
- package/dist/src/render/isolated-ssr-renderer.js +1 -0
- package/dist/src/render/ssr.js +90 -0
- package/dist/src/schemas/api.js +1 -0
- package/dist/src/schemas/core.js +1 -0
- package/dist/src/schemas/index.js +1 -0
- package/dist/src/schemas/layout.js +1 -0
- package/dist/src/schemas/routing/index.js +1 -0
- package/dist/src/schemas/routing.js +1 -0
- package/dist/src/types/as-island.js +1 -0
- package/{src → dist/src}/types/image.d.ts +106 -106
- package/{src → dist/src}/types/index.d.ts +22 -22
- package/{src → dist/src}/types/island-jsx.d.ts +33 -33
- package/{src → dist/src}/types/island-prop.d.ts +20 -20
- package/dist/src/types/layout.js +1 -0
- package/{src → dist/src}/types/mdx.d.ts +6 -6
- package/dist/src/types/routing.js +1 -0
- package/dist/src/types/types.js +1 -0
- package/{src → dist/src}/types/urlpattern.d.ts +49 -49
- package/{src → dist/src}/types/vite-env.d.ts +11 -11
- package/dist/src/utils/dev-logger.js +12 -0
- package/dist/src/utils/fs.js +1 -0
- package/dist/src/vite-plugin/auto-discover.js +1 -0
- package/dist/src/vite-plugin/config.js +1 -0
- package/dist/src/vite-plugin/errors.js +1 -0
- package/dist/src/vite-plugin/image-optimization.js +45 -0
- package/dist/src/vite-plugin/integration-activator.js +1 -0
- package/dist/src/vite-plugin/island-sidecar-plugin.js +1 -0
- package/dist/src/vite-plugin/module-discovery.js +1 -0
- package/dist/src/vite-plugin/nitro-integration.js +42 -0
- package/dist/src/vite-plugin/plugin.js +1 -0
- package/dist/src/vite-plugin/types.js +1 -0
- package/dist/src/vite-plugin/validation.js +2 -0
- package/package.json +57 -26
- package/mod.ts +0 -302
- package/src/build/integration-bundler-plugin.ts +0 -116
- package/src/build/integration-config.ts +0 -168
- package/src/build/integration-detection-plugin.ts +0 -117
- package/src/build/integration-resolver-plugin.ts +0 -90
- package/src/build/island-manifest.ts +0 -269
- package/src/build/island-types-generator.ts +0 -476
- package/src/build/mdx-island-transform.ts +0 -464
- package/src/build/mdx-plugin.ts +0 -98
- package/src/build/page-island-transform.ts +0 -598
- package/src/build/prop-extractors/index.ts +0 -21
- package/src/build/prop-extractors/lit.ts +0 -140
- package/src/build/prop-extractors/qwik.ts +0 -16
- package/src/build/prop-extractors/solid.ts +0 -125
- package/src/build/prop-extractors/svelte.ts +0 -194
- package/src/build/prop-extractors/vue.ts +0 -111
- package/src/build/sidecar-file-manager.ts +0 -104
- package/src/build/sidecar-renderer.ts +0 -30
- package/src/client/adapters/index.js +0 -12
- package/src/client/adapters/index.ts +0 -13
- package/src/client/adapters/lit-adapter.js +0 -467
- package/src/client/adapters/lit-adapter.ts +0 -654
- package/src/client/adapters/preact-adapter.js +0 -223
- package/src/client/adapters/preact-adapter.ts +0 -331
- package/src/client/adapters/qwik-adapter.js +0 -259
- package/src/client/adapters/qwik-adapter.ts +0 -345
- package/src/client/adapters/react-adapter.js +0 -220
- package/src/client/adapters/react-adapter.ts +0 -353
- package/src/client/adapters/solid-adapter.js +0 -295
- package/src/client/adapters/solid-adapter.ts +0 -451
- package/src/client/adapters/svelte-adapter.js +0 -368
- package/src/client/adapters/svelte-adapter.ts +0 -524
- package/src/client/adapters/vue-adapter.js +0 -278
- package/src/client/adapters/vue-adapter.ts +0 -467
- package/src/client/components.js +0 -23
- package/src/client/components.ts +0 -35
- package/src/client/css-hmr-handler.js +0 -263
- package/src/client/css-hmr-handler.ts +0 -344
- package/src/client/framework-adapter.js +0 -283
- package/src/client/framework-adapter.ts +0 -462
- package/src/client/hmr-coordinator.js +0 -274
- package/src/client/hmr-coordinator.ts +0 -396
- package/src/client/hmr-error-overlay.js +0 -533
- package/src/client/main.js +0 -816
- package/src/client/types/vite-virtual-modules.d.ts +0 -60
- package/src/components/Image.tsx +0 -123
- package/src/components/IslandErrorBoundary.tsx +0 -145
- package/src/components/LayoutDataErrorBoundary.tsx +0 -141
- package/src/components/LayoutErrorBoundary.tsx +0 -127
- package/src/components/PersistentIsland.tsx +0 -52
- package/src/components/StreamingErrorBoundary.tsx +0 -233
- package/src/components/StreamingLayout.tsx +0 -538
- package/src/core/components/component-analyzer.ts +0 -192
- package/src/core/components/component-detection.ts +0 -508
- package/src/core/components/enhanced-framework-detector.ts +0 -500
- package/src/core/components/framework-registry.ts +0 -563
- package/src/core/content/mdx-processor.ts +0 -46
- package/src/core/integrations/index.ts +0 -19
- package/src/core/integrations/loader.ts +0 -125
- package/src/core/integrations/registry.ts +0 -175
- package/src/core/islands/island-persistence.ts +0 -325
- package/src/core/islands/island-state-serializer.ts +0 -258
- package/src/core/islands/persistent-island-context.tsx +0 -80
- package/src/core/islands/use-persistent-state.ts +0 -68
- package/src/core/layout/enhanced-layout-resolver.ts +0 -322
- package/src/core/layout/layout-cache-manager.ts +0 -485
- package/src/core/layout/layout-composer.ts +0 -357
- package/src/core/layout/layout-data-loader.ts +0 -516
- package/src/core/layout/layout-discovery.ts +0 -243
- package/src/core/layout/layout-matcher.ts +0 -299
- package/src/core/layout/layout-types.ts +0 -110
- package/src/core/modules/framework-module-resolver.ts +0 -273
- package/src/islands/component-analysis.ts +0 -213
- package/src/islands/css-utils.ts +0 -565
- package/src/islands/discovery/index.ts +0 -80
- package/src/islands/discovery/registry.ts +0 -340
- package/src/islands/discovery/resolver.ts +0 -477
- package/src/islands/discovery/scanner.ts +0 -386
- package/src/islands/discovery/types.ts +0 -117
- package/src/islands/discovery/validator.ts +0 -544
- package/src/islands/discovery/watcher.ts +0 -368
- package/src/islands/framework-detection.ts +0 -428
- package/src/islands/integration-loader.ts +0 -490
- package/src/islands/island.tsx +0 -565
- package/src/islands/render-cache.ts +0 -550
- package/src/islands/types.ts +0 -80
- package/src/islands/universal-css-collector.ts +0 -157
- package/src/islands/universal-head-collector.ts +0 -137
- package/src/layout-system.ts +0 -218
- package/src/middleware/discovery.ts +0 -268
- package/src/middleware/executor.ts +0 -315
- package/src/middleware/index.ts +0 -76
- package/src/middleware/types.ts +0 -99
- package/src/nitro/build-config.ts +0 -576
- package/src/nitro/config.ts +0 -483
- package/src/nitro/error-handler.ts +0 -636
- package/src/nitro/index.ts +0 -173
- package/src/nitro/island-manifest.ts +0 -584
- package/src/nitro/middleware-adapter.ts +0 -260
- package/src/nitro/renderer.ts +0 -1471
- package/src/nitro/route-discovery.ts +0 -439
- package/src/nitro/types.ts +0 -321
- package/src/render/collect-css.ts +0 -198
- package/src/render/isolated-ssr-renderer.ts +0 -654
- package/src/render/ssr.ts +0 -1030
- package/src/schemas/api.ts +0 -30
- package/src/schemas/core.ts +0 -64
- package/src/schemas/index.ts +0 -212
- package/src/schemas/layout.ts +0 -279
- package/src/schemas/routing/index.ts +0 -38
- package/src/schemas/routing.ts +0 -376
- package/src/types/as-island.ts +0 -20
- package/src/types/layout.ts +0 -285
- package/src/types/routing.ts +0 -555
- package/src/types/types.ts +0 -5
- package/src/utils/dev-logger.ts +0 -299
- package/src/utils/fs.ts +0 -151
- package/src/vite-plugin/auto-discover.ts +0 -551
- package/src/vite-plugin/config.ts +0 -266
- package/src/vite-plugin/errors.ts +0 -127
- package/src/vite-plugin/image-optimization.ts +0 -156
- package/src/vite-plugin/integration-activator.ts +0 -126
- package/src/vite-plugin/island-sidecar-plugin.ts +0 -176
- package/src/vite-plugin/module-discovery.ts +0 -189
- package/src/vite-plugin/nitro-integration.ts +0 -1354
- package/src/vite-plugin/plugin.ts +0 -409
- package/src/vite-plugin/types.ts +0 -327
- package/src/vite-plugin/validation.ts +0 -228
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type declarations for framework runtime imports
|
|
3
|
-
*
|
|
4
|
-
* These are dynamic imports that are resolved by Vite at runtime in the browser.
|
|
5
|
-
* The actual packages are provided by the user's project dependencies.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
declare module 'react' {
|
|
9
|
-
export function createElement<P = Record<string, unknown>>(
|
|
10
|
-
component: unknown,
|
|
11
|
-
props: P | null,
|
|
12
|
-
...children: unknown[]
|
|
13
|
-
): unknown;
|
|
14
|
-
export const version: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
declare module 'react-dom/client' {
|
|
18
|
-
export interface Root {
|
|
19
|
-
render(element: unknown): void;
|
|
20
|
-
unmount(): void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function hydrateRoot(
|
|
24
|
-
container: HTMLElement,
|
|
25
|
-
element: unknown,
|
|
26
|
-
options?: {
|
|
27
|
-
onRecoverableError?: (error: Error) => void;
|
|
28
|
-
}
|
|
29
|
-
): Root;
|
|
30
|
-
|
|
31
|
-
export function createRoot(container: HTMLElement): Root;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
declare module 'vue' {
|
|
35
|
-
export interface App {
|
|
36
|
-
mount(rootContainer: HTMLElement | string, isHydrate?: boolean): unknown;
|
|
37
|
-
unmount(): void;
|
|
38
|
-
use(plugin: unknown, ...options: unknown[]): App;
|
|
39
|
-
component(name: string, component: unknown): App;
|
|
40
|
-
directive(name: string, directive: unknown): App;
|
|
41
|
-
provide(key: string | symbol, value: unknown): App;
|
|
42
|
-
config: {
|
|
43
|
-
errorHandler?: (err: Error, instance: unknown, info: string) => void;
|
|
44
|
-
warnHandler?: (msg: string, instance: unknown, trace: string) => void;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function createApp(rootComponent: unknown, rootProps?: Record<string, unknown>): App;
|
|
49
|
-
export const version: string;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
declare module 'svelte' {
|
|
54
|
-
export interface SvelteComponent {
|
|
55
|
-
new (options: {
|
|
56
|
-
target: HTMLElement;
|
|
57
|
-
props?: Record<string, unknown>;
|
|
58
|
-
hydrate?: boolean;
|
|
59
|
-
intro?: boolean;
|
|
60
|
-
anchor?: Element | null;
|
|
61
|
-
context?: Map<unknown, unknown>;
|
|
62
|
-
}): {
|
|
63
|
-
$set(props: Record<string, unknown>): void;
|
|
64
|
-
$destroy(): void;
|
|
65
|
-
$on?(event: string, handler: (...args: unknown[]) => void): () => void;
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for framework runtime imports
|
|
3
|
+
*
|
|
4
|
+
* These are dynamic imports that are resolved by Vite at runtime in the browser.
|
|
5
|
+
* The actual packages are provided by the user's project dependencies.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare module 'react' {
|
|
9
|
+
export function createElement<P = Record<string, unknown>>(
|
|
10
|
+
component: unknown,
|
|
11
|
+
props: P | null,
|
|
12
|
+
...children: unknown[]
|
|
13
|
+
): unknown;
|
|
14
|
+
export const version: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare module 'react-dom/client' {
|
|
18
|
+
export interface Root {
|
|
19
|
+
render(element: unknown): void;
|
|
20
|
+
unmount(): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function hydrateRoot(
|
|
24
|
+
container: HTMLElement,
|
|
25
|
+
element: unknown,
|
|
26
|
+
options?: {
|
|
27
|
+
onRecoverableError?: (error: Error) => void;
|
|
28
|
+
}
|
|
29
|
+
): Root;
|
|
30
|
+
|
|
31
|
+
export function createRoot(container: HTMLElement): Root;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module 'vue' {
|
|
35
|
+
export interface App {
|
|
36
|
+
mount(rootContainer: HTMLElement | string, isHydrate?: boolean): unknown;
|
|
37
|
+
unmount(): void;
|
|
38
|
+
use(plugin: unknown, ...options: unknown[]): App;
|
|
39
|
+
component(name: string, component: unknown): App;
|
|
40
|
+
directive(name: string, directive: unknown): App;
|
|
41
|
+
provide(key: string | symbol, value: unknown): App;
|
|
42
|
+
config: {
|
|
43
|
+
errorHandler?: (err: Error, instance: unknown, info: string) => void;
|
|
44
|
+
warnHandler?: (msg: string, instance: unknown, trace: string) => void;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createApp(rootComponent: unknown, rootProps?: Record<string, unknown>): App;
|
|
49
|
+
export const version: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
declare module 'svelte' {
|
|
54
|
+
export interface SvelteComponent {
|
|
55
|
+
new (options: {
|
|
56
|
+
target: HTMLElement;
|
|
57
|
+
props?: Record<string, unknown>;
|
|
58
|
+
hydrate?: boolean;
|
|
59
|
+
intro?: boolean;
|
|
60
|
+
anchor?: Element | null;
|
|
61
|
+
context?: Map<unknown, unknown>;
|
|
62
|
+
}): {
|
|
63
|
+
$set(props: Record<string, unknown>): void;
|
|
64
|
+
$destroy(): void;
|
|
65
|
+
$on?(event: string, handler: (...args: unknown[]) => void): () => void;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definitions for Vite HMR API
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
declare module 'vite/types/hmrPayload' {
|
|
6
|
-
export interface HMRPayload {
|
|
7
|
-
type: 'update' | 'full-reload' | 'prune' | 'error' | 'connected' | 'custom';
|
|
8
|
-
updates?: Update[];
|
|
9
|
-
timestamp?: number;
|
|
10
|
-
path?: string;
|
|
11
|
-
err?: Error;
|
|
12
|
-
data?: unknown;
|
|
13
|
-
event?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface Update {
|
|
17
|
-
type: 'js-update' | 'css-update';
|
|
18
|
-
path: string;
|
|
19
|
-
acceptedPath: string;
|
|
20
|
-
timestamp: number;
|
|
21
|
-
explicitImportRequired?: boolean;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
declare global {
|
|
26
|
-
interface ImportMeta {
|
|
27
|
-
hot?: {
|
|
28
|
-
accept(): void;
|
|
29
|
-
accept(cb: (mod: unknown) => void): void;
|
|
30
|
-
accept(dep: string, cb: (mod: unknown) => void): void;
|
|
31
|
-
accept(deps: readonly string[], cb: (mods: unknown[]) => void): void;
|
|
32
|
-
|
|
33
|
-
dispose(cb: (data: unknown) => void): void;
|
|
34
|
-
decline(): void;
|
|
35
|
-
invalidate(): void;
|
|
36
|
-
|
|
37
|
-
on(event: string, cb: (payload: unknown) => void): void;
|
|
38
|
-
off(event: string, cb: (payload: unknown) => void): void;
|
|
39
|
-
send(event: string, data?: unknown): void;
|
|
40
|
-
|
|
41
|
-
data: unknown;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export {};
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for Vite HMR API
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
declare module 'vite/types/hmrPayload' {
|
|
6
|
+
export interface HMRPayload {
|
|
7
|
+
type: 'update' | 'full-reload' | 'prune' | 'error' | 'connected' | 'custom';
|
|
8
|
+
updates?: Update[];
|
|
9
|
+
timestamp?: number;
|
|
10
|
+
path?: string;
|
|
11
|
+
err?: Error;
|
|
12
|
+
data?: unknown;
|
|
13
|
+
event?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Update {
|
|
17
|
+
type: 'js-update' | 'css-update';
|
|
18
|
+
path: string;
|
|
19
|
+
acceptedPath: string;
|
|
20
|
+
timestamp: number;
|
|
21
|
+
explicitImportRequired?: boolean;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare global {
|
|
26
|
+
interface ImportMeta {
|
|
27
|
+
hot?: {
|
|
28
|
+
accept(): void;
|
|
29
|
+
accept(cb: (mod: unknown) => void): void;
|
|
30
|
+
accept(dep: string, cb: (mod: unknown) => void): void;
|
|
31
|
+
accept(deps: readonly string[], cb: (mods: unknown[]) => void): void;
|
|
32
|
+
|
|
33
|
+
dispose(cb: (data: unknown) => void): void;
|
|
34
|
+
decline(): void;
|
|
35
|
+
invalidate(): void;
|
|
36
|
+
|
|
37
|
+
on(event: string, cb: (payload: unknown) => void): void;
|
|
38
|
+
off(event: string, cb: (payload: unknown) => void): void;
|
|
39
|
+
send(event: string, data?: unknown): void;
|
|
40
|
+
|
|
41
|
+
data: unknown;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for Vite virtual modules
|
|
3
|
+
*
|
|
4
|
+
* These modules are resolved by Vite at runtime in the browser.
|
|
5
|
+
* They don't exist as actual files but are provided by Vite's plugin system.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare module '/@useavalon/preact/client' {
|
|
9
|
+
export function hydrate(container: Element, component: unknown, props?: Record<string, unknown>): void;
|
|
10
|
+
export function getHydrationScript(): string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare module '/@useavalon/react/client' {
|
|
14
|
+
export function hydrate(container: Element, component: unknown, props?: Record<string, unknown>): void;
|
|
15
|
+
export function getHydrationScript(): string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare module '/@useavalon/vue/client' {
|
|
19
|
+
export function hydrate(container: Element, component: unknown, props?: Record<string, unknown>): void;
|
|
20
|
+
export function getHydrationScript(): string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare module '/@useavalon/svelte/client' {
|
|
24
|
+
export function hydrate(container: Element, component: unknown, props?: Record<string, unknown>): void;
|
|
25
|
+
export function getHydrationScript(): string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare module '/@useavalon/solid/client' {
|
|
29
|
+
export function hydrate(container: Element, component: unknown, props?: Record<string, unknown>): void;
|
|
30
|
+
export function getHydrationScript(): string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare module '/@useavalon/lit/client' {
|
|
34
|
+
export function hydrate(container: Element, component: unknown, props?: Record<string, unknown>): void;
|
|
35
|
+
export function getHydrationScript(): string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
declare module '/@useavalon/qwik/client' {
|
|
39
|
+
export function hydrate(container: Element, component: unknown, props?: Record<string, unknown>): void;
|
|
40
|
+
export function getHydrationScript(): string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// HMR adapter virtual modules
|
|
44
|
+
declare module '/@useavalon/react/client/hmr' {
|
|
45
|
+
export { reactAdapter } from '@useavalon/react/client/hmr';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
declare module '/@useavalon/preact/client/hmr' {
|
|
49
|
+
export { preactAdapter } from '@useavalon/preact/client/hmr';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare module '/@useavalon/vue/client/hmr' {
|
|
53
|
+
export { vueAdapter } from '@useavalon/vue/client/hmr';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare module '/@useavalon/svelte/client/hmr' {
|
|
57
|
+
export { svelteAdapter } from '@useavalon/svelte/client/hmr';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
declare module '/@useavalon/solid/client/hmr' {
|
|
61
|
+
export { solidAdapter } from '@useavalon/solid/client/hmr';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare module '/@useavalon/lit/client/hmr' {
|
|
65
|
+
export { litAdapter } from '@useavalon/lit/client/hmr';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
declare module '/@useavalon/qwik/client/hmr' {
|
|
69
|
+
export { qwikAdapter } from '@useavalon/qwik/client/hmr';
|
|
70
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";function t(e){return/\s\d+w/.test(e)}export function Image({src:n,alt:r,sizes:i,loading:a=`lazy`,decoding:o=`async`,width:s,height:c,className:l,style:u}){let d,f,p,m;return typeof n==`object`&&n?(d=n.src,f=n.srcset,p=n.width,m=n.height):typeof n==`string`&&(t(n)?(f=n,d=n.split(`,`)[0]?.trim().split(` `)[0]):d=n),e(`img`,{src:d,srcSet:f,sizes:i,alt:r,loading:a,decoding:o,width:s??p,height:c??m,className:l,style:u})}export default Image;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Component as e}from"preact";import{jsx as t,jsxs as n}from"react/jsx-runtime";export class IslandErrorBoundary extends e{constructor(e){super(e),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){let n={layoutPath:`island:${this.props.islandId}`,errorType:`island`,timestamp:Date.now(),componentStack:t.componentStack,errorBoundary:`IslandErrorBoundary`};if(this.setState({errorInfo:n}),this.props.onError&&this.props.onError(e,n),typeof Deno<`u`&&Deno.env.get(`NODE_ENV`)===`development`&&console.error(`Island Error [${this.props.islandId}]:`,e),!this.props.isolateError)throw e}handleRemoveIsland=()=>{let e=document.querySelector(`[data-island-id="${this.props.islandId}"]`);e&&e.remove()};handleReloadIsland=()=>{this.setState({hasError:!1,error:null,errorInfo:null})};renderFallback(){let{error:e}=this.state,{fallback:r,islandId:i}=this.props;if(r&&e)return r(e,i);let a=typeof Deno<`u`&&Deno.env.get(`NODE_ENV`)===`development`;return t(`div`,{class:`island-error-boundary`,"data-island-error":i,children:n(`div`,{class:`island-error-container`,children:[n(`div`,{class:`island-error-header`,children:[t(`span`,{class:`island-error-icon`,children:`⚠️`}),t(`span`,{class:`island-error-title`,children:`Island Error`})]}),n(`p`,{class:`island-error-message`,children:[`An error occurred in island "`,i,`". The rest of the page should work normally.`]}),n(`div`,{class:`island-error-actions`,children:[t(`button`,{onClick:this.handleReloadIsland,class:`island-reload-button`,children:`Reload Island`}),t(`button`,{onClick:this.handleRemoveIsland,class:`island-remove-button`,children:`Remove Island`})]}),a&&e&&n(`details`,{class:`island-error-details`,children:[t(`summary`,{children:`Error Details (Development)`}),n(`div`,{class:`island-error-info`,children:[n(`p`,{children:[t(`strong`,{children:`Island ID:`}),` `,i]}),n(`p`,{children:[t(`strong`,{children:`Error:`}),` `,e.message]})]}),t(`pre`,{class:`island-error-stack`,children:e.stack})]})]})})}render(){return this.state.hasError?this.renderFallback():this.props.children}}export function withIslandErrorBoundary(e,n,i){return function(a){return t(IslandErrorBoundary,{islandId:n,fallback:i?.fallback,isolateError:i?.isolateError??!0,onError:i?.onError,children:t(e,{...a})})}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Component as e}from"preact";import{jsx as t,jsxs as n}from"react/jsx-runtime";export class LayoutDataErrorBoundary extends e{maxRetries=3;constructor(e){super(e),this.state={hasError:!1,error:null,errorInfo:null,retryCount:0,isRetrying:!1,fallbackData:e.fallbackData||null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){let n={layoutPath:this.props.layoutPath,errorType:`loader`,timestamp:Date.now(),componentStack:t.componentStack,errorBoundary:`LayoutDataErrorBoundary`};this.setState({errorInfo:n}),this.props.onError&&this.props.onError(e,n)}handleRetry=async()=>{if(!(this.state.retryCount>=this.maxRetries||!this.props.retryLoader)){this.setState({isRetrying:!0});try{let e=await this.props.retryLoader();this.setState({hasError:!1,error:null,errorInfo:null,retryCount:this.state.retryCount+1,isRetrying:!1,fallbackData:e})}catch(e){this.setState({retryCount:this.state.retryCount+1,isRetrying:!1,error:e instanceof Error?e:Error(String(e))})}}};handleUseFallback=()=>{this.state.fallbackData&&this.setState({hasError:!1,error:null,errorInfo:null})};renderErrorUI(){let{error:e,retryCount:r,isRetrying:i,fallbackData:a}=this.state,o=r<this.maxRetries&&this.props.retryLoader,s=a!==null,c=typeof Deno<`u`&&Deno.env.get(`NODE_ENV`)===`development`;return t(`div`,{class:`layout-data-error-boundary`,children:n(`div`,{class:`error-container`,children:[t(`h3`,{children:`Data Loading Error`}),n(`p`,{children:[`Failed to load data for layout: `,this.props.layoutPath]}),n(`div`,{class:`error-actions`,children:[o&&t(`button`,{onClick:this.handleRetry,disabled:i,class:`retry-button`,children:i?`Retrying...`:`Retry (${this.maxRetries-r} left)`}),s&&t(`button`,{onClick:this.handleUseFallback,class:`fallback-button`,children:`Use Cached Data`})]}),c&&e&&n(`details`,{class:`error-details`,children:[t(`summary`,{children:`Error Details (Development)`}),n(`div`,{class:`error-info`,children:[n(`p`,{children:[t(`strong`,{children:`Error:`}),` `,e.message]}),n(`p`,{children:[t(`strong`,{children:`Layout:`}),` `,this.props.layoutPath]}),n(`p`,{children:[t(`strong`,{children:`Retry Count:`}),` `,r]})]}),t(`pre`,{class:`error-stack`,children:e.stack})]})]})})}render(){return this.state.hasError?this.renderErrorUI():this.props.children}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Component as e}from"preact";import{jsxs as t,jsx as n}from"react/jsx-runtime";export class LayoutErrorBoundary extends e{maxRetries=3;constructor(e){super(e),this.state={hasError:!1,error:null,errorInfo:null,retryCount:0}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){let n={layoutPath:this.props.layoutPath||`unknown`,errorType:this.props.errorType||`component`,timestamp:Date.now(),componentStack:t.componentStack,errorBoundary:this.constructor.name};this.setState({errorInfo:n}),this.props.onError&&this.props.onError(e,n),typeof Deno<`u`&&Deno.env.get(`NODE_ENV`)===`development`&&(console.error(`Layout Error Boundary caught an error:`,e),console.error(`Error Info:`,n),console.error(`Component Stack:`,t.componentStack))}handleRetry=()=>{this.state.retryCount<this.maxRetries&&this.setState({hasError:!1,error:null,errorInfo:null,retryCount:this.state.retryCount+1})};renderFallback(){let{error:e}=this.state,{fallback:r}=this.props;return r&&e?r(e,this.handleRetry):n(`div`,{class:`layout-error-boundary`,children:t(`div`,{class:`error-container`,children:[n(`h2`,{children:`Something went wrong`}),n(`p`,{children:`An error occurred while rendering this layout.`}),this.state.retryCount<this.maxRetries&&t(`button`,{onClick:this.handleRetry,class:`retry-button`,children:[`Try Again (`,this.maxRetries-this.state.retryCount,` attempts left)`]}),typeof Deno<`u`&&Deno.env.get(`NODE_ENV`)===`development`&&t(`details`,{class:`error-details`,children:[n(`summary`,{children:`Error Details (Development)`}),n(`pre`,{children:e?.stack}),this.state.errorInfo&&t(`div`,{children:[t(`p`,{children:[n(`strong`,{children:`Layout Path:`}),` `,this.state.errorInfo.layoutPath]}),t(`p`,{children:[n(`strong`,{children:`Error Type:`}),` `,this.state.errorInfo.errorType]}),t(`p`,{children:[n(`strong`,{children:`Timestamp:`}),` `,new Date(this.state.errorInfo.timestamp).toISOString()]})]})]})]})})}render(){return this.state.hasError?this.renderFallback():this.props.children}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{PersistentIslandProvider as e}from"../core/islands/persistent-island-context.js";import{defaultIslandPersistence as t}from"../core/islands/island-persistence.js";import{jsx as n}from"preact/jsx-runtime";export function PersistentIsland({persistentId:r,children:i,persistence:a=t}){return n(e,{persistentId:r,persistence:a,children:n(`div`,{"data-persistent-id":r,children:i})})}export default PersistentIsland;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Component as e}from"preact";import{jsx as t,jsxs as n}from"react/jsx-runtime";export class StreamingErrorBoundary extends e{constructor(e){super(e),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){if(this.setState({errorInfo:t}),console.error(`[StreamingErrorBoundary] Caught error:`,{componentId:this.props.componentId,error:e.message,stack:e.stack,componentStack:t.componentStack}),this.props.onError&&this.props.onError(e,t),!this.props.isolateError)throw e}handleRetry=()=>{this.setState({hasError:!1,error:null,errorInfo:null})};renderFallback(){let{error:e}=this.state,{fallback:r,componentId:i}=this.props;if(r&&e)return r(e,this.handleRetry);let a=typeof Deno<`u`&&Deno.env.get(`DENO_ENV`)!==`production`;return n(`div`,{class:`streaming-error-boundary`,"data-error-boundary":`true`,"data-component-id":i,style:{background:`#fff3cd`,border:`2px solid #ffc107`,borderRadius:`8px`,padding:`20px`,margin:`20px 0`,fontFamily:`system-ui, -apple-system, sans-serif`},children:[n(`div`,{class:`error-boundary-header`,style:{display:`flex`,alignItems:`center`,gap:`10px`,marginBottom:`10px`},children:[t(`span`,{style:{fontSize:`24px`},children:`⚠️`}),t(`h3`,{style:{margin:0,color:`#856404`},children:`Component Error`})]}),t(`p`,{style:{margin:`10px 0`,color:`#856404`},children:`An error occurred while rendering this component. The rest of the page should work normally.`}),t(`button`,{onClick:this.handleRetry,style:{background:`#ffc107`,border:`none`,borderRadius:`4px`,padding:`8px 16px`,cursor:`pointer`,fontWeight:`bold`,color:`#856404`,marginTop:`10px`},children:`Retry`}),a&&e&&n(`details`,{style:{marginTop:`15px`},children:[t(`summary`,{style:{cursor:`pointer`,color:`#856404`,fontWeight:`bold`},children:`Error Details (Development Mode)`}),n(`div`,{style:{marginTop:`10px`},children:[i&&n(`p`,{children:[t(`strong`,{children:`Component ID:`}),` `,i]}),n(`p`,{children:[t(`strong`,{children:`Error:`}),` `,e.message]}),e.stack&&t(`pre`,{style:{background:`#f5f5f5`,padding:`10px`,borderRadius:`4px`,overflowX:`auto`,fontSize:`12px`,marginTop:`10px`},children:e.stack}),this.state.errorInfo?.componentStack&&n(`div`,{children:[t(`p`,{children:t(`strong`,{children:`Component Stack:`})}),t(`pre`,{style:{background:`#f5f5f5`,padding:`10px`,borderRadius:`4px`,overflowX:`auto`,fontSize:`12px`,marginTop:`10px`},children:this.state.errorInfo.componentStack})]})]})]})]})}render(){return this.state.hasError?this.renderFallback():this.props.children}}export function withStreamingErrorBoundary(e,n){return function(i){return t(StreamingErrorBoundary,{componentId:n?.componentId,fallback:n?.fallback,isolateError:n?.isolateError??!0,onError:n?.onError,children:t(e,{...i})})}}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import{Component as e}from"preact";import{useState as t,useEffect as n,useRef as r}from"preact/hooks";import{jsxs as i,jsx as a}from"react/jsx-runtime";export function StreamingLayout(e){let{component:o,componentProps:c={},children:l,fallback:u,priority:d=`medium`,isReady:f,timeout:p=5e3,onError:m,onLoadingChange:h}=e;if(typeof window>`u`)return l;let[g,_]=t({isReady:!1,isLoading:!0,error:null,hasTimedOut:!1}),v=r(),y=r(!0);return n(()=>()=>{y.current=!1},[]),n(()=>{if(!f){_(e=>({...e,isReady:!0,isLoading:!1})),h?.(!1);return}let e=!1;return(async()=>{try{p>0&&(v.current=setTimeout(()=>{!e&&y.current&&(_(e=>({...e,hasTimedOut:!0,isLoading:!1})),h?.(!1))},p));let t=await f();if(e||!y.current)return;v.current&&clearTimeout(v.current),_(e=>({...e,isReady:t,isLoading:!1,hasTimedOut:!1})),h?.(!1)}catch(t){if(e||!y.current)return;v.current&&clearTimeout(v.current),_(e=>({...e,error:t,isLoading:!1})),h?.(!1)}})(),()=>{e=!0,v.current&&clearTimeout(v.current)}},[f,p,h]),g.error?m?m(g.error):i(`div`,{class:`streaming-error`,"data-priority":d,children:[i(`p`,{children:[`Failed to load component: `,g.error.message]}),a(`button`,{onClick:()=>{_({isReady:!1,isLoading:!0,error:null,hasTimedOut:!1}),h?.(!0)},children:`Retry`})]}):g.hasTimedOut?a(`div`,{class:`streaming-timeout`,"data-priority":d,children:u||i(`div`,{class:`timeout-message`,children:[a(`p`,{children:`Component loading timed out`}),a(`button`,{onClick:()=>{_({isReady:!1,isLoading:!0,error:null,hasTimedOut:!1}),h?.(!0)},children:`Retry`})]})}):g.isLoading||!g.isReady?a(`div`,{class:`streaming-loading`,"data-priority":d,children:u||a(s,{priority:d})}):a(`div`,{class:`streaming-ready`,"data-priority":d,children:a(o,{...c,children:l})})}function s({priority:e}){return i(`div`,{class:`streaming-skeleton ${`skeleton-${e}`}`,children:[i(`div`,{class:`skeleton-content`,children:[a(`div`,{class:`skeleton-line skeleton-line-1`}),a(`div`,{class:`skeleton-line skeleton-line-2`}),a(`div`,{class:`skeleton-line skeleton-line-3`})]}),a(`style`,{children:`
|
|
2
|
+
.streaming-skeleton {
|
|
3
|
+
padding: 1rem;
|
|
4
|
+
border-radius: 0.5rem;
|
|
5
|
+
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
|
|
6
|
+
background-size: 200% 100%;
|
|
7
|
+
animation: skeleton-loading 1.5s infinite;
|
|
8
|
+
}
|
|
9
|
+
.skeleton-content {
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
gap: 0.5rem;
|
|
13
|
+
}
|
|
14
|
+
.skeleton-line {
|
|
15
|
+
height: 1rem;
|
|
16
|
+
background: rgba(255, 255, 255, 0.8);
|
|
17
|
+
border-radius: 0.25rem;
|
|
18
|
+
}
|
|
19
|
+
.skeleton-line-1 { width: 100%; }
|
|
20
|
+
.skeleton-line-2 { width: 75%; }
|
|
21
|
+
.skeleton-line-3 { width: 50%; }
|
|
22
|
+
.skeleton-high { border-left: 4px solid #ef4444; }
|
|
23
|
+
.skeleton-medium { border-left: 4px solid #f59e0b; }
|
|
24
|
+
.skeleton-low { border-left: 4px solid #10b981; }
|
|
25
|
+
@keyframes skeleton-loading {
|
|
26
|
+
0% { background-position: 200% 0; }
|
|
27
|
+
100% { background-position: -200% 0; }
|
|
28
|
+
}
|
|
29
|
+
`})]})}export function StreamingSuspense(e){let{fallback:o,children:c,priority:u=`medium`,timeout:d=5e3,onError:f}=e,[p,m]=t(!0),[h,g]=t(null),[_,v]=t(!1),y=r(),b=r(!0);n(()=>()=>{b.current=!1},[]),n(()=>(d>0&&(y.current=setTimeout(()=>{b.current&&p&&(v(!0),m(!1))},d)),()=>{y.current&&clearTimeout(y.current)}),[d,p]);let x=e=>{g(e),m(!1),y.current&&clearTimeout(y.current)};return h?f?f(h):i(`div`,{class:`streaming-suspense-error`,"data-priority":u,children:[i(`p`,{children:[`Suspense boundary error: `,h.message]}),a(`button`,{onClick:()=>{g(null),m(!0),v(!1)},children:`Retry`})]}):_?a(`div`,{class:`streaming-suspense-timeout`,"data-priority":u,children:o||i(`div`,{class:`suspense-timeout-message`,children:[a(`p`,{children:`Suspense boundary timed out`}),a(`button`,{onClick:()=>{v(!1),m(!0)},children:`Retry`})]})}):p?a(`div`,{class:`streaming-suspense-loading`,"data-priority":u,children:o||a(s,{priority:u})}):a(`div`,{class:`streaming-suspense-ready`,"data-priority":u,children:a(l,{onError:x,children:c})})}class l extends e{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`StreamingErrorBoundary caught an error:`,e,t),this.props.onError?.(e)}render(){return this.state.hasError?i(`div`,{class:`streaming-error-boundary`,children:[a(`p`,{children:`Something went wrong in streaming component.`}),a(`button`,{onClick:()=>this.setState({hasError:!1,error:void 0}),children:`Retry`})]}):this.props.children}}export function withStreaming(e,t={}){return function(n){return a(StreamingLayout,{component:e,componentProps:n,priority:`medium`,...t})}}export function useStreamingState(e,r=5e3){let[i,a]=t({isReady:!1,isLoading:!0,error:null,hasTimedOut:!1});n(()=>{if(!e){a(e=>({...e,isReady:!0,isLoading:!1}));return}let t=!1,n;return(async()=>{try{r>0&&(n=setTimeout(()=>{t||a(e=>({...e,hasTimedOut:!0,isLoading:!1}))},r));let i=await e();if(t)return;n&&clearTimeout(n),a(e=>({...e,isReady:i,isLoading:!1,hasTimedOut:!1}))}catch(e){if(t)return;n&&clearTimeout(n),a(t=>({...t,error:e,isLoading:!1}))}})(),()=>{t=!0,n&&clearTimeout(n)}},[e,r]);let o=()=>{a({isReady:!1,isLoading:!0,error:null,hasTimedOut:!1})};return{...i,retry:o}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{analyzeComponent as e,shouldHydrateComponent as t,createComponentMetadata as n}from"./component-detection.js";export async function analyzeComponentFile(r,i={}){try{let{readFile:a}=await import(`node:fs/promises`),o=await a(r,`utf-8`),s=e(r,o),l=t(s,i),u=n(r,o,s);return i.logDecisions&&c(r,s,l),{metadata:u,decision:l,analysis:s}}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Failed to analyze component ${r}: ${t}`)}}export function analyzeComponentContent(r,i,a={}){let o=e(r,i),s=t(o,a),l=n(r,i,o);return a.logDecisions&&c(r,o,s),{metadata:l,decision:s,analysis:o}}export async function analyzeComponents(e,t={}){let n=new Map;for(let i of e)try{let e=await analyzeComponentFile(i,t);n.set(i,e)}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`Failed to analyze ${i}:`,t)}return n}export async function shouldHydrate(e,t={}){try{return(await analyzeComponentFile(e,t)).decision.shouldHydrate}catch(t){let n=t instanceof Error?t.message:String(t);return console.error(`Error checking hydration for ${e}:`,n),!0}}export async function getComponentFramework(e){try{return(await analyzeComponentFile(e)).analysis.framework}catch(t){let n=t instanceof Error?t.message:String(t);return console.error(`Error detecting framework for ${e}:`,n),`unknown`}}function c(e,t,n){let r=t.framework.toUpperCase(),i=n.shouldHydrate?`HYDRATE`:`SSR-ONLY`;console.log(`[Component Analysis] ${e}`),console.log(` Framework: ${r}`),console.log(` Has Script: ${t.hasScript}`),console.log(` Has Hydrate Function: ${t.hasHydrateFunction}`),console.log(` Strategy: ${i}`),console.log(` Reason: ${n.reason}`),n.warnings&&n.warnings.length>0&&(console.log(` Warnings:`),n.warnings.forEach(e=>console.log(` - ${e}`))),console.log(``)}export function generateAnalysisSummary(e){let t={total:e.size,byFramework:{},byStrategy:{},withWarnings:0};for(let[,n]of e){let e=n.analysis.framework;t.byFramework[e]=(t.byFramework[e]||0)+1;let r=n.decision.shouldHydrate?`hydrate`:`ssr-only`;t.byStrategy[r]=(t.byStrategy[r]||0)+1,n.decision.warnings&&n.decision.warnings.length>0&&t.withWarnings++}return t}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const e={vue:{fileExtensions:[`.vue`],scriptTags:[`<script>`,`<script setup>`,`<script lang="ts">`,`<script setup lang="ts">`],hydratePatterns:[`hydrate`,`mount`,`createApp`,`Vue.createApp`],imports:[`vue`,`@vue/`,`vue/`]},svelte:{fileExtensions:[`.svelte`],scriptTags:[`<script>`,`<script lang="ts">`,`<script context="module">`],hydratePatterns:[`hydrate`,`mount`,`$:`,`onMount`],imports:[`svelte`,`svelte/`]},solid:{fileExtensions:[`.tsx`,`.jsx`,`.solid.tsx`,`.solid.jsx`],scriptTags:[],hydratePatterns:[`hydrate`,`render`,`createSignal`,`createEffect`],imports:[`solid-js`,`solid-js/web`]},preact:{fileExtensions:[`.tsx`,`.jsx`,`.preact.tsx`,`.preact.jsx`],scriptTags:[],hydratePatterns:[`hydrate`,`render`],imports:[`preact`,`preact/hooks`]},react:{fileExtensions:[`.tsx`,`.jsx`,`.react.tsx`,`.react.jsx`],scriptTags:[],hydratePatterns:[`hydrate`,`render`],imports:[`react`,`react-dom`]},lit:{fileExtensions:[`.ts`,`.js`],scriptTags:[],hydratePatterns:[`LitElement`,`customElement`,`@customElement`],imports:[`lit`,`lit-element`,`lit/`]},qwik:{fileExtensions:[`.tsx`,`.jsx`,`.qwik.tsx`,`.qwik.jsx`],scriptTags:[],hydratePatterns:[`component$`,`useSignal`,`useStore`,`useTask$`,`useVisibleTask$`],imports:[`@builder.io/qwik`,`@builder.io/qwik/`]}};function t(e){return e.includes(`.solid.`)?`solid`:e.includes(`.preact.`)?`preact`:e.includes(`.react.`)?`react`:e.includes(`.qwik.`)?`qwik`:null}function n(e,t){return e.endsWith(`.vue`)?`vue`:e.endsWith(`.svelte`)?`svelte`:(e.endsWith(`.ts`)||e.endsWith(`.js`))&&(t.includes(`lit`)||t.includes(`LitElement`)||t.includes(`@customElement`))?`lit`:e.endsWith(`.tsx`)||e.endsWith(`.jsx`)?r(t):null}function r(e){return e.includes(`solid-js`)||e.includes(`from "solid-js"`)||e.includes(`from 'solid-js'`)?`solid`:e.includes(`@builder.io/qwik`)||e.includes(`from "@builder.io/qwik"`)||e.includes(`from '@builder.io/qwik'`)?`qwik`:e.includes(`preact`)||e.includes(`from "preact"`)||e.includes(`from 'preact'`)?`preact`:e.includes(`react`)&&!e.includes(`preact`)?`react`:`preact`}export function detectFramework(e,r){return t(e)??n(e,r)??i(r)}function i(t){for(let[n,r]of Object.entries(e))if(r.imports.some(e=>t.includes(e)))return n;return`unknown`}export function hasScriptSection(e,t){switch(t){case`vue`:return/<script[^>]*>/i.test(e);case`svelte`:return e.includes(`<script>`)||e.includes(`<script `)||e.includes(`<script
|
|
2
|
+
`)||e.includes(`<script `);case`solid`:case`preact`:case`react`:case`qwik`:return e.includes(`function`)||e.includes(`=>`)||e.includes(`const`)||e.includes(`let`);case`lit`:return e.includes(`class`)||e.includes(`LitElement`)||e.includes(`@customElement`);default:return e.includes(`<script>`)||e.includes(`function`)||e.includes(`=>`)}}export function hasHydrateFunction(t,n){if(!e[n])return!1;if([`export function hydrate`,`export const hydrate`,`function hydrate(`,`const hydrate =`,`let hydrate =`,`var hydrate =`].some(e=>t.toLowerCase().includes(e.toLowerCase())))return!0;switch(n){case`vue`:return t.includes(`createApp`)&&t.includes(`mount`);case`svelte`:return t.includes(`import`)&&t.includes(`hydrate`)&&(t.includes(`svelte`)||t.includes(`hydrate(`));case`solid`:return t.includes(`hydrate`)&&t.includes(`solid-js`)||t.includes(`render`)&&t.includes(`solid-js/web`);case`preact`:return t.includes(`hydrate`)&&t.includes(`preact`)||t.includes(`render`)&&t.includes(`preact`);case`react`:return t.includes(`hydrate`)&&t.includes(`react`)||t.includes(`render`)&&t.includes(`react-dom`);case`qwik`:return t.includes(`component$`)||t.includes(`@builder.io/qwik`);default:return!1}}export function extractVueScript(e){return o(e)}export function extractSvelteScript(e){return o(e)}function o(e){let t=/<script[^>]*>([\s\S]*?)<\/script>/gi,n=[],r;for(;(r=t.exec(e))!==null;)n.push(r[0]);return n.join(`
|
|
3
|
+
`)}const s=/^\s*return\s*\(/;function c(e){return e.split(`
|
|
4
|
+
`).filter(e=>{let t=e.trim();return!t.startsWith(`<`)&&!t.startsWith(`</`)&&!s.exec(t)}).join(`
|
|
5
|
+
`)}export function extractSolidScript(e){return c(e)}export function extractPreactScript(e){return c(e)}export function extractReactScript(e){return c(e)}export function analyzeComponent(e,t){let n=detectFramework(e,t),r=hasScriptSection(t,n),i=r?hasHydrateFunction(t,n):!1,a;if(r)switch(n){case`svelte`:a=l(t,i);break;case`solid`:case`preact`:case`react`:a=`hydrate`;break;case`qwik`:a=`hydrate`;break;case`vue`:a=i?`hydrate`:`ssr-only`;break;default:a=i?`hydrate`:`ssr-only`;break}else a=`ssr-only`;return{hasScript:r,hasHydrateFunction:i,framework:n,recommendedStrategy:a}}function l(e,t){if(t)return`hydrate`;let n=`on:.onclick.onchange.oninput.onsubmit.onkeydown.onkeyup.onmousedown.onmouseup.bind:.$:.$state.$derived.$effect.$props.onMount.onDestroy.beforeUpdate.afterUpdate.tick.writable.readable.derived.get(.set(.update(.subscribe(`.split(`.`).some(t=>e.includes(t));return[`export let`].some(t=>e.includes(t))&&!n?`ssr-only`:`hydrate`}const u={solid:`SolidJS component detected - uses integration system`,preact:`preact component with script content - likely needs hydration`,react:`react component with script content - likely needs hydration`,svelte:`Svelte component with script section - uses Svelte hydration system`,vue:`Vue component with script section - uses Vue integration system`,lit:`Lit component detected - Web Components require client-side registration`,qwik:`Qwik component detected - uses resumability instead of hydration`};export function shouldHydrateComponent(e,t={}){if(t.forceSSROnly)return{shouldHydrate:!1,reason:`Explicitly configured for SSR-only rendering`};if(t.detectScripts===!1)return{shouldHydrate:!0,reason:`Script detection disabled, defaulting to hydration`};if(!e.hasScript)return{shouldHydrate:!1,reason:`No script section detected, using SSR-only rendering`};let n=u[e.framework];return n?{shouldHydrate:!0,reason:n}:e.hasHydrateFunction?{shouldHydrate:!0,reason:`Component has script section with explicit hydration functions`}:{shouldHydrate:!1,reason:`Component has script section but no explicit hydrate function, using SSR-only`,warnings:[`Component has script section but no clear hydrate function detected`]}}export function createComponentMetadata(e,t,n){let r=`medium`;return n.framework!==`unknown`&&n.hasScript&&n.hasHydrateFunction||n.framework!==`unknown`&&!n.hasScript?r=`high`:n.framework===`unknown`&&(r=`low`),{path:e,framework:n.framework===`unknown`?`vue`:n.framework,hasScript:n.hasScript,hasHydrateFunction:n.hasHydrateFunction,renderStrategy:n.recommendedStrategy,detectionConfidence:r}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class EnhancedFrameworkDetector{frameworkRegistry;constructor(e){this.frameworkRegistry=new Map;let t=e||this.getDefaultFrameworkConfigs();Object.entries(t).forEach(([e,t])=>{this.frameworkRegistry.set(e,t)})}detectFramework(e,t){let n=this.extractDetectionCriteria(e,t),r=[],i=[];if(e.includes(`.solid.`))return r.push(`Explicit Solid naming convention (.solid.tsx/.solid.jsx)`),{framework:`solid`,confidence:`high`,evidence:r,warnings:i};if(e.includes(`.preact.`))return r.push(`Explicit Preact naming convention (.preact.tsx/.preact.jsx)`),{framework:`preact`,confidence:`high`,evidence:r,warnings:i};if(e.includes(`.react.`))return r.push(`Explicit React naming convention (.react.tsx/.react.jsx)`),{framework:`react`,confidence:`high`,evidence:r,warnings:i};if(e.includes(`.lit.`))return r.push(`Explicit Lit naming convention (.lit.ts/.lit.js)`),{framework:`lit`,confidence:`high`,evidence:r,warnings:i};if(e.includes(`.qwik.`))return r.push(`Explicit Qwik naming convention (.qwik.tsx/.qwik.jsx)`),{framework:`qwik`,confidence:`high`,evidence:r,warnings:i};let a=new Map;for(let[e,t]of this.frameworkRegistry){let i=this.calculateFrameworkScore(n,t,r);a.set(e,i)}let o=Array.from(a.entries()).sort(([,e],[,t])=>t-e),[s,c]=o[0]||[`unknown`,0],[l,u]=o[1]||[`unknown`,0],d;return c>=3&&c-u>=2?d=`high`:c>=2?d=`medium`:(d=`low`,i.push(`Framework detection has low confidence - consider adding explicit JSX import source or use naming convention (.solid.tsx, .preact.tsx)`)),c===u&&c>0&&(i.push(`Ambiguous detection between ${s} and ${l} - consider using naming convention`),d=`low`),{framework:c>0?s:`unknown`,confidence:d,evidence:r,warnings:i}}extractDetectionCriteria(e,t){return{fileExtension:this.getFileExtension(e),jsxImportSource:this.parseJSXImportSource(t),imports:this.extractImportStatements(t),content:t}}calculateFrameworkScore(e,t,n){let r=0;e.jsxImportSource&&t.jsxImportSources.includes(e.jsxImportSource)&&(r+=3,n.push(`JSX import source: @jsxImportSource ${e.jsxImportSource}`));for(let i of t.detectionPatterns.imports)e.imports.some(e=>i.test(e))&&(r+=2,n.push(`Framework import detected: ${i.source}`));for(let i of t.detectionPatterns.content)i.test(e.content)&&(r+=1,n.push(`Framework-specific content pattern: ${i.source}`));return t.fileExtensions.includes(e.fileExtension)&&(r+=.5,n.push(`File extension: ${e.fileExtension}`)),r}parseJSXImportSource(e){let t=/@jsxImportSource\s+([^\s*]+)/.exec(e);if(t)return t[1]}extractImportStatements(e){let t=[],n=/from\s+['"]([^'"]+)['"]/g,r=/import\s+['"]([^'"]+)['"]/g,i=/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,a;for(;(a=n.exec(e))!==null;)t.push(a[1]);for(;(a=r.exec(e))!==null;)t.push(a[1]);for(;(a=i.exec(e))!==null;)t.push(a[1]);return t}getFileExtension(e){if(e.includes(`.solid.`))return`.solid.tsx`;if(e.includes(`.preact.`))return`.preact.tsx`;if(e.includes(`.react.`))return`.react.tsx`;if(e.includes(`.lit.`))return`.lit.ts`;let t=e.lastIndexOf(`.`);return t===-1?``:e.substring(t)}getDefaultFrameworkConfigs(){return{preact:{name:`preact`,fileExtensions:[`.tsx`,`.jsx`,`.preact.tsx`,`.preact.jsx`],jsxImportSources:[`preact`],ssrModules:[`preact-render-to-string`],hydrationModules:[`preact`],detectionPatterns:{imports:[/^preact$/,/^preact\//,/preact-render-to-string/],content:[/\buseState\b/,/\buseEffect\b/,/\buseCallback\b/,/\buseMemo\b/,/\buseRef\b/,/from\s+['"]preact['"]/],jsxPragmas:[`@jsxImportSource preact`]}},solid:{name:`solid`,fileExtensions:[`.tsx`,`.jsx`,`.solid.tsx`,`.solid.jsx`],jsxImportSources:[`solid-js`],ssrModules:[`solid-js/web`],hydrationModules:[`solid-js/web`],detectionPatterns:{imports:[/^solid-js$/,/^solid-js\//,/solid-js\/web/],content:[/\bcreateSignal\b/,/\bcreateEffect\b/,/\bcreateMemo\b/,/\bcreateResource\b/,/\bonMount\b/,/\bonCleanup\b/,/from\s+['"]solid-js['"]/],jsxPragmas:[`@jsxImportSource solid-js`]}},vue:{name:`vue`,fileExtensions:[`.vue`],jsxImportSources:[`vue`],ssrModules:[`vue/server-renderer`],hydrationModules:[`vue`],detectionPatterns:{imports:[/^vue$/,/^@vue\//,/vue\/server-renderer/],content:[/<template>/,/<script>/,/<style>/,/\bref\b/,/\breactive\b/,/\bcomputed\b/,/\bwatchEffect\b/,/from\s+['"]vue['"]/],jsxPragmas:[`@jsxImportSource vue`]}},svelte:{name:`svelte`,fileExtensions:[`.svelte`],jsxImportSources:[`svelte`],ssrModules:[`svelte/server`],hydrationModules:[`svelte`],detectionPatterns:{imports:[/^svelte$/,/^svelte\//,/svelte\/store/],content:[/<script>/,/<style>/,/\$:/,/\bonMount\b/,/\bafterUpdate\b/,/\bbeforeUpdate\b/,/from\s+['"]svelte['"]/],jsxPragmas:[`@jsxImportSource svelte`]}},react:{name:`react`,fileExtensions:[`.jsx`,`.tsx`,`.react.jsx`,`.react.tsx`],jsxImportSources:[`react`],ssrModules:[`react-dom/server`],hydrationModules:[`react-dom/client`],detectionPatterns:{imports:[/^react$/,/^react\//,/^react-dom$/,/^react-dom\//,/from\s+['"]react['"]/,/from\s+['"]react\/[^'"]+['"]/,/from\s+['"]react-dom['"]/],content:[/\buseState\b/,/\buseEffect\b/,/\buseContext\b/,/\buseReducer\b/,/\buseCallback\b/,/\buseMemo\b/,/\buseRef\b/,/\buseTransition\b/,/\buseDeferredValue\b/,/\buseId\b/,/\buseImperativeHandle\b/,/\buseLayoutEffect\b/,/["']use client["']/,/["']use server["']/,/from\s+['"]react['"]/,/import\s+.*\s+from\s+['"]react['"]/],jsxPragmas:[`@jsxImportSource react`]}},lit:{name:`lit`,fileExtensions:[`.ts`,`.js`,`.lit.ts`,`.lit.js`],jsxImportSources:[`lit`],ssrModules:[`@lit-labs/ssr`],hydrationModules:[`lit`],detectionPatterns:{imports:[/^lit$/,/^lit\//,/^@lit\//,/^@lit-labs\/ssr/,/from\s+['"]lit['"]/,/from\s+['"]lit\/[^'"]+['"]/,/from\s+['"]@lit\/[^'"]+['"]/],content:[/\bLitElement\b/,/\bcustomElement\b/,/@customElement/,/@property/,/@state/,/@query/,/@queryAll/,/\bhtml`/,/\bcss`/,/extends\s+LitElement/,/from\s+['"]lit['"]/,/import\s+.*\s+from\s+['"]lit['"]/],jsxPragmas:[`@jsxImportSource lit`]}},qwik:{name:`qwik`,fileExtensions:[`.tsx`,`.jsx`,`.qwik.tsx`,`.qwik.jsx`],jsxImportSources:[`@builder.io/qwik`],ssrModules:[`@builder.io/qwik/server`],hydrationModules:[`@builder.io/qwik`],detectionPatterns:{imports:[/^@builder\.io\/qwik$/,/^@builder\.io\/qwik\//,/from\s+['"]@builder\.io\/qwik['"]/,/from\s+['"]@builder\.io\/qwik\/[^'"]+['"]/],content:[/\bcomponent\$/,/\buseSignal\b/,/\buseStore\b/,/\buseTask\$/,/\buseVisibleTask\$/,/\buseResource\$/,/\buseContext\b/,/\buseContextProvider\b/,/\$\(\s*\(/,/from\s+['"]@builder\.io\/qwik['"]/,/import\s+.*\s+from\s+['"]@builder\.io\/qwik['"]/],jsxPragmas:[`@jsxImportSource @builder.io/qwik`]}}}}addFrameworkConfig(e,t){this.frameworkRegistry.set(e,t)}getFrameworkConfigs(){return new Map(this.frameworkRegistry)}validateFrameworkConfig(e){let t=[];return(!e.name||e.name.trim()===``)&&t.push(`Framework name is required`),(!e.fileExtensions||e.fileExtensions.length===0)&&t.push(`At least one file extension is required`),(!e.detectionPatterns.imports||e.detectionPatterns.imports.length===0)&&t.push(`At least one import pattern is required for detection`),(!e.ssrModules||e.ssrModules.length===0)&&t.push(`At least one SSR module is required`),(!e.hydrationModules||e.hydrationModules.length===0)&&t.push(`At least one hydration module is required`),t}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class FrameworkRegistry{frameworks;config;constructor(e={}){this.frameworks=new Map,this.config={enableValidation:!0,allowCustomFrameworks:!0,defaultFramework:`unknown`,...e},this.initializeDefaultFrameworks()}registerFramework(e,t){let n=this.validateFrameworkConfig(t);return this.config.enableValidation&&!n.isValid?n:!this.config.allowCustomFrameworks&&!this.isDefaultFramework(e)?{isValid:!1,errors:[`Custom framework '${e}' not allowed`],warnings:[]}:(this.frameworks.set(e,{...t}),{isValid:!0,errors:[],warnings:n.warnings})}getFramework(e){return this.frameworks.get(e)}getAllFrameworks(){return new Map(this.frameworks)}getFrameworksByExtension(e){let t=[];for(let[n,r]of this.frameworks)r.fileExtensions.includes(e)&&t.push(n);return t}getFrameworksByJSXImportSource(e){let t=[];for(let[n,r]of this.frameworks)r.jsxImportSources.includes(e)&&t.push(n);return t}unregisterFramework(e){return this.isDefaultFramework(e)?!1:this.frameworks.delete(e)}updateFramework(e,t){let n=this.frameworks.get(e);if(!n)return{isValid:!1,errors:[`Framework '${e}' not found`],warnings:[]};let r={...n,...t},i=this.validateFrameworkConfig(r);return this.config.enableValidation&&!i.isValid?i:(this.frameworks.set(e,r),{isValid:!0,errors:[],warnings:i.warnings})}validateFrameworkConfig(e){let t=[],n=[];return this.validateRequiredFields(e,t,n),this.validateDetectionPatterns(e,t,n),this.validateCrossFrameworkConflicts(e,n),{isValid:t.length===0,errors:t,warnings:n}}validateRequiredFields(e,t,n){if((!e.name||e.name.trim()===``)&&t.push(`Framework name is required and cannot be empty`),!e.fileExtensions||e.fileExtensions.length===0)t.push(`At least one file extension is required`);else for(let n of e.fileExtensions)n.startsWith(`.`)||t.push(`File extension '${n}' must start with a dot`);(!e.jsxImportSources||e.jsxImportSources.length===0)&&n.push(`No JSX import sources defined - detection may be less accurate`),(!e.ssrModules||e.ssrModules.length===0)&&t.push(`At least one SSR module is required`),(!e.hydrationModules||e.hydrationModules.length===0)&&t.push(`At least one hydration module is required`)}validateDetectionPatterns(e,t,n){if(!e.detectionPatterns){t.push(`Detection patterns are required`);return}(!e.detectionPatterns.imports||e.detectionPatterns.imports.length===0)&&t.push(`At least one import pattern is required for detection`),(!e.detectionPatterns.content||e.detectionPatterns.content.length===0)&&n.push(`No content patterns defined - detection may be less accurate`),(!e.detectionPatterns.jsxPragmas||e.detectionPatterns.jsxPragmas.length===0)&&n.push(`No JSX pragmas defined - detection may be less accurate`)}validateCrossFrameworkConflicts(e,t){if(!(!e.fileExtensions||!e.jsxImportSources)){for(let[n,r]of this.frameworks)if(n!==e.name){if(r.fileExtensions){let i=e.fileExtensions.filter(e=>r.fileExtensions.includes(e));i.length>0&&t.push(`File extensions ${i.join(`, `)} overlap with framework '${n}'`)}if(r.jsxImportSources){let i=e.jsxImportSources.filter(e=>r.jsxImportSources.includes(e));i.length>0&&t.push(`JSX import sources ${i.join(`, `)} overlap with framework '${n}'`)}}}}isDefaultFramework(e){return[`preact`,`solid`,`vue`,`svelte`,`react`,`lit`,`qwik`].includes(e)}initializeDefaultFrameworks(){let e=this.getDefaultFrameworkConfigs();for(let[t,n]of Object.entries(e))this.frameworks.set(t,n)}getDefaultFrameworkConfigs(){return{preact:{name:`preact`,fileExtensions:[`.tsx`,`.jsx`],jsxImportSources:[`preact`],ssrModules:[`preact-render-to-string`],hydrationModules:[`preact`],detectionPatterns:{imports:[/^preact$/,/^preact\//,/preact-render-to-string/],content:[/\buseState\b/,/\buseEffect\b/,/\buseCallback\b/,/\buseMemo\b/,/\buseRef\b/,/\buseContext\b/,/\buseReducer\b/,/from\s+['"]preact['"]/,/import\s+.*\s+from\s+['"]preact['"]/],jsxPragmas:[`@jsxImportSource preact`]}},solid:{name:`solid`,fileExtensions:[`.tsx`,`.jsx`],jsxImportSources:[`solid-js`],ssrModules:[`solid-js/web`],hydrationModules:[`solid-js/web`],detectionPatterns:{imports:[/^solid-js$/,/^solid-js\//,/solid-js\/web/,/solid-js\/store/],content:[/\bcreateSignal\b/,/\bcreateEffect\b/,/\bcreateMemo\b/,/\bcreateResource\b/,/\bcreateStore\b/,/\bonMount\b/,/\bonCleanup\b/,/\bShow\b/,/\bFor\b/,/from\s+['"]solid-js['"]/,/import\s+.*\s+from\s+['"]solid-js['"]/],jsxPragmas:[`@jsxImportSource solid-js`]}},vue:{name:`vue`,fileExtensions:[`.vue`],jsxImportSources:[`vue`],ssrModules:[`vue/server-renderer`],hydrationModules:[`vue`],detectionPatterns:{imports:[/^vue$/,/^@vue\//,/vue\/server-renderer/,/vue\/composition-api/],content:[/<template>/,/<script>/,/<style>/,/\bref\b/,/\breactive\b/,/\bcomputed\b/,/\bwatchEffect\b/,/\bwatch\b/,/\bonMounted\b/,/\bonUnmounted\b/,/from\s+['"]vue['"]/,/import\s+.*\s+from\s+['"]vue['"]/],jsxPragmas:[`@jsxImportSource vue`]}},svelte:{name:`svelte`,fileExtensions:[`.svelte`],jsxImportSources:[`svelte`],ssrModules:[`svelte/server`],hydrationModules:[`svelte`],detectionPatterns:{imports:[/^svelte$/,/^svelte\//,/svelte\/store/,/svelte\/motion/,/svelte\/transition/],content:[/<script>/,/<style>/,/\$:/,/\bonMount\b/,/\bafterUpdate\b/,/\bbeforeUpdate\b/,/\bonDestroy\b/,/\btick\b/,/from\s+['"]svelte['"]/,/import\s+.*\s+from\s+['"]svelte['"]/],jsxPragmas:[`@jsxImportSource svelte`]}},react:{name:`react`,fileExtensions:[`.jsx`,`.tsx`],jsxImportSources:[`react`],ssrModules:[`react-dom/server`],hydrationModules:[`react-dom/client`],detectionPatterns:{imports:[/^react$/,/^react\//,/^react-dom$/,/^react-dom\//,/from\s+['"]react['"]/,/from\s+['"]react\/[^'"]+['"]/,/from\s+['"]react-dom['"]/],content:[/\buseState\b/,/\buseEffect\b/,/\buseContext\b/,/\buseReducer\b/,/\buseCallback\b/,/\buseMemo\b/,/\buseRef\b/,/\buseTransition\b/,/\buseDeferredValue\b/,/\buseId\b/,/\buseImperativeHandle\b/,/\buseLayoutEffect\b/,/["']use client["']/,/["']use server["']/,/from\s+['"]react['"]/,/import\s+.*\s+from\s+['"]react['"]/],jsxPragmas:[`@jsxImportSource react`]}},lit:{name:`lit`,fileExtensions:[`.ts`,`.js`],jsxImportSources:[`lit`],ssrModules:[`@lit-labs/ssr`],hydrationModules:[`lit`],detectionPatterns:{imports:[/^lit$/,/^lit\//,/^@lit\//,/^@lit-labs\/ssr/,/from\s+['"]lit['"]/,/from\s+['"]lit\/[^'"]+['"]/,/from\s+['"]@lit\/[^'"]+['"]/],content:[/\bLitElement\b/,/\bcustomElement\b/,/@customElement/,/@property/,/@state/,/@query/,/@queryAll/,/\bhtml`/,/\bcss`/,/extends\s+LitElement/,/from\s+['"]lit['"]/,/import\s+.*\s+from\s+['"]lit['"]/],jsxPragmas:[`@jsxImportSource lit`]}},qwik:{name:`qwik`,fileExtensions:[`.tsx`,`.jsx`],jsxImportSources:[`@builder.io/qwik`],ssrModules:[`@builder.io/qwik/server`],hydrationModules:[`@builder.io/qwik`],detectionPatterns:{imports:[/^@builder\.io\/qwik$/,/^@builder\.io\/qwik\//,/from\s+['"]@builder\.io\/qwik['"]/,/from\s+['"]@builder\.io\/qwik\/[^'"]+['"]/],content:[/\bcomponent\$/,/\buseSignal\b/,/\buseStore\b/,/\buseTask\$/,/\buseVisibleTask\$/,/\buseResource\$/,/\buseContext\b/,/\$\(\s*\(/,/from\s+['"]@builder\.io\/qwik['"]/,/import\s+.*\s+from\s+['"]@builder\.io\/qwik['"]/],jsxPragmas:[`@jsxImportSource @builder.io/qwik`]}}}}exportConfig(){let e={};for(let[t,n]of this.frameworks)e[t]={...n};return e}importConfig(e){let t=[];for(let[n,r]of Object.entries(e)){let e=this.registerFramework(n,r);t.push(e)}return t}reset(){this.frameworks.clear(),this.initializeDefaultFrameworks()}getStats(){let e=new Set([`preact`,`solid`,`vue`,`svelte`,`react`,`lit`,`qwik`]),t=Array.from(this.frameworks.keys()).filter(t=>e.has(t)).length,n=new Set;for(let e of this.frameworks.values())e.fileExtensions.forEach(e=>n.add(e));return{totalFrameworks:this.frameworks.size,defaultFrameworks:t,customFrameworks:this.frameworks.size-t,supportedExtensions:Array.from(n).sort((e,t)=>e.localeCompare(t))}}}export const defaultFrameworkRegistry=new FrameworkRegistry;export function createFrameworkConfig(e,t){return{name:e,fileExtensions:t.fileExtensions,jsxImportSources:t.jsxImportSources||[],ssrModules:t.ssrModules,hydrationModules:t.hydrationModules,detectionPatterns:{imports:t.importPatterns.map(e=>typeof e==`string`?new RegExp(e):e),content:(t.contentPatterns||[]).map(e=>typeof e==`string`?new RegExp(e):e),jsxPragmas:t.jsxPragmas||[]}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{extname as e}from"node:path";import{readFile as t}from"node:fs/promises";import{h as n}from"preact";import{marked as r}from"marked";export class MDXProcessor{async processMDXFile(e){try{let i=await t(e,`utf-8`);return{default:()=>n(`div`,{dangerouslySetInnerHTML:{__html:r(i)}})}}catch(t){throw Error(`Failed to process MDX file ${e}: ${t instanceof Error?t.message:String(t)}`)}}static isMDXFile(t){let n=e(t);return n===`.mdx`||n===`.md`}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{IntegrationRegistry,registry}from"./registry.js";export{loadIntegration,detectAndLoadIntegration,detectFrameworkFromPath,detectFrameworkFromContent,preloadIntegrations,getLoadedIntegrations,clearIntegrationCache,isIntegrationLoaded}from"./loader.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{registry as e}from"./registry.js";const t=new Map;export async function loadIntegration(n){if(t.has(n))return t.get(n);let r=await e.load(n);return t.set(n,r),r}export async function detectAndLoadIntegration(e){return await loadIntegration(detectFrameworkFromPath(e))}export function detectFrameworkFromPath(e){return e.endsWith(`.vue`)?`vue`:e.endsWith(`.svelte`)?`svelte`:e.includes(`.solid.`)?`solid`:e.includes(`.qwik.`)?`qwik`:`preact`}export function detectFrameworkFromContent(e,t){let n=detectFrameworkFromPath(e);return n!==`preact`||!t?n:t.includes(`solid-js`)?`solid`:t.includes(`@builder.io/qwik`)?`qwik`:(t.includes(`preact`),`preact`)}export async function preloadIntegrations(e){await Promise.all(e.map(e=>loadIntegration(e)))}export function getLoadedIntegrations(){return Array.from(t.values())}export function clearIntegrationCache(){t.clear()}export function isIntegrationLoaded(e){return t.has(e)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{dirname as e,join as t}from"node:path";import{statSync as n}from"node:fs";function r(){let r=process.cwd();for(let i=0;i<10;i++){try{if(n(t(r,`packages`,`integrations`)).isDirectory())return r}catch{}let i=e(r);if(i===r)break;r=i}return process.cwd()}export class IntegrationRegistry{integrations=new Map;loadingPromises=new Map;register(e){if(!e.name)throw Error(`Integration must have a name`);this.integrations.set(e.name,e)}get(e){return this.integrations.get(e)}has(e){return this.integrations.has(e)}async load(e){let t=this.integrations.get(e);if(t)return t;let n=this.loadingPromises.get(e);if(n)return n;let r=this.loadIntegration(e);this.loadingPromises.set(e,r);try{let e=await r;return this.register(e),e}finally{this.loadingPromises.delete(e)}}async loadIntegration(e){let n=`${e}Integration`;try{let t=await import(`@useavalon/${e}`),r=t[n]||t.default;if(r)return r}catch{}try{let i=await import(`file://${t(r(),`packages`,`integrations`,e,`mod.ts`)}`),a=i[n]||i.default;if(a)return a}catch{}throw Error(`Failed to load integration for framework '${e}'. Make sure @useavalon/${e} is installed.\nInstall it with: bun add @useavalon/${e}`)}getAll(){return Array.from(this.integrations.values())}getAllNames(){return Array.from(this.integrations.keys())}unregister(e){return this.integrations.delete(e)}clear(){this.integrations.clear(),this.loadingPromises.clear()}get size(){return this.integrations.size}}globalThis.__avalonIntegrationRegistry??=new IntegrationRegistry;export const registry=globalThis.__avalonIntegrationRegistry;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{IslandStateSerializer as e}from"./island-state-serializer.js";export class IslandPersistence{storageType;keyPrefix;storage=null;constructor(e={}){this.storageType=e.storageType||`session`,this.keyPrefix=e.keyPrefix||`island-state`,typeof window<`u`&&(this.storage=this.storageType===`session`?sessionStorage:localStorage)}saveState(t,n){if(!this.storage){console.warn(`Island persistence: Storage not available (server-side or unsupported browser)`);return}try{let r=this.getStorageKey(t),i=e.serialize({state:n,timestamp:Date.now(),version:`1.0`});this.storage.setItem(r,i),console.log(`Island state saved for ${t}`)}catch(e){console.error(`Failed to save island state for ${t}:`,e)}}loadState(t){if(!this.storage)return console.warn(`Island persistence: Storage not available (server-side or unsupported browser)`),null;try{let n=this.getStorageKey(t),r=this.storage.getItem(n);if(!r)return null;let i=e.deserialize(r);return!i.state||!i.timestamp||!i.version?(console.warn(`Invalid island state format for ${t}, clearing...`),this.clearState(t),null):(console.log(`Island state loaded for ${t}`),i.state)}catch(e){return console.error(`Failed to load island state for ${t}:`,e),this.clearState(t),null}}clearState(e){if(this.storage)try{let t=this.getStorageKey(e);this.storage.removeItem(t),console.log(`Island state cleared for ${e}`)}catch(t){console.error(`Failed to clear island state for ${e}:`,t)}}hasState(e){if(!this.storage)return!1;try{let t=this.getStorageKey(e);return this.storage.getItem(t)!==null}catch(t){return console.error(`Failed to check island state for ${e}:`,t),!1}}getStoredIds(){if(!this.storage)return[];try{let e=[],t=this.keyPrefix.length+1;for(let n=0;n<this.storage.length;n++){let r=this.storage.key(n);r&&r.startsWith(this.keyPrefix+`:`)&&e.push(r.substring(t))}return e}catch(e){return console.error(`Failed to get stored island IDs:`,e),[]}}clearAllStates(){if(this.storage)try{let e=[];for(let t=0;t<this.storage.length;t++){let n=this.storage.key(t);n&&n.startsWith(this.keyPrefix+`:`)&&e.push(n)}e.forEach(e=>this.storage.removeItem(e)),console.log(`Cleared ${e.length} island states`)}catch(e){console.error(`Failed to clear all island states:`,e)}}getStorageKey(e){return`${this.keyPrefix}:${e}`}getConfig(){return{storageType:this.storageType,keyPrefix:this.keyPrefix,available:this.storage!==null}}getStorageStats(){if(!this.storage)return{totalKeys:0,islandKeys:0,estimatedSize:0};try{let e=0,t=0;for(let n=0;n<this.storage.length;n++){let r=this.storage.key(n);if(r&&r.startsWith(this.keyPrefix+`:`)){e++;let n=this.storage.getItem(r);n&&(t+=r.length+n.length)}}return{totalKeys:this.storage.length,islandKeys:e,estimatedSize:t}}catch(e){return console.error(`Failed to get storage stats:`,e),{totalKeys:0,islandKeys:0,estimatedSize:0}}}replacer(e,t){return t instanceof Date?{__type:`Date`,__value:t.toISOString()}:t instanceof RegExp?{__type:`RegExp`,__value:{source:t.source,flags:t.flags}}:t instanceof Map?{__type:`Map`,__value:Array.from(t.entries())}:t instanceof Set?{__type:`Set`,__value:Array.from(t.values())}:typeof t==`function`?(console.warn(`Function found in island state at key "${e}", converting to null`),null):t===void 0?null:t}reviver(e,t){if(t&&typeof t==`object`){let e=t;if(e.__type&&e.__value!==void 0)switch(e.__type){case`Date`:return new Date(e.__value);case`RegExp`:{let t=e.__value;return new RegExp(t.source,t.flags)}case`Map`:return new Map(e.__value);case`Set`:return new Set(e.__value);default:return console.warn(`Unknown special type "${e.__type}" in serialized state`),e.__value}}return t}}export const defaultIslandPersistence=new IslandPersistence({storageType:`session`,keyPrefix:`island-state`});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class IslandStateSerializer{static serialize(t){try{let n=IslandStateSerializer.transformForSerialization(t);return JSON.stringify(n)}catch(e){throw console.error(`Failed to serialize island state:`,e),Error(`State serialization failed: ${e instanceof Error?e.message:String(e)}`)}}static deserialize(t){try{return JSON.parse(t,IslandStateSerializer.reviver)}catch(e){throw console.error(`Failed to deserialize island state:`,e),Error(`State deserialization failed: ${e instanceof Error?e.message:String(e)}`)}}static transformForSerialization(t){if(t===null)return t;if(t===void 0)return null;if(t instanceof Date)return{__type:`Date`,__value:t.toISOString()};if(t instanceof RegExp)return{__type:`RegExp`,__value:{source:t.source,flags:t.flags}};if(t instanceof Map)return{__type:`Map`,__value:Array.from(t.entries()).map(([t,n])=>[IslandStateSerializer.transformForSerialization(t),IslandStateSerializer.transformForSerialization(n)])};if(t instanceof Set)return{__type:`Set`,__value:Array.from(t.values()).map(t=>IslandStateSerializer.transformForSerialization(t))};if(typeof t==`function`)return console.warn(`Function found in island state, converting to null`),null;if(Array.isArray(t))return t.map(t=>IslandStateSerializer.transformForSerialization(t));if(typeof t==`object`){let n={},r=t;for(let t in r)Object.hasOwn(r,t)&&(n[t]=IslandStateSerializer.transformForSerialization(r[t]));return n}return t}static reviver(e,t){if(t&&typeof t==`object`){let e=t;if(e.__type&&e.__value!==void 0)switch(e.__type){case`Date`:return new Date(e.__value);case`RegExp`:{let t=e.__value;return new RegExp(t.source,t.flags)}case`Map`:return new Map(e.__value);case`Set`:return new Set(e.__value);case`undefined`:return null;default:return console.warn(`Unknown special type "${typeof e.__type==`string`?e.__type:`non-string`}" in serialized state`),e.__value}}return t}static validate(e){let t=[];try{let n=this.serialize(e),r=new Blob([n]).size,i=5*1024*1024;r>i&&t.push(`Serialized state size (${Math.round(r/1024)}KB) exceeds recommended limit (${Math.round(i/1024)}KB)`),this.deserialize(n)}catch(e){t.push(e instanceof Error?e.message:String(e))}return{valid:t.length===0,errors:t}}static getSize(e){try{let t=this.serialize(e),n=new Blob([t]).size,r=n/1024,i=r/1024,a;return a=i>=1?`${i.toFixed(2)} MB`:r>=1?`${r.toFixed(2)} KB`:`${n} bytes`,{bytes:n,kilobytes:r,megabytes:i,readable:a}}catch(e){return console.error(`Failed to calculate state size:`,e),{bytes:0,kilobytes:0,megabytes:0,readable:`0 bytes`}}}static clone(e){try{let t=this.serialize(e);return this.deserialize(t)}catch(t){return console.error(`Failed to clone island state:`,t),{...e}}}static equals(e,t){try{return this.serialize(e)===this.serialize(t)}catch(e){return console.error(`Failed to compare island states:`,e),!1}}static sanitize(e){try{let t=this.serialize(e);return this.deserialize(t)}catch(e){return console.error(`Failed to sanitize island state:`,e),{}}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createContext as e}from"preact";import{useContext as t}from"preact/hooks";import{defaultIslandPersistence as n}from"./island-persistence.js";import{jsx as r}from"react/jsx-runtime";export const PersistentIslandContextProvider=e(null);export function createPersistentIslandContext(e,t=n){return{saveState:n=>{t.saveState(e,n)},loadState:()=>t.loadState(e),clearState:()=>{t.clearState(e)}}}export function usePersistentIslandContext(){let e=t(PersistentIslandContextProvider);if(!e)throw Error(`usePersistentIslandContext must be used within a PersistentIsland component`);return e}export function PersistentIslandProvider({persistentId:e,children:t,persistence:i=n}){let a=createPersistentIslandContext(e,i);return r(PersistentIslandContextProvider.Provider,{value:a,children:t})}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as e,useEffect as t,useCallback as n}from"preact/hooks";import{IslandStateSerializer as r}from"./island-state-serializer.js";export function usePersistentState(i,a,o){let s=o?.storage??`session`,c=`avalon-island:${i}`,[l,u]=e(()=>{if(typeof window>`u`)return a;try{let e=(s===`local`?localStorage:sessionStorage).getItem(c);return e===null?a:r.deserialize(e).v??a}catch{return a}});return t(()=>{if(!(typeof window>`u`))try{(s===`local`?localStorage:sessionStorage).setItem(c,r.serialize({v:l}))}catch{}},[l,c,s]),[l,n(e=>{u(t=>typeof e==`function`?e(t):e)},[]),n(()=>{if(u(a),!(typeof window>`u`))try{(s===`local`?localStorage:sessionStorage).removeItem(c)}catch{}},[a,c,s])]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{render as e}from"preact-render-to-string";import{LayoutDiscovery as t}from"./layout-discovery.js";import{LayoutMatcher as n}from"./layout-matcher.js";import{LayoutComposer as r}from"./layout-composer.js";import{LayoutDataLoader as i}from"./layout-data-loader.js";import{LayoutCacheManager as a,defaultCacheConfig as o}from"./layout-cache-manager.js";function s(e,t){return e(t)}export class EnhancedLayoutResolver{layoutDiscovery;layoutMatcher;layoutComposer;layoutDataLoader;cache;cacheManager;options;constructor(e){this.options={baseDirectory:e.baseDirectory,filePattern:e.filePattern||`_layout.tsx`,excludeDirectories:e.excludeDirectories||[`node_modules`,`.git`,`dist`],enableWatching:e.enableWatching||!1,developmentMode:e.developmentMode||!1,enableCaching:e.enableCaching??!0,cacheTTL:e.cacheTTL||300*1e3,maxCacheSize:e.maxCacheSize||1e3,enableMetrics:e.enableMetrics??!0,enableDebugInfo:e.enableDebugInfo||!1},this.layoutDiscovery=new t(this.options),this.layoutMatcher=new n({developmentMode:this.options.developmentMode}),this.layoutComposer=new r(this.options),this.layoutDataLoader=new i({developmentMode:this.options.developmentMode,enableParallelLoading:!0,continueOnError:!0}),this.cache={resolved:new Map,handlers:new Map,data:new Map,ttl:new Map},this.cacheManager=new a({...o,defaultTtl:this.options.cacheTTL,maxEntries:this.options.maxCacheSize,enableStats:this.options.enableMetrics})}async resolveLayouts(e,t,n){let r=performance.now(),i=this.generateCacheKey(e,t,n);if(this.options.enableCaching){let t=this.cacheManager.getResolvedLayout(i);if(t)return this.options.developmentMode&&console.log(`[EnhancedLayoutResolver] Cache hit for route: ${e}`),{...t,metadata:{...t.metadata,cacheHit:!0}}}let a=[],o=[];try{o=await this.layoutComposer.resolveLayouts(e,t);let r=await this.layoutDataLoader.loadLayoutData(o,n),{errors:i}=this.layoutDataLoader.processLoadingResults(r,o);a.push(...i)}catch(t){a.push({layoutPath:e,errorType:`rendering`,timestamp:Date.now()}),this.options.developmentMode&&console.warn(`[EnhancedLayoutResolver] Error resolving layouts:`,t)}let s=performance.now()-r,c={handlers:o,dataLoaders:o.map(e=>e.loader).filter(e=>e!==void 0),errorBoundaries:[],streamingComponents:[],metadata:{totalLayouts:o.length,resolutionTime:s,cacheHit:!1}};if(this.options.enableCaching){this.cacheManager.setResolvedLayout(i,c);for(let e of o)this.cacheManager.addDependency(i,e.path)}return this.options.developmentMode&&(a.length>0&&console.warn(`[EnhancedLayoutResolver] ${a.length} error(s) during layout resolution for ${e}`),console.log(`[EnhancedLayoutResolver] Resolved ${o.length} layouts for ${e} in ${s.toFixed(2)}ms`)),c}async resolveAndRender(e,t,n){let r=await this.resolveLayouts(e,t,n);this.options.developmentMode&&console.log(`[EnhancedLayoutResolver] Rendering ${r.handlers.length} layouts for ${e}`);let i=await this.layoutDataLoader.loadLayoutData(r.handlers,n),{data:a}=this.layoutDataLoader.processLoadingResults(i,r.handlers);return this.options.developmentMode&&this.renderLayoutsToString(r,t,n,a),r}renderLayoutsToString(t,n,r,i=[]){try{let a=n.default??(()=>null);for(let e=t.handlers.length-1;e>=0;e--){let r=t.handlers[e].component,o=a,c=i[e]||{};a=e=>s(r,{...e,data:c,frontmatter:n.frontmatter,children:s(o,e)})}return e(s(a,{children:null,data:{},route:{path:new URL(r.request.url).pathname,params:r.params,query:r.query}}))}catch(e){return this.options.developmentMode&&console.warn(`[EnhancedLayoutResolver] Rendering failed:`,e),``}}getCachedResolution(e){return this.cacheManager.getResolvedLayout(e)}invalidateCacheByFilePath(e){return this.cacheManager.invalidateByFilePath(e)}clearCache(){this.cacheManager.clear(),this.cache.resolved.clear(),this.cache.handlers.clear(),this.cache.data.clear(),this.cache.ttl.clear(),this.layoutDiscovery.clearCache(),this.layoutComposer.clearCache()}setCaching(e){this.options.enableCaching=e,e||this.clearCache()}generateCacheKey(e,t,n){return`${e}:${t.layoutConfig?JSON.stringify(t.layoutConfig):``}:${n.request.method}:${n.request.url}`}getResolverStats(){let e=this.cacheManager.getStats(),t=this.layoutDiscovery.getCacheStats();return{cacheSize:e.totalEntries,cacheHitRate:this.cacheManager.getHitRate(),totalResolutions:e.hits+e.misses,averageResolutionTime:0,errorCount:0,cacheStats:e,discoveryStats:t}}updateOptions(e){Object.assign(this.options,e),e.developmentMode!==void 0&&this.layoutDataLoader.updateOptions({developmentMode:e.developmentMode})}getOptions(){return{...this.options}}getLayoutDiscovery(){return this.layoutDiscovery}getLayoutMatcher(){return this.layoutMatcher}getLayoutComposer(){return this.layoutComposer}getLayoutDataLoader(){return this.layoutDataLoader}getCacheManager(){return this.cacheManager}destroy(){this.cacheManager.destroy()}}export function createEnhancedLayoutResolver(e){return new EnhancedLayoutResolver(e)}export const EnhancedLayoutResolverUtils={createBasicConfig(e,t=!1){return{baseDirectory:e,developmentMode:t,enableCaching:!0,enableMetrics:t,enableDebugInfo:t}},createProductionConfig(e){return{baseDirectory:e,developmentMode:!1,enableCaching:!0,enableMetrics:!1,enableDebugInfo:!1}}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class LayoutCacheManager{resolvedLayouts=new Map;layoutHandlers=new Map;layoutData=new Map;dependencyGraph=new Map;accessOrder=new Map;accessCounter=0;stats={hits:0,misses:0,evictions:0,totalEntries:0,memoryUsage:0};cleanupTimer;constructor(e){this.config=e,process.env.NODE_ENV!==`test`&&this.startCleanupTimer()}setResolvedLayout(e,t,n){let r={value:t,timestamp:Date.now(),ttl:n||this.config.defaultTtl,accessCount:0,lastAccessed:Date.now()};this.resolvedLayouts.set(e,r),this.updateAccessOrder(e),this.updateStats(),this.enforceMaxEntries()}getResolvedLayout(e){let t=this.resolvedLayouts.get(e);return t?this.isExpired(t)?(this.resolvedLayouts.delete(e),this.accessOrder.delete(e),this.stats.misses++,this.stats.evictions++,null):(t.accessCount++,t.lastAccessed=Date.now(),this.updateAccessOrder(e),this.stats.hits++,t.value):(this.stats.misses++,null)}setLayoutHandler(e,t,n){let r={value:t,timestamp:Date.now(),ttl:n||this.config.defaultTtl,accessCount:0,lastAccessed:Date.now()};this.layoutHandlers.set(e,r),this.updateAccessOrder(e),this.updateStats(),this.enforceMaxEntries()}getLayoutHandler(e){let t=this.layoutHandlers.get(e);return t?this.isExpired(t)?(this.layoutHandlers.delete(e),this.accessOrder.delete(e),this.stats.misses++,this.stats.evictions++,null):(t.accessCount++,t.lastAccessed=Date.now(),this.updateAccessOrder(e),this.stats.hits++,t.value):(this.stats.misses++,null)}setLayoutData(e,t,n){let r={value:t,timestamp:Date.now(),ttl:n||this.config.defaultTtl,accessCount:0,lastAccessed:Date.now()};this.layoutData.set(e,r),this.updateAccessOrder(e),this.updateStats(),this.enforceMaxEntries()}getLayoutData(e){let t=this.layoutData.get(e);return t?this.isExpired(t)?(this.layoutData.delete(e),this.accessOrder.delete(e),this.stats.misses++,this.stats.evictions++,null):(t.accessCount++,t.lastAccessed=Date.now(),this.updateAccessOrder(e),this.stats.hits++,t.value):(this.stats.misses++,null)}invalidateResolvedLayout(e){let t=this.resolvedLayouts.delete(e);return this.accessOrder.delete(e),this.invalidateDependents(e),t}invalidateLayoutHandler(e){let t=this.layoutHandlers.delete(e);return this.accessOrder.delete(e),this.invalidateDependents(e),t}invalidateLayoutData(e){let t=this.layoutData.delete(e);return this.accessOrder.delete(e),this.invalidateDependents(e),t}invalidateByFilePath(e){let t=0,n=this.normalizePath(e);for(let e of this.resolvedLayouts.keys())this.isKeyAffectedByPath(e,n)&&(this.resolvedLayouts.delete(e),this.accessOrder.delete(e),t++);for(let e of this.layoutHandlers.keys())this.isKeyAffectedByPath(e,n)&&(this.layoutHandlers.delete(e),this.accessOrder.delete(e),t++);for(let e of this.layoutData.keys())this.isKeyAffectedByPath(e,n)&&(this.layoutData.delete(e),this.accessOrder.delete(e),t++);return this.updateStats(),t}addDependency(e,t){this.dependencyGraph.has(t)||this.dependencyGraph.set(t,new Set),this.dependencyGraph.get(t).add(e)}removeDependency(e,t){let n=this.dependencyGraph.get(t);n&&(n.delete(e),n.size===0&&this.dependencyGraph.delete(t))}invalidateByPattern(e){let t=0;for(let n of this.resolvedLayouts.keys())e.test(n)&&(this.resolvedLayouts.delete(n),t++);for(let n of this.layoutHandlers.keys())e.test(n)&&(this.layoutHandlers.delete(n),t++);for(let n of this.layoutData.keys())e.test(n)&&(this.layoutData.delete(n),t++);return this.updateStats(),t}clear(){this.resolvedLayouts.clear(),this.layoutHandlers.clear(),this.layoutData.clear(),this.dependencyGraph.clear(),this.accessOrder.clear(),this.accessCounter=0,this.resetStats()}getStats(){return this.updateStats(),{...this.stats}}getHitRate(){let e=this.stats.hits+this.stats.misses;return e===0?0:this.stats.hits/e}isExpired(e){return Date.now()-e.timestamp>e.ttl}invalidateDependents(e){let t=this.dependencyGraph.get(e);if(t){for(let e of t)this.resolvedLayouts.delete(e),this.layoutHandlers.delete(e),this.layoutData.delete(e),this.accessOrder.delete(e),this.invalidateDependents(e);this.dependencyGraph.delete(e)}}normalizePath(e){return e.replaceAll(`\\`,`/`).toLowerCase()}isKeyAffectedByPath(e,t){let n=e.toLowerCase();return n.includes(t)||n.includes(t.replace(`_layout.tsx`,``))||n.includes(t.replace(`.tsx`,``))}updateAccessOrder(e){this.accessOrder.set(e,++this.accessCounter)}updateStats(){this.config.enableStats&&(this.stats.totalEntries=this.resolvedLayouts.size+this.layoutHandlers.size+this.layoutData.size,this.stats.memoryUsage=this.estimateMemoryUsage())}estimateMemoryUsage(){let e=0;for(let[t,n]of this.resolvedLayouts)e+=t.length*2,e+=JSON.stringify(n.value).length*2,e+=64;for(let[t]of this.layoutHandlers)e+=t.length*2,e+=256,e+=64;for(let[t,n]of this.layoutData)e+=t.length*2,e+=JSON.stringify(n.value).length*2,e+=64;return e}enforceMaxEntries(){let e=this.resolvedLayouts.size+this.layoutHandlers.size+this.layoutData.size;if(e<=this.config.maxEntries)return;let t=Array.from(this.accessOrder.entries()).sort((e,t)=>e[1]-t[1]).map(([e])=>e),n=e-this.config.maxEntries,r=0;for(let e of t){if(r>=n)break;let t=!1;this.resolvedLayouts.has(e)&&(this.resolvedLayouts.delete(e),t=!0),this.layoutHandlers.has(e)&&(this.layoutHandlers.delete(e),t=!0),this.layoutData.has(e)&&(this.layoutData.delete(e),t=!0),t&&(this.accessOrder.delete(e),this.stats.evictions++,r++)}}startCleanupTimer(){this.cleanupTimer&&clearInterval(this.cleanupTimer),this.cleanupTimer=setInterval(()=>{this.cleanup()},this.config.cleanupInterval)}cleanup(){let e=Date.now();for(let[t,n]of this.resolvedLayouts)e-n.timestamp>n.ttl&&(this.resolvedLayouts.delete(t),this.accessOrder.delete(t),this.stats.evictions++);for(let[t,n]of this.layoutHandlers)e-n.timestamp>n.ttl&&(this.layoutHandlers.delete(t),this.accessOrder.delete(t),this.stats.evictions++);for(let[t,n]of this.layoutData)e-n.timestamp>n.ttl&&(this.layoutData.delete(t),this.accessOrder.delete(t),this.stats.evictions++);for(let e of this.accessOrder.keys())!this.resolvedLayouts.has(e)&&!this.layoutHandlers.has(e)&&!this.layoutData.has(e)&&this.accessOrder.delete(e);this.updateStats()}resetStats(){this.stats={hits:0,misses:0,evictions:0,totalEntries:0,memoryUsage:0}}destroy(){this.cleanupTimer&&=(clearInterval(this.cleanupTimer),void 0),this.clear()}}export const defaultCacheConfig={defaultTtl:300*1e3,maxEntries:1e3,cleanupInterval:60*1e3,enableStats:!0,enableCompression:!0,intelligentInvalidation:!0,preloadThreshold:.8};export const layoutCache=new LayoutCacheManager(defaultCacheConfig);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{resolve as e,relative as t}from"node:path";import{statSync as n}from"node:fs";import r from"node:process";import{LayoutDiscovery as i}from"./layout-discovery.js";function a(e){return/^[A-Za-z]:[\\/]/.test(e)?`file:///${e.replaceAll(`\\`,`/`)}`:e}function o(e){try{return n(e),!0}catch{return!1}}function s(e){return new RegExp(e.replaceAll(`*`,`.*`))}export class LayoutComposer{layoutDiscovery;customLayoutCache=new Map;developmentMode;constructor(e){this.layoutDiscovery=new i(e),this.developmentMode=e.developmentMode||!1}async resolveLayouts(e,t){try{let n=t.layoutConfig;if(!n)return await this.layoutDiscovery.buildLayoutChain(new URL(`http://localhost${e}`));if(n.replaceLayout)return this.developmentMode&&console.log(`[LayoutComposer] Replacing all layouts for route: ${e}`),await this.handleReplaceLayout(e,n);let r=await this.layoutDiscovery.buildLayoutChain(new URL(`http://localhost${e}`));return await this.applyConfiguration(r,n)}catch(t){return this.developmentMode&&console.warn(`[LayoutComposer] Error resolving layouts for ${e}: ${t instanceof Error?t.message:String(t)}`),await this.layoutDiscovery.buildLayoutChain(new URL(`http://localhost${e}`))}}async applyConfiguration(e,t){let n=[...e];return t.onlyLayouts&&t.onlyLayouts.length>0&&(n=await this.applyOnlyLayouts(n,t.onlyLayouts)),t.skipLayouts&&t.skipLayouts.length>0&&(n=this.applySkipLayouts(n,t.skipLayouts)),t.customLayout&&(n=await this.addCustomLayout(n,t.customLayout)),n}async handleReplaceLayout(e,t){if(t.customLayout){let e=await this.loadCustomLayout(t.customLayout);return e?[e]:[]}return[]}matchesLayoutPattern(e,n){if(n.includes(`*`)){let i=s(n);return i.test(e.path)||i.test(t(r.cwd(),e.path))}return e.path===n||e.path.endsWith(n)||t(r.cwd(),e.path)===n||t(r.cwd(),e.path).endsWith(n)}applySkipLayouts(e,n){return e.filter(e=>{let i=n.some(t=>this.matchesLayoutPattern(e,t));return i&&this.developmentMode&&console.log(`[LayoutComposer] Skipping layout: ${t(r.cwd(),e.path)}`),!i})}async applyOnlyLayouts(e,n){let i=[];for(let a of n){let n=e.filter(e=>this.matchesLayoutPattern(e,a));if(n.length>0)i.push(...n),this.developmentMode&&console.log(`[LayoutComposer] Kept layouts from onlyLayouts: ${n.map(e=>t(r.cwd(),e.path)).join(`, `)}`);else{let e=await this.loadCustomLayout(a);e&&(i.push(e),this.developmentMode&&console.log(`[LayoutComposer] Added custom layout from onlyLayouts: ${a}`))}}return i.sort((e,t)=>e.priority-t.priority),i}async addCustomLayout(e,n){try{let i=await this.loadCustomLayout(n);if(!i)return this.developmentMode&&console.warn(`[LayoutComposer] Failed to load custom layout: ${n}`),e;let a={...i,priority:Math.max(...e.map(e=>e.priority),0)+10},o=[...e,a];return o.sort((e,t)=>e.priority-t.priority),this.developmentMode&&console.log(`[LayoutComposer] Added custom layout: ${t(r.cwd(),n)}`),o}catch(t){return this.developmentMode&&console.warn(`[LayoutComposer] Error adding custom layout ${n}: ${t instanceof Error?t.message:String(t)}`),e}}resolveLayoutPath(t){if(t.startsWith(`/`)||t.startsWith(`file://`)||/^[A-Za-z]:[\\/]/.test(t))return t;let n=this.layoutDiscovery.getOptions().baseDirectory;return[e(t),e(`src`,t),e(`src/pages`,t),e(`src/layouts`,t),e(n,`..`,t),e(n,t)].find(e=>o(e))||t}async loadCustomLayout(e){if(this.customLayoutCache.has(e))return this.customLayoutCache.get(e);try{let t=this.resolveLayoutPath(e);if(!o(t))return this.developmentMode&&console.warn(`[LayoutComposer] Custom layout file not found: ${t}`),null;let n=await import(a(t));if(!n.default||typeof n.default!=`function`)return this.developmentMode&&console.warn(`[LayoutComposer] Custom layout file does not export a default component: ${t}`),null;let r={component:n.default,loader:n.layoutLoader,path:t,priority:1e3};return this.customLayoutCache.set(e,r),r}catch(t){return this.developmentMode&&console.warn(`[LayoutComposer] Failed to load custom layout ${e}: ${t instanceof Error?t.message:String(t)}`),null}}validateLayoutConfig(e){let t=[];return e.replaceLayout&&e.onlyLayouts&&e.onlyLayouts.length>0&&t.push(`replaceLayout and onlyLayouts cannot be used together`),e.replaceLayout&&e.skipLayouts&&e.skipLayouts.length>0&&t.push(`replaceLayout and skipLayouts cannot be used together`),e.skipLayouts&&!Array.isArray(e.skipLayouts)&&t.push(`skipLayouts must be an array of strings`),e.onlyLayouts&&!Array.isArray(e.onlyLayouts)&&t.push(`onlyLayouts must be an array of strings`),e.customLayout&&typeof e.customLayout!=`string`&&t.push(`customLayout must be a string path`),{valid:t.length===0,errors:t}}getCompositionStats(){return{customLayoutCacheSize:this.customLayoutCache.size,discoveryStats:this.layoutDiscovery.getCacheStats()}}clearCache(){this.customLayoutCache.clear(),this.layoutDiscovery.clearCache()}clearCustomLayoutCache(){this.customLayoutCache.clear()}getLayoutDiscovery(){return this.layoutDiscovery}setDevelopmentMode(e){this.developmentMode=e}isDevelopmentMode(){return this.developmentMode}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class LayoutDataLoadingError extends Error{constructor(e,t,n){super(e),this.layoutPath=t,this.originalError=n,this.name=`LayoutDataLoadingError`}}export class LayoutDataLoader{options;constructor(e={}){this.options={timeout:e.timeout??5e3,enableParallelLoading:e.enableParallelLoading??!0,continueOnError:e.continueOnError??!0,developmentMode:e.developmentMode??!1,maxRetries:e.maxRetries??2,retryDelay:e.retryDelay??1e3}}async loadLayoutData(e,t){let n=e.filter(e=>e.loader);return n.length===0?[]:this.options.enableParallelLoading?await this.loadDataInParallel(n,t):await this.loadDataSequentially(n,t)}async loadDataInParallel(t,n){let r=Math.min(t.length,5),i=[];for(let a=0;a<t.length;a+=r){let o=t.slice(a,a+r),s=o.map(e=>this.loadSingleLayoutData(e,n));if(this.options.continueOnError){let t=(await Promise.allSettled(s)).map((t,n)=>{if(t.status===`fulfilled`)return t.value;{let r=o[n];return{success:!1,data:{},error:new LayoutDataLoadingError(`Layout data loading failed: ${t.reason}`,r.path,t.reason instanceof Error?t.reason:Error(String(t.reason))),loadingTime:0,layoutPath:r.path}}});i.push(...t)}else try{let e=await Promise.all(s);i.push(...e)}catch(e){throw e}}return i}async loadDataSequentially(t,n){let r=[];for(let i of t)try{let e=await this.loadSingleLayoutData(i,n);if(r.push(e),!this.options.continueOnError&&!e.success)break}catch(t){let n={success:!1,data:{},error:new LayoutDataLoadingError(`Layout data loading failed: ${t instanceof Error?t.message:String(t)}`,i.path,t instanceof Error?t:Error(String(t))),loadingTime:0,layoutPath:i.path};if(r.push(n),!this.options.continueOnError)break}return r}async loadSingleLayoutData(t,n){if(!t.loader)return{success:!0,data:{},loadingTime:0,layoutPath:t.path};let r,i=0;for(;i<=this.options.maxRetries;){let e=performance.now();try{let r=await this.executeLoaderWithTimeout(t.loader,n),i=performance.now()-e;return this.options.developmentMode&&console.log(`[Layout] Loaded data for ${t.path} in ${i.toFixed(2)}ms`),{success:!0,data:r,loadingTime:i,layoutPath:t.path}}catch(e){r=e instanceof Error?e:Error(String(e)),i++,this.options.developmentMode&&console.warn(`[Layout] Data loading attempt ${i} failed for ${t.path}: ${r.message}`),i<=this.options.maxRetries&&await this.delay(this.options.retryDelay)}}return{success:!1,data:{},error:new LayoutDataLoadingError(`Layout data loading failed after ${this.options.maxRetries+1} attempts: ${r?.message}`,t.path,r),loadingTime:0,layoutPath:t.path}}executeLoaderWithTimeout(e,t){return new Promise((n,r)=>{let i=setTimeout(()=>{r(Error(`Layout data loading timed out after ${this.options.timeout}ms`))},this.options.timeout);Promise.resolve(e(t)).then(e=>{clearTimeout(i),n(e)}).catch(e=>{clearTimeout(i),r(e)})})}createEnhancedContext(e,t){let n={...e,state:new Map(e.state)};return n.state.set(`parentLayoutData`,t),n}processLoadingResults(e,t){let n=[],r=[],i=new Map;return e.forEach(e=>{i.set(e.layoutPath,e)}),t.forEach(e=>{let t=i.get(e.path);t?t.success?n.push(t.data):(n.push({}),t.error&&(r.push({layoutPath:e.path,errorType:`loader`,timestamp:Date.now()}),this.options.developmentMode&&console.error(`[Layout] Data loading error for ${e.path}:`,t.error))):n.push({})}),{data:n,errors:r}}createFallbackData(e,t){return{__layoutError:!0,__layoutPath:e,__errorMessage:t.message,__errorType:`data-loading`,__timestamp:Date.now()}}validateLayoutData(t,n){if(t==null)return{};if(typeof t!=`object`)throw new LayoutDataLoadingError(`Layout loader must return an object, got ${typeof t}`,n);if(Array.isArray(t))throw new LayoutDataLoadingError(`Layout loader must return an object, not an array`,n);return t}delay(e){return new Promise(t=>setTimeout(t,e))}async preloadLayoutData(e,t,n=`medium`){let r=e.filter(e=>e.loader);if(r.length===0)return;let i=this.options.timeout;switch(n){case`high`:this.options.timeout=i*.5;break;case`low`:this.options.timeout=i*2;break}try{let e=await this.loadDataInParallel(r,t);if(this.options.developmentMode){let t=e.filter(e=>e.success).length;console.log(`[LayoutDataLoader] Preloaded ${t}/${e.length} layouts (priority: ${n})`)}}catch(e){this.options.developmentMode&&console.warn(`[LayoutDataLoader] Preload failed:`,e)}finally{this.options.timeout=i}}getOptions(){return{...this.options}}updateOptions(e){Object.assign(this.options,e)}}export const defaultLayoutDataLoader=new LayoutDataLoader;export function createLayoutDataLoader(e={}){return new LayoutDataLoader(e)}export async function loadSingleLayoutData(e,n,r={}){return(await new LayoutDataLoader(r).loadLayoutData([e],n))[0]||{success:!0,data:{},loadingTime:0,layoutPath:e.path}}export function mergeLayoutData(...e){let t={};for(let n of e)n&&typeof n==`object`&&!Array.isArray(n)&&Object.assign(t,n);return t}export function getParentLayoutData(e){let t=e.state.get(`parentLayoutData`);return Array.isArray(t)?t:[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{join as e,resolve as t,relative as n}from"node:path";import{statSync as r}from"node:fs";function i(e){return/^[A-Za-z]:[\\/]/.test(e)?`file:///${e.replaceAll(`\\`,`/`)}`:e}function a(e){try{return r(e),!0}catch{return!1}}function o(e){let t=e.split(`/`).filter(Boolean),n=[``];for(let e=0;e<t.length;e++)n.push(`/`+t.slice(0,e+1).join(`/`));return n}export class LayoutDiscovery{layoutCache=new Map;routeCache=new Map;baseDirectory;filePattern;developmentMode;constructor(e){this.baseDirectory=t(e.baseDirectory),this.filePattern=e.filePattern||`_layout.tsx`,this.developmentMode=e.developmentMode||!1,this.developmentMode&&console.log(`[LayoutDiscovery] baseDirectory=${this.baseDirectory}, filePattern=${this.filePattern}`)}discoverLayouts(t){let n=`layouts-${t}`;if(this.routeCache.has(n))return Promise.resolve(this.routeCache.get(n));let r=[],i=o(t);for(let t of i){let n=e(t===``?this.baseDirectory:e(this.baseDirectory,t),this.filePattern);if(a(n)){let e=t===``?0:t.split(`/`).filter(Boolean).length;r.push({pattern:new URLPattern({pathname:e===0?`*`:`${t}/*`}),layoutPath:n,priority:e*10,type:e===0?`root`:`nested`,depth:e})}}return r.sort((e,t)=>e.priority-t.priority),this.routeCache.set(n,r),Promise.resolve(r)}async buildLayoutChain(e){let t=await this.discoverLayouts(e.pathname),n=[];for(let e of t)try{let t=await this.loadLayout(e.layoutPath);t&&n.push(t)}catch(t){this.developmentMode&&console.warn(`[Layout] Failed to load ${e.layoutPath}: ${t instanceof Error?t.message:String(t)}`)}return n}async buildLayoutChainWithData(e,t){let n=await this.buildLayoutChain(e),r=[],i=[];for(let e of n)if(e.loader)try{let n=await e.loader(t);r.push(n)}catch(t){this.developmentMode&&console.warn(`[Layout] Data loader error for ${e.path}:`,t),i.push({layoutPath:e.path,errorType:`loader`,timestamp:Date.now()}),r.push({})}else r.push({});return{handlers:n,data:r,errors:i}}async loadLayout(e){if(this.layoutCache.has(e))return this.layoutCache.get(e);try{let t=await import(i(e));if(!t.default||typeof t.default!=`function`)return this.developmentMode&&console.warn(`[Layout] No default export in ${e}`),null;let r=n(this.baseDirectory,e).split(`/`).filter(Boolean),a=Math.max(0,(r.length-1)*10),o={component:t.default,loader:t.layoutLoader,path:e,priority:a};return this.layoutCache.set(e,o),o}catch(t){return this.developmentMode&&console.warn(`[Layout] Failed to load ${e}: ${t instanceof Error?t.message:String(t)}`),null}}clearCache(){this.layoutCache.clear(),this.routeCache.clear()}clearLayoutCache(e){this.layoutCache.delete(e),this.routeCache.clear()}getCacheStats(){return{layoutCount:this.layoutCache.size,routeCacheCount:this.routeCache.size}}getOptions(){return{baseDirectory:this.baseDirectory,filePattern:this.filePattern,developmentMode:this.developmentMode}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class BuiltInLayoutRules{static API_ROUTES_SKIP_LAYOUTS={matches:e=>e.path.startsWith(`/api/`),apply:!1,priority:100};static MOBILE_LAYOUT_DETECTION={matches:(e,t)=>{let n=e.headers.get(`user-agent`)?.toLowerCase()||``,r=/mobile|android|iphone|ipad|phone|tablet/i.test(n);return t?.includes(`/mobile/`)??!1?!r:r},apply:!1,priority:50};static HEADER_BASED_SKIP={matches:e=>{let t=e.headers.get(`x-skip-layout`);return t===`true`||t===`1`},apply:!1,priority:90};static ADMIN_LAYOUT_RESTRICTION={matches:(e,t)=>t?.includes(`/admin/`)?!e.path.startsWith(`/admin/`):!1,apply:!1,priority:60};static getAllRules(){return[this.API_ROUTES_SKIP_LAYOUTS,this.MOBILE_LAYOUT_DETECTION,this.HEADER_BASED_SKIP,this.ADMIN_LAYOUT_RESTRICTION]}}export class LayoutMatcher{rules=[];developmentMode;constructor(e={}){this.developmentMode=e.developmentMode||!1,this.addBuiltInRules()}addRule(e){if(!e.matches||typeof e.matches!=`function`)throw Error(`Layout rule must have a valid matches function`);if(typeof e.apply!=`boolean`)throw TypeError(`Layout rule must have a boolean apply property`);if(typeof e.priority!=`number`)throw TypeError(`Layout rule must have a numeric priority`);this.rules.push(e),this.sortRulesByPriority(),this.developmentMode&&console.log(`[LayoutMatcher] Added rule with priority ${e.priority}`)}removeRule(e){let t=this.rules.indexOf(e);t>-1&&(this.rules.splice(t,1),this.developmentMode&&console.log(`[LayoutMatcher] Removed rule with priority ${e.priority}`))}shouldApplyLayout(e,t){try{let n=this.getMatchingRules(t,e);if(n.length===0)return!0;let r=this.resolveRuleConflicts(n);return this.developmentMode&&console.log(`[LayoutMatcher] Layout ${e} for route ${t.path}: ${r?`APPLY`:`SKIP`} (${n.length} rules matched)`),r}catch(t){return this.developmentMode&&console.warn(`[LayoutMatcher] Error evaluating rules for layout ${e}: ${t instanceof Error?t.message:String(t)}`),!0}}getRules(){return[...this.rules]}clearRules(){this.rules=[],this.developmentMode&&console.log(`[LayoutMatcher] Cleared all rules`)}addBuiltInRules(){for(let t of BuiltInLayoutRules.getAllRules())this.rules.push(t);this.sortRulesByPriority(),this.developmentMode&&console.log(`[LayoutMatcher] Added ${this.rules.length} built-in rules`)}sortRulesByPriority(){this.rules.sort((e,t)=>t.priority-e.priority)}getMatchingRules(e,t){let n=[];for(let r of this.rules)try{r.matches(e,t)&&n.push(r)}catch(e){this.developmentMode&&console.warn(`[LayoutMatcher] Error in rule evaluation: ${e instanceof Error?e.message:String(e)}`)}return n}resolveRuleConflicts(e){if(e.length===0)return!0;if(e.length===1)return e[0].apply;let t=new Map;for(let n of e)t.has(n.priority)||t.set(n.priority,[]),t.get(n.priority).push(n);let n=Array.from(t.keys()).sort((e,t)=>t-e),r=t.get(n[0]);return r.length===1?r[0].apply:this.resolveEqualPriorityConflicts(r)}resolveEqualPriorityConflicts(e){let t=e.filter(e=>e.apply).length,n=e.filter(e=>!e.apply).length;return n>t?(this.developmentMode&&console.log(`[LayoutMatcher] Conflict resolution: SKIP`),!1):t>n?(this.developmentMode&&console.log(`[LayoutMatcher] Conflict resolution: APPLY`),!0):(this.developmentMode&&console.log(`[LayoutMatcher] Conflict resolution: SKIP (tie-breaker)`),!1)}static createCustomRule(e,t,n=10){return{matches:e,apply:t,priority:n}}static createPathRule(e,t,n=10){return{matches:typeof e==`string`?t=>t.path.includes(e):t=>e.test(t.path),apply:t,priority:n}}static createHeaderRule(e,t,n,r=10){return{matches:n=>{let r=n.headers.get(e.toLowerCase());return r?typeof t==`string`?r===t:t.test(r):!1},apply:n,priority:r}}static createMethodRule(e,t,n=10){let r=new Set((Array.isArray(e)?e:[e]).map(e=>e.toUpperCase()));return{matches:e=>r.has(e.method.toUpperCase()),apply:t,priority:n}}getDebugInfo(e,t){let n=this.getMatchingRules(t,e),r=this.shouldApplyLayout(e,t);return{totalRules:this.rules.length,matchingRules:n.map(e=>({priority:e.priority,apply:e.apply})),finalDecision:r,conflictResolution:n.length>1?`priority-based`:`single-rule`}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={solid:{extensions:[`.tsx`,`.jsx`],hydrationExtension:`.js`,mimeType:`application/javascript`,transformPath:(e,t)=>e.endsWith(`.tsx`)?e.replace(/\.tsx$/,`.js`):e.endsWith(`.jsx`)?e.replace(/\.jsx$/,`.js`):e},preact:{extensions:[`.tsx`,`.jsx`],hydrationExtension:`.js`,mimeType:`application/javascript`,transformPath:(e,t)=>e.endsWith(`.tsx`)?e.replace(/\.tsx$/,`.js`):e.endsWith(`.jsx`)?e.replace(/\.jsx$/,`.js`):e},vue:{extensions:[`.vue`],hydrationExtension:`.js`,mimeType:`application/javascript`,transformPath:(e,t)=>e.endsWith(`.vue`)?e.replace(/\.vue$/,`.js`):e},svelte:{extensions:[`.svelte`],hydrationExtension:`.js`,mimeType:`application/javascript`,transformPath:(e,t)=>e.endsWith(`.svelte`)?e.replace(/\.svelte$/,`.js`):e},qwik:{extensions:[`.tsx`,`.jsx`],hydrationExtension:`.js`,mimeType:`application/javascript`,transformPath:(e,t)=>e.endsWith(`.tsx`)?e.replace(/\.tsx$/,`.js`):e.endsWith(`.jsx`)?e.replace(/\.jsx$/,`.js`):e}};export class FrameworkModuleResolver{mode;baseUrl;constructor(e=`development`,t=``){this.mode=e,this.baseUrl=t}resolveModule(t,n,r={}){let i=e[n];if(!i)throw Error(`Unknown framework: ${n}`);let{forHydration:a=!1,baseUrl:o=this.baseUrl}=r,s=t,c=!1,l=this.getMimeType(t);if(a){let e=i.transformPath(t,this.mode);e!==t&&(s=e,c=!0,l=i.mimeType)}let u=this.generateModuleUrl(s,o);return{originalPath:t,resolvedPath:s,framework:n,shouldTransform:c,mimeType:l,url:u}}needsTransformation(t,n){let r=e[n];return r?r.transformPath(t,this.mode)!==t:!1}getMimeType(e){switch(this.getFileExtension(e)){case`.js`:case`.mjs`:return`application/javascript`;case`.ts`:case`.tsx`:case`.jsx`:return`application/javascript`;case`.css`:return`text/css`;case`.json`:return`application/json`;case`.vue`:case`.svelte`:return`application/javascript`;default:return`text/plain`}}generateModuleUrl(e,t=this.baseUrl){let n=e.startsWith(`/`)?e:`/${e}`;return t?`${t.replace(/\/$/,``)}${n}`:n}getSupportedFrameworks(){return Object.keys(e)}getFrameworkConfig(t){return e[t]}isFrameworkSupported(t){return t in e}getFileExtension(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.substring(t)}setMode(e){this.mode=e}getMode(){return this.mode}setBaseUrl(e){this.baseUrl=e}getBaseUrl(){return this.baseUrl}}export const frameworkModuleResolver=new FrameworkModuleResolver;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{analyzeComponentContent as e}from"../core/components/component-analyzer.js";import{resolveIslandPath as t}from"./framework-detection.js";import{getCachedAnalysis as n,setCachedAnalysis as r,getCachedPath as i,setCachedPath as a}from"./render-cache.js";import{readFile as o}from"node:fs/promises";function s(e,t){let n=e.split(`/`).pop()?.replace(/\.(tsx|jsx|vue|svelte|ts|js)$/,``)||``,r=e.split(`.`).pop()||`tsx`;return[t.startsWith(`/`)?t.substring(1):t,e.startsWith(`/`)?e.substring(1):e,`src/islands/${n}.${r}`,`src/islands/${n}.tsx`,`islands/${n}.${r}`,`islands/${n}.tsx`,`src/islands/${n}.svelte`,`src/islands/${n}.vue`,`src/islands/${n}.solid.tsx`]}async function c(e){try{return await o(e,`utf-8`)}catch{return null}}export async function analyzeComponentFile(o,l={}){let u=n(o);if(u)return u;let d=i(o);d||=await t(o);let f=s(o,d);for(let t of f){let n=await c(t);if(n!==null){a(o,t);let i=e(t,n,l);return r(o,i),i}}throw Error(`Component file not found: ${o}`)}export async function renderComponentSSROnly({src:e,condition:t,props:n,framework:r,renderOptions:i}){try{let{default:a}=await import(`./island.js`),{loadIntegration:o}=await import(`./integration-loader.js`),{detectFramework:s}=await import(`./framework-detection.js`),c;c=r||(e.endsWith(`.vue`)?`vue`:e.endsWith(`.svelte`)?`svelte`:e.endsWith(`.tsx`)||e.endsWith(`.jsx`)||e.endsWith(`.ts`)||e.endsWith(`.js`)?await s(e):`preact`);let l=await o(c),u=globalThis.__viteDevServer,d=process.env.NODE_ENV!==`production`;return a({src:e,condition:t,props:n,children:(await l.render({component:null,props:n,src:e,condition:t,ssrOnly:!0,viteServer:u,isDev:d})).html,ssr:!0,framework:c,ssrOnly:!0,renderOptions:i,hydrationData:void 0})}catch(t){throw process.env.NODE_ENV!==`production`&&console.error(`SSR-only rendering failed for ${e}:`,t),t}}
|