diff --git a/docs/changelog.rst b/docs/changelog.rst index cdddde1..e8883bb 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,6 +2,15 @@ Changelog ========= +Version 1.5.2 +------------- + +Unreleased. + +* Keep the hue of ``lch()`` and ``oklch()`` when lightness is ``none``. + https://github.com/Kozea/tinycss2/issues/80 + + Version 1.5.1 ------------- diff --git a/tests/test_tinycss2.py b/tests/test_tinycss2.py index 98fbf7c..958d243 100644 --- a/tests/test_tinycss2.py +++ b/tests/test_tinycss2.py @@ -547,6 +547,19 @@ def test_color_oklab_4_with_5(input): return result +def test_lch_none_lightness_keeps_hue(): + color = parse_color4("lch(none 50 180)") + assert color.coordinates == (None, 50.0, 180.0) + color = parse_color4("oklch(none 0.1 180)") + assert color.coordinates == (None, 0.1, 180.0) + color = parse_color4("lch(50 20 none)") + assert color.coordinates == (50.0, 20.0, None) + color = parse_color4("lch(40 20 180)") + assert color.coordinates == (40.0, 20.0, 180.0) + color = parse_color4("lab(none 10 20)") + assert color.coordinates == (None, 10.0, 20.0) + + @json_test() def test_color_lch_4(input): if not (color := parse_color4(input)): diff --git a/tinycss2/color4.py b/tinycss2/color4.py index 8087323..1c0fc0b 100644 --- a/tinycss2/color4.py +++ b/tinycss2/color4.py @@ -327,7 +327,7 @@ def _parse_lch(args, alpha): None if args[0].type == 'ident' else args[0].value, None if args[1].type == 'ident' else ( args[1].value * (1 if args[1].type == 'number' else 1.5)), - None if args[0].type == 'ident' else hue, + None if args[2].type == 'ident' else hue, ] return Color('lch', coordinates, alpha) @@ -372,7 +372,7 @@ def _parse_oklch(args, alpha): args[0].value * (1 if args[0].type == 'number' else 0.01)), None if args[1].type == 'ident' else ( args[1].value * (1 if args[1].type == 'number' else 0.004)), - None if args[0].type == 'ident' else hue, + None if args[2].type == 'ident' else hue, ] return Color('oklch', coordinates, alpha)