@kilivi/payloadcms-theme-management 0.1.6 → 0.1.8
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/dist/components/ServerThemeInjector.d.ts +1 -1
- package/dist/components/ServerThemeInjector.d.ts.map +1 -1
- package/dist/components/{ServerThemeInjector.jsx → ServerThemeInjector.js} +47 -34
- package/dist/components/ServerThemeInjector.js.map +1 -0
- package/dist/components/ThemePreview.js +318 -0
- package/dist/components/ThemePreview.js.map +1 -0
- package/dist/components/typographyPreviewUtils.js +12 -17
- package/dist/components/typographyPreviewUtils.js.map +1 -1
- package/dist/constants/themeFonts.js +94 -24
- package/dist/constants/themeFonts.js.map +1 -1
- package/dist/fields/ColorPickerField.js +332 -0
- package/dist/fields/ColorPickerField.js.map +1 -0
- package/dist/fields/RadiusField.js +174 -0
- package/dist/fields/RadiusField.js.map +1 -0
- package/dist/fields/ThemeColorPickerField.js +163 -0
- package/dist/fields/ThemeColorPickerField.js.map +1 -0
- package/dist/fields/ThemePreviewField.js +558 -0
- package/dist/fields/ThemePreviewField.js.map +1 -0
- package/dist/fields/ThemeTokenSelectField.js +209 -0
- package/dist/fields/ThemeTokenSelectField.js.map +1 -0
- package/dist/fields/colorModeFields.js +167 -73
- package/dist/fields/colorModeFields.js.map +1 -1
- package/dist/fields/themeConfigurationField.d.ts +1 -1
- package/dist/fields/themeConfigurationField.d.ts.map +1 -1
- package/dist/fields/themeConfigurationField.js +224 -131
- package/dist/fields/themeConfigurationField.js.map +1 -1
- package/dist/index.d.ts +17 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -52
- package/dist/index.js.map +1 -1
- package/dist/payload-types.js +2 -2
- package/dist/payload-types.js.map +1 -1
- package/dist/plugin.d.ts +1 -2
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +2 -1
- package/dist/plugin.js.map +1 -1
- package/dist/presets.js +66 -65
- package/dist/presets.js.map +1 -1
- package/dist/providers/Theme/index.d.ts +1 -1
- package/dist/providers/Theme/index.d.ts.map +1 -1
- package/dist/providers/Theme/{index.jsx → index.js} +61 -31
- package/dist/providers/Theme/index.js.map +1 -0
- package/dist/providers/Theme/shared.d.ts +1 -1
- package/dist/providers/Theme/shared.d.ts.map +1 -1
- package/dist/providers/Theme/shared.js +34 -9
- package/dist/providers/Theme/shared.js.map +1 -1
- package/dist/providers/Theme/themeConfig.d.ts +1 -1
- package/dist/providers/Theme/themeConfig.d.ts.map +1 -1
- package/dist/providers/Theme/themeConfig.js +37 -36
- package/dist/providers/Theme/themeConfig.js.map +1 -1
- package/dist/providers/Theme/types.js +15 -13
- package/dist/providers/Theme/types.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +3 -2
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/resolveThemeConfiguration.d.ts +3 -3
- package/dist/utils/resolveThemeConfiguration.d.ts.map +1 -1
- package/dist/utils/resolveThemeConfiguration.js +53 -34
- package/dist/utils/resolveThemeConfiguration.js.map +1 -1
- package/dist/utils/themeAssets.d.ts +1 -1
- package/dist/utils/themeAssets.d.ts.map +1 -1
- package/dist/utils/themeAssets.js +4 -4
- package/dist/utils/themeAssets.js.map +1 -1
- package/dist/utils/themeColors.js +95 -41
- package/dist/utils/themeColors.js.map +1 -1
- package/dist/utils/themeUtils.d.ts +2 -2
- package/dist/utils/themeUtils.d.ts.map +1 -1
- package/dist/utils/themeUtils.js +32 -47
- package/dist/utils/themeUtils.js.map +1 -1
- package/package.json +13 -5
- package/dist/components/ServerThemeInjector.jsx.map +0 -1
- package/dist/components/ThemePreview.jsx +0 -231
- package/dist/components/ThemePreview.jsx.map +0 -1
- package/dist/fields/ColorPickerField.jsx +0 -205
- package/dist/fields/ColorPickerField.jsx.map +0 -1
- package/dist/fields/RadiusField.jsx +0 -123
- package/dist/fields/RadiusField.jsx.map +0 -1
- package/dist/fields/ThemeColorPickerField.jsx +0 -110
- package/dist/fields/ThemeColorPickerField.jsx.map +0 -1
- package/dist/fields/ThemePreviewField.jsx +0 -420
- package/dist/fields/ThemePreviewField.jsx.map +0 -1
- package/dist/fields/ThemeTokenSelectField.jsx +0 -151
- package/dist/fields/ThemeTokenSelectField.jsx.map +0 -1
- package/dist/providers/Theme/index.jsx.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerThemeInjector.d.ts","sourceRoot":"","sources":["../../src/components/ServerThemeInjector.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ServerThemeInjector.d.ts","sourceRoot":"","sources":["../../src/components/ServerThemeInjector.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAatD,UAAU,wBAAwB;IAChC,YAAY,EAAE,WAAW,GAAG,IAAI,CAAA;CACjC;AAMD;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,EAAE,YAAY,EAAE,EAAE,QAAQ,CAAC,wBAAwB,CAAC,wCA0F7F"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { getBorderRadiusConfig } from '../providers/Theme/themeConfig.js';
|
|
3
|
+
import { resolveThemeConfiguration } from '../utils/resolveThemeConfiguration.js';
|
|
4
|
+
import { createFallbackCriticalCSS, getThemeCriticalCSS, getThemeCSSPath } from '../utils/themeAssets.js';
|
|
5
|
+
import { generateThemeColorsCss } from '../utils/themeColors.js';
|
|
6
|
+
import { generateThemeCSS } from '../utils/themeUtils.js';
|
|
6
7
|
/**
|
|
7
8
|
* Server-side theme CSS injector to prevent FOUC
|
|
8
9
|
* This component injects critical theme CSS directly into the HTML head during SSR
|
|
9
|
-
*/
|
|
10
|
-
export async function ServerThemeInjector({ siteSettings }) {
|
|
10
|
+
*/ export async function ServerThemeInjector({ siteSettings }) {
|
|
11
11
|
const resolvedConfiguration = resolveThemeConfiguration(siteSettings?.themeConfiguration);
|
|
12
|
-
const { theme, borderRadius, customCSS, lightMode, darkMode, fontScale, spacing, animationLevel, allowColorModeToggle, colorMode, typography
|
|
13
|
-
const baseThemeConfiguration = {
|
|
12
|
+
const { theme, borderRadius, customCSS, lightMode, darkMode, fontScale, spacing, animationLevel, allowColorModeToggle, colorMode, typography } = resolvedConfiguration;
|
|
13
|
+
const baseThemeConfiguration = {
|
|
14
|
+
...siteSettings?.themeConfiguration ?? {}
|
|
15
|
+
};
|
|
14
16
|
if ('typography' in baseThemeConfiguration) {
|
|
15
17
|
delete baseThemeConfiguration.typography;
|
|
16
18
|
}
|
|
@@ -26,7 +28,7 @@ export async function ServerThemeInjector({ siteSettings }) {
|
|
|
26
28
|
customCSS: customCSS ?? undefined,
|
|
27
29
|
lightMode,
|
|
28
30
|
darkMode,
|
|
29
|
-
typography: typography ?? undefined
|
|
31
|
+
typography: typography ?? undefined
|
|
30
32
|
};
|
|
31
33
|
let criticalCSS = await getThemeCriticalCSS(theme);
|
|
32
34
|
criticalCSS ??= createFallbackCriticalCSS(theme);
|
|
@@ -36,40 +38,51 @@ export async function ServerThemeInjector({ siteSettings }) {
|
|
|
36
38
|
medium: 'medium',
|
|
37
39
|
large: 'large',
|
|
38
40
|
xl: 'xl',
|
|
39
|
-
full: 'xl'
|
|
41
|
+
full: 'xl'
|
|
40
42
|
};
|
|
41
43
|
const mappedBorderRadius = borderRadiusMap[borderRadius ?? 'medium'] ?? 'medium';
|
|
42
44
|
const borderRadiusConfig = getBorderRadiusConfig(mappedBorderRadius);
|
|
43
|
-
const cssRecord = typeof borderRadiusConfig?.css === 'string'
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const borderRadiusCSS = Object.entries(cssRecord)
|
|
47
|
-
|
|
48
|
-
.join('\n');
|
|
49
|
-
const borderRadiusBlock = borderRadiusCSS
|
|
50
|
-
? `:root {
|
|
45
|
+
const cssRecord = typeof borderRadiusConfig?.css === 'string' ? {
|
|
46
|
+
'--radius-default': borderRadiusConfig.css
|
|
47
|
+
} : borderRadiusConfig?.css ?? {};
|
|
48
|
+
const borderRadiusCSS = Object.entries(cssRecord).map(([property, value])=>` ${property}: ${value};`).join('\n');
|
|
49
|
+
const borderRadiusBlock = borderRadiusCSS ? `:root {
|
|
51
50
|
${borderRadiusCSS}
|
|
52
|
-
}`
|
|
53
|
-
: '';
|
|
51
|
+
}` : '';
|
|
54
52
|
const themeConfigurationCSS = generateThemeCSS(normalizedThemeConfiguration);
|
|
55
|
-
const colorModesCSS = generateThemeColorsCss({
|
|
53
|
+
const colorModesCSS = generateThemeColorsCss({
|
|
54
|
+
themeName: theme,
|
|
55
|
+
lightMode,
|
|
56
|
+
darkMode
|
|
57
|
+
});
|
|
56
58
|
const customCSSBlock = typeof customCSS === 'string' ? customCSS.trim() : '';
|
|
57
59
|
const combinedCSS = [
|
|
58
60
|
criticalCSS,
|
|
59
61
|
borderRadiusBlock,
|
|
60
62
|
themeConfigurationCSS,
|
|
61
63
|
colorModesCSS,
|
|
62
|
-
customCSSBlock
|
|
63
|
-
]
|
|
64
|
-
.filter((block) => Boolean(block?.trim?.().length))
|
|
65
|
-
.join('\n\n');
|
|
64
|
+
customCSSBlock
|
|
65
|
+
].filter((block)=>Boolean(block?.trim?.().length)).join('\n\n');
|
|
66
66
|
const themeCSSPath = getThemeCSSPath(theme);
|
|
67
|
-
return (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
68
|
+
children: [
|
|
69
|
+
/*#__PURE__*/ _jsx("style", {
|
|
70
|
+
id: "theme-critical-css",
|
|
71
|
+
dangerouslySetInnerHTML: {
|
|
72
|
+
__html: combinedCSS
|
|
73
|
+
}
|
|
74
|
+
}),
|
|
75
|
+
/*#__PURE__*/ _jsx("link", {
|
|
76
|
+
rel: "preload",
|
|
77
|
+
href: themeCSSPath,
|
|
78
|
+
as: "style"
|
|
79
|
+
}),
|
|
80
|
+
/*#__PURE__*/ _jsx("link", {
|
|
81
|
+
rel: "stylesheet",
|
|
82
|
+
href: themeCSSPath
|
|
83
|
+
})
|
|
84
|
+
]
|
|
85
|
+
});
|
|
74
86
|
}
|
|
75
|
-
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=ServerThemeInjector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/ServerThemeInjector.tsx"],"sourcesContent":["import type { SiteSetting } from '../payload-types.js'\nimport { getBorderRadiusConfig } from '../providers/Theme/themeConfig.js'\nimport type { BorderRadiusPreset, ThemeDefaults } from '../providers/Theme/types.js'\nimport type { ThemeTypographyPreset } from '../presets.js'\nimport { resolveThemeConfiguration } from '../utils/resolveThemeConfiguration.js'\nimport {\n createFallbackCriticalCSS,\n getThemeCriticalCSS,\n getThemeCSSPath,\n} from '../utils/themeAssets.js'\nimport { generateThemeColorsCss } from '../utils/themeColors.js'\nimport { generateThemeCSS } from '../utils/themeUtils.js'\n\ninterface ServerThemeInjectorProps {\n siteSettings: SiteSetting | null\n}\n\ntype RuntimeThemeConfiguration = Omit<NonNullable<SiteSetting['themeConfiguration']>, 'typography'> & {\n typography?: ThemeTypographyPreset | null\n}\n\n/**\n * Server-side theme CSS injector to prevent FOUC\n * This component injects critical theme CSS directly into the HTML head during SSR\n */\nexport async function ServerThemeInjector({ siteSettings }: Readonly<ServerThemeInjectorProps>) {\n const resolvedConfiguration = resolveThemeConfiguration(siteSettings?.themeConfiguration)\n const {\n theme,\n borderRadius,\n customCSS,\n lightMode,\n darkMode,\n fontScale,\n spacing,\n animationLevel,\n allowColorModeToggle,\n colorMode,\n typography,\n } = resolvedConfiguration\n\n const baseThemeConfiguration = { ...(siteSettings?.themeConfiguration ?? {}) }\n if ('typography' in baseThemeConfiguration) {\n delete (baseThemeConfiguration as Record<string, unknown>).typography\n }\n\n const normalizedThemeConfiguration: RuntimeThemeConfiguration = {\n ...baseThemeConfiguration,\n theme,\n colorMode,\n allowColorModeToggle,\n borderRadius,\n fontScale,\n spacing,\n animationLevel,\n customCSS: customCSS ?? undefined,\n lightMode,\n darkMode,\n typography: typography ?? undefined,\n }\n\n let criticalCSS = await getThemeCriticalCSS(theme as ThemeDefaults)\n criticalCSS ??= createFallbackCriticalCSS(theme as ThemeDefaults)\n\n const borderRadiusMap: Record<string, BorderRadiusPreset> = {\n none: 'none',\n small: 'small',\n medium: 'medium',\n large: 'large',\n xl: 'xl',\n full: 'xl',\n }\n const mappedBorderRadius = borderRadiusMap[borderRadius ?? 'medium'] ?? 'medium'\n const borderRadiusConfig = getBorderRadiusConfig(mappedBorderRadius)\n const cssRecord = typeof borderRadiusConfig?.css === 'string'\n ? { '--radius-default': borderRadiusConfig.css }\n : borderRadiusConfig?.css ?? {}\n\n const borderRadiusCSS = Object.entries(cssRecord)\n .map(([property, value]) => ` ${property}: ${value};`)\n .join('\\n')\n\n const borderRadiusBlock = borderRadiusCSS\n ? `:root {\n${borderRadiusCSS}\n}`\n : ''\n\n const themeConfigurationCSS = generateThemeCSS(normalizedThemeConfiguration)\n const colorModesCSS = generateThemeColorsCss({ themeName: theme, lightMode, darkMode })\n const customCSSBlock = typeof customCSS === 'string' ? customCSS.trim() : ''\n\n const combinedCSS = [\n criticalCSS,\n borderRadiusBlock,\n themeConfigurationCSS,\n colorModesCSS,\n customCSSBlock,\n ]\n .filter((block) => Boolean(block?.trim?.().length))\n .join('\\n\\n')\n\n const themeCSSPath = getThemeCSSPath(theme as ThemeDefaults)\n return (\n <>\n <style\n id=\"theme-critical-css\"\n dangerouslySetInnerHTML={{\n __html: combinedCSS,\n }}\n />\n <link rel=\"preload\" href={themeCSSPath} as=\"style\" />\n <link rel=\"stylesheet\" href={themeCSSPath} />\n </>\n )\n}\n"],"names":["getBorderRadiusConfig","resolveThemeConfiguration","createFallbackCriticalCSS","getThemeCriticalCSS","getThemeCSSPath","generateThemeColorsCss","generateThemeCSS","ServerThemeInjector","siteSettings","resolvedConfiguration","themeConfiguration","theme","borderRadius","customCSS","lightMode","darkMode","fontScale","spacing","animationLevel","allowColorModeToggle","colorMode","typography","baseThemeConfiguration","normalizedThemeConfiguration","undefined","criticalCSS","borderRadiusMap","none","small","medium","large","xl","full","mappedBorderRadius","borderRadiusConfig","cssRecord","css","borderRadiusCSS","Object","entries","map","property","value","join","borderRadiusBlock","themeConfigurationCSS","colorModesCSS","themeName","customCSSBlock","trim","combinedCSS","filter","block","Boolean","length","themeCSSPath","style","id","dangerouslySetInnerHTML","__html","link","rel","href","as"],"mappings":";AACA,SAASA,qBAAqB,QAAQ,oCAAmC;AAGzE,SAASC,yBAAyB,QAAQ,wCAAuC;AACjF,SACEC,yBAAyB,EACzBC,mBAAmB,EACnBC,eAAe,QACV,0BAAyB;AAChC,SAASC,sBAAsB,QAAQ,0BAAyB;AAChE,SAASC,gBAAgB,QAAQ,yBAAwB;AAUzD;;;CAGC,GACD,OAAO,eAAeC,oBAAoB,EAAEC,YAAY,EAAsC;IAC5F,MAAMC,wBAAwBR,0BAA0BO,cAAcE;IACtE,MAAM,EACJC,KAAK,EACLC,YAAY,EACZC,SAAS,EACTC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,OAAO,EACPC,cAAc,EACdC,oBAAoB,EACpBC,SAAS,EACTC,UAAU,EACX,GAAGZ;IAEJ,MAAMa,yBAAyB;QAAE,GAAId,cAAcE,sBAAsB,CAAC,CAAC;IAAE;IAC7E,IAAI,gBAAgBY,wBAAwB;QAC1C,OAAO,AAACA,uBAAmDD,UAAU;IACvE;IAEA,MAAME,+BAA0D;QAC9D,GAAGD,sBAAsB;QACzBX;QACA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;;;AAGnC"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useField } from '@payloadcms/ui';
|
|
4
|
+
import React, { useMemo } from 'react';
|
|
5
|
+
import { themeIsValid } from '../providers/Theme/types.js';
|
|
6
|
+
import { defaultThemePresets } from '../presets.js';
|
|
7
|
+
const DEFAULT_THEME_KEY = 'cool';
|
|
8
|
+
const basePresetMap = defaultThemePresets.reduce((accumulator, preset)=>{
|
|
9
|
+
accumulator[preset.name] = preset;
|
|
10
|
+
return accumulator;
|
|
11
|
+
}, {});
|
|
12
|
+
const fallbackPreset = basePresetMap[DEFAULT_THEME_KEY] ?? defaultThemePresets[0];
|
|
13
|
+
const fallbackLightMode = fallbackPreset?.lightMode ?? {
|
|
14
|
+
primary: '#3b82f6',
|
|
15
|
+
accent: '#06b6d4',
|
|
16
|
+
background: '#ffffff',
|
|
17
|
+
foreground: '#1f2937'
|
|
18
|
+
};
|
|
19
|
+
export default function ThemePreview() {
|
|
20
|
+
// Get individual field values using useField hooks
|
|
21
|
+
const { value: selectedTheme } = useField({
|
|
22
|
+
path: 'themeConfiguration.theme'
|
|
23
|
+
});
|
|
24
|
+
const { value: primaryColor } = useField({
|
|
25
|
+
path: 'themeConfiguration.customization.primaryColor'
|
|
26
|
+
});
|
|
27
|
+
const { value: accentColor } = useField({
|
|
28
|
+
path: 'themeConfiguration.customization.accentColor'
|
|
29
|
+
});
|
|
30
|
+
const { value: backgroundColor } = useField({
|
|
31
|
+
path: 'themeConfiguration.customization.backgroundColor'
|
|
32
|
+
});
|
|
33
|
+
const { value: textColor } = useField({
|
|
34
|
+
path: 'themeConfiguration.customization.textColor'
|
|
35
|
+
});
|
|
36
|
+
// Determine current theme and if overrides are active
|
|
37
|
+
const currentTheme = themeIsValid(selectedTheme) ? selectedTheme : fallbackPreset?.name ?? 'cool';
|
|
38
|
+
const hasOverrides = Boolean(primaryColor || accentColor || backgroundColor || textColor);
|
|
39
|
+
const themeColors = useMemo(()=>{
|
|
40
|
+
const preset = basePresetMap[currentTheme] ?? fallbackPreset;
|
|
41
|
+
const lightMode = preset?.lightMode ?? fallbackLightMode;
|
|
42
|
+
return {
|
|
43
|
+
primary: lightMode?.primary ?? fallbackLightMode.primary,
|
|
44
|
+
accent: lightMode?.accent ?? lightMode?.secondary ?? fallbackLightMode.accent ?? fallbackLightMode.primary,
|
|
45
|
+
background: lightMode?.background ?? fallbackLightMode.background,
|
|
46
|
+
text: lightMode?.foreground ?? fallbackLightMode.foreground
|
|
47
|
+
};
|
|
48
|
+
}, [
|
|
49
|
+
currentTheme
|
|
50
|
+
]);
|
|
51
|
+
const currentColors = useMemo(()=>({
|
|
52
|
+
primary: primaryColor || themeColors.primary,
|
|
53
|
+
accent: accentColor || themeColors.accent,
|
|
54
|
+
background: backgroundColor || themeColors.background,
|
|
55
|
+
text: textColor || themeColors.text
|
|
56
|
+
}), [
|
|
57
|
+
primaryColor,
|
|
58
|
+
accentColor,
|
|
59
|
+
backgroundColor,
|
|
60
|
+
textColor,
|
|
61
|
+
themeColors
|
|
62
|
+
]);
|
|
63
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
64
|
+
className: "theme-preview",
|
|
65
|
+
style: {
|
|
66
|
+
marginTop: '20px'
|
|
67
|
+
},
|
|
68
|
+
children: [
|
|
69
|
+
/*#__PURE__*/ _jsx("div", {
|
|
70
|
+
style: {
|
|
71
|
+
fontSize: '16px',
|
|
72
|
+
fontWeight: '600',
|
|
73
|
+
marginBottom: '16px',
|
|
74
|
+
color: '#374151'
|
|
75
|
+
},
|
|
76
|
+
children: "🎨 Live Theme Preview"
|
|
77
|
+
}),
|
|
78
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
79
|
+
className: "preview-container",
|
|
80
|
+
style: {
|
|
81
|
+
border: '2px solid #e5e7eb',
|
|
82
|
+
borderRadius: '12px',
|
|
83
|
+
overflow: 'hidden',
|
|
84
|
+
backgroundColor: currentColors.background,
|
|
85
|
+
color: currentColors.text,
|
|
86
|
+
minHeight: '300px'
|
|
87
|
+
},
|
|
88
|
+
children: [
|
|
89
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
90
|
+
style: {
|
|
91
|
+
backgroundColor: currentColors.primary,
|
|
92
|
+
color: currentColors.background,
|
|
93
|
+
padding: '16px 24px',
|
|
94
|
+
display: 'flex',
|
|
95
|
+
justifyContent: 'space-between',
|
|
96
|
+
alignItems: 'center'
|
|
97
|
+
},
|
|
98
|
+
children: [
|
|
99
|
+
/*#__PURE__*/ _jsx("div", {
|
|
100
|
+
style: {
|
|
101
|
+
fontSize: '20px',
|
|
102
|
+
fontWeight: '700'
|
|
103
|
+
},
|
|
104
|
+
children: "Your Website"
|
|
105
|
+
}),
|
|
106
|
+
/*#__PURE__*/ _jsxs("nav", {
|
|
107
|
+
style: {
|
|
108
|
+
display: 'flex',
|
|
109
|
+
gap: '24px',
|
|
110
|
+
fontSize: '14px'
|
|
111
|
+
},
|
|
112
|
+
children: [
|
|
113
|
+
/*#__PURE__*/ _jsx("span", {
|
|
114
|
+
children: "Home"
|
|
115
|
+
}),
|
|
116
|
+
/*#__PURE__*/ _jsx("span", {
|
|
117
|
+
children: "About"
|
|
118
|
+
}),
|
|
119
|
+
/*#__PURE__*/ _jsx("span", {
|
|
120
|
+
children: "Services"
|
|
121
|
+
}),
|
|
122
|
+
/*#__PURE__*/ _jsx("span", {
|
|
123
|
+
children: "Contact"
|
|
124
|
+
})
|
|
125
|
+
]
|
|
126
|
+
})
|
|
127
|
+
]
|
|
128
|
+
}),
|
|
129
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
130
|
+
style: {
|
|
131
|
+
padding: '32px 24px'
|
|
132
|
+
},
|
|
133
|
+
children: [
|
|
134
|
+
/*#__PURE__*/ _jsx("h1", {
|
|
135
|
+
style: {
|
|
136
|
+
fontSize: '32px',
|
|
137
|
+
fontWeight: '800',
|
|
138
|
+
marginBottom: '16px',
|
|
139
|
+
color: currentColors.text
|
|
140
|
+
},
|
|
141
|
+
children: "Welcome to Your Site"
|
|
142
|
+
}),
|
|
143
|
+
/*#__PURE__*/ _jsx("p", {
|
|
144
|
+
style: {
|
|
145
|
+
fontSize: '16px',
|
|
146
|
+
lineHeight: '1.6',
|
|
147
|
+
marginBottom: '24px',
|
|
148
|
+
color: currentColors.text,
|
|
149
|
+
opacity: 0.8
|
|
150
|
+
},
|
|
151
|
+
children: "This is how your content will look with the selected theme. The colors and styling will be applied across your entire website."
|
|
152
|
+
}),
|
|
153
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
154
|
+
style: {
|
|
155
|
+
display: 'flex',
|
|
156
|
+
gap: '12px',
|
|
157
|
+
marginBottom: '32px'
|
|
158
|
+
},
|
|
159
|
+
children: [
|
|
160
|
+
/*#__PURE__*/ _jsx("button", {
|
|
161
|
+
style: {
|
|
162
|
+
backgroundColor: currentColors.primary,
|
|
163
|
+
color: currentColors.background,
|
|
164
|
+
border: 'none',
|
|
165
|
+
padding: '12px 24px',
|
|
166
|
+
borderRadius: '6px',
|
|
167
|
+
fontSize: '14px',
|
|
168
|
+
fontWeight: '600',
|
|
169
|
+
cursor: 'pointer'
|
|
170
|
+
},
|
|
171
|
+
children: "Primary Button"
|
|
172
|
+
}),
|
|
173
|
+
/*#__PURE__*/ _jsx("button", {
|
|
174
|
+
style: {
|
|
175
|
+
backgroundColor: 'transparent',
|
|
176
|
+
color: currentColors.primary,
|
|
177
|
+
border: `2px solid ${currentColors.primary}`,
|
|
178
|
+
padding: '10px 24px',
|
|
179
|
+
borderRadius: '6px',
|
|
180
|
+
fontSize: '14px',
|
|
181
|
+
fontWeight: '600',
|
|
182
|
+
cursor: 'pointer'
|
|
183
|
+
},
|
|
184
|
+
children: "Secondary Button"
|
|
185
|
+
})
|
|
186
|
+
]
|
|
187
|
+
}),
|
|
188
|
+
/*#__PURE__*/ _jsx("div", {
|
|
189
|
+
style: {
|
|
190
|
+
backgroundColor: currentColors.text,
|
|
191
|
+
color: currentColors.background,
|
|
192
|
+
padding: '24px',
|
|
193
|
+
borderRadius: '8px',
|
|
194
|
+
opacity: 0.05,
|
|
195
|
+
marginBottom: '16px'
|
|
196
|
+
}
|
|
197
|
+
}),
|
|
198
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
199
|
+
style: {
|
|
200
|
+
border: `1px solid ${currentColors.text}`,
|
|
201
|
+
padding: '20px',
|
|
202
|
+
borderRadius: '8px',
|
|
203
|
+
opacity: 0.1
|
|
204
|
+
},
|
|
205
|
+
children: [
|
|
206
|
+
/*#__PURE__*/ _jsx("h3", {
|
|
207
|
+
style: {
|
|
208
|
+
fontSize: '18px',
|
|
209
|
+
fontWeight: '600',
|
|
210
|
+
marginBottom: '12px',
|
|
211
|
+
color: currentColors.text
|
|
212
|
+
},
|
|
213
|
+
children: "Sample Card"
|
|
214
|
+
}),
|
|
215
|
+
/*#__PURE__*/ _jsx("p", {
|
|
216
|
+
style: {
|
|
217
|
+
fontSize: '14px',
|
|
218
|
+
color: currentColors.text,
|
|
219
|
+
opacity: 0.7
|
|
220
|
+
},
|
|
221
|
+
children: "This shows how cards and content blocks will appear."
|
|
222
|
+
})
|
|
223
|
+
]
|
|
224
|
+
})
|
|
225
|
+
]
|
|
226
|
+
}),
|
|
227
|
+
/*#__PURE__*/ _jsx("div", {
|
|
228
|
+
style: {
|
|
229
|
+
backgroundColor: currentColors.accent,
|
|
230
|
+
color: currentColors.background,
|
|
231
|
+
padding: '16px 24px',
|
|
232
|
+
textAlign: 'center',
|
|
233
|
+
fontSize: '14px',
|
|
234
|
+
marginTop: 'auto'
|
|
235
|
+
},
|
|
236
|
+
children: "© 2025 Your Website. Powered by PayloadCMS."
|
|
237
|
+
})
|
|
238
|
+
]
|
|
239
|
+
}),
|
|
240
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
241
|
+
style: {
|
|
242
|
+
marginTop: '12px',
|
|
243
|
+
fontSize: '12px',
|
|
244
|
+
color: '#6b7280',
|
|
245
|
+
display: 'grid',
|
|
246
|
+
gridTemplateColumns: 'repeat(2, 1fr)',
|
|
247
|
+
gap: '8px'
|
|
248
|
+
},
|
|
249
|
+
children: [
|
|
250
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
251
|
+
children: [
|
|
252
|
+
/*#__PURE__*/ _jsx("strong", {
|
|
253
|
+
children: "Active Theme:"
|
|
254
|
+
}),
|
|
255
|
+
" ",
|
|
256
|
+
currentTheme
|
|
257
|
+
]
|
|
258
|
+
}),
|
|
259
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
260
|
+
children: [
|
|
261
|
+
/*#__PURE__*/ _jsx("strong", {
|
|
262
|
+
children: "Primary:"
|
|
263
|
+
}),
|
|
264
|
+
" ",
|
|
265
|
+
currentColors.primary
|
|
266
|
+
]
|
|
267
|
+
}),
|
|
268
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
269
|
+
children: [
|
|
270
|
+
/*#__PURE__*/ _jsx("strong", {
|
|
271
|
+
children: "Accent:"
|
|
272
|
+
}),
|
|
273
|
+
" ",
|
|
274
|
+
currentColors.accent
|
|
275
|
+
]
|
|
276
|
+
}),
|
|
277
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
278
|
+
children: [
|
|
279
|
+
/*#__PURE__*/ _jsx("strong", {
|
|
280
|
+
children: "Background:"
|
|
281
|
+
}),
|
|
282
|
+
" ",
|
|
283
|
+
currentColors.background
|
|
284
|
+
]
|
|
285
|
+
})
|
|
286
|
+
]
|
|
287
|
+
}),
|
|
288
|
+
hasOverrides && /*#__PURE__*/ _jsxs("div", {
|
|
289
|
+
style: {
|
|
290
|
+
marginTop: '8px',
|
|
291
|
+
padding: '8px 12px',
|
|
292
|
+
backgroundColor: '#fef3c7',
|
|
293
|
+
borderRadius: '6px',
|
|
294
|
+
fontSize: '11px',
|
|
295
|
+
color: '#92400e',
|
|
296
|
+
display: 'flex',
|
|
297
|
+
alignItems: 'center',
|
|
298
|
+
gap: '6px'
|
|
299
|
+
},
|
|
300
|
+
children: [
|
|
301
|
+
/*#__PURE__*/ _jsx("span", {
|
|
302
|
+
children: "⚡"
|
|
303
|
+
}),
|
|
304
|
+
/*#__PURE__*/ _jsxs("span", {
|
|
305
|
+
children: [
|
|
306
|
+
/*#__PURE__*/ _jsx("strong", {
|
|
307
|
+
children: "Custom colors applied"
|
|
308
|
+
}),
|
|
309
|
+
" - overriding theme defaults"
|
|
310
|
+
]
|
|
311
|
+
})
|
|
312
|
+
]
|
|
313
|
+
})
|
|
314
|
+
]
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
//# sourceMappingURL=ThemePreview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/ThemePreview.tsx"],"sourcesContent":["'use client'\n\nimport { useField } from '@payloadcms/ui'\nimport React, { useMemo } from 'react'\nimport { themeIsValid } from '../providers/Theme/types.js'\nimport { defaultThemePresets } from '../presets.js'\n\nconst DEFAULT_THEME_KEY = 'cool'\nconst basePresetMap = defaultThemePresets.reduce<\n Record<string, (typeof defaultThemePresets)[number]>\n>((accumulator, preset) => {\n accumulator[preset.name] = preset\n return accumulator\n}, {})\n\nconst fallbackPreset = basePresetMap[DEFAULT_THEME_KEY] ?? defaultThemePresets[0]\nconst fallbackLightMode = fallbackPreset?.lightMode ?? {\n primary: '#3b82f6',\n accent: '#06b6d4',\n background: '#ffffff',\n foreground: '#1f2937',\n}\n\nexport default function ThemePreview() {\n // Get individual field values using useField hooks\n const { value: selectedTheme } = useField<string>({ path: 'themeConfiguration.theme' })\n const { value: primaryColor } = useField<string>({\n path: 'themeConfiguration.customization.primaryColor',\n })\n const { value: accentColor } = useField<string>({\n path: 'themeConfiguration.customization.accentColor',\n })\n const { value: backgroundColor } = useField<string>({\n path: 'themeConfiguration.customization.backgroundColor',\n })\n const { value: textColor } = useField<string>({\n path: 'themeConfiguration.customization.textColor',\n })\n\n // Determine current theme and if overrides are active\n const currentTheme = themeIsValid(selectedTheme)\n ? selectedTheme\n : (fallbackPreset?.name ?? 'cool')\n const hasOverrides = Boolean(primaryColor || accentColor || backgroundColor || textColor)\n\n const themeColors = useMemo(() => {\n const preset = basePresetMap[currentTheme] ?? fallbackPreset\n const lightMode = preset?.lightMode ?? fallbackLightMode\n\n return {\n primary: lightMode?.primary ?? fallbackLightMode.primary,\n accent:\n lightMode?.accent ??\n lightMode?.secondary ??\n fallbackLightMode.accent ??\n fallbackLightMode.primary,\n background: lightMode?.background ?? fallbackLightMode.background,\n text: lightMode?.foreground ?? fallbackLightMode.foreground,\n }\n }, [currentTheme])\n\n const currentColors = useMemo(\n () => ({\n primary: primaryColor || themeColors.primary,\n accent: accentColor || themeColors.accent,\n background: backgroundColor || themeColors.background,\n text: textColor || themeColors.text,\n }),\n [primaryColor, accentColor, backgroundColor, textColor, themeColors],\n )\n\n return (\n <div className=\"theme-preview\" style={{ marginTop: '20px' }}>\n <div\n style={{\n fontSize: '16px',\n fontWeight: '600',\n marginBottom: '16px',\n color: '#374151',\n }}\n >\n 🎨 Live Theme Preview\n </div>\n\n <div\n className=\"preview-container\"\n style={{\n border: '2px solid #e5e7eb',\n borderRadius: '12px',\n overflow: 'hidden',\n backgroundColor: currentColors.background,\n color: currentColors.text,\n minHeight: '300px',\n }}\n >\n {/* Header */}\n <div\n style={{\n backgroundColor: currentColors.primary,\n color: currentColors.background,\n padding: '16px 24px',\n display: 'flex',\n justifyContent: 'space-between',\n alignItems: 'center',\n }}\n >\n <div style={{ fontSize: '20px', fontWeight: '700' }}>Your Website</div>\n <nav style={{ display: 'flex', gap: '24px', fontSize: '14px' }}>\n <span>Home</span>\n <span>About</span>\n <span>Services</span>\n <span>Contact</span>\n </nav>\n </div>\n\n {/* Content */}\n <div style={{ padding: '32px 24px' }}>\n <h1\n style={{\n fontSize: '32px',\n fontWeight: '800',\n marginBottom: '16px',\n color: currentColors.text,\n }}\n >\n Welcome to Your Site\n </h1>\n\n <p\n style={{\n fontSize: '16px',\n lineHeight: '1.6',\n marginBottom: '24px',\n color: currentColors.text,\n opacity: 0.8,\n }}\n >\n This is how your content will look with the selected theme. The colors and styling will\n be applied across your entire website.\n </p>\n\n {/* Buttons */}\n <div style={{ display: 'flex', gap: '12px', marginBottom: '32px' }}>\n <button\n style={{\n backgroundColor: currentColors.primary,\n color: currentColors.background,\n border: 'none',\n padding: '12px 24px',\n borderRadius: '6px',\n fontSize: '14px',\n fontWeight: '600',\n cursor: 'pointer',\n }}\n >\n Primary Button\n </button>\n <button\n style={{\n backgroundColor: 'transparent',\n color: currentColors.primary,\n border: `2px solid ${currentColors.primary}`,\n padding: '10px 24px',\n borderRadius: '6px',\n fontSize: '14px',\n fontWeight: '600',\n cursor: 'pointer',\n }}\n >\n Secondary Button\n </button>\n </div>\n\n {/* Card */}\n <div\n style={{\n backgroundColor: currentColors.text,\n color: currentColors.background,\n padding: '24px',\n borderRadius: '8px',\n opacity: 0.05,\n marginBottom: '16px',\n }}\n />\n <div\n style={{\n border: `1px solid ${currentColors.text}`,\n padding: '20px',\n borderRadius: '8px',\n opacity: 0.1,\n }}\n >\n <h3\n style={{\n fontSize: '18px',\n fontWeight: '600',\n marginBottom: '12px',\n color: currentColors.text,\n }}\n >\n Sample Card\n </h3>\n <p\n style={{\n fontSize: '14px',\n color: currentColors.text,\n opacity: 0.7,\n }}\n >\n This shows how cards and content blocks will appear.\n </p>\n </div>\n </div>\n\n {/* Footer */}\n <div\n style={{\n backgroundColor: currentColors.accent,\n color: currentColors.background,\n padding: '16px 24px',\n textAlign: 'center',\n fontSize: '14px',\n marginTop: 'auto',\n }}\n >\n © 2025 Your Website. Powered by PayloadCMS.\n </div>\n </div>\n\n {/* Theme info */}\n <div\n style={{\n marginTop: '12px',\n fontSize: '12px',\n color: '#6b7280',\n display: 'grid',\n gridTemplateColumns: 'repeat(2, 1fr)',\n gap: '8px',\n }}\n >\n <div>\n <strong>Active Theme:</strong> {currentTheme}\n </div>\n <div>\n <strong>Primary:</strong> {currentColors.primary}\n </div>\n <div>\n <strong>Accent:</strong> {currentColors.accent}\n </div>\n <div>\n <strong>Background:</strong> {currentColors.background}\n </div>\n </div>\n\n {/* Customization indicator */}\n {hasOverrides && (\n <div\n style={{\n marginTop: '8px',\n padding: '8px 12px',\n backgroundColor: '#fef3c7',\n borderRadius: '6px',\n fontSize: '11px',\n color: '#92400e',\n display: 'flex',\n alignItems: 'center',\n gap: '6px',\n }}\n >\n <span>⚡</span>\n <span>\n <strong>Custom colors applied</strong> - overriding theme defaults\n </span>\n </div>\n )}\n </div>\n )\n}\n"],"names":["useField","React","useMemo","themeIsValid","defaultThemePresets","DEFAULT_THEME_KEY","basePresetMap","reduce","accumulator","preset","name","fallbackPreset","fallbackLightMode","lightMode","primary","accent","background","foreground","ThemePreview","value","selectedTheme","path","primaryColor","accentColor","backgroundColor","textColor","currentTheme","hasOverrides","Boolean","themeColors","secondary","text","currentColors","div","className","style","marginTop","fontSize","fontWeight","marginBottom","color","border","borderRadius","overflow","minHeight","padding","display","justifyContent","alignItems","nav","gap","span","h1","p","lineHeight","opacity","button","cursor","h3","textAlign","gridTemplateColumns","strong"],"mappings":"AAAA;;AAEA,SAASA,QAAQ,QAAQ,iBAAgB;AACzC,OAAOC,SAASC,OAAO,QAAQ,QAAO;AACtC,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,mBAAmB,QAAQ,gBAAe;AAEnD,MAAMC,oBAAoB;AAC1B,MAAMC,gBAAgBF,oBAAoBG,MAAM,CAE9C,CAACC,aAAaC;IACdD,WAAW,CAACC,OAAOC,IAAI,CAAC,GAAGD;IAC3B,OAAOD;AACT,GAAG,CAAC;AAEJ,MAAMG,iBAAiBL,aAAa,CAACD,kBAAkB,IAAID,mBAAmB,CAAC,EAAE;AACjF,MAAMQ,oBAAoBD,gBAAgBE,aAAa;IACrDC,SAAS;IACTC,QAAQ;IACRC,YAAY;IACZC,YAAY;AACd;AAEA,eAAe,SAASC;IACtB,mDAAmD;IACnD,MAAM,EAAEC,OAA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SAAS;oBACTrB,iBAAiB;oBACjBkB,cAAc;oBACdL,UAAU;oBACVG,OAAO;oBACPM,SAAS;oBACTE,YAAY;oBACZE,KAAK;gBACP;;kCAEA,KAACC;kCAAK;;kCACN,MAACA;;0CACC,KAACU;0CAAO;;4BAA8B;;;;;;;AAMlD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BODY_FONT_OPTIONS, FONT_VALUE_TO_CSS, HEADING_FONT_OPTIONS } from '
|
|
2
|
-
import { defaultThemePresets } from '../presets';
|
|
1
|
+
import { BODY_FONT_OPTIONS, FONT_VALUE_TO_CSS, HEADING_FONT_OPTIONS } from '../constants/themeFonts.js';
|
|
2
|
+
import { defaultThemePresets } from '../presets.js';
|
|
3
3
|
const FALLBACK_THEME = defaultThemePresets[0]?.name ?? 'cool';
|
|
4
|
-
const fallbackPreset = defaultThemePresets.find((preset)
|
|
4
|
+
const fallbackPreset = defaultThemePresets.find((preset)=>preset.name === FALLBACK_THEME) ?? defaultThemePresets[0];
|
|
5
5
|
const FONT_VAR_FALLBACK = {
|
|
6
6
|
'var(--font-geist-sans)': '"Geist Sans", system-ui, sans-serif',
|
|
7
7
|
'var(--font-geist-mono)': '"Geist Mono", SFMono-Regular, ui-monospace, monospace',
|
|
@@ -10,11 +10,10 @@ const FONT_VAR_FALLBACK = {
|
|
|
10
10
|
'var(--font-playfair)': '"Playfair Display", "Times New Roman", serif',
|
|
11
11
|
'var(--font-lora)': '"Lora", "Times New Roman", serif',
|
|
12
12
|
'var(--font-manrope)': '"Manrope", system-ui, sans-serif',
|
|
13
|
-
'var(--font-urbanist)': '"Urbanist", system-ui, sans-serif'
|
|
13
|
+
'var(--font-urbanist)': '"Urbanist", system-ui, sans-serif'
|
|
14
14
|
};
|
|
15
15
|
function withFallback(fontFamily, fallback) {
|
|
16
|
-
if (!fontFamily)
|
|
17
|
-
return fallback;
|
|
16
|
+
if (!fontFamily) return fallback;
|
|
18
17
|
if (fontFamily.startsWith('var(')) {
|
|
19
18
|
const mappedFallback = FONT_VAR_FALLBACK[fontFamily] ?? fallback;
|
|
20
19
|
return `${fontFamily}, ${mappedFallback}`;
|
|
@@ -22,7 +21,7 @@ function withFallback(fontFamily, fallback) {
|
|
|
22
21
|
return fontFamily;
|
|
23
22
|
}
|
|
24
23
|
function getPresetTypography(themeName) {
|
|
25
|
-
const preset = defaultThemePresets.find((item)
|
|
24
|
+
const preset = defaultThemePresets.find((item)=>item.name === themeName) ?? fallbackPreset;
|
|
26
25
|
return preset?.typography;
|
|
27
26
|
}
|
|
28
27
|
function resolveFontFamily(value, customValue, fallback) {
|
|
@@ -42,9 +41,8 @@ function resolveFontFamily(value, customValue, fallback) {
|
|
|
42
41
|
return withFallback(fallback, fallbackPreset?.typography?.fontFamily ?? 'system-ui, sans-serif');
|
|
43
42
|
}
|
|
44
43
|
function resolveOptionLabel(options, value, locale = 'en') {
|
|
45
|
-
const option = options.find((item)
|
|
46
|
-
if (!option)
|
|
47
|
-
return value ?? '';
|
|
44
|
+
const option = options.find((item)=>item.value === value);
|
|
45
|
+
if (!option) return value ?? '';
|
|
48
46
|
if (typeof option.label === 'string') {
|
|
49
47
|
return option.label;
|
|
50
48
|
}
|
|
@@ -62,19 +60,16 @@ export function resolveTypographyPreview(selection, themeName) {
|
|
|
62
60
|
const headingFontCustom = selection?.headingFontCustom ?? undefined;
|
|
63
61
|
const resolvedBodyFont = resolveFontFamily(bodyFontValue, bodyFontCustom, fallbackBody);
|
|
64
62
|
const resolvedHeadingFont = resolveFontFamily(headingFontValue, headingFontCustom, fallbackHeading);
|
|
65
|
-
const baseFontSize = selection?.baseFontSize && selection.baseFontSize !== 'preset'
|
|
66
|
-
|
|
67
|
-
: fallbackSize;
|
|
68
|
-
const lineHeight = selection?.lineHeight && selection.lineHeight !== 'preset'
|
|
69
|
-
? selection.lineHeight
|
|
70
|
-
: fallbackLineHeight;
|
|
63
|
+
const baseFontSize = selection?.baseFontSize && selection.baseFontSize !== 'preset' ? selection.baseFontSize : fallbackSize;
|
|
64
|
+
const lineHeight = selection?.lineHeight && selection.lineHeight !== 'preset' ? selection.lineHeight : fallbackLineHeight;
|
|
71
65
|
return {
|
|
72
66
|
bodyFont: resolvedBodyFont,
|
|
73
67
|
headingFont: resolvedHeadingFont,
|
|
74
68
|
baseFontSize,
|
|
75
69
|
lineHeight,
|
|
76
70
|
bodyLabel: resolveOptionLabel(BODY_FONT_OPTIONS, bodyFontValue),
|
|
77
|
-
headingLabel: resolveOptionLabel(HEADING_FONT_OPTIONS, headingFontValue)
|
|
71
|
+
headingLabel: resolveOptionLabel(HEADING_FONT_OPTIONS, headingFontValue)
|
|
78
72
|
};
|
|
79
73
|
}
|
|
74
|
+
|
|
80
75
|
//# sourceMappingURL=typographyPreviewUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/components/typographyPreviewUtils.ts"],"sourcesContent":["import { BODY_FONT_OPTIONS, FONT_VALUE_TO_CSS, HEADING_FONT_OPTIONS } from '../constants/themeFonts.js'\nimport { defaultThemePresets } from '../presets.js'\n\nexport interface TypographySelection {\n bodyFont?: string | null\n headingFont?: string | null\n bodyFontCustom?: string | null\n headingFontCustom?: string | null\n baseFontSize?: string | null\n lineHeight?: string | null\n}\n\nexport interface ResolvedTypographyPreview {\n bodyFont: string\n headingFont: string\n baseFontSize: string\n lineHeight: string\n bodyLabel: string\n headingLabel: string\n}\n\nconst FALLBACK_THEME = defaultThemePresets[0]?.name ?? 'cool'\nconst fallbackPreset =\n defaultThemePresets.find((preset) => preset.name === FALLBACK_THEME) ?? defaultThemePresets[0]\n\nconst FONT_VAR_FALLBACK: Record<string, string> = {\n 'var(--font-geist-sans)': '\"Geist Sans\", system-ui, sans-serif',\n 'var(--font-geist-mono)': '\"Geist Mono\", SFMono-Regular, ui-monospace, monospace',\n 'var(--font-inter)': '\"Inter\", system-ui, sans-serif',\n 'var(--font-outfit)': '\"Outfit\", system-ui, sans-serif',\n 'var(--font-playfair)': '\"Playfair Display\", \"Times New Roman\", serif',\n 'var(--font-lora)': '\"Lora\", \"Times New Roman\", serif',\n 'var(--font-manrope)': '\"Manrope\", system-ui, sans-serif',\n 'var(--font-urbanist)': '\"Urbanist\", system-ui, sans-serif',\n}\n\nfunction withFallback(fontFamily: string, fallback: string): string {\n if (!fontFamily) return fallback\n\n if (fontFamily.startsWith('var(')) {\n const mappedFallback = FONT_VAR_FALLBACK[fontFamily] ?? fallback\n return `${fontFamily}, ${mappedFallback}`\n }\n\n return fontFamily\n}\n\nfunction getPresetTypography(themeName?: string) {\n const preset = defaultThemePresets.find((item) => item.name === themeName) ?? fallbackPreset\n return preset?.typography\n}\n\nfunction resolveFontFamily(\n value: string | null | undefined,\n customValue: string | null | undefined,\n fallback: string,\n): string {\n if (!value || value === 'preset') {\n return withFallback(fallback, fallbackPreset?.typography?.fontFamily ?? 'system-ui, sans-serif')\n }\n\n if (value === 'custom') {\n if (customValue && customValue.trim().length > 0) {\n return customValue.trim()\n }\n return withFallback(fallback, fallbackPreset?.typography?.fontFamily ?? 'system-ui, sans-serif')\n }\n\n const preconfigured = FONT_VALUE_TO_CSS[value]\n if (preconfigured) {\n return withFallback(\n preconfigured,\n fallbackPreset?.typography?.fontFamily ?? 'system-ui, sans-serif',\n )\n }\n\n return withFallback(fallback, fallbackPreset?.typography?.fontFamily ?? 'system-ui, sans-serif')\n}\n\nfunction resolveOptionLabel(\n options: ReadonlyArray<{ label: string | Record<string, string>; value: string }>,\n value?: string | null,\n locale: 'en' | 'cs' = 'en',\n): string {\n const option = options.find((item) => item.value === value)\n if (!option) return value ?? ''\n if (typeof option.label === 'string') {\n return option.label\n }\n return option.label?.[locale] ?? Object.values(option.label)[0] ?? option.value\n}\n\nexport function resolveTypographyPreview(\n selection: TypographySelection | null | undefined,\n themeName?: string,\n): ResolvedTypographyPreview {\n const presetTypography = getPresetTypography(themeName)\n const fallbackBody = presetTypography?.fontFamily ?? 'system-ui, sans-serif'\n const fallbackHeading = presetTypography?.headingFamily ?? fallbackBody\n const fallbackSize = presetTypography?.baseFontSize ?? '16px'\n const fallbackLineHeight = presetTypography?.lineHeight ?? '1.6'\n\n const bodyFontValue = selection?.bodyFont ?? 'preset'\n const headingFontValue = selection?.headingFont ?? 'preset'\n const bodyFontCustom = selection?.bodyFontCustom ?? undefined\n const headingFontCustom = selection?.headingFontCustom ?? undefined\n const resolvedBodyFont = resolveFontFamily(bodyFontValue, bodyFontCustom, fallbackBody)\n const resolvedHeadingFont = resolveFontFamily(\n headingFontValue,\n headingFontCustom,\n fallbackHeading,\n )\n\n const baseFontSize =\n selection?.baseFontSize && selection.baseFontSize !== 'preset'\n ? selection.baseFontSize\n : fallbackSize\n const lineHeight =\n selection?.lineHeight && selection.lineHeight !== 'preset'\n ? selection.lineHeight\n : fallbackLineHeight\n\n return {\n bodyFont: resolvedBodyFont,\n headingFont: resolvedHeadingFont,\n baseFontSize,\n lineHeight,\n bodyLabel: resolveOptionLabel(BODY_FONT_OPTIONS, bodyFontValue),\n headingLabel: resolveOptionLabel(HEADING_FONT_OPTIONS, headingFontValue),\n }\n}\n"],"names":["BODY_FONT_OPTIONS","FONT_VALUE_TO_CSS","HEADING_FONT_OPTIONS","defaultThemePresets","FALLBACK_THEME","name","fallbackPreset","find","preset","FONT_VAR_FALLBACK","withFallback","fontFamily","fallback","startsWith","mappedFallback","getPresetTypography","themeName","item","typography","resolveFontFamily","value","customValue","trim","length","preconfigured","resolveOptionLabel","options","locale","option","label","Object","values","resolveTypographyPreview","selection","presetTypography","fallbackBody","fallbackHeading","headingFamily","fallbackSize","baseFontSize","fallbackLineHeight","lineHeight","bodyFontValue","bodyFont","headingFontValue","headingFont","bodyFontCustom","undefined","headingFontCustom","resolvedBodyFont","resolvedHeadingFont","bodyLabel","headingLabel"],"mappings":"AAAA,SAASA,iBAAiB,EAAEC,iBAAiB,EAAEC,oBAAoB,QAAQ,6BAA4B;AACvG,SAASC,mBAAmB,QAAQ,gBAAe;AAoBnD,MAA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