@kilivi/payloadcms-theme-management 0.1.12 → 0.1.15
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 +2 -0
- package/dist/components/ServerThemeInjector.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/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/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/package.json +1 -1
package/README.md
CHANGED
|
@@ -292,6 +292,20 @@ See [TEST_APP_GUIDE.md](./TEST_APP_GUIDE.md) for instructions on creating a test
|
|
|
292
292
|
|
|
293
293
|
## Troubleshooting
|
|
294
294
|
|
|
295
|
+
### Type Conflicts: `Type 'SiteSetting' is not assignable to type 'SiteSetting'`
|
|
296
|
+
|
|
297
|
+
**Problem:** You see errors about incompatible types even though you're passing the correct data structure.
|
|
298
|
+
|
|
299
|
+
**Why This Happens:** Your app's generated `payload-types.ts` might have slightly different type definitions than the plugin's (e.g., different font options, field variations).
|
|
300
|
+
|
|
301
|
+
**Solution:** Update to v0.1.11+ which uses generic types instead of strict payload-types:
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
pnpm update @kilivi/payloadcms-theme-management@latest
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
The plugin now accepts any compatible theme configuration structure, regardless of your Payload version or type variations. See [TYPE_INDEPENDENCE_GUIDE.md](./TYPE_INDEPENDENCE_GUIDE.md) for technical details.
|
|
308
|
+
|
|
295
309
|
### `Module not found: Can't resolve 'fs/promises'`
|
|
296
310
|
|
|
297
311
|
**Solution:** Make sure you're using v0.1.9+ and importing server components from `/server`:
|
|
@@ -325,6 +339,7 @@ pnpm payload generate:types
|
|
|
325
339
|
|
|
326
340
|
## Documentation
|
|
327
341
|
|
|
342
|
+
- [Type Independence Guide](./TYPE_INDEPENDENCE_GUIDE.md) - Understanding type safety without coupling
|
|
328
343
|
- [Migration Guide](./MIGRATION_GUIDE.md) - Upgrading from older versions
|
|
329
344
|
- [Test App Guide](./TEST_APP_GUIDE.md) - Create a test application
|
|
330
345
|
- [Server/Client Separation](./SERVER_CLIENT_SEPARATION.md) - Technical details
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Client-side theme initialization script
|
|
4
|
+
* Prevents FOUC by applying theme mode before React hydration
|
|
5
|
+
* Handles:
|
|
6
|
+
* - System preference detection
|
|
7
|
+
* - User preference from localStorage
|
|
8
|
+
* - Admin-controlled color mode toggle
|
|
9
|
+
* - Auto mode with system preference fallback
|
|
10
|
+
*/
|
|
11
|
+
export declare const InitTheme: React.FC;
|
|
12
|
+
//# sourceMappingURL=InitTheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InitTheme.d.ts","sourceRoot":"","sources":["../../src/components/InitTheme.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EA2D7B,CAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import Script from 'next/script';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { modeLocalStorageKey } from '../providers/Theme/shared.js';
|
|
5
|
+
/**
|
|
6
|
+
* Client-side theme initialization script
|
|
7
|
+
* Prevents FOUC by applying theme mode before React hydration
|
|
8
|
+
* Handles:
|
|
9
|
+
* - System preference detection
|
|
10
|
+
* - User preference from localStorage
|
|
11
|
+
* - Admin-controlled color mode toggle
|
|
12
|
+
* - Auto mode with system preference fallback
|
|
13
|
+
*/ export const InitTheme = ()=>{
|
|
14
|
+
return /*#__PURE__*/ _jsx(Script, {
|
|
15
|
+
dangerouslySetInnerHTML: {
|
|
16
|
+
__html: `
|
|
17
|
+
(function () {
|
|
18
|
+
function getImplicitModePreference() {
|
|
19
|
+
var mediaQuery = '(prefers-color-scheme: dark)'
|
|
20
|
+
var mql = window.matchMedia(mediaQuery)
|
|
21
|
+
return mql.matches ? 'dark' : 'light'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function modeIsValid(mode) {
|
|
25
|
+
return mode === 'light' || mode === 'dark'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Get current mode from server-set attribute
|
|
29
|
+
var currentMode = document.documentElement.getAttribute('data-theme-mode')
|
|
30
|
+
var allowToggle = document.documentElement.getAttribute('data-allow-color-mode-toggle') === 'true'
|
|
31
|
+
|
|
32
|
+
// Only override mode if admin allows toggle and user has preference
|
|
33
|
+
if (allowToggle) {
|
|
34
|
+
var modePreference = window.localStorage.getItem('${modeLocalStorageKey}')
|
|
35
|
+
|
|
36
|
+
if (modeIsValid(modePreference)) {
|
|
37
|
+
currentMode = modePreference
|
|
38
|
+
} else if (currentMode === 'auto') {
|
|
39
|
+
currentMode = getImplicitModePreference()
|
|
40
|
+
}
|
|
41
|
+
} else if (currentMode === 'auto') {
|
|
42
|
+
// Admin set auto mode - use system preference
|
|
43
|
+
currentMode = getImplicitModePreference()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Apply the determined mode
|
|
47
|
+
if (currentMode && modeIsValid(currentMode)) {
|
|
48
|
+
document.documentElement.setAttribute('data-theme-mode', currentMode)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Listen for system theme changes only when needed
|
|
52
|
+
if (allowToggle || currentMode === 'auto') {
|
|
53
|
+
var mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
|
|
54
|
+
mediaQuery.addEventListener('change', function(e) {
|
|
55
|
+
var shouldUpdate = allowToggle
|
|
56
|
+
? !window.localStorage.getItem('${modeLocalStorageKey}')
|
|
57
|
+
: document.documentElement.getAttribute('data-theme-mode') === 'auto'
|
|
58
|
+
|
|
59
|
+
if (shouldUpdate) {
|
|
60
|
+
document.documentElement.setAttribute('data-theme-mode', e.matches ? 'dark' : 'light')
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
})();
|
|
65
|
+
`
|
|
66
|
+
},
|
|
67
|
+
id: "theme-script",
|
|
68
|
+
strategy: "beforeInteractive"
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=InitTheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/InitTheme.tsx"],"sourcesContent":["import Script from 'next/script'\nimport React from 'react'\nimport { modeLocalStorageKey } from '../providers/Theme/shared.js'\n\n/**\n * Client-side theme initialization script\n * Prevents FOUC by applying theme mode before React hydration\n * Handles:\n * - System preference detection\n * - User preference from localStorage\n * - Admin-controlled color mode toggle\n * - Auto mode with system preference fallback\n */\nexport const InitTheme: React.FC = () => {\n return (\n <Script\n dangerouslySetInnerHTML={{\n __html: `\n (function () {\n function getImplicitModePreference() {\n var mediaQuery = '(prefers-color-scheme: dark)'\n var mql = window.matchMedia(mediaQuery)\n return mql.matches ? 'dark' : 'light'\n }\n\n function modeIsValid(mode) {\n return mode === 'light' || mode === 'dark'\n }\n\n // Get current mode from server-set attribute\n var currentMode = document.documentElement.getAttribute('data-theme-mode')\n var allowToggle = document.documentElement.getAttribute('data-allow-color-mode-toggle') === 'true'\n \n // Only override mode if admin allows toggle and user has preference\n if (allowToggle) {\n var modePreference = window.localStorage.getItem('${modeLocalStorageKey}')\n \n if (modeIsValid(modePreference)) {\n currentMode = modePreference\n } else if (currentMode === 'auto') {\n currentMode = getImplicitModePreference()\n }\n } else if (currentMode === 'auto') {\n // Admin set auto mode - use system preference\n currentMode = getImplicitModePreference()\n }\n\n // Apply the determined mode\n if (currentMode && modeIsValid(currentMode)) {\n document.documentElement.setAttribute('data-theme-mode', currentMode)\n }\n\n // Listen for system theme changes only when needed\n if (allowToggle || currentMode === 'auto') {\n var mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')\n mediaQuery.addEventListener('change', function(e) {\n var shouldUpdate = allowToggle \n ? !window.localStorage.getItem('${modeLocalStorageKey}')\n : document.documentElement.getAttribute('data-theme-mode') === 'auto'\n \n if (shouldUpdate) {\n document.documentElement.setAttribute('data-theme-mode', e.matches ? 'dark' : 'light')\n }\n })\n }\n })();\n `,\n }}\n id=\"theme-script\"\n strategy=\"beforeInteractive\"\n />\n )\n}\n"],"names":["Script","React","modeLocalStorageKey","InitTheme","dangerouslySetInnerHTML","__html","id","strategy"],"mappings":";AAAA,OAAOA,YAAY,cAAa;AAChC,OAAOC,WAAW,QAAO;AACzB,SAASC,mBAAmB,QAAQ,+BAA8B;AAElE;;;;;;;;CAQC,GACD,OAAO,MAAMC,YAAsB;IACjC,qBACE,KAACH;QACCI,yBAAyB;YACvBC,QAAQ,CAAC;;;;;;;;;;;;;;;;;;wDAkBuC,EAAEH,oBAAoB;;;;;;;;;;;;;;;;;;;;;;0CAsBpC,EAAEA,oBAAoB;;;;;;;;;EAS9D,CAAC;QACG;QACAI,IAAG;QACHC,UAAS;;AAGf,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServerThemeInjector.d.ts","sourceRoot":"","sources":["../../src/components/ServerThemeInjector.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ServerThemeInjector.d.ts","sourceRoot":"","sources":["../../src/components/ServerThemeInjector.tsx"],"names":[],"mappings":"AAcA,UAAU,wBAAwB;IAChC;;;;;;;;;OASG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B;AAMD;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,EAAE,kBAAkB,EAAE,EAAE,QAAQ,CAAC,wBAAwB,CAAC,wCAwFnG"}
|
|
@@ -4,6 +4,7 @@ import { resolveThemeConfiguration } from '../utils/resolveThemeConfiguration.js
|
|
|
4
4
|
import { createFallbackCriticalCSS, getThemeCriticalCSS, getThemeCSSPath } from '../utils/themeAssets.js';
|
|
5
5
|
import { generateThemeColorsCss } from '../utils/themeColors.js';
|
|
6
6
|
import { generateThemeCSS } from '../utils/themeUtils.js';
|
|
7
|
+
import { InitTheme } from './InitTheme.js';
|
|
7
8
|
/**
|
|
8
9
|
* Server-side theme CSS injector to prevent FOUC
|
|
9
10
|
* This component injects critical theme CSS directly into the HTML head during SSR
|
|
@@ -62,6 +63,7 @@ ${borderRadiusCSS}
|
|
|
62
63
|
const themeCSSPath = getThemeCSSPath(theme);
|
|
63
64
|
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
64
65
|
children: [
|
|
66
|
+
/*#__PURE__*/ _jsx(InitTheme, {}),
|
|
65
67
|
/*#__PURE__*/ _jsx("style", {
|
|
66
68
|
id: "theme-critical-css",
|
|
67
69
|
dangerouslySetInnerHTML: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/ServerThemeInjector.tsx"],"sourcesContent":["import { 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 type { ResolvedThemeConfiguration } 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 /**\n * Theme configuration object from your site settings.\n * Pass the themeConfiguration field directly, not the entire site settings object.\n * \n * @example\n * ```tsx\n * const siteSettings = await payload.findGlobal({ slug: 'site-settings' })\n * <ServerThemeInjector themeConfiguration={siteSettings.themeConfiguration} />\n * ```\n */\n themeConfiguration?: unknown\n}\n\ntype RuntimeThemeConfiguration = Omit<ResolvedThemeConfiguration, '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({ themeConfiguration }: Readonly<ServerThemeInjectorProps>) {\n // Accept unknown type to avoid type conflicts between app's payload-types and plugin's payload-types\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const resolvedConfiguration = resolveThemeConfiguration(themeConfiguration as any)\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 // Use resolved configuration directly\n const normalizedThemeConfiguration: RuntimeThemeConfiguration = {\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","themeConfiguration","resolvedConfiguration","theme","borderRadius","customCSS","lightMode","darkMode","fontScale","spacing","animationLevel","allowColorModeToggle","colorMode","typography","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":";AAAA,SAASA,qBAAqB,QAAQ,oCAAmC;AAGzE,SAASC,yBAAyB,QAAQ,wCAAuC;AAEjF,SACEC,yBAAyB,EACzBC,mBAAmB,EACnBC,eAAe,QACV,0BAAyB;AAChC,SAASC,sBAAsB,QAAQ,0BAAyB;AAChE,SAASC,gBAAgB,QAAQ,yBAAwB;
|
|
1
|
+
{"version":3,"sources":["../../src/components/ServerThemeInjector.tsx"],"sourcesContent":["import { 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 type { ResolvedThemeConfiguration } 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'\nimport { InitTheme } from './InitTheme.js'\n\ninterface ServerThemeInjectorProps {\n /**\n * Theme configuration object from your site settings.\n * Pass the themeConfiguration field directly, not the entire site settings object.\n * \n * @example\n * ```tsx\n * const siteSettings = await payload.findGlobal({ slug: 'site-settings' })\n * <ServerThemeInjector themeConfiguration={siteSettings.themeConfiguration} />\n * ```\n */\n themeConfiguration?: unknown\n}\n\ntype RuntimeThemeConfiguration = Omit<ResolvedThemeConfiguration, '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({ themeConfiguration }: Readonly<ServerThemeInjectorProps>) {\n // Accept unknown type to avoid type conflicts between app's payload-types and plugin's payload-types\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const resolvedConfiguration = resolveThemeConfiguration(themeConfiguration as any)\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 // Use resolved configuration directly\n const normalizedThemeConfiguration: RuntimeThemeConfiguration = {\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 <InitTheme />\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","InitTheme","ServerThemeInjector","themeConfiguration","resolvedConfiguration","theme","borderRadius","customCSS","lightMode","darkMode","fontScale","spacing","animationLevel","allowColorModeToggle","colorMode","typography","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":";AAAA,SAASA,qBAAqB,QAAQ,oCAAmC;AAGzE,SAASC,yBAAyB,QAAQ,wCAAuC;AAEjF,SACEC,yBAAyB,EACzBC,mBAAmB,EACnBC,eAAe,QACV,0BAAyB;AAChC,SAASC,sBAAsB,QAAQ,0BAAyB;AAChE,SAASC,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,SAAS,QAAQ,iBAAgB;AAoB1C;;;CAGC,GACD,OAAO,eAAeC,oBAAoB,EAAEC,kBAAkB,EAAsC;IAClG,qGAAqG;IACrG,8DAA8D;IAC9D,MAAMC,wBAAwBT,0BAA0BQ;IACxD,MAAM,EACJE,KAAK,EACLC,YAAY,EACZC,SAAS,EACTC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,OAAO,EACPC,cAAc,EACdC,oBAAoB,EACpBC,SAAS,EACTC,UAAU,EACX,GAAGX;IAEJ,sCAAsC;IACtC,MAAMY,+BAA0D;QAC9DX;QACAS;QACAD;QACAP;QACAI;QACAC;QACAC;QACAL,WAAWA,aAAaU;QACxBT;QACAC;QACAM,YAAYA,cAAcE;IAC5B;IAEA,IAAIC,cAAc,MAAMrB,oBAAoBQ;IAC5Ca,gBAAgBtB,0BAA0BS;IAE1C,MAAMc,kBAAsD;QAC1DC,MAAM;QACNC,OAAO;QACPC,QAAQ;QACRC,OAAO;QACPC,IAAI;QACJC,MAAM;IACR;IACA,MAAMC,qBAAqBP,eAAe,CAACb,gBAAgB,SAAS,IAAI;IACxE,MAAMqB,qBAAqBjC,sBAAsBgC;IACjD,MAAME,YAAY,OAAOD,oBAAoBE,QAAQ,WACjD;QAAE,oBAAoBF,mBAAmBE,GAAG;IAAC,IAC7CF,oBAAoBE,OAAO,CAAC;IAEhC,MAAMC,kBAAkBC,OAAOC,OAAO,CAACJ,WACpCK,GAAG,CAAC,CAAC,CAACC,UAAUC,MAAM,GAAK,CAAC,EAAE,EAAED,SAAS,EAAE,EAAEC,MAAM,CAAC,CAAC,EACrDC,IAAI,CAAC;IAER,MAAMC,oBAAoBP,kBACtB,CAAC;AACP,EAAEA,gBAAgB;CACjB,CAAC,GACI;IAEJ,MAAMQ,wBAAwBtC,iBAAiBgB;IAC/C,MAAMuB,gBAAgBxC,uBAAuB;QAAEyC,WAAWnC;QAAOG;QAAWC;IAAS;IACrF,MAAMgC,iBAAiB,OAAOlC,cAAc,WAAWA,UAAUmC,IAAI,KAAK;IAE1E,MAAMC,cAAc;QAClBzB;QACAmB;QACAC;QACAC;QACAE;KACD,CACEG,MAAM,CAAC,CAACC,QAAUC,QAAQD,OAAOH,SAASK,SAC1CX,IAAI,CAAC;IAER,MAAMY,eAAelD,gBAAgBO;IACrC,qBACE;;0BACE,KAACJ;0BACD,KAACgD;gBACCC,IAAG;gBACHC,yBAAyB;oBACvBC,QAAQT;gBACV;;0BAEF,KAACU;gBAAKC,KAAI;gBAAUC,MAAMP;gBAAcQ,IAAG;;0BAC3C,KAACH;gBAAKC,KAAI;gBAAaC,MAAMP;;;;AAGnC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,10 @@ export { defaultThemePresets } from './presets.js';
|
|
|
11
11
|
export type { ThemePreset, ThemeTypographyPreset } from './presets.js';
|
|
12
12
|
export type { ThemeManagementPluginOptions, FetchThemeConfigurationOptions } from './types.js';
|
|
13
13
|
export { DEFAULT_THEME_CONFIGURATION, resolveThemeConfiguration, } from './utils/resolveThemeConfiguration.js';
|
|
14
|
+
export type { ResolvedThemeConfiguration } from './utils/resolveThemeConfiguration.js';
|
|
14
15
|
export { generateThemeColorsCss, hexToHsl } from './utils/themeColors.js';
|
|
15
16
|
export { generateThemeCSS, getThemeStyles } from './utils/themeUtils.js';
|
|
17
|
+
export { getThemeHtmlAttributes } from './utils/themeHtmlAttributes.js';
|
|
16
18
|
export type { Mode, ThemeDefaults } from './providers/Theme/types.js';
|
|
17
19
|
export { ThemeProvider } from './providers/Theme/index.js';
|
|
18
20
|
export declare const ThemeManagementPlugin: (options?: ThemeManagementPluginOptions) => Plugin;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmC,MAAM,EAAE,MAAM,SAAS,CAAA;AAEtE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,OAAO,KAAK,EACV,8BAA8B,EAC9B,4BAA4B,EAC7B,MAAM,YAAY,CAAA;AA2BnB,eAAO,MAAM,qBAAqB,GAAI,UAAS,4BAAiC,KAAG,MAqElF,CAAA;AAED,KAAK,iBAAiB,GAAG,MAAM,GAAG,8BAA8B,CAAA;AAEhE,eAAO,MAAM,uBAAuB,GAClC,UAAU,iBAAiB,KAC1B,OAAO,CAAC,sBAAsB,GAAG,IAAI,CA8CvC,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,KAAG,WAAW,GAAG,IAEhE,CAAA;AAED,eAAO,MAAM,wBAAwB,QAAO,WAAW,EAEtD,CAAA;AAID,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAClD,YAAY,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AACtE,YAAY,EAAE,4BAA4B,EAAE,8BAA8B,EAAE,MAAM,YAAY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CAAA;AACzE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAEvE,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE1D,eAAO,MAAM,qBAAqB,aApJa,4BAA4B,KAAQ,MAoJzB,CAAA;AAC1D,oDAAoD;AACpD,eAAO,MAAM,wBAAwB,aAtJU,4BAA4B,KAAQ,MAsJtB,CAAA;AAE7D,eAAe,qBAAqB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -101,6 +101,7 @@ export { defaultThemePresets } from './presets.js';
|
|
|
101
101
|
export { DEFAULT_THEME_CONFIGURATION, resolveThemeConfiguration } from './utils/resolveThemeConfiguration.js';
|
|
102
102
|
export { generateThemeColorsCss, hexToHsl } from './utils/themeColors.js';
|
|
103
103
|
export { generateThemeCSS, getThemeStyles } from './utils/themeUtils.js';
|
|
104
|
+
export { getThemeHtmlAttributes } from './utils/themeHtmlAttributes.js';
|
|
104
105
|
export { ThemeProvider } from './providers/Theme/index.js';
|
|
105
106
|
export const ThemeManagementPlugin = themeManagementPlugin;
|
|
106
107
|
/** @deprecated use {@link themeManagementPlugin} */ export const themeConfigurationPlugin = themeManagementPlugin;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionConfig, Config, Field, Plugin } from 'payload'\nimport { createThemeConfigurationField } from './fields/themeConfigurationField.js'\nimport type { SiteThemeConfiguration } from './payload-types.js'\nimport type { ThemePreset } from './presets.js'\nimport { defaultThemePresets } from './presets.js'\nimport type {\n FetchThemeConfigurationOptions,\n ThemeManagementPluginOptions,\n} from './types.js'\n\nconst THEME_FIELD_NAME = 'themeConfiguration'\n\nconst removeExistingThemeField = (fields: Field[] = []): Field[] =>\n fields.filter((field) => {\n const candidate = field as { name?: unknown }\n return candidate?.name !== THEME_FIELD_NAME\n })\n\nconst upsertThemeField = (\n fields: Field[] | undefined,\n themeField: Field,\n enableLogging: boolean,\n): Field[] => {\n const sanitized = removeExistingThemeField(fields ?? [])\n\n if (enableLogging) {\n console.log('🎨 Theme Management Plugin: injecting theme configuration field')\n }\n\n return [...sanitized, themeField]\n}\n\nconst ensureCollectionsArray = (collections: Config['collections']): CollectionConfig[] =>\n Array.isArray(collections) ? collections : []\n\nexport const themeManagementPlugin = (options: ThemeManagementPluginOptions = {}): Plugin => {\n return (config: Config): Config => {\n const {\n enabled = true,\n targetCollection = 'site-settings',\n themePresets = defaultThemePresets,\n defaultTheme = 'cool',\n includeColorModeToggle = true,\n includeCustomCSS = true,\n includeBrandIdentity = false,\n enableAdvancedFeatures = true,\n enableLogging = false,\n } = options\n\n if (!enabled) {\n if (enableLogging) {\n console.log('🎨 Theme Management Plugin: disabled via options, skipping.')\n }\n return config\n }\n\n const themeField = createThemeConfigurationField({\n themePresets,\n defaultTheme,\n includeColorModeToggle,\n includeCustomCSS,\n includeBrandIdentity: includeBrandIdentity ?? false,\n enableAdvancedFeatures,\n })\n\n let collectionTouched = false\n\n const collections = ensureCollectionsArray(config.collections).map((collection) => {\n if (collection.slug !== targetCollection) {\n return collection\n }\n\n collectionTouched = true\n\n if (enableLogging) {\n console.log(\n `🎨 Theme Management Plugin: enhancing collection \"${collection.slug}\"`,\n )\n }\n\n const existingFields = Array.isArray(collection.fields) ? collection.fields : []\n\n const fields = upsertThemeField(existingFields, themeField, enableLogging)\n\n return {\n ...collection,\n fields,\n }\n })\n\n if (!collectionTouched) {\n if (enableLogging) {\n console.warn(\n `🎨 Theme Management Plugin: collection \"${targetCollection}\" was not found, leaving config untouched.`,\n )\n }\n return config\n }\n\n return {\n ...config,\n collections,\n }\n }\n}\n\ntype FetchOptionsInput = string | FetchThemeConfigurationOptions\n\nexport const fetchThemeConfiguration = async (\n options?: FetchOptionsInput,\n): Promise<SiteThemeConfiguration | null> => {\n const normalizedOptions =\n typeof options === 'string'\n ? { tenantSlug: options }\n : options ?? {}\n\n const {\n tenantSlug,\n collectionSlug = 'site-settings',\n depth,\n locale,\n draft,\n queryParams = {},\n } = normalizedOptions\n\n const params = new URLSearchParams({ limit: '1' })\n\n if (typeof depth === 'number') params.set('depth', String(depth))\n if (tenantSlug) params.set('tenant', tenantSlug)\n if (locale) params.set('locale', locale)\n if (draft) params.set('draft', 'true')\n\n Object.entries(queryParams).forEach(([key, value]) => {\n if (value === undefined) return\n params.set(key, String(value))\n })\n\n const url = `/api/${collectionSlug}?${params.toString()}`\n\n try {\n const response = await fetch(url)\n if (!response.ok) {\n throw new Error(`Failed to fetch theme configuration (status ${response.status})`)\n }\n\n const data = (await response.json()) as {\n docs?: Array<{ themeConfiguration?: SiteThemeConfiguration }>\n }\n\n const doc = data.docs?.[0]\n\n return doc?.themeConfiguration ?? null\n } catch (error) {\n console.warn('Failed to fetch theme configuration:', error)\n return null\n }\n}\n\nexport const getThemePreset = (themeName: string): ThemePreset | null => {\n return defaultThemePresets.find((preset) => preset.name === themeName) || null\n}\n\nexport const getAvailableThemePresets = (): ThemePreset[] => {\n return defaultThemePresets\n}\n\n\n\nexport { defaultThemePresets } from './presets.js'\nexport type { ThemePreset, ThemeTypographyPreset } from './presets.js'\nexport type { ThemeManagementPluginOptions, FetchThemeConfigurationOptions } from './types.js'\nexport {\n DEFAULT_THEME_CONFIGURATION,\n resolveThemeConfiguration,\n} from './utils/resolveThemeConfiguration.js'\nexport { generateThemeColorsCss, hexToHsl } from './utils/themeColors.js'\nexport { generateThemeCSS, getThemeStyles } from './utils/themeUtils.js'\n\nexport type { Mode, ThemeDefaults } from './providers/Theme/types.js'\nexport { ThemeProvider } from './providers/Theme/index.js'\n\nexport const ThemeManagementPlugin = themeManagementPlugin\n/** @deprecated use {@link themeManagementPlugin} */\nexport const themeConfigurationPlugin = themeManagementPlugin\n\nexport default themeManagementPlugin"],"names":["createThemeConfigurationField","defaultThemePresets","THEME_FIELD_NAME","removeExistingThemeField","fields","filter","field","candidate","name","upsertThemeField","themeField","enableLogging","sanitized","console","log","ensureCollectionsArray","collections","Array","isArray","themeManagementPlugin","options","config","enabled","targetCollection","themePresets","defaultTheme","includeColorModeToggle","includeCustomCSS","includeBrandIdentity","enableAdvancedFeatures","collectionTouched","map","collection","slug","existingFields","warn","fetchThemeConfiguration","normalizedOptions","tenantSlug","collectionSlug","depth","locale","draft","queryParams","params","URLSearchParams","limit","set","String","Object","entries","forEach","key","value","undefined","url","toString","response","fetch","ok","Error","status","data","json","doc","docs","themeConfiguration","error","getThemePreset","themeName","find","preset","getAvailableThemePresets","DEFAULT_THEME_CONFIGURATION","resolveThemeConfiguration","generateThemeColorsCss","hexToHsl","generateThemeCSS","getThemeStyles","ThemeProvider","ThemeManagementPlugin","themeConfigurationPlugin"],"mappings":"AACA,SAASA,6BAA6B,QAAQ,sCAAqC;AAGnF,SAASC,mBAAmB,QAAQ,eAAc;AAMlD,MAAMC,mBAAmB;AAEzB,MAAMC,2BAA2B,CAACC,SAAkB,EAAE,GACpDA,OAAOC,MAAM,CAAC,CAACC;QACb,MAAMC,YAAYD;QAClB,OAAOC,WAAWC,SAASN;IAC7B;AAEF,MAAMO,mBAAmB,CACvBL,QACAM,YACAC;IAEA,MAAMC,YAAYT,yBAAyBC,UAAU,EAAE;IAEvD,IAAIO,eAAe;QACnBE,QAAQC,GAAG,CAAC;IACZ;IAEA,OAAO;WAAIF;QAAWF;KAAW;AACnC;AAEA,MAAMK,yBAAyB,CAACC,cAC9BC,MAAMC,OAAO,CAACF,eAAeA,cAAc,EAAE;AAE/C,OAAO,MAAMG,wBAAwB,CAACC,UAAwC,CAAC,CAAC;IAC9E,OAAO,CAACC;QACN,MAAM,EACJC,UAAU,IAAI,EACdC,mBAAmB,eAAe,EAClCC,eAAevB,mBAAmB,EAClCwB,eAAe,MAAM,EACrBC,yBAAyB,IAAI,EAC7BC,mBAA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OAAO;IAAI;IAEhD,IAAI,OAAON,UAAU,UAAUI,OAAOG,GAAG,CAAC,SAASC,OAAOR;IAC1D,IAAIF,YAAYM,OAAOG,GAAG,CAAC,UAAUT;IACrC,IAAIG,QAAQG,OAAOG,GAAG,CAAC,UAAUN;IACjC,IAAIC,OAAOE,OAAOG,GAAG,CAAC,SAAS;IAE/BE,OAAOC,OAAO,CAACP,aAAaQ,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;QAC/C,IAAIA,UAAUC,WAAW;QACzBV,OAAOG,GAAG,CAACK,KAAKJ,OAAOK;IACzB;IAEA,MAAME,MAAM,CAAC,KAAK,EAAEhB,eAAe,CAAC,EAAEK,OAAOY,QAAQ,IAAI;IAEzD,IAAI;QACF,MAAMC,WAAW,MAAMC,MAAMH;QAC7B,IAAI,CAACE,SAASE,EAAE,EAAE;YAChB,MAAM,IAAIC,MAAM,CAAC,4CAA4C,EAAEH,SAASI,MAAM,CAAC,CAAC,CAAC;QACnF;QAEA,MAAMC,OAAQ,MAAML,SAASM,IAAI;QAIjC,MAAMC,MAAMF,KAAKG,IAAI,EAAE,CAAC,EAAE;QAE1B,OAAOD,KAAKE,sBAAsB;IACpC,EAAE,OAAOC,OAAO;QACdtD,QAAQsB,IAAI,CAAC,wCAAwCgC;QACrD,OAAO;IACT;AACF,EAAC;AAED,OAAO,MAAMC,iBAAiB,CAACC;IAC7B,OAAOpE,oBAAoBqE,IAAI,CAAC,CAACC,SAAWA,OAAO/D,IAAI,KAAK6D,cAAc;AAC5E,EAAC;AAED,OAAO,MAAMG,2BAA2B;IACtC,OAAOvE;AACT,EAAC;AAID,SAASA,mBAAmB,QAAQ,eAAc;AAGlD,SACEwE,2BAA2B,EAC3BC,yBAAyB,QACpB,uCAAsC;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionConfig, Config, Field, Plugin } from 'payload'\nimport { createThemeConfigurationField } from './fields/themeConfigurationField.js'\nimport type { SiteThemeConfiguration } from './payload-types.js'\nimport type { ThemePreset } from './presets.js'\nimport { defaultThemePresets } from './presets.js'\nimport type {\n FetchThemeConfigurationOptions,\n ThemeManagementPluginOptions,\n} from './types.js'\n\nconst THEME_FIELD_NAME = 'themeConfiguration'\n\nconst removeExistingThemeField = (fields: Field[] = []): Field[] =>\n fields.filter((field) => {\n const candidate = field as { name?: unknown }\n return candidate?.name !== THEME_FIELD_NAME\n })\n\nconst upsertThemeField = (\n fields: Field[] | undefined,\n themeField: Field,\n enableLogging: boolean,\n): Field[] => {\n const sanitized = removeExistingThemeField(fields ?? [])\n\n if (enableLogging) {\n console.log('🎨 Theme Management Plugin: injecting theme configuration field')\n }\n\n return [...sanitized, themeField]\n}\n\nconst ensureCollectionsArray = (collections: Config['collections']): CollectionConfig[] =>\n Array.isArray(collections) ? collections : []\n\nexport const themeManagementPlugin = (options: ThemeManagementPluginOptions = {}): Plugin => {\n return (config: Config): Config => {\n const {\n enabled = true,\n targetCollection = 'site-settings',\n themePresets = defaultThemePresets,\n defaultTheme = 'cool',\n includeColorModeToggle = true,\n includeCustomCSS = true,\n includeBrandIdentity = false,\n enableAdvancedFeatures = true,\n enableLogging = false,\n } = options\n\n if (!enabled) {\n if (enableLogging) {\n console.log('🎨 Theme Management Plugin: disabled via options, skipping.')\n }\n return config\n }\n\n const themeField = createThemeConfigurationField({\n themePresets,\n defaultTheme,\n includeColorModeToggle,\n includeCustomCSS,\n includeBrandIdentity: includeBrandIdentity ?? false,\n enableAdvancedFeatures,\n })\n\n let collectionTouched = false\n\n const collections = ensureCollectionsArray(config.collections).map((collection) => {\n if (collection.slug !== targetCollection) {\n return collection\n }\n\n collectionTouched = true\n\n if (enableLogging) {\n console.log(\n `🎨 Theme Management Plugin: enhancing collection \"${collection.slug}\"`,\n )\n }\n\n const existingFields = Array.isArray(collection.fields) ? collection.fields : []\n\n const fields = upsertThemeField(existingFields, themeField, enableLogging)\n\n return {\n ...collection,\n fields,\n }\n })\n\n if (!collectionTouched) {\n if (enableLogging) {\n console.warn(\n `🎨 Theme Management Plugin: collection \"${targetCollection}\" was not found, leaving config untouched.`,\n )\n }\n return config\n }\n\n return {\n ...config,\n collections,\n }\n }\n}\n\ntype FetchOptionsInput = string | FetchThemeConfigurationOptions\n\nexport const fetchThemeConfiguration = async (\n options?: FetchOptionsInput,\n): Promise<SiteThemeConfiguration | null> => {\n const normalizedOptions =\n typeof options === 'string'\n ? { tenantSlug: options }\n : options ?? {}\n\n const {\n tenantSlug,\n collectionSlug = 'site-settings',\n depth,\n locale,\n draft,\n queryParams = {},\n } = normalizedOptions\n\n const params = new URLSearchParams({ limit: '1' })\n\n if (typeof depth === 'number') params.set('depth', String(depth))\n if (tenantSlug) params.set('tenant', tenantSlug)\n if (locale) params.set('locale', locale)\n if (draft) params.set('draft', 'true')\n\n Object.entries(queryParams).forEach(([key, value]) => {\n if (value === undefined) return\n params.set(key, String(value))\n })\n\n const url = `/api/${collectionSlug}?${params.toString()}`\n\n try {\n const response = await fetch(url)\n if (!response.ok) {\n throw new Error(`Failed to fetch theme configuration (status ${response.status})`)\n }\n\n const data = (await response.json()) as {\n docs?: Array<{ themeConfiguration?: SiteThemeConfiguration }>\n }\n\n const doc = data.docs?.[0]\n\n return doc?.themeConfiguration ?? null\n } catch (error) {\n console.warn('Failed to fetch theme configuration:', error)\n return null\n }\n}\n\nexport const getThemePreset = (themeName: string): ThemePreset | null => {\n return defaultThemePresets.find((preset) => preset.name === themeName) || null\n}\n\nexport const getAvailableThemePresets = (): ThemePreset[] => {\n return defaultThemePresets\n}\n\n\n\nexport { defaultThemePresets } from './presets.js'\nexport type { ThemePreset, ThemeTypographyPreset } from './presets.js'\nexport type { ThemeManagementPluginOptions, FetchThemeConfigurationOptions } from './types.js'\nexport {\n DEFAULT_THEME_CONFIGURATION,\n resolveThemeConfiguration,\n} from './utils/resolveThemeConfiguration.js'\nexport type { ResolvedThemeConfiguration } from './utils/resolveThemeConfiguration.js'\nexport { generateThemeColorsCss, hexToHsl } from './utils/themeColors.js'\nexport { generateThemeCSS, getThemeStyles } from './utils/themeUtils.js'\nexport { getThemeHtmlAttributes } from './utils/themeHtmlAttributes.js'\n\nexport type { Mode, ThemeDefaults } from './providers/Theme/types.js'\nexport { ThemeProvider } from './providers/Theme/index.js'\n\nexport const ThemeManagementPlugin = themeManagementPlugin\n/** @deprecated use {@link themeManagementPlugin} */\nexport const themeConfigurationPlugin = themeManagementPlugin\n\nexport default themeManagementPlugin"],"names":["createThemeConfigurationField","defaultThemePresets","THEME_FIELD_NAME","removeExistingThemeField","fields","filter","field","candidate","name","upsertThemeField","themeField","enableLogging","sanitized","console","log","ensureCollectionsArray","collections","Array","isArray","themeManagementPlugin","options","config","enabled","targetCollection","themePresets","defaultTheme","includeColorModeToggle","includeCustomCSS","includeBrandIdentity","enableAdvancedFeatures","collectionTouched","map","collection","slug","existingFields","warn","fetchThemeConfiguration","normalizedOptions","tenantSlug","collectionSlug","depth","locale","draft","queryParams","params","URLSearchParams","limit","set","String","Object","entries","forEach","key","value","undefined","url","toString","response","fetch","ok","Error","status","data","json","doc","docs","themeConfiguration","error","getThemePreset","themeName","find","preset","getAvailableThemePresets","DEFAULT_THEME_CONFIGURATION","resolveThemeConfiguration","generateThemeColorsCss","hexToHsl","generateThemeCSS","getThemeStyles","getThemeHtmlAttributes","ThemeProvider","ThemeManagementPlugin","themeConfigurationPlugin"],"mappings":"AACA,SAASA,6BAA6B,QAAQ,sCAAqC;AAGnF,SAASC,mBAAmB,QAAQ,eAAc;AAMlD,MAAMC,mBAAmB;AAEzB,MAAMC,2BAA2B,CAACC,SAAkB,EAAE,GACpDA,OAAOC,MAAM,CAAC,CAACC;QACb,MAAMC,YAAYD;QAClB,OAAOC,WAAWC,SAASN;IAC7B;AAEF,MAAMO,mBAAmB,CACvBL,QACAM,YACAC;IAEA,MAAMC,YAAYT,yBAAyBC,UAAU,EAAE;IAEvD,IAAIO,eAAe;QACnBE,QAAQC,GAAG,CAAC;IACZ;IAEA,OAAO;WAAIF;QAAWF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,EAAC;AAED,OAAO,MAAMG,2BAA2B;IACtC,OAAOvE;AACT,EAAC;AAID,SAASA,mBAAmB,QAAQ,eAAc;AAGlD,SACEwE,2BAA2B,EAC3BC,yBAAyB,QACpB,uCAAsC;AAE7C,SAASC,sBAAsB,EAAEC,QAAQ,QAAQ,yBAAwB;AACzE,SAASC,gBAAgB,EAAEC,cAAc,QAAQ,wBAAuB;AACxE,SAASC,sBAAsB,QAAQ,iCAAgC;AAGvE,SAASC,aAAa,QAAQ,6BAA4B;AAE1D,OAAO,MAAMC,wBAAwB9D,sBAAqB;AAC1D,kDAAkD,GAClD,OAAO,MAAM+D,2BAA2B/D,sBAAqB;AAE7D,eAAeA,sBAAqB"}
|
|
@@ -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,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,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C,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,8BAA0D;IACrEC,OAAON;IACPO,WAAW;IACXC,sBAAsB;IACtBC,cAAc;IACdC,WAAW;IACXC,SAAS;IACTC,gBAA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AwB;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'\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\n/**\n * Generic theme configuration structure that matches Payload's generated types\n * without depending on specific payload-types versions\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\n/**\n * Generic theme configuration interface that accepts any compatible structure\n * This avoids type conflicts between different versions of payload-types\n */\ninterface GenericThemeConfiguration {\n theme?: string | null\n colorMode?: string | null\n allowColorModeToggle?: boolean | null\n borderRadius?: string | null\n fontScale?: string | null\n spacing?: string | null\n animationLevel?: string | null\n customCSS?: string | null\n lightMode?: {\n primary?: string | null\n secondary?: string | null\n accent?: string | null\n neutral?: string | null\n success?: string | null\n warning?: string | null\n error?: string | null\n info?: string | null\n } | null\n darkMode?: {\n primary?: string | null\n secondary?: string | null\n accent?: string | null\n neutral?: string | null\n success?: string | null\n warning?: string | null\n error?: string | null\n info?: string | null\n } | null\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<GenericThemeConfiguration['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?: GenericThemeConfiguration | 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?: GenericThemeConfiguration['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;AAE9D,SAASC,YAAY,QAAQ,8BAA6B;AAE1D,SAASC,mBAAmB,QAAQ,gBAAe;AAmDnD,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,8BAA0D;IACrEC,OAAON;IACPO,WAAW;IACXC,sBAAsB;IACtBC,cAAc;IACdC,WAAW;IACXC,SAAS;IACTC,gBAAgB;IAChBC,WAAW;IACXC,WAAWb,sBAAsBa;IACjCC,UAAUd,sBAAsBc;IAChCC,YAAYf,sBAAsBe,cAAc;AAClD,EAAC;AAED,SAASC,oBAAoBC,KAAc;IACzC,IAAI,OAAOA,UAAU,UAAU;QAC7B,IAAI1B,qBAAqB2B,QAAQ,CAACD,QAA8B;YAC9D,OAAOA;QACT;QAEA,MAAME,cA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OI,UAAUF,YAAY;AAC/B"}
|
|
@@ -0,0 +1,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'\n\n/**\n * Generates HTML attributes for the <html> element based on theme configuration\n * This ensures the theme is applied before React hydration to prevent FOUC\n * \n * @example\n * ```tsx\n * const siteSettings = await payload.findGlobal({ slug: 'site-settings' })\n * const themeConfig = resolveThemeConfiguration(siteSettings?.themeConfiguration)\n * const htmlAttrs = getThemeHtmlAttributes(themeConfig)\n * \n * <html {...htmlAttrs} className={yourClassName}>\n * ```\n */\nexport function getThemeHtmlAttributes(config: ResolvedThemeConfiguration): {\n 'data-theme': string\n 'data-theme-mode': string\n 'data-border-radius': string\n 'data-font-scale': string\n 'data-spacing': string\n 'data-animation-level': string\n 'data-allow-color-mode-toggle': string\n suppressHydrationWarning: true\n} {\n return {\n 'data-theme': config.theme,\n 'data-theme-mode': config.colorMode,\n 'data-border-radius': config.borderRadius,\n 'data-font-scale': config.fontScale,\n 'data-spacing': config.spacing,\n 'data-animation-level': config.animationLevel,\n 'data-allow-color-mode-toggle': config.allowColorModeToggle ? 'true' : 'false',\n suppressHydrationWarning: true,\n }\n}\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"}
|