mherchel / contrast-grid

App for contrastgrid.com
MIT License
7 stars 4 forks source link

Transparency data not used in color display or contrast calcuations #5

Open extra808 opened 2 years ago

extra808 commented 2 years ago

When an input color includes transparency (#00636366, hsla(180, 100%, 19.4%, 0.4), rgba(0, 99, 99, 0.4), etc.) what's displayed in the output table is the color without transparency. Also, the contrast value calculated is for the color without transparency.

Transparency included in the text color complicates the contrast calculation but an accurate number is possible. When the background color includes transparency, the actual displayed color depends on the color(s) behind the element. I like what Lea Verou's Contrast Ratio site appears to do, calculates the contrast if the color behind the element is white, again if the color behind is black, then displays a contrast value halfway between with a +/- value, like error bars.

Until/unless the transparency data is included in the calculation, I think the directions should have a note about what happens to it.

mherchel commented 2 years ago

Thanks for the suggestion!

I'm using the https://github.com/bgrins/TinyColor library to do all the color calculations. It does have some support for transparency.

I wonder how common this is? In the meantime I don't mind creating a note.