chroma.js icon indicating copy to clipboard operation
chroma.js copied to clipboard

hsla plain JS object constructor does not take alpha into account

Open ephemere000 opened this issue 5 years ago • 1 comments

chroma( {r:255, g:45, b:33, a:0.5} ) will work fine. We can see the alpha channel properly set in the chroma object and chroma( {r:255, g:45, b:33, a:0.5} ).alpha() returns 0.5.

BUT

chroma({ h:120, s:0.8, l:0.75, a:0.5}) will not consider the value a:0.5. We can see the alpha channel set to 1 instead of 0.5 in the chroma object and chroma({ h:120, s:1, l:0.75, a:0.5}).alpha() returns 1.

ephemere000 avatar Apr 30 '19 16:04 ephemere000

For a quick fix, src/io/hsl/index.js should be unpacking as 'hsla' like the 'rgba' one in src/io/rgb.index.js is doing.

I do wonder whether alpha support should be refactored as a general-purpose "add-on" in light of #244: maybe instead of defining RGBA as a separate color space, the code should just say "I know about solid color specifications like RGB and HSL and stuff, and all these solid colors can have an alpha after them".

Artoria2e5 avatar Apr 09 '21 22:04 Artoria2e5