meno-core 1.0.10 → 1.0.11
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.
|
@@ -8,7 +8,7 @@ import type { ComponentDefinition, JSONPage } from '../../shared/types';
|
|
|
8
8
|
import type { SlugMap } from '../../shared/slugTranslator';
|
|
9
9
|
import type { CMSService } from '../services/cmsService';
|
|
10
10
|
import { loadBreakpointConfig, loadResponsiveScalesConfig, loadIconsConfig, loadPrefetchConfig } from '../jsonLoader';
|
|
11
|
-
import { generateFontCSS } from '../../shared/fontLoader';
|
|
11
|
+
import { generateFontCSS, generateFontPreloadTags } from '../../shared/fontLoader';
|
|
12
12
|
import { colorService } from '../services/ColorService';
|
|
13
13
|
import { generateThemeColorVariablesCSS } from '../cssGenerator';
|
|
14
14
|
import { generateUtilityCSS, extractUtilityClassesFromHTML, generateAllInteractiveCSS } from '../../shared/cssGeneration';
|
|
@@ -178,8 +178,9 @@ export async function generateSSRHTML(
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
// Generate font CSS from project config
|
|
181
|
+
// Generate font CSS and preload tags from project config
|
|
182
182
|
const fontCSS = generateFontCSS();
|
|
183
|
+
const fontPreloadTags = generateFontPreloadTags();
|
|
183
184
|
|
|
184
185
|
// Load icons config for favicon and apple touch icon
|
|
185
186
|
const iconsConfig = await loadIconsConfig();
|
|
@@ -239,7 +240,7 @@ export async function generateSSRHTML(
|
|
|
239
240
|
<head>
|
|
240
241
|
<meta charset="UTF-8">
|
|
241
242
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
242
|
-
${iconTags ? iconTags + '\n ' : ''}${rendered.meta}
|
|
243
|
+
${iconTags ? iconTags + '\n ' : ''}${fontPreloadTags ? fontPreloadTags + '\n ' : ''}${rendered.meta}
|
|
243
244
|
${configInlineScript}${cmsInlineScript}<style>
|
|
244
245
|
${fontCSS ? fontCSS + '\n ' : ''}${themeColorVariablesCSS ? themeColorVariablesCSS + '\n ' : ''}* {
|
|
245
246
|
margin: 0;
|
package/lib/shared/fontLoader.ts
CHANGED
|
@@ -84,6 +84,37 @@ export function generateFontCSS(): string {
|
|
|
84
84
|
.join('\n\n');
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Get font MIME type for preload "type" attribute
|
|
89
|
+
*/
|
|
90
|
+
function getFontMimeType(path: string): string {
|
|
91
|
+
if (path.endsWith('.woff2')) return 'font/woff2';
|
|
92
|
+
if (path.endsWith('.woff')) return 'font/woff';
|
|
93
|
+
if (path.endsWith('.ttf')) return 'font/ttf';
|
|
94
|
+
if (path.endsWith('.otf')) return 'font/otf';
|
|
95
|
+
return 'font/ttf';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Generate font preload link tags for early font loading
|
|
100
|
+
* This prevents font swap flash on SPA navigation by ensuring fonts are
|
|
101
|
+
* loaded and cached before they're needed.
|
|
102
|
+
*/
|
|
103
|
+
export function generateFontPreloadTags(): string {
|
|
104
|
+
const config = getProjectConfig();
|
|
105
|
+
const fonts = config.fonts || [];
|
|
106
|
+
|
|
107
|
+
if (fonts.length === 0) return '';
|
|
108
|
+
|
|
109
|
+
return fonts
|
|
110
|
+
.map((font: FontConfig) => {
|
|
111
|
+
const mimeType = getFontMimeType(font.path);
|
|
112
|
+
// crossorigin is required for fonts to be cached properly
|
|
113
|
+
return `<link rel="preload" href="${font.path}" as="font" type="${mimeType}" crossorigin>`;
|
|
114
|
+
})
|
|
115
|
+
.join('\n ');
|
|
116
|
+
}
|
|
117
|
+
|
|
87
118
|
export function getFontFamilies(): Record<string, number[]> {
|
|
88
119
|
const config = getProjectConfig();
|
|
89
120
|
const fonts = config.fonts || [];
|