2222def named_color (obj : 'Color' , alpha : Optional [bool ], fit : Union [str , bool ]) -> Optional [str ]:
2323 """Get the CSS color name."""
2424
25- a = get_alpha (obj , alpha , False )
25+ a = get_alpha (obj , alpha , False , False )
2626 if a is None :
2727 a = 1
28- method = None if not isinstance (fit , str ) else fit
29- coords = alg .no_nans (obj .clone ().fit (method = method )[:- 1 ])
30- return to_name (coords + [a ])
28+ return to_name (get_coords (obj , fit , False , False ) + [a ])
3129
3230
3331def named_color_function (
@@ -44,7 +42,7 @@ def named_color_function(
4442 """Translate to CSS function form `name(...)`."""
4543
4644 # Create the function `name` or `namea` if old legacy form.
47- a = get_alpha (obj , alpha , none )
45+ a = get_alpha (obj , alpha , none , legacy )
4846 string = ['{}{}(' .format (func , 'a' if legacy and a is not None else EMPTY )]
4947
5048 # Iterate the coordinates formatting them for percent, not percent, and even scaling them (sRGB).
@@ -85,7 +83,7 @@ def color_function(
8583
8684 # Export in the `color(space ...)` format
8785 coords = get_coords (obj , fit , none , False )
88- a = get_alpha (obj , alpha , none )
86+ a = get_alpha (obj , alpha , none , False )
8987 return (
9088 'color({} {}{})' .format (
9189 obj ._space ._serialize ()[0 ],
@@ -98,15 +96,14 @@ def color_function(
9896def get_coords (obj : 'Color' , fit : Union [str , bool ], none : bool , legacy : bool ) -> Vector :
9997 """Get the coordinates."""
10098
101- method = None if not isinstance (fit , str ) else fit
102- coords = obj .fit (method = method )[:- 1 ] if fit else obj [:- 1 ]
99+ coords = obj .fit (method = None if not isinstance (fit , str ) else fit )[:- 1 ] if fit else obj [:- 1 ]
103100 return alg .no_nans (coords ) if legacy or not none else coords
104101
105102
106- def get_alpha (obj : 'Color' , alpha : Optional [bool ], none : bool ) -> Optional [float ]:
103+ def get_alpha (obj : 'Color' , alpha : Optional [bool ], none : bool , legacy : bool ) -> Optional [float ]:
107104 """Get the alpha if required."""
108105
109- a = alg .no_nan (obj [- 1 ]) if not none else obj [- 1 ]
106+ a = alg .no_nan (obj [- 1 ]) if not none or legacy else obj [- 1 ]
110107 alpha = alpha is not False and (alpha is True or a < 1.0 or alg .is_nan (a ))
111108 return None if not alpha else a
112109
@@ -120,9 +117,8 @@ def hexadecimal(
120117) -> str :
121118 """Get the hex `RGB` value."""
122119
123- method = None if not isinstance (fit , str ) else fit
124- coords = [c for c in alg .no_nans (obj .fit (method = method )[:- 1 ])]
125- a = get_alpha (obj , alpha , False )
120+ coords = get_coords (obj , fit , False , False )
121+ a = get_alpha (obj , alpha , False , False )
126122
127123 if a is not None :
128124 value = "#{:02x}{:02x}{:02x}{:02x}" .format (
0 commit comments