From bc86c8a36dd5b3a5e359a30f58a3648aacdef7dc Mon Sep 17 00:00:00 2001 From: SrJuggernaut Date: Sat, 6 Sep 2025 17:24:35 -0600 Subject: [PATCH] feat: includeColors to make the themes lightweight --- src/colors/generateColors.ts | 6 +++--- src/index.ts | 14 ++++++++------ src/types.ts | 4 ++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/colors/generateColors.ts b/src/colors/generateColors.ts index 2eb207b..661e3d5 100644 --- a/src/colors/generateColors.ts +++ b/src/colors/generateColors.ts @@ -1,12 +1,12 @@ import type { Recursive, Token } from '@pandacss/types' import * as radixColors from '@radix-ui/colors' -import { type RequireDarkForeground, requireDarkForeground } from '@/types.js' +import { type BrandColor, type Color, type RequireDarkForeground, requireDarkForeground } from '@/types.js' -const generateColors = () => { +const generateColors = (include?: Color[]) => { const colors: Recursive> = {} for (const [key, value] of Object.entries(radixColors)) { const colorName = /([a-z]*)/.exec(key)?.[1] as keyof typeof radixColors - // if (colorName === 'default' || !colorName) continue + if (include !== undefined && !include.includes(colorName as BrandColor)) continue const newColor: Recursive> = {} const isAlpha = key.endsWith('A') const isP3 = key.includes('P3') diff --git a/src/index.ts b/src/index.ts index 9c96a1c..86e739f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,24 +4,26 @@ import generateNeutralColor from '@/colors/generateNeutralColor.js' import buttonRecipe from '@/recipes/button.js' import { detailsRecipe } from '@/recipes/details.js' import inputRecipe from '@/recipes/input.js' -import type { BrandColor, ColorVariation, NeutralColor } from '@/types.js' +import { type BrandColor, type Color, type ColorVariation, color, type NeutralColor } from '@/types.js' import generateSemanticColors from './colors/generateSemanticColors.js' -export type themeConfig = { +export type ThemeConfig = { neutral?: NeutralColor semanticColors?: Record colorVariation?: ColorVariation + includeColors?: Color[] } -const defaultConfig: Required = { +const defaultConfig: Required = { neutral: 'slate', colorVariation: { dark: false, p3: false, alpha: false }, - semanticColors: { primary: 'teal' } + semanticColors: { primary: 'teal' }, + includeColors: color } -const srJuggernautPandaPreset = (config?: themeConfig) => { +const srJuggernautPandaPreset = (config?: ThemeConfig) => { const mergedConfig = { ...defaultConfig, ...config } - const colors = generateColors() + const colors = generateColors(config?.includeColors) const neutral = generateNeutralColor(mergedConfig.neutral, mergedConfig.colorVariation) const semanticColors = generateSemanticColors(mergedConfig.semanticColors, mergedConfig.colorVariation) return definePreset({ diff --git a/src/types.ts b/src/types.ts index e76df07..9df7615 100644 --- a/src/types.ts +++ b/src/types.ts @@ -32,6 +32,10 @@ export const neutralColor = ['gray', 'mauve', 'slate', 'sage', 'olive', 'sand'] export type NeutralColor = (typeof neutralColor)[number] +export const color = [...brandColor, ...neutralColor] + +export type Color = BrandColor | NeutralColor + export type ColorVariation = { dark?: boolean p3?: boolean