mdbassit / Coloris

A lightweight and elegant JavaScript color picker. Written in vanilla ES6, no dependencies. Accessible.
https://coloris.js.org/examples.html
MIT License
470 stars 58 forks source link

Incorrect output value of alpha channel in 8-digit Hex Code #134

Closed AnonUsr-Dev closed 8 months ago

AnonUsr-Dev commented 8 months ago
Page:
mdbassit commented 8 months ago

That's probably an artifact of the rounding of the alpha value. This color picker only supports integer alpha values between 0 and 100, but the hex alpha values (which go from 0 to 255) map to decimal values which are then rounded to the closest integer value.

Could you explain how this presents a problem for you? I'd be quite surprised if anyone can tell the difference between alpha values 50 and 51, let alone 50.5!

AnonUsr-Dev commented 8 months ago

I reported it as a issues because when creating an app for this type of conversion, only the input for the alpha channel is rounded. If it is based on a human sense, then it is not a problem at all. Thank you for the good color picker. image

mdbassit commented 8 months ago

Thanks for the kind words.

By the way, the color picker already has a built-in format conversion tool that you can activate by setting the option formatToggle to true, though it doesn't support the hwb color format.

In your screenshot, what are those values in the 3rd and 4th fields?

AnonUsr-Dev commented 8 months ago

I am aware that there are built-in conversions, but I wanted an app that could quickly and easily copy each format and also provide features like rounding to 3-digits hex values. To achieve this, I'm using a combination of external libraries to convert the output of Coloris. While bug-fixing in this app, I noticed an unexpected rounding behavior and was able to reproduce it using Coloris alone then i reported.

It's a very straightforward idea, but I think that by reducing the slider's step from 1 to, for example, 0.001, we can minimize the necessary changes to the current calculation function and potentially resolve this issue.

Considering that it hasn't been reported by others, it might be a niche issue. That's why, If it's feasible, I kindly request you to please take it into consideration. Thank you.

AnonUsr-Dev commented 8 months ago

im not aware of the specific circumstances that led to the use of toFixed of internal alpha value, so I cannot ascertain if this is the correct fix. However, based on my usage, I implemented the following approach for the correction, which I will provide for your reference.(AnonUsr-Dev/Coloris@0d8ca4d)

mdbassit commented 8 months ago

im not aware of the specific circumstances that led to the use of toFixed of internal alpha value, so I cannot ascertain if this is the correct fix.

The use of toFixed() to format the alpha value was a workaround to fix the bug #35, which was caused by the Chrome bug https://issues.chromium.org/issues/40824169.

It looks like the Chrome bug has been fixed around 16 months ago, so it probably safe to remove that workaround. I just need to test it to make sure there will be no regressions.

AnonUsr-Dev commented 8 months ago

i understand, Thank you for your response to this issue.

mdbassit commented 8 months ago

I just published a new version that should fix your problem.