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

Implement Advanced Perceptual Contrast Algorithm (APCA) #562

Open
djfarly opened this issue Jan 27, 2021 · 3 comments
Open

Implement Advanced Perceptual Contrast Algorithm (APCA) #562

djfarly opened this issue Jan 27, 2021 · 3 comments

Comments

@djfarly
Copy link

djfarly commented Jan 27, 2021

Summary

Google Chrome added a new experimental feature to replace the AA/AAA contrast ratio guidelines with APCA.

In that spirit, it seems reasonable to me to add that algorithm to polished as well.

The Algorithm is said to be more context depended (font size, weight). I am not sure, whether Chrome uses those values as parameters for the calculation or just to make suggestions. (This needs investigation).

The standard implementation only takes two colors as input which seems to make the most sense to me, as polished is a color lib.

You can also check out this Demo, which is one of the more confusing things I've looked at.

Basic Example

getPerceptualContrast(color1: string, color2: string): number
import { getPerceptualContrast } from 'polished';

const perceptualContrast = getPerceptualContrast('#444', '#fff');

Reasoning

In the long run this may very well replace WCAG AA/AAA contrasts, as it is seemingly better suited for perceptual contrasts.

If used more it would presumably result in more accessible (color-contrast-wise) web in general.


I'd be happy to try and create a PR (following the standard implementation) if there is enough interest in this.

@djfarly
Copy link
Author

djfarly commented Jan 27, 2021

Note that it might make sense to wait a little since there seem to be changes to the algorithm still:
https://bugs.chromium.org/p/chromium/issues/detail?id=1121900#c26

@djfarly
Copy link
Author

djfarly commented Jan 27, 2021

@Myndex
Copy link

Myndex commented Nov 4, 2021

Hello, I just stumbled upon this issue thread. I wanted to mention a few related things.

  • APCA was developed independently as part of the future WCAG 3 standard.
    • APCA uses modern vision science and is perceptually uniform
    • Studies demonstrate that APCA for WCAG 3 works much better then WCAG 2
    • APCA can be used today, however, WCAG 3 is not the standard yet, and APCA it is not backwards compatible with WCAG 2
      • This is mainly an issue if you have a law to follow that demands WCAG 2 AA as a web standard
      • Unfortunately WCAG 2 is substantially incorrect in certain areas of perception due to its basis on older standards and technologies. It is due to this that APCA was developed as the replacement for use in WCAG 3, but only partial backwards compatibility is possible.
  • There is an APCA GitHub repo and the discussion tab is open if you have questions or comments.
  • The repo has the basic APCA code, which returns a perceptually uniform contrast value.
  • This iteration has been stable since February, future iterations of course planned.
    • While it is still pre-release beta, the general functioning is demonstrably useful.
    • This version is set for sRGB, a next iteration will change the inputs to allow any additive colorspace.
  • You CAN use APCA simply to evaluate a perceived contrast (such as Lc75). But ALSO:
    • There are a variety of lookup tables that can be used to relate a contrast to a font size and weight.
    • Rounding the contrast to an integer is allowed, and interpolation can be used with a lookup table.
  • For simplicity, you can also use the "simple key levels" method (Lc 45, 60, 75), which compares to WCAG 2 contrast (with one very light color) as:
    • Lc 45 is "sort of" like 3:1
    • Lc 60 is "sort of" like 4.5:1
    • Lc 75 is "sort of" like 7:1
  • Unlike WCAG 2, APCA is polarity sensitive, so the BG and TEXT colors must be sent to the correct inputs.

Please feel free to hit me up with any questions or comments.

Thank you,

Andy

Andrew Somers
W3 AGWG Invited Expert
Color Science Researcher
Myndex Perception Research

THE REVOLUTION WILL BE READABLE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants