@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
package/src/islands/css-utils.ts
DELETED
|
@@ -1,565 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CSS Utilities Module
|
|
3
|
-
*
|
|
4
|
-
* This module contains all CSS-related utilities for the Island system:
|
|
5
|
-
* - Svelte SSR CSS collection and management
|
|
6
|
-
* - CSS scoping for component isolation
|
|
7
|
-
* - CSS optimization and minification
|
|
8
|
-
* - CSS parsing and deduplication
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
// Enhanced global CSS collector for SSR with scoping support
|
|
12
|
-
declare global {
|
|
13
|
-
var __svelteSSRCSS: Map<string, SvelteSSRCSSEntry> | undefined;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface SvelteSSRCSSEntry {
|
|
17
|
-
css: string;
|
|
18
|
-
scopeId: string;
|
|
19
|
-
src: string;
|
|
20
|
-
isGlobal: boolean;
|
|
21
|
-
timestamp: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Initialize enhanced global CSS collector
|
|
25
|
-
if (typeof globalThis !== "undefined" && !globalThis.__svelteSSRCSS) {
|
|
26
|
-
globalThis.__svelteSSRCSS = new Map();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Add CSS to the global Svelte SSR collection with scoping information
|
|
31
|
-
*/
|
|
32
|
-
export function addSvelteSSRCSS(
|
|
33
|
-
css: string,
|
|
34
|
-
scopeId: string,
|
|
35
|
-
src: string,
|
|
36
|
-
isGlobal = false,
|
|
37
|
-
): void {
|
|
38
|
-
if (!globalThis.__svelteSSRCSS) {
|
|
39
|
-
globalThis.__svelteSSRCSS = new Map();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const entry: SvelteSSRCSSEntry = {
|
|
43
|
-
css: css.trim(),
|
|
44
|
-
scopeId,
|
|
45
|
-
src,
|
|
46
|
-
isGlobal,
|
|
47
|
-
timestamp: Date.now(),
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// Use scopeId as key to prevent duplicates from the same component
|
|
51
|
-
globalThis.__svelteSSRCSS.set(scopeId, entry);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Get collected Svelte SSR CSS with enhanced processing and deduplication
|
|
56
|
-
* Enhanced version with better CSS management and document head injection support
|
|
57
|
-
*/
|
|
58
|
-
export function getSvelteSSRCSS(clear = false) {
|
|
59
|
-
if (!globalThis.__svelteSSRCSS || globalThis.__svelteSSRCSS.size === 0) {
|
|
60
|
-
return "";
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const entries = Array.from(globalThis.__svelteSSRCSS.values());
|
|
64
|
-
|
|
65
|
-
// Sort entries: global styles first, then component styles by timestamp
|
|
66
|
-
entries.sort((a, b) => {
|
|
67
|
-
if (a.isGlobal && !b.isGlobal) return -1;
|
|
68
|
-
if (!a.isGlobal && b.isGlobal) return 1;
|
|
69
|
-
return a.timestamp - b.timestamp;
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// Separate global and component-scoped CSS for better organization
|
|
73
|
-
const globalEntries = entries.filter((entry) => entry.isGlobal);
|
|
74
|
-
const componentEntries = entries.filter((entry) => !entry.isGlobal);
|
|
75
|
-
|
|
76
|
-
// Process global CSS
|
|
77
|
-
const globalCSS = globalEntries.map((entry) => {
|
|
78
|
-
const comment = `/* Global CSS from: ${entry.src} */`;
|
|
79
|
-
return `${comment}\n${entry.css}`;
|
|
80
|
-
}).join("\n\n");
|
|
81
|
-
|
|
82
|
-
// Process component-scoped CSS
|
|
83
|
-
const componentCSS = componentEntries.map((entry) => {
|
|
84
|
-
const comment = `/* Component CSS: ${entry.src} (${entry.scopeId}) */`;
|
|
85
|
-
return `${comment}\n${entry.css}`;
|
|
86
|
-
}).join("\n\n");
|
|
87
|
-
|
|
88
|
-
// Combine in proper order: global first, then component-specific
|
|
89
|
-
const combinedCSS = [globalCSS, componentCSS].filter((css) => css.trim())
|
|
90
|
-
.join("\n\n");
|
|
91
|
-
|
|
92
|
-
// Apply enhanced CSS optimization and deduplication
|
|
93
|
-
const optimizedCSS = optimizeSvelteSSRCSS(combinedCSS);
|
|
94
|
-
|
|
95
|
-
if (clear) {
|
|
96
|
-
globalThis.__svelteSSRCSS.clear();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return optimizedCSS;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Get CSS formatted for document head injection during SSR
|
|
104
|
-
* Returns CSS wrapped in appropriate style tags with metadata
|
|
105
|
-
*/
|
|
106
|
-
export function getSvelteSSRCSSForHead(clear = false) {
|
|
107
|
-
const css = getSvelteSSRCSS(clear);
|
|
108
|
-
|
|
109
|
-
if (!css.trim()) {
|
|
110
|
-
return "";
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Wrap in style tag with metadata for identification and debugging
|
|
114
|
-
const timestamp = new Date().toISOString();
|
|
115
|
-
const styleTag =
|
|
116
|
-
`<style data-svelte-ssr="true" data-generated="${timestamp}">\n${css}\n</style>`;
|
|
117
|
-
|
|
118
|
-
return styleTag;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Get CSS statistics for debugging and monitoring
|
|
123
|
-
*/
|
|
124
|
-
export function getSvelteSSRCSSStats() {
|
|
125
|
-
if (!globalThis.__svelteSSRCSS || globalThis.__svelteSSRCSS.size === 0) {
|
|
126
|
-
return {
|
|
127
|
-
totalComponents: 0,
|
|
128
|
-
globalComponents: 0,
|
|
129
|
-
scopedComponents: 0,
|
|
130
|
-
totalCSSSize: 0,
|
|
131
|
-
averageCSSSize: 0,
|
|
132
|
-
oldestTimestamp: 0,
|
|
133
|
-
newestTimestamp: 0,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const entries = Array.from(globalThis.__svelteSSRCSS.values());
|
|
138
|
-
const globalEntries = entries.filter((entry) => entry.isGlobal);
|
|
139
|
-
const scopedEntries = entries.filter((entry) => !entry.isGlobal);
|
|
140
|
-
const totalCSSSize = entries.reduce(
|
|
141
|
-
(sum, entry) => sum + entry.css.length,
|
|
142
|
-
0,
|
|
143
|
-
);
|
|
144
|
-
const timestamps = entries.map((entry) => entry.timestamp);
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
totalComponents: entries.length,
|
|
148
|
-
globalComponents: globalEntries.length,
|
|
149
|
-
scopedComponents: scopedEntries.length,
|
|
150
|
-
totalCSSSize,
|
|
151
|
-
averageCSSSize: entries.length > 0
|
|
152
|
-
? Math.round(totalCSSSize / entries.length)
|
|
153
|
-
: 0,
|
|
154
|
-
oldestTimestamp: Math.min(...timestamps),
|
|
155
|
-
newestTimestamp: Math.max(...timestamps),
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Get CSS for specific component scope
|
|
161
|
-
*/
|
|
162
|
-
export function getSvelteComponentCSS(scopeId: string) {
|
|
163
|
-
if (!globalThis.__svelteSSRCSS) {
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const entry = globalThis.__svelteSSRCSS.get(scopeId);
|
|
168
|
-
return entry ? entry.css : null;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Clear CSS for specific component scope
|
|
173
|
-
*/
|
|
174
|
-
export function clearSvelteComponentCSS(scopeId: string) {
|
|
175
|
-
if (!globalThis.__svelteSSRCSS) {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const deleted = globalThis.__svelteSSRCSS.delete(scopeId);
|
|
180
|
-
if (deleted) {
|
|
181
|
-
// CSS cleared for component scope
|
|
182
|
-
}
|
|
183
|
-
return deleted;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Optimize collected Svelte SSR CSS by removing duplicates and minifying
|
|
188
|
-
* Enhanced version with better deduplication and cross-component optimization
|
|
189
|
-
*/
|
|
190
|
-
function optimizeSvelteSSRCSS(css: string) {
|
|
191
|
-
try {
|
|
192
|
-
// Use the enhanced CSS optimization functions
|
|
193
|
-
const optimizedCSS = optimizeComponentCSS(css);
|
|
194
|
-
|
|
195
|
-
// Additional optimizations specific to SSR CSS collection
|
|
196
|
-
const finalCSS = optimizeSSRCSSCollection(optimizedCSS);
|
|
197
|
-
|
|
198
|
-
return finalCSS;
|
|
199
|
-
} catch (error) {
|
|
200
|
-
console.warn(`⚠️ Failed to optimize Svelte SSR CSS:`, error);
|
|
201
|
-
return css;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Apply SSR-specific CSS optimizations across multiple components
|
|
207
|
-
*/
|
|
208
|
-
function optimizeSSRCSSCollection(css: string) {
|
|
209
|
-
try {
|
|
210
|
-
// Remove duplicate comments
|
|
211
|
-
const withoutDuplicateComments = removeDuplicateComments(css);
|
|
212
|
-
|
|
213
|
-
// Optimize cross-component CSS patterns
|
|
214
|
-
const crossOptimized = optimizeCrossComponentCSS(withoutDuplicateComments);
|
|
215
|
-
|
|
216
|
-
// Apply final formatting based on environment
|
|
217
|
-
const isDev = process.env.NODE_ENV !== "production";
|
|
218
|
-
if (!isDev) {
|
|
219
|
-
return minifyCSS(crossOptimized);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// Keep readable format in development with proper indentation
|
|
223
|
-
return formatDevelopmentCSS(crossOptimized);
|
|
224
|
-
} catch (error) {
|
|
225
|
-
console.warn(`⚠️ Failed to apply SSR CSS collection optimizations:`, error);
|
|
226
|
-
return css;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Remove duplicate CSS comments while preserving important ones
|
|
232
|
-
*/
|
|
233
|
-
function removeDuplicateComments(css: string) {
|
|
234
|
-
const seenComments = new Set<string>();
|
|
235
|
-
|
|
236
|
-
return css.replace(/\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\//g, (comment) => {
|
|
237
|
-
// Keep important comments (those with specific markers)
|
|
238
|
-
if (
|
|
239
|
-
comment.includes("!important") || comment.includes("@preserve") ||
|
|
240
|
-
comment.includes("license")
|
|
241
|
-
) {
|
|
242
|
-
return comment;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Remove duplicate comments
|
|
246
|
-
if (seenComments.has(comment)) {
|
|
247
|
-
return "";
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
seenComments.add(comment);
|
|
251
|
-
return comment;
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Optimize CSS patterns that appear across multiple components
|
|
257
|
-
*/
|
|
258
|
-
function optimizeCrossComponentCSS(css: string) {
|
|
259
|
-
// This could be extended to merge similar rules across components
|
|
260
|
-
// For now, just clean up whitespace and formatting
|
|
261
|
-
return css
|
|
262
|
-
.replace(/\n\s*\n\s*\n/g, "\n\n") // Collapse multiple empty lines
|
|
263
|
-
.replace(/^\s*\n/gm, "") // Remove empty lines at start of sections
|
|
264
|
-
.trim();
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Format CSS for development with proper indentation and spacing
|
|
269
|
-
*/
|
|
270
|
-
function formatDevelopmentCSS(css: string) {
|
|
271
|
-
return css
|
|
272
|
-
.replace(/\{/g, " {\n ")
|
|
273
|
-
.replace(/;/g, ";\n ")
|
|
274
|
-
.replace(/\}/g, "\n}\n")
|
|
275
|
-
.replace(/\n {2}\n/g, "\n")
|
|
276
|
-
.replace(/\n\n+/g, "\n\n")
|
|
277
|
-
.trim();
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Apply CSS scoping to selectors with advanced logic
|
|
282
|
-
* Enhanced version with better selector parsing and scoping rules
|
|
283
|
-
*/
|
|
284
|
-
export function applyCSSScoping(cssContent: string, scopeId: string) {
|
|
285
|
-
return cssContent.replace(/([^{}]+){/g, (match, selector) => {
|
|
286
|
-
const trimmedSelector = selector.trim();
|
|
287
|
-
|
|
288
|
-
// Skip at-rules (@media, @keyframes, @import, etc.)
|
|
289
|
-
if (trimmedSelector.startsWith("@")) {
|
|
290
|
-
return match;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// Skip selectors that already have scoping
|
|
294
|
-
if (trimmedSelector.includes(`[data-${scopeId}]`)) {
|
|
295
|
-
return match;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// Skip :global() selectors (remove the wrapper)
|
|
299
|
-
if (trimmedSelector.includes(":global(")) {
|
|
300
|
-
const globalSelector = trimmedSelector.replace(
|
|
301
|
-
/:global\(([^)]+)\)/g,
|
|
302
|
-
"$1",
|
|
303
|
-
);
|
|
304
|
-
return `${globalSelector} {`;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// Apply scoping to each selector in a comma-separated list
|
|
308
|
-
const scopedSelectors = trimmedSelector
|
|
309
|
-
.split(",")
|
|
310
|
-
.map((sel: string) => applySelectorScoping(sel.trim(), scopeId))
|
|
311
|
-
.join(", ");
|
|
312
|
-
|
|
313
|
-
return `${scopedSelectors} {`;
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Apply scoping to a single CSS selector with comprehensive logic
|
|
319
|
-
*/
|
|
320
|
-
export function applySelectorScoping(selector: string, scopeId: string) {
|
|
321
|
-
// Handle empty or invalid selectors
|
|
322
|
-
if (!selector || selector.length === 0) {
|
|
323
|
-
return selector;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// Skip already scoped selectors
|
|
327
|
-
if (selector.includes(`[data-${scopeId}]`)) {
|
|
328
|
-
return selector;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// Handle complex selectors with combinators (>, +, ~, space)
|
|
332
|
-
const combinatorRegex = /(\s*[>+~]\s*|\s+)/;
|
|
333
|
-
const parts = selector.split(combinatorRegex);
|
|
334
|
-
|
|
335
|
-
if (parts.length > 1) {
|
|
336
|
-
// Complex selector with combinators - scope the first part only
|
|
337
|
-
const firstPart = parts[0].trim();
|
|
338
|
-
const rest = parts.slice(1).join("");
|
|
339
|
-
return applySingleSelectorScoping(firstPart, scopeId) + rest;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// Simple selector
|
|
343
|
-
return applySingleSelectorScoping(selector, scopeId);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Apply scoping to a single, simple CSS selector
|
|
348
|
-
*/
|
|
349
|
-
function applySingleSelectorScoping(selector: string, scopeId: string) {
|
|
350
|
-
// Handle pseudo-elements (::before, ::after)
|
|
351
|
-
const pseudoElementMatch = selector.match(/^([^:]+)(::.*)?$/);
|
|
352
|
-
if (pseudoElementMatch) {
|
|
353
|
-
const [, baseSelector, pseudoElement] = pseudoElementMatch;
|
|
354
|
-
return `${baseSelector}[data-${scopeId}]${pseudoElement || ""}`;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// Handle pseudo-classes (:hover, :focus, :nth-child, etc.)
|
|
358
|
-
const pseudoClassMatch = selector.match(/^([^:]+)(:.*)?$/);
|
|
359
|
-
if (pseudoClassMatch) {
|
|
360
|
-
const [, baseSelector, pseudoClass] = pseudoClassMatch;
|
|
361
|
-
return `${baseSelector}[data-${scopeId}]${pseudoClass || ""}`;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// Simple selector without pseudo-classes/elements
|
|
365
|
-
return `${selector}[data-${scopeId}]`;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Optimize component CSS by removing duplicates and applying minification
|
|
370
|
-
* Enhanced version with better deduplication and optimization strategies
|
|
371
|
-
*/
|
|
372
|
-
export function optimizeComponentCSS(css: string) {
|
|
373
|
-
try {
|
|
374
|
-
// Parse CSS into rules with better handling
|
|
375
|
-
const rules = parseCSRules(css);
|
|
376
|
-
const optimizedRules = deduplicateCSRules(rules);
|
|
377
|
-
|
|
378
|
-
// Reconstruct CSS
|
|
379
|
-
const optimizedCSS = optimizedRules.join("\n");
|
|
380
|
-
|
|
381
|
-
// Apply environment-specific optimizations
|
|
382
|
-
const isDev = process.env.NODE_ENV !== "production";
|
|
383
|
-
if (!isDev) {
|
|
384
|
-
return minifyCSS(optimizedCSS);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
return optimizedCSS;
|
|
388
|
-
} catch (error) {
|
|
389
|
-
console.warn(`⚠️ Failed to optimize component CSS:`, error);
|
|
390
|
-
return css;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* Parse CSS into individual rules with proper handling of nested structures
|
|
396
|
-
*/
|
|
397
|
-
function parseCSRules(css: string) {
|
|
398
|
-
const rules: string[] = [];
|
|
399
|
-
let currentRule = "";
|
|
400
|
-
let braceDepth = 0;
|
|
401
|
-
let inString = false;
|
|
402
|
-
let stringChar = "";
|
|
403
|
-
|
|
404
|
-
for (let i = 0; i < css.length; i++) {
|
|
405
|
-
const char = css[i];
|
|
406
|
-
const prevChar = i > 0 ? css[i - 1] : "";
|
|
407
|
-
|
|
408
|
-
// Handle string literals
|
|
409
|
-
if ((char === '"' || char === "'") && prevChar !== "\\") {
|
|
410
|
-
if (!inString) {
|
|
411
|
-
inString = true;
|
|
412
|
-
stringChar = char;
|
|
413
|
-
} else if (char === stringChar) {
|
|
414
|
-
inString = false;
|
|
415
|
-
stringChar = "";
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
if (!inString) {
|
|
420
|
-
if (char === "{") {
|
|
421
|
-
braceDepth++;
|
|
422
|
-
} else if (char === "}") {
|
|
423
|
-
braceDepth--;
|
|
424
|
-
|
|
425
|
-
if (braceDepth === 0) {
|
|
426
|
-
// End of a complete rule
|
|
427
|
-
currentRule += char;
|
|
428
|
-
const trimmedRule = currentRule.trim();
|
|
429
|
-
if (trimmedRule && !isEmptyRule(trimmedRule)) {
|
|
430
|
-
rules.push(trimmedRule);
|
|
431
|
-
}
|
|
432
|
-
currentRule = "";
|
|
433
|
-
continue;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
currentRule += char;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// Handle any remaining content
|
|
442
|
-
if (currentRule.trim()) {
|
|
443
|
-
rules.push(currentRule.trim());
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
return rules;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Deduplicate CSS rules while preserving order and handling specificity
|
|
451
|
-
*/
|
|
452
|
-
function deduplicateCSRules(rules: string[]) {
|
|
453
|
-
const seenRules = new Map<string, { rule: string; index: number }>();
|
|
454
|
-
const result: string[] = [];
|
|
455
|
-
|
|
456
|
-
for (let i = 0; i < rules.length; i++) {
|
|
457
|
-
const rule = rules[i];
|
|
458
|
-
const ruleKey = extractRuleKey(rule);
|
|
459
|
-
|
|
460
|
-
if (ruleKey) {
|
|
461
|
-
const existing = seenRules.get(ruleKey);
|
|
462
|
-
if (existing) {
|
|
463
|
-
// Replace earlier rule with later one (cascade order)
|
|
464
|
-
result[existing.index] = rule;
|
|
465
|
-
seenRules.set(ruleKey, { rule, index: existing.index });
|
|
466
|
-
} else {
|
|
467
|
-
// New rule
|
|
468
|
-
const index = result.length;
|
|
469
|
-
result.push(rule);
|
|
470
|
-
seenRules.set(ruleKey, { rule, index });
|
|
471
|
-
}
|
|
472
|
-
} else {
|
|
473
|
-
// Non-standard rule (at-rules, etc.) - keep as-is
|
|
474
|
-
result.push(rule);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
return result.filter((rule) => rule !== null);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* Extract a key for rule deduplication (selector + property combination)
|
|
483
|
-
*/
|
|
484
|
-
function extractRuleKey(rule: string) {
|
|
485
|
-
const match = rule.match(/^([^{]+)\{([^}]+)\}/);
|
|
486
|
-
if (!match) return null;
|
|
487
|
-
|
|
488
|
-
const selector = match[1].trim();
|
|
489
|
-
const declarations = match[2].trim();
|
|
490
|
-
|
|
491
|
-
// For deduplication, we consider rules with the same selector as duplicates
|
|
492
|
-
// Later rules will override earlier ones (CSS cascade)
|
|
493
|
-
return selector;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
* Check if a CSS rule is effectively empty
|
|
498
|
-
*/
|
|
499
|
-
function isEmptyRule(rule: string) {
|
|
500
|
-
const match = rule.match(/^[^{]+\{([^}]*)\}/);
|
|
501
|
-
if (!match) return true;
|
|
502
|
-
|
|
503
|
-
const declarations = match[1].trim();
|
|
504
|
-
return declarations.length === 0 || declarations === ";";
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Minify CSS for production builds
|
|
509
|
-
*/
|
|
510
|
-
export function minifyCSS(css: string) {
|
|
511
|
-
return css
|
|
512
|
-
// Remove comments
|
|
513
|
-
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
514
|
-
// Remove unnecessary whitespace
|
|
515
|
-
.replace(/\s+/g, " ")
|
|
516
|
-
// Remove whitespace around braces and semicolons
|
|
517
|
-
.replace(/\s*{\s*/g, "{")
|
|
518
|
-
.replace(/\s*}\s*/g, "}")
|
|
519
|
-
.replace(/\s*;\s*/g, ";")
|
|
520
|
-
.replace(/;\s*}/g, "}")
|
|
521
|
-
// Remove trailing semicolons before closing braces
|
|
522
|
-
.replace(/;}/g, "}")
|
|
523
|
-
// Trim
|
|
524
|
-
.trim();
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* Generate consistent scope ID for any component framework
|
|
529
|
-
* Provides unified scoping across Vue, Svelte, and other frameworks
|
|
530
|
-
*/
|
|
531
|
-
export function generateComponentScopeId(
|
|
532
|
-
src: string,
|
|
533
|
-
framework: string = "component",
|
|
534
|
-
) {
|
|
535
|
-
const cleanPath = src
|
|
536
|
-
.replace(/^\/+/, "") // Remove leading slashes
|
|
537
|
-
.replace(/\.(svelte|tsx|jsx|vue|ts|js)$/, "") // Remove file extensions
|
|
538
|
-
.replace(/[^a-zA-Z0-9\/]/g, "-") // Replace special chars with hyphens
|
|
539
|
-
.replace(/\/+/g, "-") // Replace path separators with hyphens
|
|
540
|
-
.replace(/-+/g, "-") // Collapse multiple hyphens
|
|
541
|
-
.replace(/^-|-$/g, "") // Remove leading/trailing hyphens
|
|
542
|
-
.toLowerCase();
|
|
543
|
-
|
|
544
|
-
// Add framework prefix and hash for collision resistance
|
|
545
|
-
const hash = simpleHash(src);
|
|
546
|
-
return `${framework}-${cleanPath}-${hash}`;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* Simple hash function for generating consistent short hashes
|
|
551
|
-
*/
|
|
552
|
-
export function simpleHash(str: string) {
|
|
553
|
-
let hash = 0;
|
|
554
|
-
for (let i = 0; i < str.length; i++) {
|
|
555
|
-
const char = str.charCodeAt(i);
|
|
556
|
-
hash = ((hash << 5) - hash) + char;
|
|
557
|
-
hash = hash & hash; // Convert to 32-bit integer
|
|
558
|
-
}
|
|
559
|
-
return Math.abs(hash).toString(36).substring(0, 6);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
// Note: processSvelteSSRCSS, extractRawCSSFromHead, and applySvelteComponentScoping
|
|
563
|
-
// were removed as they are not used anywhere in the codebase.
|
|
564
|
-
// They were originally intended for Svelte SSR CSS processing but are superseded
|
|
565
|
-
// by the Svelte 5 render() function which handles CSS differently.
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Island Discovery Module
|
|
3
|
-
*
|
|
4
|
-
* Exports all types and functions for discovering island components
|
|
5
|
-
* in nested directory structures.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// Types
|
|
9
|
-
export type {
|
|
10
|
-
IslandDirectory,
|
|
11
|
-
DiscoveredIsland,
|
|
12
|
-
IslandCollision,
|
|
13
|
-
IslandChangeEvent,
|
|
14
|
-
IslandFileExtension,
|
|
15
|
-
IslandDiscoveryConfig,
|
|
16
|
-
} from "./types.ts";
|
|
17
|
-
|
|
18
|
-
export {
|
|
19
|
-
ISLAND_FILE_EXTENSIONS,
|
|
20
|
-
DEFAULT_DISCOVERY_CONFIG,
|
|
21
|
-
isSupportedIslandExtension,
|
|
22
|
-
} from "./types.ts";
|
|
23
|
-
|
|
24
|
-
// Scanner functions
|
|
25
|
-
export {
|
|
26
|
-
discoverIslandDirectories,
|
|
27
|
-
discoverIslandsInDirectory,
|
|
28
|
-
discoverAllIslands,
|
|
29
|
-
isIslandsDirectory,
|
|
30
|
-
getDefaultIslandsPath,
|
|
31
|
-
hasDefaultIslandsDirectory,
|
|
32
|
-
getQualifiedIslandName,
|
|
33
|
-
parseQualifiedIslandName,
|
|
34
|
-
} from "./scanner.ts";
|
|
35
|
-
|
|
36
|
-
// Registry
|
|
37
|
-
export {
|
|
38
|
-
IslandRegistry,
|
|
39
|
-
createIslandRegistry,
|
|
40
|
-
} from "./registry.ts";
|
|
41
|
-
|
|
42
|
-
// Resolver
|
|
43
|
-
export type {
|
|
44
|
-
ResolutionResult,
|
|
45
|
-
ImportPathOptions,
|
|
46
|
-
} from "./resolver.ts";
|
|
47
|
-
|
|
48
|
-
export {
|
|
49
|
-
IslandResolver,
|
|
50
|
-
createIslandResolver,
|
|
51
|
-
} from "./resolver.ts";
|
|
52
|
-
|
|
53
|
-
// Validator
|
|
54
|
-
export type {
|
|
55
|
-
ValidationResult,
|
|
56
|
-
ValidationError,
|
|
57
|
-
ValidationWarning,
|
|
58
|
-
CircularDependency,
|
|
59
|
-
} from "./validator.ts";
|
|
60
|
-
|
|
61
|
-
export {
|
|
62
|
-
IslandValidator,
|
|
63
|
-
createIslandValidator,
|
|
64
|
-
validateAllIslands,
|
|
65
|
-
formatValidationError,
|
|
66
|
-
formatValidationWarning,
|
|
67
|
-
formatCircularDependency,
|
|
68
|
-
formatValidationResult,
|
|
69
|
-
} from "./validator.ts";
|
|
70
|
-
|
|
71
|
-
// Watcher
|
|
72
|
-
export type {
|
|
73
|
-
IslandChangeCallback,
|
|
74
|
-
IslandWatcherOptions,
|
|
75
|
-
} from "./watcher.ts";
|
|
76
|
-
|
|
77
|
-
export {
|
|
78
|
-
IslandWatcher,
|
|
79
|
-
createIslandWatcher,
|
|
80
|
-
} from "./watcher.ts";
|