omgovich / colord

👑 A tiny yet powerful tool for high-performance color manipulations and conversions
https://colord.omgovich.ru
MIT License
1.63k stars 48 forks source link

hue changed to zero #81

Closed georggrubner closed 2 years ago

georggrubner commented 2 years ago

When creating an hsl object with a specific hue, but saturation an lightness set to 0, the hue will also be set to zero

test case:

expect(colord({ h: 50, s: 0, l: 0 }).toHsl().h).toBe(50)

this test will fail and the received result. The expected result is, that the hue stays the same.

omgovich commented 2 years ago

Hi!

Not sure it's a bug: a color with no saturation and lightness is black. Black doesn't have any hue since... you know... it's black :)

georggrubner commented 2 years ago

Well, we use colord for our color picker. As you can see, when you change the hue, color panel should change. This is only possible if we know the hue.

colorpicker

We had to implement a fix on our side, where we override the hue manually on the object colord gives us. This extra step should not be necessary. An HSL object passed to the colrd function should always be the same as the one we receive when calling toHsl()

omgovich commented 2 years ago

As a developer of a color picker component, I would highly recommend storing the current hue in a separate variable.

You can't rely on color conversion libraries here since white, black and any grayscale color could break the conversion between color spaces.

georggrubner commented 2 years ago

This makes sense. Thanks for your help!