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

a11y does not support opacity #93

Open dasveloper opened 2 years ago

dasveloper commented 2 years ago

The a11y plugin doesn't support opacity. It would be great if it did.

Black on white = 21
colord('#000000').contrast('#FFFFFF')

Transparent black on white = 21, even though the text is invisible.
colord('#00000000').contrast('#FFFFFF')

Black on white is readable
colord('#000000').isReadable('#FFFFFF')

Transparent black on white is readable, even though the text is invisible.
colord('#00000000').isReadable('#FFFFFF')

ciampo commented 1 year ago

I think an important consideration to make when implementing such a feature (and the reason why colord may not support it yet) is that the computation of contrast/readability should take into account also the underlying "background" color.

For example:

colord("#ffffff").isReadable("#ff000080"); // true (white on 50% transparent red)

should return very different results if the color "underlying" the transparent red is black or white.

In short, the contrast calculation should be done against the equivalent "compound" solid color

ciampo commented 1 year ago

Update: as @t-hamano pointed out in https://github.com/WordPress/gutenberg/pull/47373#issuecomment-1404555650 , the mix plugin could be used to calculate the compound color, which can then be fed to the relevant a11y util