File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @compai/css-gui ' : patch
3
+ ---
4
+
5
+ Ignore colors with alpha in regen
Original file line number Diff line number Diff line change 7
7
sample ,
8
8
} from 'lodash-es'
9
9
import getContrast from 'get-contrast'
10
+ import * as culori from 'culori'
10
11
import { ThemeColor } from '../components/primitives/ColorPicker/PalettePicker'
11
12
import { RegenOptions } from '../components/schemas/types'
12
13
import { Color } from '../types/css'
@@ -77,6 +78,10 @@ export function randomColor({
77
78
const [ path , value ] = curr
78
79
79
80
try {
81
+ if ( hasAlpha ( value ) ) {
82
+ return acc
83
+ }
84
+
80
85
if (
81
86
getContrast . ratio ( value , colorToContrastWith ) >= CONTRAST_THRESHOLD
82
87
) {
@@ -101,6 +106,18 @@ export function randomHexColor() {
101
106
)
102
107
}
103
108
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
+
104
121
type Key = string | number
105
122
type KeyPath = Key [ ]
106
123
type Obj = Record < string , any >
You can’t perform that action at this time.
0 commit comments