-
Notifications
You must be signed in to change notification settings - Fork 13
Fixes Tint, Shade, and Contrast Alpha Interference Issue #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes Tint, Shade, and Contrast Alpha Interference Issue #26
Conversation
|
poke @ianstormtaylor |
|
@ianstormtaylor any progress? |
|
@ianstormtaylor I guess you are super busy and you maybe don't do css anymore. Could you add collaborator to this module and transfert it maybe? |
|
Oh shoot for some reason I thought that you were a collaborator on this one already @MoOx! I'm definitely happy to add you and anyone else who wants to maintain it. |
|
Excellent, thanks @ianstormtaylor. I need to take another look at this to refresh my memory on what I was up to. But @MoOx you wanna give this another look and a 👍 if it's ready to go? Anyone else too, if you see anything that needs fixin', holler |
|
My time is limited but I gave a quick look: it seems you know what you are talking about, so I will go for merge if you are still confident that this PR is a proper bugfix. |
|
Finally had a look at this to get myself back up to speed. All looks good. Tests still passing. Gonna merge. |
The problem
The
tint,shade, andcontrastadjusters incorrectly modify the alpha value of the base color.Current results:
Expected results:
From usage and reading the spec, I expected
tint,shade, andcontrastto leave the alpha value of the base color as is.The cause
These three adjusters make use of
Color.mix. Tint and shade do so here https://github.com/ianstormtaylor/css-color-function/blob/master/lib/adjusters.js#L41 and contrast here https://github.com/ianstormtaylor/css-color-function/blob/master/lib/adjusters.js#L82Looking at Qix-/color, the
mixmethod is ported from the Sassmixhttps://github.com/Qix-/color/blob/0.11.3/index.js#L295 According to the Sass docs http://sass-lang.com/documentation/Sass/Script/Functions.html#mix-instance_method themixmethod mixes color channels and the alpha channel.Reading through the Color Level 4 spec, it seems like the only adjusters that should modify the alpha value of the base color are
alphaandblenda.My solution in this PR
First, I wrote failing tests for tint, shade, and contrast. A thing to note about both Tint and Shade is that order mattered. If
tint/shadecame beforealpha, the expected result was produced. Ifalphacame first, the unexpected value was produced.Code changes; What I did in both the
blendmethod and within thecontrastmethod was hold on to the initial alpha value of the base color. Then set the alpha to1, then callColor.mix. After themixwas complete, set the alpha back to the initial alpha value.This ensures
Color.mixdoes not attempt to mix an alpha value less than one.Background
I first hit this issue in tylergaw/colorme#3. Found it first in the colorme.io UI just from usage. Fiddled with the adjusters enough and found the pattern. From there, I just followed the thread until I bumped into the
Color.mixusage.I have a PR in for colorme pointing it to my branch of css-color-function tylergaw/colorme#6 for now. And that branch is deployed at
https://colorme.ioThanks, let me know if there's anything else you want me to tweak.