File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -32,10 +32,18 @@ export function useColorManipulation<T extends AnyColor>(
3232 // Trigger `onChange` callback only if an updated color is different from cached one;
3333 // save the new color to the ref to prevent unnecessary updates
3434 useEffect ( ( ) => {
35- let newColor ;
35+ const { a, ...hsv } = hsva ;
36+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
37+ const { a : _ , ...cacheHsv } = cache . current . hsva ;
38+
39+ // When alpha channel is changed, use cached RGB values to prevent rounding errors
40+ const newColor = equalColorObjects ( hsv , cacheHsv )
41+ ? Object . assign ( { } , cache . current . color , { a } )
42+ : colorModel . fromHsva ( hsva ) ;
43+
3644 if (
3745 ! equalColorObjects ( hsva , cache . current . hsva ) &&
38- ! colorModel . equal ( ( newColor = colorModel . fromHsva ( hsva ) ) , cache . current . color )
46+ ! colorModel . equal ( newColor , cache . current . color )
3947 ) {
4048 cache . current = { hsva, color : newColor } ;
4149 onChangeCallback ( newColor ) ;
You can’t perform that action at this time.
0 commit comments