chore: initial commit
I just realized i was using this without commiting it, so this is a very big commit
This commit is contained in:
35
src/colors/generateColors.ts
Normal file
35
src/colors/generateColors.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { Recursive, Token } from '@pandacss/types'
|
||||
import * as radixColors from '@radix-ui/colors'
|
||||
import { type RequireDarkForeground, requireDarkForeground } from '@/types.js'
|
||||
|
||||
const generateColors = () => {
|
||||
const colors: Recursive<Token<string>> = {}
|
||||
for (const [key, value] of Object.entries(radixColors)) {
|
||||
const colorName = /([a-z]*)/.exec(key)?.[1] as keyof typeof radixColors
|
||||
// if (colorName === 'default' || !colorName) continue
|
||||
const newColor: Recursive<Token<string>> = {}
|
||||
const isAlpha = key.endsWith('A')
|
||||
const isP3 = key.includes('P3')
|
||||
const isDark = key.includes('Dark')
|
||||
const newColorName = `${colorName}${isDark ? 'Dark' : ''}${isP3 ? 'P3' : ''}${isAlpha ? 'Alpha' : ''}`
|
||||
|
||||
newColor.foreground = {
|
||||
value: requireDarkForeground.includes(colorName as RequireDarkForeground) ? '#000' : '#fff'
|
||||
}
|
||||
|
||||
for (const [subKey, subValue] of Object.entries(value)) {
|
||||
const colorNumber = /.*?([0-9]{1,2})$/.exec(subKey)?.[1]
|
||||
newColor[`${colorNumber}`] = { value: subValue }
|
||||
if (colorNumber === '9') {
|
||||
newColor.DEFAULT = { value: subValue }
|
||||
}
|
||||
}
|
||||
|
||||
colors[newColorName] = newColor
|
||||
}
|
||||
return colors
|
||||
}
|
||||
|
||||
export default generateColors
|
||||
|
||||
export type GeneratedColorsReturn = ReturnType<typeof generateColors>
|
||||
Reference in New Issue
Block a user