Myndex
  • Member for 2 years, 7 months
  • Last seen more than a month ago
Stats
318
reputation
3k
reached
11
answers
0
questions
Loading…
About

APCA npm Package

One result of my last few years of research into human visual perepotion has been the creation of the Advanced Perceptual Contrast Algorithm for WCAG_3 (Silver).

While research continues, the public beta APCA npm package is now available: apca-w3

Install:

     npm i apca-w3

Usage:

And the API is trivially simple: send it two colors, it returns a signed INT of the Lc value (lightness contrast).

     Lc = APCAcontrast( sRGBtoY( textColor ), sRGBtoY( backgroundColor ) );

Implementation notes:

Color sent to the required parsing function sRGBtoY() can be a 3 or 6 character hex string #fff or a3b3d4 (hash # is optional but not required), a named CSS color (such as aquamarine), as rgb(99,122,14), or as a number 0x123456 or 15213412. Text color first, background color second — do not swap colors, as use case affects results. light text on a dark background returns a negative value.

For questions and comments please visit the main APCA repo discussion area.

Thank you!

Andy

Badges
This user doesn’t have any gold badges yet.
1
silver badge
7
bronze badges
7
Score
3
Posts
27
Posts %
6
Score
5
Posts
45
Posts %
5
Score
5
Posts
45
Posts %
4
Score
1
Posts
9
Posts %
4
Score
1
Posts
9
Posts %
3
Score
2
Posts
18
Posts %