@kilivi/payloadcms-theme-management 0.1.12 → 0.1.13
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 +15 -0
- package/dist/components/InitTheme.d.ts +12 -0
- package/dist/components/InitTheme.d.ts.map +1 -0
- package/dist/components/InitTheme.js +72 -0
- package/dist/components/InitTheme.js.map +1 -0
- package/dist/components/ServerThemeInjector.d.ts.map +1 -1
- package/dist/components/ServerThemeInjector.js +5 -3
- package/dist/components/ServerThemeInjector.js.map +1 -1
- package/dist/components/ThemePreview.js.map +1 -1
- package/dist/components/typographyPreviewUtils.js.map +1 -1
- package/dist/constants/themeFonts.js.map +1 -1
- package/dist/fields/ColorPickerField.js.map +1 -1
- package/dist/fields/RadiusField.js.map +1 -1
- package/dist/fields/ThemeColorPickerField.css +138 -138
- package/dist/fields/ThemeColorPickerField.js.map +1 -1
- package/dist/fields/ThemePreviewField.js.map +1 -1
- package/dist/fields/ThemeTokenSelectField.js.map +1 -1
- package/dist/fields/colorModeFields.js.map +1 -1
- package/dist/fields/themeConfigurationField.js +3 -3
- package/dist/fields/themeConfigurationField.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/payload-types.js +3 -3
- package/dist/payload-types.js.map +1 -1
- package/dist/plugin.js.map +1 -1
- package/dist/presets.js.map +1 -1
- package/dist/providers/Theme/index.js.map +1 -1
- package/dist/providers/Theme/shared.js.map +1 -1
- package/dist/providers/Theme/themeConfig.js.map +1 -1
- package/dist/providers/Theme/types.js.map +1 -1
- package/dist/server.js.map +1 -1
- package/dist/src/--verbose/dist/fields/ThemeColorPickerField.scss +138 -0
- package/dist/src/dist/fields/ThemeColorPickerField.scss +138 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/resolveThemeConfiguration.d.ts +40 -5
- package/dist/utils/resolveThemeConfiguration.d.ts.map +1 -1
- package/dist/utils/resolveThemeConfiguration.js.map +1 -1
- package/dist/utils/themeAssets.js.map +1 -1
- package/dist/utils/themeColors.js.map +1 -1
- package/dist/utils/themeHtmlAttributes.d.ts +25 -0
- package/dist/utils/themeHtmlAttributes.d.ts.map +1 -0
- package/dist/utils/themeHtmlAttributes.js +26 -0
- package/dist/utils/themeHtmlAttributes.js.map +1 -0
- package/dist/utils/themeUtils.js +6 -6
- package/dist/utils/themeUtils.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
.theme-color-picker-field {
|
|
2
|
+
margin-bottom: 1rem;
|
|
3
|
+
|
|
4
|
+
.field-header {
|
|
5
|
+
margin-bottom: 0.5rem;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.field-label {
|
|
9
|
+
display: block;
|
|
10
|
+
font-weight: 500;
|
|
11
|
+
font-size: 0.875rem;
|
|
12
|
+
color: var(--theme-text);
|
|
13
|
+
margin-bottom: 0.25rem;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.field-description {
|
|
17
|
+
font-size: 0.75rem;
|
|
18
|
+
color: var(--theme-elevation-400);
|
|
19
|
+
margin-top: 0.25rem;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.color-picker-container {
|
|
23
|
+
display: flex;
|
|
24
|
+
gap: 0.75rem;
|
|
25
|
+
align-items: center;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.color-input-wrapper {
|
|
29
|
+
display: flex;
|
|
30
|
+
gap: 0.5rem;
|
|
31
|
+
flex: 1;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.color-input {
|
|
35
|
+
width: 60px;
|
|
36
|
+
height: 38px;
|
|
37
|
+
border: 1px solid var(--theme-elevation-200);
|
|
38
|
+
border-radius: 4px;
|
|
39
|
+
cursor: pointer;
|
|
40
|
+
padding: 2px;
|
|
41
|
+
|
|
42
|
+
&:hover {
|
|
43
|
+
border-color: var(--theme-elevation-400);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
&:focus {
|
|
47
|
+
outline: 2px solid var(--theme-elevation-500);
|
|
48
|
+
outline-offset: 1px;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.text-input {
|
|
53
|
+
flex: 1;
|
|
54
|
+
height: 38px;
|
|
55
|
+
padding: 0 0.75rem;
|
|
56
|
+
border: 1px solid var(--theme-elevation-200);
|
|
57
|
+
border-radius: 4px;
|
|
58
|
+
font-family: monospace;
|
|
59
|
+
font-size: 0.875rem;
|
|
60
|
+
background: var(--theme-elevation-0);
|
|
61
|
+
color: var(--theme-text);
|
|
62
|
+
|
|
63
|
+
&:hover {
|
|
64
|
+
border-color: var(--theme-elevation-400);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
&:focus {
|
|
68
|
+
outline: 2px solid var(--theme-elevation-500);
|
|
69
|
+
outline-offset: 1px;
|
|
70
|
+
border-color: var(--theme-elevation-500);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
&::placeholder {
|
|
74
|
+
color: var(--theme-elevation-400);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&:invalid {
|
|
78
|
+
border-color: #ef4444;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.color-preview {
|
|
83
|
+
width: 120px;
|
|
84
|
+
height: 38px;
|
|
85
|
+
border-radius: 4px;
|
|
86
|
+
border: 1px solid var(--theme-elevation-200);
|
|
87
|
+
display: flex;
|
|
88
|
+
align-items: center;
|
|
89
|
+
justify-content: center;
|
|
90
|
+
position: relative;
|
|
91
|
+
overflow: hidden;
|
|
92
|
+
|
|
93
|
+
.preview-label {
|
|
94
|
+
font-size: 0.75rem;
|
|
95
|
+
font-family: monospace;
|
|
96
|
+
padding: 0.25rem 0.5rem;
|
|
97
|
+
background: rgba(255, 255, 255, 0.9);
|
|
98
|
+
border-radius: 2px;
|
|
99
|
+
backdrop-filter: blur(4px);
|
|
100
|
+
color: #000;
|
|
101
|
+
font-weight: 500;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.mini-preview {
|
|
106
|
+
margin-top: 1rem;
|
|
107
|
+
padding: 1rem;
|
|
108
|
+
border-radius: 6px;
|
|
109
|
+
border: 1px solid;
|
|
110
|
+
|
|
111
|
+
.preview-card {
|
|
112
|
+
padding: 1rem;
|
|
113
|
+
border-radius: 4px;
|
|
114
|
+
border: 1px solid;
|
|
115
|
+
display: flex;
|
|
116
|
+
gap: 0.5rem;
|
|
117
|
+
flex-wrap: wrap;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.preview-button {
|
|
121
|
+
padding: 0.5rem 1rem;
|
|
122
|
+
border-radius: 4px;
|
|
123
|
+
border: none;
|
|
124
|
+
font-size: 0.875rem;
|
|
125
|
+
font-weight: 500;
|
|
126
|
+
cursor: pointer;
|
|
127
|
+
transition: opacity 0.2s;
|
|
128
|
+
|
|
129
|
+
&:hover {
|
|
130
|
+
opacity: 0.9;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
&.secondary {
|
|
134
|
+
border: 1px solid currentColor;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
.theme-color-picker-field {
|
|
2
|
+
margin-bottom: 1rem;
|
|
3
|
+
|
|
4
|
+
.field-header {
|
|
5
|
+
margin-bottom: 0.5rem;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.field-label {
|
|
9
|
+
display: block;
|
|
10
|
+
font-weight: 500;
|
|
11
|
+
font-size: 0.875rem;
|
|
12
|
+
color: var(--theme-text);
|
|
13
|
+
margin-bottom: 0.25rem;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.field-description {
|
|
17
|
+
font-size: 0.75rem;
|
|
18
|
+
color: var(--theme-elevation-400);
|
|
19
|
+
margin-top: 0.25rem;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.color-picker-container {
|
|
23
|
+
display: flex;
|
|
24
|
+
gap: 0.75rem;
|
|
25
|
+
align-items: center;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.color-input-wrapper {
|
|
29
|
+
display: flex;
|
|
30
|
+
gap: 0.5rem;
|
|
31
|
+
flex: 1;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.color-input {
|
|
35
|
+
width: 60px;
|
|
36
|
+
height: 38px;
|
|
37
|
+
border: 1px solid var(--theme-elevation-200);
|
|
38
|
+
border-radius: 4px;
|
|
39
|
+
cursor: pointer;
|
|
40
|
+
padding: 2px;
|
|
41
|
+
|
|
42
|
+
&:hover {
|
|
43
|
+
border-color: var(--theme-elevation-400);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
&:focus {
|
|
47
|
+
outline: 2px solid var(--theme-elevation-500);
|
|
48
|
+
outline-offset: 1px;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.text-input {
|
|
53
|
+
flex: 1;
|
|
54
|
+
height: 38px;
|
|
55
|
+
padding: 0 0.75rem;
|
|
56
|
+
border: 1px solid var(--theme-elevation-200);
|
|
57
|
+
border-radius: 4px;
|
|
58
|
+
font-family: monospace;
|
|
59
|
+
font-size: 0.875rem;
|
|
60
|
+
background: var(--theme-elevation-0);
|
|
61
|
+
color: var(--theme-text);
|
|
62
|
+
|
|
63
|
+
&:hover {
|
|
64
|
+
border-color: var(--theme-elevation-400);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
&:focus {
|
|
68
|
+
outline: 2px solid var(--theme-elevation-500);
|
|
69
|
+
outline-offset: 1px;
|
|
70
|
+
border-color: var(--theme-elevation-500);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
&::placeholder {
|
|
74
|
+
color: var(--theme-elevation-400);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&:invalid {
|
|
78
|
+
border-color: #ef4444;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.color-preview {
|
|
83
|
+
width: 120px;
|
|
84
|
+
height: 38px;
|
|
85
|
+
border-radius: 4px;
|
|
86
|
+
border: 1px solid var(--theme-elevation-200);
|
|
87
|
+
display: flex;
|
|
88
|
+
align-items: center;
|
|
89
|
+
justify-content: center;
|
|
90
|
+
position: relative;
|
|
91
|
+
overflow: hidden;
|
|
92
|
+
|
|
93
|
+
.preview-label {
|
|
94
|
+
font-size: 0.75rem;
|
|
95
|
+
font-family: monospace;
|
|
96
|
+
padding: 0.25rem 0.5rem;
|
|
97
|
+
background: rgba(255, 255, 255, 0.9);
|
|
98
|
+
border-radius: 2px;
|
|
99
|
+
backdrop-filter: blur(4px);
|
|
100
|
+
color: #000;
|
|
101
|
+
font-weight: 500;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.mini-preview {
|
|
106
|
+
margin-top: 1rem;
|
|
107
|
+
padding: 1rem;
|
|
108
|
+
border-radius: 6px;
|
|
109
|
+
border: 1px solid;
|
|
110
|
+
|
|
111
|
+
.preview-card {
|
|
112
|
+
padding: 1rem;
|
|
113
|
+
border-radius: 4px;
|
|
114
|
+
border: 1px solid;
|
|
115
|
+
display: flex;
|
|
116
|
+
gap: 0.5rem;
|
|
117
|
+
flex-wrap: wrap;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.preview-button {
|
|
121
|
+
padding: 0.5rem 1rem;
|
|
122
|
+
border-radius: 4px;
|
|
123
|
+
border: none;
|
|
124
|
+
font-size: 0.875rem;
|
|
125
|
+
font-weight: 500;
|
|
126
|
+
cursor: pointer;
|
|
127
|
+
transition: opacity 0.2s;
|
|
128
|
+
|
|
129
|
+
&:hover {
|
|
130
|
+
opacity: 0.9;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
&.secondary {
|
|
134
|
+
border: 1px solid currentColor;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { ThemePreset } from './presets.js'\n\nexport interface ThemeManagementPluginOptions {\n\t/** Whether the plugin should register itself */\n\tenabled?: boolean\n\t/** Collection slug that stores site-level settings (default: `site-settings`) */\n\ttargetCollection?: string\n\t/** Theme presets available to editors */\n\tthemePresets?: ThemePreset[]\n\t/** Default preset name when no value is stored */\n\tdefaultTheme?: string\n\t/** Allow editors to toggle between light / dark / auto modes */\n\tincludeColorModeToggle?: boolean\n\t/** Expose custom CSS editor */\n\tincludeCustomCSS?: boolean\n\t/** Reserved for future use, keeps API parity */\n\tincludeBrandIdentity?: boolean\n\t/** Enable advanced controls such as animation level */\n\tenableAdvancedFeatures?: boolean\n\t/** Log helpful messages during config mutation */\n\tenableLogging?: boolean\n}\n\nexport interface FetchThemeConfigurationOptions {\n\t/** Optional tenant identifier if your project is multi-tenant */\n\ttenantSlug?: string\n\t/** Collection slug override (default: `site-settings`) */\n\tcollectionSlug?: string\n\t/** Depth parameter passed to Payload REST API */\n\tdepth?: number\n\t/** Locale parameter passed to Payload REST API */\n\tlocale?: string\n\t/** Include draft documents */\n\tdraft?: boolean\n\t/** Extra query parameters to append to the request */\n\tqueryParams?: Record<string, string | number | boolean>\n}\n\n"],"names":[],"mappings":"AAuBA,WAaC"}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { ThemePreset } from './presets.js'\r\n\r\nexport interface ThemeManagementPluginOptions {\r\n\t/** Whether the plugin should register itself */\r\n\tenabled?: boolean\r\n\t/** Collection slug that stores site-level settings (default: `site-settings`) */\r\n\ttargetCollection?: string\r\n\t/** Theme presets available to editors */\r\n\tthemePresets?: ThemePreset[]\r\n\t/** Default preset name when no value is stored */\r\n\tdefaultTheme?: string\r\n\t/** Allow editors to toggle between light / dark / auto modes */\r\n\tincludeColorModeToggle?: boolean\r\n\t/** Expose custom CSS editor */\r\n\tincludeCustomCSS?: boolean\r\n\t/** Reserved for future use, keeps API parity */\r\n\tincludeBrandIdentity?: boolean\r\n\t/** Enable advanced controls such as animation level */\r\n\tenableAdvancedFeatures?: boolean\r\n\t/** Log helpful messages during config mutation */\r\n\tenableLogging?: boolean\r\n}\r\n\r\nexport interface FetchThemeConfigurationOptions {\r\n\t/** Optional tenant identifier if your project is multi-tenant */\r\n\ttenantSlug?: string\r\n\t/** Collection slug override (default: `site-settings`) */\r\n\tcollectionSlug?: string\r\n\t/** Depth parameter passed to Payload REST API */\r\n\tdepth?: number\r\n\t/** Locale parameter passed to Payload REST API */\r\n\tlocale?: string\r\n\t/** Include draft documents */\r\n\tdraft?: boolean\r\n\t/** Extra query parameters to append to the request */\r\n\tqueryParams?: Record<string, string | number | boolean>\r\n}\r\n\r\n"],"names":[],"mappings":"AAuBA,WAaC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type { SiteSetting } from '../payload-types.js';
|
|
2
1
|
import type { Mode, ThemeDefaults } from '../providers/Theme/types.js';
|
|
3
2
|
import type { ThemeTypographyPreset } from '../presets.js';
|
|
3
|
+
/**
|
|
4
|
+
* Generic theme configuration structure that matches Payload's generated types
|
|
5
|
+
* without depending on specific payload-types versions
|
|
6
|
+
*/
|
|
4
7
|
interface ThemeTypographyOverride {
|
|
5
8
|
bodyFont?: string | null;
|
|
6
9
|
headingFont?: string | null;
|
|
@@ -9,9 +12,41 @@ interface ThemeTypographyOverride {
|
|
|
9
12
|
baseFontSize?: string | null;
|
|
10
13
|
lineHeight?: string | null;
|
|
11
14
|
}
|
|
12
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Generic theme configuration interface that accepts any compatible structure
|
|
17
|
+
* This avoids type conflicts between different versions of payload-types
|
|
18
|
+
*/
|
|
19
|
+
interface GenericThemeConfiguration {
|
|
20
|
+
theme?: string | null;
|
|
21
|
+
colorMode?: string | null;
|
|
22
|
+
allowColorModeToggle?: boolean | null;
|
|
23
|
+
borderRadius?: string | null;
|
|
24
|
+
fontScale?: string | null;
|
|
25
|
+
spacing?: string | null;
|
|
26
|
+
animationLevel?: string | null;
|
|
27
|
+
customCSS?: string | null;
|
|
28
|
+
lightMode?: {
|
|
29
|
+
primary?: string | null;
|
|
30
|
+
secondary?: string | null;
|
|
31
|
+
accent?: string | null;
|
|
32
|
+
neutral?: string | null;
|
|
33
|
+
success?: string | null;
|
|
34
|
+
warning?: string | null;
|
|
35
|
+
error?: string | null;
|
|
36
|
+
info?: string | null;
|
|
37
|
+
} | null;
|
|
38
|
+
darkMode?: {
|
|
39
|
+
primary?: string | null;
|
|
40
|
+
secondary?: string | null;
|
|
41
|
+
accent?: string | null;
|
|
42
|
+
neutral?: string | null;
|
|
43
|
+
success?: string | null;
|
|
44
|
+
warning?: string | null;
|
|
45
|
+
error?: string | null;
|
|
46
|
+
info?: string | null;
|
|
47
|
+
} | null;
|
|
13
48
|
typography?: ThemeTypographyOverride | null;
|
|
14
|
-
}
|
|
49
|
+
}
|
|
15
50
|
declare const BORDER_RADIUS_VALUES: readonly ["none", "small", "medium", "large", "xl"];
|
|
16
51
|
declare const FONT_SCALE_VALUES: readonly ["small", "medium", "large"];
|
|
17
52
|
declare const SPACING_VALUES: readonly ["compact", "medium", "spacious"];
|
|
@@ -20,7 +55,7 @@ type BorderRadiusOption = (typeof BORDER_RADIUS_VALUES)[number];
|
|
|
20
55
|
type FontScaleOption = (typeof FONT_SCALE_VALUES)[number];
|
|
21
56
|
type SpacingOption = (typeof SPACING_VALUES)[number];
|
|
22
57
|
type AnimationLevelOption = (typeof ANIMATION_LEVEL_VALUES)[number];
|
|
23
|
-
type ThemeColorConfiguration = NonNullable<
|
|
58
|
+
type ThemeColorConfiguration = NonNullable<GenericThemeConfiguration['lightMode']>;
|
|
24
59
|
export interface ResolvedThemeConfiguration {
|
|
25
60
|
theme: ThemeDefaults;
|
|
26
61
|
colorMode: Mode;
|
|
@@ -35,6 +70,6 @@ export interface ResolvedThemeConfiguration {
|
|
|
35
70
|
typography: ThemeTypographyPreset | null;
|
|
36
71
|
}
|
|
37
72
|
export declare const DEFAULT_THEME_CONFIGURATION: ResolvedThemeConfiguration;
|
|
38
|
-
export declare function resolveThemeConfiguration(themeConfiguration?:
|
|
73
|
+
export declare function resolveThemeConfiguration(themeConfiguration?: GenericThemeConfiguration | null): ResolvedThemeConfiguration;
|
|
39
74
|
export {};
|
|
40
75
|
//# sourceMappingURL=resolveThemeConfiguration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveThemeConfiguration.d.ts","sourceRoot":"","sources":["../../src/utils/resolveThemeConfiguration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"resolveThemeConfiguration.d.ts","sourceRoot":"","sources":["../../src/utils/resolveThemeConfiguration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAEtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAG1D;;;GAGG;AACH,UAAU,uBAAuB;IAC/B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B;AAED;;;GAGG;AACH,UAAU,yBAAyB;IACjC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,oBAAoB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACrC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B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ACjE,QAAA,MAAM,sBAAsB,gDAAiD,CAAA;AAM7E,KAAK,kBAAkB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAA;AAC/D,KAAK,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AACzD,KAAK,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAA;AACpD,KAAK,oBAAoB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAA;AAInE,KAAK,uBAAuB,GAAG,WAAW,CAAC,yBAAyB,CAAC,WAAW,CAAC,CAAC,CAAA;AAOlF,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,aAAa,CAAA;IACpB,SAAS,EAAE,IAAI,CAAA;IACf,oBAAoB,EAAE,OAAO,CAAA;IAC7B,YAAY,EAAE,kBAAkB,CAAA;IAChC,SAAS,EAAE,eAAe,CAAA;IAC1B,OAAO,EAAE,aAAa,CAAA;IACtB,cAAc,EAAE,oBAAoB,CAAA;IACpC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,SAAS,CAAC,EAAE,uBAAuB,CAAA;IACnC,QAAQ,CAAC,EAAE,uBAAuB,CAAA;IAClC,UAAU,EAAE,qBAAqB,GAAG,IAAI,CAAA;CACzC;AAED,eAAO,MAAM,2BAA2B,EAAE,0BAYzC,CAAA;AA4CD,wBAAgB,yBAAyB,CACvC,kBAAkB,CAAC,EAAE,yBAAyB,GAAG,IAAI,GACpD,0BAA0B,CA0D5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/resolveThemeConfiguration.ts"],"sourcesContent":["import { FONT_VALUE_TO_CSS } from '../constants/themeFonts.js'\nimport type { SiteSetting } from '../payload-types.js'\nimport type { Mode, ThemeDefaults } from '../providers/Theme/types.js'\nimport { themeIsValid } from '../providers/Theme/types.js'\nimport type { ThemeTypographyPreset } from '../presets.js'\nimport { defaultThemePresets } from '../presets.js'\n\ninterface ThemeTypographyOverride {\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\ntype SiteThemeConfiguration = SiteSetting['themeConfiguration'] & {\n typography?: ThemeTypographyOverride | null\n}\n\nconst BORDER_RADIUS_VALUES = ['none', 'small', 'medium', 'large', 'xl'] as const\nconst LEGACY_BORDER_RADIUS_ALIASES: Record<string, (typeof BORDER_RADIUS_VALUES)[number]> = {\n full: 'xl',\n}\nconst FONT_SCALE_VALUES = ['small', 'medium', 'large'] as const\nconst SPACING_VALUES = ['compact', 'medium', 'spacious'] as const\nconst ANIMATION_LEVEL_VALUES = ['none', 'reduced', 'medium', 'high'] as const\nconst LEGACY_ANIMATION_ALIASES: Record<string, (typeof ANIMATION_LEVEL_VALUES)[number]> = {\n full: 'high',\n}\nconst MODE_VALUES = ['auto', 'light', 'dark'] as const\n\ntype BorderRadiusOption = (typeof BORDER_RADIUS_VALUES)[number]\ntype FontScaleOption = (typeof FONT_SCALE_VALUES)[number]\ntype SpacingOption = (typeof SPACING_VALUES)[number]\ntype AnimationLevelOption = (typeof ANIMATION_LEVEL_VALUES)[number]\n\ntype ThemeModeOption = (typeof MODE_VALUES)[number]\n\ntype ThemeColorConfiguration = NonNullable<SiteThemeConfiguration['lightMode']>\n\nconst DEFAULT_THEME_NAME: ThemeDefaults = 'cool'\nconst DEFAULT_THEME_PRESET = defaultThemePresets.find(\n (preset) => preset.name === DEFAULT_THEME_NAME,\n)\n\nexport interface ResolvedThemeConfiguration {\n theme: ThemeDefaults\n colorMode: Mode\n allowColorModeToggle: boolean\n borderRadius: BorderRadiusOption\n fontScale: FontScaleOption\n spacing: SpacingOption\n animationLevel: AnimationLevelOption\n customCSS: string | null\n lightMode?: ThemeColorConfiguration\n darkMode?: ThemeColorConfiguration\n typography: ThemeTypographyPreset | null\n}\n\nexport const DEFAULT_THEME_CONFIGURATION: ResolvedThemeConfiguration = {\n theme: DEFAULT_THEME_NAME,\n colorMode: 'auto',\n allowColorModeToggle: true,\n borderRadius: 'medium',\n fontScale: 'medium',\n spacing: 'medium',\n animationLevel: 'medium',\n customCSS: null,\n lightMode: DEFAULT_THEME_PRESET?.lightMode,\n darkMode: DEFAULT_THEME_PRESET?.darkMode,\n typography: DEFAULT_THEME_PRESET?.typography ?? null,\n}\n\nfunction resolveBorderRadius(value: unknown): BorderRadiusOption {\n if (typeof value === 'string') {\n if (BORDER_RADIUS_VALUES.includes(value as BorderRadiusOption)) {\n return value as BorderRadiusOption\n }\n\n const legacyMatch = LEGACY_BORDER_RADIUS_ALIASES[value]\n if (legacyMatch) {\n return legacyMatch\n }\n }\n\n return DEFAULT_THEME_CONFIGURATION.borderRadius\n}\n\nfunction isFontScale(value: unknown): value is FontScaleOption {\n return typeof value === 'string' && FONT_SCALE_VALUES.includes(value as FontScaleOption)\n}\n\nfunction isSpacing(value: unknown): value is SpacingOption {\n return typeof value === 'string' && SPACING_VALUES.includes(value as SpacingOption)\n}\n\nfunction resolveAnimationLevel(value: unknown): AnimationLevelOption {\n if (typeof value === 'string') {\n if (ANIMATION_LEVEL_VALUES.includes(value as AnimationLevelOption)) {\n return value as AnimationLevelOption\n }\n\n const legacyMatch = LEGACY_ANIMATION_ALIASES[value]\n if (legacyMatch) {\n return legacyMatch\n }\n }\n\n return DEFAULT_THEME_CONFIGURATION.animationLevel\n}\n\nfunction isMode(value: unknown): value is ThemeModeOption {\n return typeof value === 'string' && MODE_VALUES.includes(value as ThemeModeOption)\n}\n\nexport function resolveThemeConfiguration(\n themeConfiguration?: SiteThemeConfiguration | null,\n): ResolvedThemeConfiguration {\n if (!themeConfiguration) {\n return DEFAULT_THEME_CONFIGURATION\n }\n\n const {\n theme,\n colorMode,\n allowColorModeToggle,\n borderRadius,\n fontScale,\n spacing,\n animationLevel,\n customCSS,\n lightMode,\n darkMode,\n typography,\n } = themeConfiguration\n\n const resolvedTheme =\n typeof theme === 'string' && themeIsValid(theme)\n ? (theme as ThemeDefaults)\n : DEFAULT_THEME_CONFIGURATION.theme\n const resolvedMode = isMode(colorMode)\n ? (colorMode as Mode)\n : DEFAULT_THEME_CONFIGURATION.colorMode\n const resolvedBorderRadius = resolveBorderRadius(borderRadius)\n const resolvedFontScale = isFontScale(fontScale)\n ? fontScale\n : DEFAULT_THEME_CONFIGURATION.fontScale\n const resolvedSpacing = isSpacing(spacing) ? spacing : DEFAULT_THEME_CONFIGURATION.spacing\n const resolvedAnimationLevel = resolveAnimationLevel(animationLevel)\n const resolvedAllowToggle =\n typeof allowColorModeToggle === 'boolean'\n ? allowColorModeToggle\n : DEFAULT_THEME_CONFIGURATION.allowColorModeToggle\n const resolvedCustomCSS = typeof customCSS === 'string' ? customCSS : null\n const preset = defaultThemePresets.find((candidate) => candidate.name === resolvedTheme)\n const baseLightMode = preset?.lightMode ?? DEFAULT_THEME_CONFIGURATION.lightMode\n const baseDarkMode = preset?.darkMode ?? DEFAULT_THEME_CONFIGURATION.darkMode\n const resolvedLightMode = mergeColorModes(baseLightMode, lightMode)\n const resolvedDarkMode = mergeColorModes(baseDarkMode, darkMode)\n const resolvedTypography =\n mergeTypography(preset?.typography, typography) ?? preset?.typography ?? null\n\n return {\n theme: resolvedTheme,\n colorMode: resolvedMode,\n allowColorModeToggle: resolvedAllowToggle,\n borderRadius: resolvedBorderRadius,\n fontScale: resolvedFontScale,\n spacing: resolvedSpacing,\n animationLevel: resolvedAnimationLevel,\n customCSS: resolvedCustomCSS,\n lightMode: resolvedLightMode,\n darkMode: resolvedDarkMode,\n typography: resolvedTypography,\n }\n}\n\nfunction mergeColorModes(\n base?: ThemeColorConfiguration,\n overrides?: SiteThemeConfiguration['lightMode'],\n): ThemeColorConfiguration | undefined {\n const merged: Record<string, string> = {}\n\n if (base) {\n Object.entries(base).forEach(([key, value]) => {\n if (typeof value === 'string' && value.trim().length > 0) {\n merged[key] = value\n }\n })\n }\n\n if (overrides) {\n Object.entries(overrides).forEach(([key, value]) => {\n if (typeof value === 'string' && value.trim().length > 0) {\n merged[key] = value\n } else if (value === null) {\n delete merged[key]\n }\n })\n }\n\n return Object.keys(merged).length > 0 ? (merged as ThemeColorConfiguration) : undefined\n}\n\nfunction mergeTypography(\n base?: ThemeTypographyPreset | null,\n overrides?: ThemeTypographyOverride | null,\n): ThemeTypographyPreset | null {\n if (!base && !overrides) {\n return base ?? null\n }\n\n const result: ThemeTypographyPreset = {\n fontFamily: base?.fontFamily ?? 'var(--font-geist-sans)',\n headingFamily: base?.headingFamily ?? 'var(--font-geist-sans)',\n baseFontSize: base?.baseFontSize ?? '16px',\n lineHeight: base?.lineHeight ?? '1.6',\n fontWeights: { ...(base?.fontWeights ?? {}) },\n letterSpacing: { ...(base?.letterSpacing ?? {}) },\n }\n\n if (overrides) {\n const resolvedBodyFont = resolveFontSelection(\n overrides.bodyFont,\n overrides.bodyFontCustom,\n base?.fontFamily,\n )\n if (resolvedBodyFont) {\n result.fontFamily = resolvedBodyFont\n }\n\n const resolvedHeadingFont = resolveFontSelection(\n overrides.headingFont,\n overrides.headingFontCustom,\n base?.headingFamily,\n )\n if (resolvedHeadingFont) {\n result.headingFamily = resolvedHeadingFont\n }\n\n if (overrides.baseFontSize && overrides.baseFontSize !== 'preset') {\n result.baseFontSize = overrides.baseFontSize\n }\n\n if (overrides.lineHeight && overrides.lineHeight !== 'preset') {\n result.lineHeight = overrides.lineHeight\n }\n }\n\n return result\n}\n\nfunction resolveFontSelection(\n selection?: string | null,\n custom?: string | null,\n fallback?: string | null,\n): string | null {\n if (!selection || selection === 'preset') {\n return fallback ?? null\n }\n\n if (selection === 'custom') {\n const trimmed = custom?.trim()\n return trimmed && trimmed.length > 0 ? trimmed : (fallback ?? null)\n }\n\n const mapped = FONT_VALUE_TO_CSS[selection]\n return mapped ?? fallback ?? null\n}\n"],"names":["FONT_VALUE_TO_CSS","themeIsValid","defaultThemePresets","BORDER_RADIUS_VALUES","LEGACY_BORDER_RADIUS_ALIASES","full","FONT_SCALE_VALUES","SPACING_VALUES","ANIMATION_LEVEL_VALUES","LEGACY_ANIMATION_ALIASES","MODE_VALUES","DEFAULT_THEME_NAME","DEFAULT_THEME_PRESET","find","preset","name","DEFAULT_THEME_CONFIGURATION","theme","colorMode","allowColorModeToggle","borderRadius","fontScale","spacing","animationLevel","customCSS","lightMode","darkMode","typography","resolveBorderRadius","value","includes","legacyMatch","isFontScale","isSpacing","resolveAnimationLevel","isMode","resolveThemeConfiguration","themeConfiguration","resolvedTheme","resolvedMode","resolvedBorderRadius","resolvedFontScale","resolvedSpacing","resolvedAnimationLevel","resolvedAllowToggle","resolvedCustomCSS","candidate","baseLightMode","baseDarkMode","resolvedLightMode","mergeColorModes","resolvedDarkMode","resolvedTypography","mergeTypography","base","overrides","merged","Object","entries","forEach","key","trim","length","keys","undefined","result","fontFamily","headingFamily","baseFontSize","lineHeight","fontWeights","letterSpacing","resolvedBodyFont","resolveFontSelection","bodyFont","bodyFontCustom","resolvedHeadingFont","headingFont","headingFontCustom","selection","custom","fallback","trimmed","mapped"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,6BAA4B;AAG9D,SAASC,YAAY,QAAQ,8BAA6B;AAE1D,SAASC,mBAAmB,QAAQ,gBAAe;AAenD,MAAMC,uBAAuB;IAAC;IAAQ;IAAS;IAAU;IAAS;CAAK;AACvE,MAAMC,+BAAsF;IAC1FC,MAAM;AACR;AACA,MAAMC,oBAAoB;IAAC;IAAS;IAAU;CAAQ;AACtD,MAAMC,iBAAiB;IAAC;IAAW;IAAU;CAAW;AACxD,MAAMC,yBAAyB;IAAC;IAAQ;IAAW;IAAU;CAAO;AACpE,MAAMC,2BAAoF;IACxFJ,MAAM;AACR;AACA,MAAMK,cAAc;IAAC;IAAQ;IAAS;CAAO;AAW7C,MAAMC,qBAAoC;AAC1C,MAAMC,uBAAuBV,oBAAoBW,IAAI,CACnD,CAACC,SAAWA,OAAOC,IAAI,KAAKJ;AAiB9B,OAAO,MAAMK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,UAAUc,UAAU;QAC1C;IACF;IAEA,OAAOJ;AACT;AAEA,SAASQ,qBACPM,SAAyB,EACzBC,MAAsB,EACtBC,QAAwB;IAExB,IAAI,CAACF,aAAaA,cAAc,UAAU;QACxC,OAAOE,YAAY;IACrB;IAEA,IAAIF,cAAc,UAAU;QAC1B,MAAMG,UAAUF,QAAQnB;QACxB,OAAOqB,WAAWA,QAAQpB,MAAM,GAAG,IAAIoB,UAAWD,YAAY;IAChE;IAEA,MAAME,SAASnF,iBAAiB,CAAC+E,UAAU;IAC3C,OAAOI,UAAUF,YAAY;AAC/B"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/resolveThemeConfiguration.ts"],"sourcesContent":["import { FONT_VALUE_TO_CSS } from '../constants/themeFonts.js'\r\nimport type { Mode, ThemeDefaults } from '../providers/Theme/types.js'\r\nimport { themeIsValid } from '../providers/Theme/types.js'\r\nimport type { ThemeTypographyPreset } from '../presets.js'\r\nimport { defaultThemePresets } from '../presets.js'\r\n\r\n/**\r\n * Generic theme configuration structure that matches Payload's generated types\r\n * without depending on specific payload-types versions\r\n */\r\ninterface ThemeTypographyOverride {\r\n bodyFont?: string | null\r\n headingFont?: string | null\r\n bodyFontCustom?: string | null\r\n headingFontCustom?: string | null\r\n baseFontSize?: string | null\r\n lineHeight?: string | null\r\n}\r\n\r\n/**\r\n * Generic theme configuration interface that accepts any compatible structure\r\n * This avoids type conflicts between different versions of payload-types\r\n */\r\ninterface GenericThemeConfiguration {\r\n theme?: string | null\r\n colorMode?: string | null\r\n allowColorModeToggle?: boolean | null\r\n borderRadius?: string | null\r\n fontScale?: string | null\r\n spacing?: string | null\r\n animationLevel?: string | null\r\n customCSS?: string | null\r\n lightMode?: {\r\n primary?: string | null\r\n secondary?: string | null\r\n accent?: string | null\r\n neutral?: string | null\r\n success?: string | null\r\n warning?: string | null\r\n error?: string | null\r\n info?: string | null\r\n } | null\r\n darkMode?: {\r\n primary?: string | null\r\n secondary?: string | null\r\n accent?: string | null\r\n neutral?: string | null\r\n success?: string | null\r\n warning?: string | null\r\n error?: string | null\r\n info?: string | null\r\n } | null\r\n typography?: ThemeTypographyOverride | null\r\n}\r\n\r\nconst BORDER_RADIUS_VALUES = ['none', 'small', 'medium', 'large', 'xl'] as const\r\nconst LEGACY_BORDER_RADIUS_ALIASES: Record<string, (typeof BORDER_RADIUS_VALUES)[number]> = {\r\n full: 'xl',\r\n}\r\nconst FONT_SCALE_VALUES = ['small', 'medium', 'large'] as const\r\nconst SPACING_VALUES = ['compact', 'medium', 'spacious'] as const\r\nconst ANIMATION_LEVEL_VALUES = ['none', 'reduced', 'medium', 'high'] as const\r\nconst LEGACY_ANIMATION_ALIASES: Record<string, (typeof ANIMATION_LEVEL_VALUES)[number]> = {\r\n full: 'high',\r\n}\r\nconst MODE_VALUES = ['auto', 'light', 'dark'] as const\r\n\r\ntype BorderRadiusOption = (typeof BORDER_RADIUS_VALUES)[number]\r\ntype FontScaleOption = (typeof FONT_SCALE_VALUES)[number]\r\ntype SpacingOption = (typeof SPACING_VALUES)[number]\r\ntype AnimationLevelOption = (typeof ANIMATION_LEVEL_VALUES)[number]\r\n\r\ntype ThemeModeOption = (typeof MODE_VALUES)[number]\r\n\r\ntype ThemeColorConfiguration = NonNullable<GenericThemeConfiguration['lightMode']>\r\n\r\nconst DEFAULT_THEME_NAME: ThemeDefaults = 'cool'\r\nconst DEFAULT_THEME_PRESET = defaultThemePresets.find(\r\n (preset) => preset.name === DEFAULT_THEME_NAME,\r\n)\r\n\r\nexport interface ResolvedThemeConfiguration {\r\n theme: ThemeDefaults\r\n colorMode: Mode\r\n allowColorModeToggle: boolean\r\n borderRadius: BorderRadiusOption\r\n fontScale: FontScaleOption\r\n spacing: SpacingOption\r\n animationLevel: AnimationLevelOption\r\n customCSS: string | null\r\n lightMode?: ThemeColorConfiguration\r\n darkMode?: ThemeColorConfiguration\r\n typography: ThemeTypographyPreset | null\r\n}\r\n\r\nexport const DEFAULT_THEME_CONFIGURATION: ResolvedThemeConfiguration = {\r\n theme: DEFAULT_THEME_NAME,\r\n colorMode: 'auto',\r\n allowColorModeToggle: true,\r\n borderRadius: 'medium',\r\n fontScale: 'medium',\r\n spacing: 'medium',\r\n animationLevel: 'medium',\r\n customCSS: null,\r\n lightMode: DEFAULT_THEME_PRESET?.lightMode,\r\n darkMode: DEFAULT_THEME_PRESET?.darkMode,\r\n typography: DEFAULT_THEME_PRESET?.typography ?? null,\r\n}\r\n\r\nfunction resolveBorderRadius(value: unknown): BorderRadiusOption {\r\n if (typeof value === 'string') {\r\n if (BORDER_RADIUS_VALUES.includes(value as BorderRadiusOption)) {\r\n return value as BorderRadiusOption\r\n }\r\n\r\n const legacyMatch = LEGACY_BORDER_RADIUS_ALIASES[value]\r\n if (legacyMatch) {\r\n return legacyMatch\r\n }\r\n }\r\n\r\n return DEFAULT_THEME_CONFIGURATION.borderRadius\r\n}\r\n\r\nfunction isFontScale(value: unknown): value is FontScaleOption {\r\n return typeof value === 'string' && FONT_SCALE_VALUES.includes(value as FontScaleOption)\r\n}\r\n\r\nfunction isSpacing(value: unknown): value is SpacingOption {\r\n return typeof value === 'string' && SPACING_VALUES.includes(value as SpacingOption)\r\n}\r\n\r\nfunction resolveAnimationLevel(value: unknown): AnimationLevelOption {\r\n if (typeof value === 'string') {\r\n if (ANIMATION_LEVEL_VALUES.includes(value as AnimationLevelOption)) {\r\n return value as AnimationLevelOption\r\n }\r\n\r\n const legacyMatch = LEGACY_ANIMATION_ALIASES[value]\r\n if (legacyMatch) {\r\n return legacyMatch\r\n }\r\n }\r\n\r\n return DEFAULT_THEME_CONFIGURATION.animationLevel\r\n}\r\n\r\nfunction isMode(value: unknown): value is ThemeModeOption {\r\n return typeof value === 'string' && MODE_VALUES.includes(value as ThemeModeOption)\r\n}\r\n\r\nexport function resolveThemeConfiguration(\r\n themeConfiguration?: GenericThemeConfiguration | null,\r\n): ResolvedThemeConfiguration {\r\n if (!themeConfiguration) {\r\n return DEFAULT_THEME_CONFIGURATION\r\n }\r\n\r\n const {\r\n theme,\r\n colorMode,\r\n allowColorModeToggle,\r\n borderRadius,\r\n fontScale,\r\n spacing,\r\n animationLevel,\r\n customCSS,\r\n lightMode,\r\n darkMode,\r\n typography,\r\n } = themeConfiguration\r\n\r\n const resolvedTheme =\r\n typeof theme === 'string' && themeIsValid(theme)\r\n ? (theme as ThemeDefaults)\r\n : DEFAULT_THEME_CONFIGURATION.theme\r\n const resolvedMode = isMode(colorMode)\r\n ? (colorMode as Mode)\r\n : DEFAULT_THEME_CONFIGURATION.colorMode\r\n const resolvedBorderRadius = resolveBorderRadius(borderRadius)\r\n const resolvedFontScale = isFontScale(fontScale)\r\n ? fontScale\r\n : DEFAULT_THEME_CONFIGURATION.fontScale\r\n const resolvedSpacing = isSpacing(spacing) ? spacing : DEFAULT_THEME_CONFIGURATION.spacing\r\n const resolvedAnimationLevel = resolveAnimationLevel(animationLevel)\r\n const resolvedAllowToggle =\r\n typeof allowColorModeToggle === 'boolean'\r\n ? allowColorModeToggle\r\n : DEFAULT_THEME_CONFIGURATION.allowColorModeToggle\r\n const resolvedCustomCSS = typeof customCSS === 'string' ? customCSS : null\r\n const preset = defaultThemePresets.find((candidate) => candidate.name === resolvedTheme)\r\n const baseLightMode = preset?.lightMode ?? DEFAULT_THEME_CONFIGURATION.lightMode\r\n const baseDarkMode = preset?.darkMode ?? DEFAULT_THEME_CONFIGURATION.darkMode\r\n const resolvedLightMode = mergeColorModes(baseLightMode, lightMode)\r\n const resolvedDarkMode = mergeColorModes(baseDarkMode, darkMode)\r\n const resolvedTypography =\r\n mergeTypography(preset?.typography, typography) ?? preset?.typography ?? null\r\n\r\n return {\r\n theme: resolvedTheme,\r\n colorMode: resolvedMode,\r\n allowColorModeToggle: resolvedAllowToggle,\r\n borderRadius: resolvedBorderRadius,\r\n fontScale: resolvedFontScale,\r\n spacing: resolvedSpacing,\r\n animationLevel: resolvedAnimationLevel,\r\n customCSS: resolvedCustomCSS,\r\n lightMode: resolvedLightMode,\r\n darkMode: resolvedDarkMode,\r\n typography: resolvedTypography,\r\n }\r\n}\r\n\r\nfunction mergeColorModes(\r\n base?: ThemeColorConfiguration,\r\n overrides?: GenericThemeConfiguration['lightMode'],\r\n): ThemeColorConfiguration | undefined {\r\n const merged: Record<string, string> = {}\r\n\r\n if (base) {\r\n Object.entries(base).forEach(([key, value]) => {\r\n if (typeof value === 'string' && value.trim().length > 0) {\r\n merged[key] = value\r\n }\r\n })\r\n }\r\n\r\n if (overrides) {\r\n Object.entries(overrides).forEach(([key, value]) => {\r\n if (typeof value === 'string' && value.trim().length > 0) {\r\n merged[key] = value\r\n } else if (value === null) {\r\n delete merged[key]\r\n }\r\n })\r\n }\r\n\r\n return Object.keys(merged).length > 0 ? (merged as ThemeColorConfiguration) : undefined\r\n}\r\n\r\nfunction mergeTypography(\r\n base?: ThemeTypographyPreset | null,\r\n overrides?: ThemeTypographyOverride | null,\r\n): ThemeTypographyPreset | null {\r\n if (!base && !overrides) {\r\n return base ?? null\r\n }\r\n\r\n const result: ThemeTypographyPreset = {\r\n fontFamily: base?.fontFamily ?? 'var(--font-geist-sans)',\r\n headingFamily: base?.headingFamily ?? 'var(--font-geist-sans)',\r\n baseFontSize: base?.baseFontSize ?? '16px',\r\n lineHeight: base?.lineHeight ?? '1.6',\r\n fontWeights: { ...(base?.fontWeights ?? {}) },\r\n letterSpacing: { ...(base?.letterSpacing ?? {}) },\r\n }\r\n\r\n if (overrides) {\r\n const resolvedBodyFont = resolveFontSelection(\r\n overrides.bodyFont,\r\n overrides.bodyFontCustom,\r\n base?.fontFamily,\r\n )\r\n if (resolvedBodyFont) {\r\n result.fontFamily = resolvedBodyFont\r\n }\r\n\r\n const resolvedHeadingFont = resolveFontSelection(\r\n overrides.headingFont,\r\n overrides.headingFontCustom,\r\n base?.headingFamily,\r\n )\r\n if (resolvedHeadingFont) {\r\n result.headingFamily = resolvedHeadingFont\r\n }\r\n\r\n if (overrides.baseFontSize && overrides.baseFontSize !== 'preset') {\r\n result.baseFontSize = overrides.baseFontSize\r\n }\r\n\r\n if (overrides.lineHeight && overrides.lineHeight !== 'preset') {\r\n result.lineHeight = overrides.lineHeight\r\n }\r\n }\r\n\r\n return result\r\n}\r\n\r\nfunction resolveFontSelection(\r\n selection?: string | null,\r\n custom?: string | null,\r\n fallback?: string | null,\r\n): string | null {\r\n if (!selection || selection === 'preset') {\r\n return fallback ?? null\r\n }\r\n\r\n if (selection === 'custom') {\r\n const trimmed = custom?.trim()\r\n return trimmed && trimmed.length > 0 ? trimmed : (fallback ?? null)\r\n }\r\n\r\n const mapped = FONT_VALUE_TO_CSS[selection]\r\n return mapped ?? fallback ?? null\r\n}\r\n"],"names":["FONT_VALUE_TO_CSS","themeIsValid","defaultThemePresets","BORDER_RADIUS_VALUES","LEGACY_BORDER_RADIUS_ALIASES","full","FONT_SCALE_VALUES","SPACING_VALUES","ANIMATION_LEVEL_VALUES","LEGACY_ANIMATION_ALIASES","MODE_VALUES","DEFAULT_THEME_NAME","DEFAULT_THEME_PRESET","find","preset","name","DEFAULT_THEME_CONFIGURATION","theme","colorMode","allowColorModeToggle","borderRadius","fontScale","spacing","animationLevel","customCSS","lightMode","darkMode","typography","resolveBorderRadius","value","includes","legacyMatch","isFontScale","isSpacing","resolveAnimationLevel","isMode","resolveThemeConfiguration","themeConfiguration","resolvedTheme","resolvedMode","resolvedBorderRadius","resolvedFontScale","resolvedSpacing","resolvedAnimationLevel","resolvedAllowToggle","resolvedCustomCSS","candidate","baseLightMode","baseDarkMode","resolvedLightMode","mergeColorModes","resolvedDarkMode","resolvedTypography","mergeTypography","base","overrides","merged","Object","entries","forEach","key","trim","length","keys","undefined","result","fontFamily","headingFamily","baseFontSize","lineHeight","fontWeights","letterSpacing","resolvedBodyFont","resolveFontSelection","bodyFont","bodyFontCustom","resolvedHeadingFont","headingFont","headingFontCustom","selection","custom","fallback","trimmed","mapped"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,6BAA4B;AAE9D,SAASC,YAAY,QAAQ,8BAA6B;A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B,WAAW;QACb,MAAMiB,mBAAmBC,qBACvBlB,UAAUmB,QAAQ,EAClBnB,UAAUoB,cAAc,EACxBrB,MAAMY;QAER,IAAIM,kBAAkB;YACpBP,OAAOC,UAAU,GAAGM;QACtB;QAEA,MAAMI,sBAAsBH,qBAC1BlB,UAAUsB,WAAW,EACrBtB,UAAUuB,iBAAiB,EAC3BxB,MAAMa;QAER,IAAIS,qBAAqB;YACvBX,OAAOE,aAAa,GAAGS;QACzB;QAEA,IAAIrB,UAAUa,YAAY,IAAIb,UAAUa,YAAY,KAAK,UAAU;YACjEH,OAAOG,YAAY,GAAGb,UAAUa,YAAY;QAC9C;QAEA,IAAIb,UAAUc,UAAU,IAAId,UAAUc,UAAU,KAAK,UAAU;YAC7DJ,OAAOI,UAAU,GAAGd,UAAUc,UAAU;QAC1C;IACF;IAEA,OAAOJ;AACT;AAEA,SAASQ,qBACPM,SAAyB,EACzBC,MAAsB,EACtBC,QAAwB;IAExB,IAAI,CAACF,aAAaA,cAAc,UAAU;QACxC,OAAOE,YAAY;IACrB;IAEA,IAAIF,cAAc,UAAU;QAC1B,MAAMG,UAAUF,QAAQnB;QACxB,OAAOqB,WAAWA,QAAQpB,MAAM,GAAG,IAAIoB,UAAWD,YAAY;IAChE;IAEA,MAAME,SAASnF,iBAAiB,CAAC+E,UAAU;IAC3C,OAAOI,UAAUF,YAAY;AAC/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/themeAssets.ts"],"sourcesContent":["import { readFile } from 'fs/promises'\nimport { join } from 'path'\nimport type { ThemeDefaults } from '../providers/Theme/types.js'\n\nconst themeCriticalFiles: Record<string, string> = {\n cool: 'cool-critical.css',\n brutal: 'brutal-critical.css',\n neon: 'neon-critical.css',\n solar: 'solar-critical.css',\n dealership: 'dealership-critical.css',\n 'real-estate': 'real-estate-critical.css',\n 'real-estate-gold': 'real-estate-gold-critical.css',\n 'real-estate-neutral': 'real-estate-neutral-critical.css',\n}\n\nconst themeFullFiles: Record<string, string> = {\n cool: 'cool.css',\n brutal: 'brutal.css',\n neon: 'neon.css',\n solar: 'solar.css',\n dealership: 'dealership.css',\n 'real-estate': 'real-estate.css',\n 'real-estate-gold': 'real-estate-gold.css',\n 'real-estate-neutral': 'real-estate-neutral.css',\n}\n\nexport async function getThemeCriticalCSS(theme: ThemeDefaults): Promise<string | null> {\n try {\n const filename = themeCriticalFiles[theme]\n if (!filename) {\n console.warn(`Critical CSS file not found for theme: ${theme}`)\n return null\n }\n\n const filePath = join(process.cwd(), 'public', 'themes', filename)\n const css = await readFile(filePath, 'utf-8')\n\n return css.replace(/\\r\\n/g, '\\n').replace(/\\r/g, '\\n')\n } catch (error) {\n console.error(`Error reading critical CSS for theme ${theme}:`, error)\n return null\n }\n}\n\nexport function getThemeCSSPath(theme: ThemeDefaults): string {\n const filename = themeFullFiles[theme]\n return `/themes/${filename}`\n}\n\nexport function generateThemePreloadLinks(theme: ThemeDefaults): string {\n const cssPath = getThemeCSSPath(theme)\n return `<link rel=\"preload\" href=\"${cssPath}\" as=\"style\" onload=\"this.onload=null;this.rel='stylesheet'\">`\n}\n\nexport function createFallbackCriticalCSS(theme: ThemeDefaults): string {\n return `\n/* Fallback critical CSS for ${theme} theme */\n[data-theme=\"${theme}\"] {\n --background: hsl(0 0% 100%);\n --foreground: hsl(222 47% 11%);\n --primary: hsl(221 83% 53%);\n --primary-foreground: hsl(210 40% 98%);\n color-scheme: light;\n}\n\n[data-theme=\"${theme}\"][data-theme-mode=\"dark\"] {\n --background: hsl(222 47% 11%);\n --foreground: hsl(210 40% 98%);\n --primary: hsl(217 91% 60%);\n --primary-foreground: hsl(222 47% 11%);\n color-scheme: dark;\n}\n`.trim()\n}\n"],"names":["readFile","join","themeCriticalFiles","cool","brutal","neon","solar","dealership","themeFullFiles","getThemeCriticalCSS","theme","filename","console","warn","filePath","process","cwd","css","replace","error","getThemeCSSPath","generateThemePreloadLinks","cssPath","createFallbackCriticalCSS","trim"],"mappings":"AAA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/themeAssets.ts"],"sourcesContent":["import { readFile } from 'fs/promises'\r\nimport { join } from 'path'\r\nimport type { ThemeDefaults } from '../providers/Theme/types.js'\r\n\r\nconst themeCriticalFiles: Record<string, string> = {\r\n cool: 'cool-critical.css',\r\n brutal: 'brutal-critical.css',\r\n neon: 'neon-critical.css',\r\n solar: 'solar-critical.css',\r\n dealership: 'dealership-critical.css',\r\n 'real-estate': 'real-estate-critical.css',\r\n 'real-estate-gold': 'real-estate-gold-critical.css',\r\n 'real-estate-neutral': 'real-estate-neutral-critical.css',\r\n}\r\n\r\nconst themeFullFiles: Record<string, string> = {\r\n cool: 'cool.css',\r\n brutal: 'brutal.css',\r\n neon: 'neon.css',\r\n solar: 'solar.css',\r\n dealership: 'dealership.css',\r\n 'real-estate': 'real-estate.css',\r\n 'real-estate-gold': 'real-estate-gold.css',\r\n 'real-estate-neutral': 'real-estate-neutral.css',\r\n}\r\n\r\nexport async function getThemeCriticalCSS(theme: ThemeDefaults): Promise<string | null> {\r\n try {\r\n const filename = themeCriticalFiles[theme]\r\n if (!filename) {\r\n console.warn(`Critical CSS file not found for theme: ${theme}`)\r\n return null\r\n }\r\n\r\n const filePath = join(process.cwd(), 'public', 'themes', filename)\r\n const css = await readFile(filePath, 'utf-8')\r\n\r\n return css.replace(/\\r\\n/g, '\\n').replace(/\\r/g, '\\n')\r\n } catch (error) {\r\n console.error(`Error reading critical CSS for theme ${theme}:`, error)\r\n return null\r\n }\r\n}\r\n\r\nexport function getThemeCSSPath(theme: ThemeDefaults): string {\r\n const filename = themeFullFiles[theme]\r\n return `/themes/${filename}`\r\n}\r\n\r\nexport function generateThemePreloadLinks(theme: ThemeDefaults): string {\r\n const cssPath = getThemeCSSPath(theme)\r\n return `<link rel=\"preload\" href=\"${cssPath}\" as=\"style\" onload=\"this.onload=null;this.rel='stylesheet'\">`\r\n}\r\n\r\nexport function createFallbackCriticalCSS(theme: ThemeDefaults): string {\r\n return `\r\n/* Fallback critical CSS for ${theme} theme */\r\n[data-theme=\"${theme}\"] {\r\n --background: hsl(0 0% 100%);\r\n --foreground: hsl(222 47% 11%);\r\n --primary: hsl(221 83% 53%);\r\n --primary-foreground: hsl(210 40% 98%);\r\n color-scheme: light;\r\n}\r\n\r\n[data-theme=\"${theme}\"][data-theme-mode=\"dark\"] {\r\n --background: hsl(222 47% 11%);\r\n --foreground: hsl(210 40% 98%);\r\n --primary: hsl(217 91% 60%);\r\n --primary-foreground: hsl(222 47% 11%);\r\n color-scheme: dark;\r\n}\r\n`.trim()\r\n}\r\n"],"names":["readFile","join","themeCriticalFiles","cool","brutal","neon","solar","dealership","themeFullFiles","getThemeCriticalCSS","theme","filename","console","warn","filePath","process","cwd","css","replace","error","getThemeCSSPath","generateThemePreloadLinks","cssPath","createFallbackCriticalCSS","trim"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAa;AACtC,SAASC,IAAI,QAAQ,OAAM;AAG3B,MAAMC,qBAA6C;IACjDC,MAAM;IACNC,QAAQ;IACRC,MAAM;IACNC,OAAO;IACPC,YAAY;IACZ,eAAe;IACf,oBAAoB;IACpB,uBAAuB;AACzB;AAEA,MAAMC,iBAAyC;IAC7CL,MAAM;IACNC,QAAQ;IACRC,MAAM;IACNC,OAAO;IACPC,YAAY;IACZ,eAAe;IACf,oBAAoB;IACpB,uBAAuB;AACzB;AAEA,OAAO,eAAeE,oBAAoBC,KAAoB;IAC5D,IAAI;QACF,MAAMC,WAAWT,kBAAkB,CAACQ,MAAM;QAC1C,IAAI,CAACC,UAAU;YACbC,QAAQC,IAAI,CAAC,CAAC,uCAAuC,EAAEH,OAAO;YAC9D,OAAO;QACT;QAEA,MAAMI,WAAWb,KAAKc,QAAQC,GAAG,IAAI,UAAU,UAAUL;QACzD,MAAMM,MAAM,MAAMjB,SAASc,UAAU;QAErC,OAAOG,IAAIC,OAAO,CAAC,SAAS,MAAMA,OAAO,CAAC,OAAO;IACnD,EAAE,OAAOC,OAAO;QACdP,QAAQO,KAAK,CAAC,CAAC,qCAAqC,EAAET,MAAM,CAAC,CAAC,EAAES;QAChE,OAAO;IACT;AACF;AAEA,OAAO,SAASC,gBAAgBV,KAAoB;IAClD,MAAMC,WAAWH,cAAc,CAACE,MAAM;IACtC,OAAO,CAAC,QAAQ,EAAEC,UAAU;AAC9B;AAEA,OAAO,SAASU,0BAA0BX,KAAoB;IAC5D,MAAMY,UAAUF,gBAAgBV;IAChC,OAAO,CAAC,0BAA0B,EAAEY,QAAQ,6DAA6D,CAAC;AAC5G;AAEA,OAAO,SAASC,0BAA0Bb,KAAoB;IAC5D,OAAO,CAAC;6BACmB,EAAEA,MAAM;aACxB,EAAEA,MAAM;;;;;;;;aAQR,EAAEA,MAAM;;;;;;;AAOrB,CAAC,CAACc,IAAI;AACN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/themeColors.ts"],"sourcesContent":["interface ColorMode {\n background?: string | null\n foreground?: string | null\n card?: string | null\n cardForeground?: string | null\n popover?: string | null\n popoverForeground?: string | null\n primary?: string | null\n primaryForeground?: string | null\n secondary?: string | null\n secondaryForeground?: string | null\n muted?: string | null\n mutedForeground?: string | null\n accent?: string | null\n accentForeground?: string | null\n destructive?: string | null\n destructiveForeground?: string | null\n border?: string | null\n input?: string | null\n ring?: string | null\n}\n\nexport interface ThemeColors {\n lightMode?: ColorMode\n darkMode?: ColorMode\n}\n\ninterface GenerateThemeColorsOptions extends ThemeColors {\n themeName?: string\n}\n\nconst COLOR_VARIABLE_MAP: Array<{ key: keyof ColorMode; variable: string }> = [\n { key: 'background', variable: '--background' },\n { key: 'foreground', variable: '--foreground' },\n { key: 'card', variable: '--card' },\n { key: 'cardForeground', variable: '--card-foreground' },\n { key: 'popover', variable: '--popover' },\n { key: 'popoverForeground', variable: '--popover-foreground' },\n { key: 'primary', variable: '--primary' },\n { key: 'primaryForeground', variable: '--primary-foreground' },\n { key: 'secondary', variable: '--secondary' },\n { key: 'secondaryForeground', variable: '--secondary-foreground' },\n { key: 'muted', variable: '--muted' },\n { key: 'mutedForeground', variable: '--muted-foreground' },\n { key: 'accent', variable: '--accent' },\n { key: 'accentForeground', variable: '--accent-foreground' },\n { key: 'destructive', variable: '--destructive' },\n { key: 'destructiveForeground', variable: '--destructive-foreground' },\n { key: 'border', variable: '--border' },\n { key: 'input', variable: '--input' },\n { key: 'ring', variable: '--ring' },\n]\n\nexport function hexToHsl(hex: string): string {\n if (!hex) return '0 0% 0%'\n\n hex = hex.replace('#', '')\n\n if (hex.length === 3) {\n hex = hex\n .split('')\n .map((char) => char + char)\n .join('')\n }\n\n const r = Number.parseInt(hex.substring(0, 2), 16) / 255\n const g = Number.parseInt(hex.substring(2, 4), 16) / 255\n const b = Number.parseInt(hex.substring(4, 6), 16) / 255\n\n const max = Math.max(r, g, b)\n const min = Math.min(r, g, b)\n let h = 0\n let s = 0\n const l = (max + min) / 2\n\n if (max !== min) {\n const d = max - min\n s = l > 0.5 ? d / (2 - max - min) : d / (max + min)\n\n switch (max) {\n case r:\n h = ((g - b) / d + (g < b ? 6 : 0)) / 6\n break\n case g:\n h = ((b - r) / d + 2) / 6\n break\n case b:\n h = ((r - g) / d + 4) / 6\n break\n }\n }\n\n h = Math.round(h * 360)\n s = Math.round(s * 100)\n const lRounded = Math.round(l * 100)\n\n return `${h} ${s}% ${lRounded}%`\n}\n\nexport function generateColorModeCss(\n colors: ColorMode,\n options: { themeName?: string; isDark?: boolean } = {},\n): string {\n if (!colors) return ''\n\n const { themeName, isDark = false } = options\n\n const cssVariables = COLOR_VARIABLE_MAP.reduce<string[]>((acc, { key, variable }) => {\n const value = normalizeColor(colors[key])\n if (!value) return acc\n acc.push(`${variable}: hsl(${hexToHsl(value)});`)\n return acc\n }, [])\n\n if (cssVariables.length === 0) return ''\n\n const selector = buildSelector(themeName, isDark)\n return `${selector} {\n ${cssVariables.join('\\n ')}\n}`\n}\n\nexport function generateThemeColorsCss(options: GenerateThemeColorsOptions): string {\n const cssBlocks: string[] = []\n const { themeName, lightMode, darkMode } = options\n\n if (lightMode) {\n const lightModeCss = generateColorModeCss(lightMode, { themeName, isDark: false })\n if (lightModeCss) cssBlocks.push(lightModeCss)\n }\n\n if (darkMode) {\n const darkModeCss = generateColorModeCss(darkMode, { themeName, isDark: true })\n if (darkModeCss) cssBlocks.push(darkModeCss)\n }\n\n return cssBlocks.join('\\n\\n')\n}\n\nfunction buildSelector(themeName: string | undefined, isDark: boolean): string {\n if (themeName) {\n if (isDark) {\n return `:root[data-theme='${themeName}'][data-theme-mode='dark'], .dark[data-theme='${themeName}']`\n }\n return `:root[data-theme='${themeName}']`\n }\n\n if (isDark) {\n return \":root[data-theme-mode='dark'], .dark\"\n }\n\n return ':root'\n}\n\nfunction normalizeColor(value: string | null | undefined): string | null {\n if (typeof value !== 'string') return null\n const trimmed = value.trim()\n return trimmed.length === 0 ? null : trimmed\n}\n"],"names":["COLOR_VARIABLE_MAP","key","variable","hexToHsl","hex","replace","length","split","map","char","join","r","Number","parseInt","substring","g","b","max","Math","min","h","s","l","d","round","lRounded","generateColorModeCss","colors","options","themeName","isDark","cssVariables","reduce","acc","value","normalizeColor","push","selector","buildSelector","generateThemeColorsCss","cssBlocks","lightMode","darkMode","lightModeCss","darkModeCss","trimmed","trim"],"mappings":"AA+BA,MAAMA,qBAAwE;IAC5E;QAAEC,KAAK;QAAcC,UAAU;IAAe;IAC9C;QAAED,KAAK;QAAcC,UAAU;IAAe;IAC9C;QAAED,KAAK;QAAQC,UAAU;IAAS;IAClC;QAAED,KAAK;QAAkBC,UAAU;IAAoB;IACvD;QAAED,KAAK;QAAWC,UAAU;IAAY;IACxC;QAAED,KAAK;QAAqBC,UAAU;IAAuB;IAC7D;QAAED,KAAK;QAAWC,UAAU;IAAY;IACxC;QAAED,KAAK;QAAqBC,UAAU;IAAuB;IAC7D;QAAED,KAAK;QAAaC,UAAU;IAAc;IAC5C;QAAED,KAAK;QAAuBC,UAAU;IAAyB;IACjE;QAAED,KAAK;QAASC,UAAU;IAAU;IACpC;QAAED,KAAK;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WC,QAAQ;QAAM;QAChF,IAAIa,cAAcH,UAAUJ,IAAI,CAACO;IACnC;IAEA,IAAID,UAAU;QACZ,MAAME,cAAclB,qBAAqBgB,UAAU;YAAEb;YAAWC,QAAQ;QAAK;QAC7E,IAAIc,aAAaJ,UAAUJ,IAAI,CAACQ;IAClC;IAEA,OAAOJ,UAAU9B,IAAI,CAAC;AACxB;AAEA,SAAS4B,cAAcT,SAA6B,EAAEC,MAAe;IACnE,IAAID,WAAW;QACb,IAAIC,QAAQ;YACV,OAAO,CAAC,kBAAkB,EAAED,UAAU,8CAA8C,EAAEA,UAAU,EAAE,CAAC;QACrG;QACA,OAAO,CAAC,kBAAkB,EAAEA,UAAU,EAAE,CAAC;IAC3C;IAEA,IAAIC,QAAQ;QACV,OAAO;IACT;IAEA,OAAO;AACT;AAEA,SAASK,eAAeD,KAAgC;IACtD,IAAI,OAAOA,UAAU,UAAU,OAAO;IACtC,MAAMW,UAAUX,MAAMY,IAAI;IAC1B,OAAOD,QAAQvC,MAAM,KAAK,IAAI,OAAOuC;AACvC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/themeColors.ts"],"sourcesContent":["interface ColorMode {\r\n background?: string | null\r\n foreground?: string | null\r\n card?: string | null\r\n cardForeground?: string | null\r\n popover?: string | null\r\n popoverForeground?: string | null\r\n primary?: string | null\r\n primaryForeground?: string | null\r\n secondary?: string | null\r\n secondaryForeground?: string | null\r\n muted?: string | null\r\n mutedForeground?: string | null\r\n accent?: string | null\r\n accentForeground?: string | null\r\n destructive?: string | null\r\n destructiveForeground?: string | null\r\n border?: string | null\r\n input?: string | null\r\n ring?: string | null\r\n}\r\n\r\nexport interface ThemeColors {\r\n lightMode?: ColorMode\r\n darkMode?: ColorMode\r\n}\r\n\r\ninterface GenerateThemeColorsOptions extends ThemeColors {\r\n themeName?: string\r\n}\r\n\r\nconst COLOR_VARIABLE_MAP: Array<{ key: keyof ColorMode; variable: string }> = [\r\n { key: 'background', variable: '--background' },\r\n { key: 'foreground', variable: '--foreground' },\r\n { key: 'card', variable: '--card' },\r\n { key: 'cardForeground', variable: '--card-foreground' },\r\n { key: 'popover', variable: '--popover' },\r\n { key: 'popoverForeground', variable: '--popover-foreground' },\r\n { key: 'primary', variable: '--primary' },\r\n { key: 'primaryForeground', variable: '--primary-foreground' },\r\n { key: 'secondary', variable: '--secondary' },\r\n { key: 'secondaryForeground', variable: '--secondary-foreground' },\r\n { key: 'muted', variable: '--muted' },\r\n { key: 'mutedForeground', variable: '--muted-foreground' },\r\n { key: 'accent', variable: '--accent' },\r\n { key: 'accentForeground', variable: '--accent-foreground' },\r\n { key: 'destructive', variable: '--destructive' },\r\n { key: 'destructiveForeground', variable: '--destructive-foreground' },\r\n { key: 'border', variable: '--border' },\r\n { key: 'input', variable: '--input' },\r\n { key: 'ring', variable: '--ring' },\r\n]\r\n\r\nexport function hexToHsl(hex: string): string {\r\n if (!hex) return '0 0% 0%'\r\n\r\n hex = hex.replace('#', '')\r\n\r\n if (hex.length === 3) {\r\n hex = hex\r\n .split('')\r\n .map((char) => char + char)\r\n .join('')\r\n }\r\n\r\n const r = Number.parseInt(hex.substring(0, 2), 16) / 255\r\n const g = Number.parseInt(hex.substring(2, 4), 16) / 255\r\n const b = Number.parseInt(hex.substring(4, 6), 16) / 255\r\n\r\n const max = Math.max(r, g, b)\r\n const min = Math.min(r, g, b)\r\n let h = 0\r\n let s = 0\r\n const l = (max + min) / 2\r\n\r\n if (max !== min) {\r\n const d = max - min\r\n s = l > 0.5 ? d / (2 - max - min) : d / (max + min)\r\n\r\n switch (max) {\r\n case r:\r\n h = ((g - b) / d + (g < b ? 6 : 0)) / 6\r\n break\r\n case g:\r\n h = ((b - r) / d + 2) / 6\r\n break\r\n case b:\r\n h = ((r - g) / d + 4) / 6\r\n break\r\n }\r\n }\r\n\r\n h = Math.round(h * 360)\r\n s = Math.round(s * 100)\r\n const lRounded = Math.round(l * 100)\r\n\r\n return `${h} ${s}% ${lRounded}%`\r\n}\r\n\r\nexport function generateColorModeCss(\r\n colors: ColorMode,\r\n options: { themeName?: string; isDark?: boolean } = {},\r\n): string {\r\n if (!colors) return ''\r\n\r\n const { themeName, isDark = false } = options\r\n\r\n const cssVariables = COLOR_VARIABLE_MAP.reduce<string[]>((acc, { key, variable }) => {\r\n const value = normalizeColor(colors[key])\r\n if (!value) return acc\r\n acc.push(`${variable}: hsl(${hexToHsl(value)});`)\r\n return acc\r\n }, [])\r\n\r\n if (cssVariables.length === 0) return ''\r\n\r\n const selector = buildSelector(themeName, isDark)\r\n return `${selector} {\r\n ${cssVariables.join('\\n ')}\r\n}`\r\n}\r\n\r\nexport function generateThemeColorsCss(options: GenerateThemeColorsOptions): string {\r\n const cssBlocks: string[] = []\r\n const { themeName, lightMode, darkMode } = options\r\n\r\n if (lightMode) {\r\n const lightModeCss = generateColorModeCss(lightMode, { themeName, isDark: false })\r\n if (lightModeCss) cssBlocks.push(lightModeCss)\r\n }\r\n\r\n if (darkMode) {\r\n const darkModeCss = generateColorModeCss(darkMode, { themeName, isDark: true })\r\n if (darkModeCss) cssBlocks.push(darkModeCss)\r\n }\r\n\r\n return cssBlocks.join('\\n\\n')\r\n}\r\n\r\nfunction buildSelector(themeName: string | undefined, isDark: boolean): string {\r\n if (themeName) {\r\n if (isDark) {\r\n return `:root[data-theme='${themeName}'][data-theme-mode='dark'], .dark[data-theme='${themeName}']`\r\n }\r\n return `:root[data-theme='${themeName}']`\r\n }\r\n\r\n if (isDark) {\r\n return \":root[data-theme-mode='dark'], .dark\"\r\n }\r\n\r\n return ':root'\r\n}\r\n\r\nfunction normalizeColor(value: string | null | undefined): string | null {\r\n if (typeof value !== 'string') return null\r\n const trimmed = value.trim()\r\n return trimmed.length === 0 ? null : trimmed\r\n}\r\n"],"names":["COLOR_VARIABLE_MAP","key","variable","hexToHsl","hex","replace","length","split","map","char","join","r","Number","parseInt","substring","g","b","max","Math","min","h","s","l","d","round","lRounded","generateColorModeCss","colors","options","themeName","isDark","cssVariables","reduce","acc","value","normalizeColor","push","selector","buildSelector","generateThemeColorsCss","cssBlocks","lightMode","darkMode","lightModeCss","darkModeCss","trimmed","trim"],"mappings":"AA+BA,MAAMA,qBAAwE;IAC5E;QAAEC,KAAK;QAAcC,UAAU;IAAe;IAC9C;QAAED,KAAK;QAAcC,UAAU;IAAe;IAC9C;QAAED,KAAK;QAAQC,UAAU;IAAS;IAClC;QAAED,KAAK;QAAkBC,UAAU;IAAoB;IACvD;QAAED,KAAK;QAAWC,UAAU;IAAY;IACxC;QAAED,KAAK;QAAqBC,UAAU;IAAuB;IAC7D;QAAED,KAAK;QAAWC,UAAU;IAAY;IACxC;QAAED,KAAK;QAAqBC,UAAU;IAAuB;IAC7D;QAAED,KAAK;QAAaC,UAAU;IAAc;IAC5C;QAAED,KAAK;QAAuBC,UAAU;IAAyB;IACjE;QAAED,KAAK;QAASC,UAAU;IAAU;IACpC;QAAED,KAAK;QAAmBC,UAAU;IAAqB;IACzD;QAAED,KAAK;QAAUC,UAAU;IAAW;IACtC;QAAED,KAAK;QAAoBC,UAAU;IAAsB;IAC3D;QAAED,KAAK;QAAeC,UAAU;IAAgB;IAChD;QAAED,KAAK;QAAyBC,UAAU;IAA2B;IACrE;QAAED,KAAK;QAAUC,UAAU;IAAW;IACtC;QAAED,KAAK;QAASC,UAAU;IAAU;IACpC;QAAED,KAAK;QAAQC,UAAU;IAAS;CACnC;AAED,OAAO,SAASC,SAASC,GAAW;IAClC,IAAI,CAACA,KAAK,OAAO;IAEjBA,MAAMA,IAAIC,OAAO,CAAC,KAAK;IAEvB,IAAID,IAAIE,MAAM,KAAK,GAAG;QACpBF,MAAMA,IACHG,KAAK,CAAC,IACNC,GAAG,CAAC,CAACC,OAASA,OAAOA,MACrBC,IAAI,CAAC;IACV;IAEA,MAAMC,IAAIC,OAAOC,QAAQ,CAACT,IAAIU,SAAS,CAAC,GAAG,IAAI,MAAM;IACrD,MAAMC,IAAIH,OAAOC,QAAQ,CAACT,IAAIU,SAAS,CAAC,GAAG,IAAI,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25 @@
|
|
|
1
|
+
import type { ResolvedThemeConfiguration } from './resolveThemeConfiguration.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generates HTML attributes for the <html> element based on theme configuration
|
|
4
|
+
* This ensures the theme is applied before React hydration to prevent FOUC
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const siteSettings = await payload.findGlobal({ slug: 'site-settings' })
|
|
9
|
+
* const themeConfig = resolveThemeConfiguration(siteSettings?.themeConfiguration)
|
|
10
|
+
* const htmlAttrs = getThemeHtmlAttributes(themeConfig)
|
|
11
|
+
*
|
|
12
|
+
* <html {...htmlAttrs} className={yourClassName}>
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function getThemeHtmlAttributes(config: ResolvedThemeConfiguration): {
|
|
16
|
+
'data-theme': string;
|
|
17
|
+
'data-theme-mode': string;
|
|
18
|
+
'data-border-radius': string;
|
|
19
|
+
'data-font-scale': string;
|
|
20
|
+
'data-spacing': string;
|
|
21
|
+
'data-animation-level': string;
|
|
22
|
+
'data-allow-color-mode-toggle': string;
|
|
23
|
+
suppressHydrationWarning: true;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=themeHtmlAttributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themeHtmlAttributes.d.ts","sourceRoot":"","sources":["../../src/utils/themeHtmlAttributes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAA;AAEhF;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,0BAA0B,GAAG;IAC1E,YAAY,EAAE,MAAM,CAAA;IACpB,iBAAiB,EAAE,MAAM,CAAA;IACzB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,iBAAiB,EAAE,MAAM,CAAA;IACzB,cAAc,EAAE,MAAM,CAAA;IACtB,sBAAsB,EAAE,MAAM,CAAA;IAC9B,8BAA8B,EAAE,MAAM,CAAA;IACtC,wBAAwB,EAAE,IAAI,CAAA;CAC/B,CAWA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates HTML attributes for the <html> element based on theme configuration
|
|
3
|
+
* This ensures the theme is applied before React hydration to prevent FOUC
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* const siteSettings = await payload.findGlobal({ slug: 'site-settings' })
|
|
8
|
+
* const themeConfig = resolveThemeConfiguration(siteSettings?.themeConfiguration)
|
|
9
|
+
* const htmlAttrs = getThemeHtmlAttributes(themeConfig)
|
|
10
|
+
*
|
|
11
|
+
* <html {...htmlAttrs} className={yourClassName}>
|
|
12
|
+
* ```
|
|
13
|
+
*/ export function getThemeHtmlAttributes(config) {
|
|
14
|
+
return {
|
|
15
|
+
'data-theme': config.theme,
|
|
16
|
+
'data-theme-mode': config.colorMode,
|
|
17
|
+
'data-border-radius': config.borderRadius,
|
|
18
|
+
'data-font-scale': config.fontScale,
|
|
19
|
+
'data-spacing': config.spacing,
|
|
20
|
+
'data-animation-level': config.animationLevel,
|
|
21
|
+
'data-allow-color-mode-toggle': config.allowColorModeToggle ? 'true' : 'false',
|
|
22
|
+
suppressHydrationWarning: true
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=themeHtmlAttributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/themeHtmlAttributes.ts"],"sourcesContent":["import type { ResolvedThemeConfiguration } from './resolveThemeConfiguration.js'\r\n\r\n/**\r\n * Generates HTML attributes for the <html> element based on theme configuration\r\n * This ensures the theme is applied before React hydration to prevent FOUC\r\n * \r\n * @example\r\n * ```tsx\r\n * const siteSettings = await payload.findGlobal({ slug: 'site-settings' })\r\n * const themeConfig = resolveThemeConfiguration(siteSettings?.themeConfiguration)\r\n * const htmlAttrs = getThemeHtmlAttributes(themeConfig)\r\n * \r\n * <html {...htmlAttrs} className={yourClassName}>\r\n * ```\r\n */\r\nexport function getThemeHtmlAttributes(config: ResolvedThemeConfiguration): {\r\n 'data-theme': string\r\n 'data-theme-mode': string\r\n 'data-border-radius': string\r\n 'data-font-scale': string\r\n 'data-spacing': string\r\n 'data-animation-level': string\r\n 'data-allow-color-mode-toggle': string\r\n suppressHydrationWarning: true\r\n} {\r\n return {\r\n 'data-theme': config.theme,\r\n 'data-theme-mode': config.colorMode,\r\n 'data-border-radius': config.borderRadius,\r\n 'data-font-scale': config.fontScale,\r\n 'data-spacing': config.spacing,\r\n 'data-animation-level': config.animationLevel,\r\n 'data-allow-color-mode-toggle': config.allowColorModeToggle ? 'true' : 'false',\r\n suppressHydrationWarning: true,\r\n }\r\n}\r\n"],"names":["getThemeHtmlAttributes","config","theme","colorMode","borderRadius","fontScale","spacing","animationLevel","allowColorModeToggle","suppressHydrationWarning"],"mappings":"AAEA;;;;;;;;;;;;CAYC,GACD,OAAO,SAASA,uBAAuBC,MAAkC;IAUvE,OAAO;QACL,cAAcA,OAAOC,KAAK;QAC1B,mBAAmBD,OAAOE,SAAS;QACnC,sBAAsBF,OAAOG,YAAY;QACzC,mBAAmBH,OAAOI,SAAS;QACnC,gBAAgBJ,OAAOK,OAAO;QAC9B,wBAAwBL,OAAOM,cAAc;QAC7C,gCAAgCN,OAAOO,oBAAoB,GAAG,SAAS;QACvEC,0BAA0B;IAC5B;AACF"}
|
package/dist/utils/themeUtils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { borderRadiusPresets } from '../providers/Theme/themeConfig.js';
|
|
2
|
-
/**
|
|
3
|
-
* Generates CSS custom properties from theme configuration
|
|
2
|
+
/**
|
|
3
|
+
* Generates CSS custom properties from theme configuration
|
|
4
4
|
*/ export function generateThemeCSS(config) {
|
|
5
5
|
const cssRules = [];
|
|
6
6
|
const customization = config.customization;
|
|
@@ -22,8 +22,8 @@ import { borderRadiusPresets } from '../providers/Theme/themeConfig.js';
|
|
|
22
22
|
appendCustomCSS(cssRules, customization);
|
|
23
23
|
return cssRules.join('\n');
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Determines if a color is light or dark
|
|
25
|
+
/**
|
|
26
|
+
* Determines if a color is light or dark
|
|
27
27
|
*/ function isLightBackground(color) {
|
|
28
28
|
// Simple heuristic: if it contains 'white', '#fff', or high RGB values, it's light
|
|
29
29
|
const lightPatterns = [
|
|
@@ -34,8 +34,8 @@ import { borderRadiusPresets } from '../providers/Theme/themeConfig.js';
|
|
|
34
34
|
];
|
|
35
35
|
return lightPatterns.some((pattern)=>pattern.test(color));
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Generate theme styles for use in components
|
|
37
|
+
/**
|
|
38
|
+
* Generate theme styles for use in components
|
|
39
39
|
*/ export function getThemeStyles(config) {
|
|
40
40
|
const styles = {};
|
|
41
41
|
const customization = config.customization;
|