-
Notifications
You must be signed in to change notification settings - Fork 779
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
fix(color-contrast): improve speed and accuracy of code blocks with syntax highlighting #2003
Conversation
@@ -14,8 +14,8 @@ describe('color.getForegroundColor', function() { | |||
|
|||
it('should return the blended color if it has alpha set', function() { | |||
fixture.innerHTML = | |||
'<div style="height: 40px; width: 30px; background-color: #800000;">' + | |||
'<div id="target" style="height: 20px; width: 15px; color: rgba(0, 0, 128, 0.5);' + | |||
'<div style="height: 40px; background-color: #800000;">' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to update these tests as my code changes made them more accurate than before. Before my changes, we would test only the first line of this fixture. However, if we look at the result of the fixture, we can see that there should be 3 background colors and 3 foreground colors, but we only calculate 1.
So I updated the tests to just focus on the single color with alpha/opacity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@straker walked me through the changes, when debugging FF & IE.
This looks good.
Code blocks with syntax highlighting could have large amounts of client rects, which would then cause it to take a few seconds each to process. Code blocks could also cause us lots of incomplete results with "partially obscured by another element."
The code changes fix the speed by focusing only on the client rects of the text nodes of the element rather than all client rects. Since each of the child nodes that have text nodes will be checked individually, there is no need for the main parent to also check those nodes as well. This reduced the large code block from 2000+ client rects to just <20, taking color contrast from running in 10+ seconds to <1 seconds.
It also adjusts the collision check to account for elements which lie exactly on the middle of the element being checked. This solved all the incomplete issues and they now return as proper pass/fail.
Closes issue: #1985
Reviewer checks
Required fields, to be filled out by PR reviewer(s)