Skip to content
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

feat(color-contrast): add support for CSS mix-blend-mode #3226

Merged
merged 26 commits into from
Dec 9, 2021

Conversation

Zidious
Copy link
Contributor

@Zidious Zidious commented Oct 20, 2021

mix-blend-mode functions:

  • unit tests
  • integration tests

This PR focuses on blending BG colours. An example of mix-blend-mode in action, consider the following:

<div id="A" style="background-color: rgba(255, 255, 255, 1.0);">
  <div id="B" style="background-color: rgba(0, 128, 0, 0.25);">
    <div id="C" style="background-color: rgba(255, 0, 0, 0.5); mix-blend-mode: difference;">
      <div id="D" style="background-color: rgba(0, 0, 255, 0.25);">Test Element</div>
    </div>
  </div>
</div>

When mix-blend-mode is applied onto a div it is considered an isolated group and therefore its own stacking context.

The stack of the above snippet would look like the following:

Root Group
  - #A
  - #B
  - isolated group
    - #C 
    - #D

When blending we do bottom up:

rootGroup = normal(B,normal(A, rootBackDrop))
isolatedGroup = normal(D, C)
difference(rootGroup, isolatedGroup) // outputs the final colour

For reference: compositing BG colours w3c assistance

Resources: Compositing and Blending - Note: further research I would like to investigate how to go about blending nested mix-blend-modes when in the same div block.

Closes issue: #3187

@Zidious Zidious requested a review from a team as a code owner October 20, 2021 14:28
@Zidious Zidious marked this pull request as draft October 20, 2021 14:28
@straker straker changed the title add mix-blend-mode functions [WIP] feat(color-contrast): ass support for CSS mix-blend-mode Oct 22, 2021
@Zidious Zidious changed the title [WIP] feat(color-contrast): ass support for CSS mix-blend-mode [WIP] feat(color-contrast): add support for CSS mix-blend-mode Oct 22, 2021
@Zidious Zidious changed the title [WIP] feat(color-contrast): add support for CSS mix-blend-mode feat(color-contrast): add support for CSS mix-blend-mode Nov 12, 2021
@Zidious Zidious marked this pull request as ready for review November 12, 2021 19:20
Copy link
Contributor

@dylanb dylanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two questions, see comments

@@ -38,9 +38,251 @@ describe('color.flattenColors', function() {
assert.equal(flat5.alpha, 1);

var flat6 = axe.commons.color.flattenColors(quarterLightGreen, halfRed);
assert.equal(flat6.red, 96);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way were were actually blending the colours was not quite accurate. When you start adding alpha values to colours the way they are calculated is different. Opacity adds another step whereby the pre-multiplied computed new RGB values need to be divided by the new computed alpha, we were missing this step:

To extract the color component of a pre-multiplied value, the formula is reversed: Co = co / αo
source: https://www.w3.org/TR/compositing-1/#simplealphacompositing
helpful source: w3c/fxtf-drafts#440 (comment)

'rgb(223, 112, 96)',
'rgb(255, 128, 128)',
'rgb(191, 223, 191)',
'rgb(125, 38, 54)',
'rgb(179, 38, 0)',
'rgb(179, 0, 77)',
'rgb(143, 192, 80)',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change? Seems like a rounding difference of some sort.

Copy link
Contributor Author

@Zidious Zidious Nov 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was caused by #3226 (comment) and the threshold of rounding was impacted

@Zidious Zidious requested a review from dylanb November 23, 2021 20:57
@WilcoFiers WilcoFiers merged commit d497f40 into develop Dec 9, 2021
@WilcoFiers WilcoFiers deleted the mix-blend-mode branch December 9, 2021 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants