Skip to content

Commit 25d3302

Browse files
authored
Merge pull request #594 from components-ai/theme-alpha
Ignore colors with alpha in regen
2 parents f127bdb + 8d69523 commit 25d3302

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

.changeset/hot-dolphins-sneeze.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@compai/css-gui': patch
3+
---
4+
5+
Ignore colors with alpha in regen

packages/gui/src/lib/color.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
sample,
88
} from 'lodash-es'
99
import getContrast from 'get-contrast'
10+
import * as culori from 'culori'
1011
import { ThemeColor } from '../components/primitives/ColorPicker/PalettePicker'
1112
import { RegenOptions } from '../components/schemas/types'
1213
import { Color } from '../types/css'
@@ -77,6 +78,10 @@ export function randomColor({
7778
const [path, value] = curr
7879

7980
try {
81+
if (hasAlpha(value)) {
82+
return acc
83+
}
84+
8085
if (
8186
getContrast.ratio(value, colorToContrastWith) >= CONTRAST_THRESHOLD
8287
) {
@@ -101,6 +106,18 @@ export function randomHexColor() {
101106
)
102107
}
103108

109+
export function hasAlpha(color: string) {
110+
if (!isValidColor(color)) {
111+
return false
112+
}
113+
const { alpha = 1 } = culori.parse(color)
114+
return alpha !== 1
115+
}
116+
117+
export function isValidColor(value: Color) {
118+
return !!culori.parse(value)
119+
}
120+
104121
type Key = string | number
105122
type KeyPath = Key[]
106123
type Obj = Record<string, any>

0 commit comments

Comments
 (0)