Skip to content

v0.4.0: All about contrast! 馃敵馃敳

Compare
Choose a tag to compare
@LeaVerou LeaVerou released this 06 Aug 15:10
· 341 commits to main since this release

The most major change in this release is new contrast methods! Until v0.3.0, Color.js only supported WCAG 2.1 contrast, which has several known problems. In this release, @svgeesus implemented four more contrast methods, and wrote all about them. There are both specific methods you can use (e.g. background.contrastAPCA(foreground) / with the OO API and contrastAPCA(background, foreground) with the procedural API as well as a generic contrast() method that accepts a parameter for the contrast algorithm (e.g. color.contrast(color2, "Weber") with the OO API or contrast(color, color2, "Weber") with the procedural API).

Breaking change: color.contrast() / contrast() will now not work without an explicit contrast algorithm, which is on par with the recent changes in CSS Color's contrast-color() function. If you try to use it without an algorithm, it will produce a TypeError listing all supported contrast algorithms.

image

Demo: To celebrate this addition, we've added a new demo app that calculates if white or black produces higher contrast over a variety of colors with the contrast algorithm you select!

image

Other changes

  • The deltaE() function now imports all deltaE methods. If you need a more tree-shakable deltaE API, import the individual methods directly.
  • The method argument in deltaE() is now case-insensitive
  • The chromaticity module has been fixed to work correctly with the procedural API

Merged Pull requests

New Contributors

Full Changelog: v0.3.0...v0.4.0