@@ -26,7 +26,7 @@ import {
2626
2727 OKLab ,
2828 OKLCH as OKLCHSpace ,
29- contrast ,
29+ contrastWCAG21 ,
3030 P3
3131} from 'colorjs.io/fn' ;
3232import HSBSpace from './color_spaces/hsb.js' ;
@@ -294,15 +294,22 @@ class Color {
294294 }
295295 return colorString ;
296296 }
297- /**
297+
298+ /**
298299 * Checks the contrast between two colors, to make sure that they
299300 * are different enough to be readable. The result of this function is
300- * a number that can be compared to `COLOR_CONTRAST_THRESHOLD_AA`,
301- * or to `COLOR_CONTRAST_THRESHOLD_AAA`. Shapes and UI elements should have color
302- * contrast at least `COLOR_CONTRAST_THRESHOLD_AA`, and text
303- * benefits from higher contrast of at least `COLOR_CONTRAST_THRESHOLD_AAA`.
301+ * a color contrast ratio that can be compared to `COLOR_CONTRAST_MINIMUM_GRAPHICS`,
302+ * or to `COLOR_CONTRAST_MINIMUM_TEXT`. The higher the ratio, the more
303+ * different colors are, and the more legible to a user.
304+ *
305+ * Graphics, interface elements, and large text should have a color
306+ * contrast ratio of at least 4.5 (`COLOR_CONTRAST_MINIMUM_GRAPHICS`)
307+ *
308+ * Smaller text - less than at least 14 point or 19 pixels -
309+ * should have a color contrast ratio of at least 7
310+ * (`COLOR_CONTRAST_MINIMUM_TEXT`)
304311 *
305- * You can also explore this
312+ * The constants are based on WCAG AAA recommendations, which you can also explore in this
306313 * <a href="https://webaim.org/resources/contrastchecker/">contrast checker tool</a>.
307314 * The contrast function in p5.js uses the WCAG 2.1 method the
308315 * <a href="https://colorjs.io/docs/contrast.html">color.js contrast</a>
@@ -359,9 +366,9 @@ class Color {
359366 * newFg1Color = color(random(255), random(255), random(255));
360367 * newFg2Color = color(random(255), random(255), random(255));
361368 * if (
362- * newBgColor.contrast(newFg2Color) > COLOR_CONTRAST_THRESHOLD_AAA &&
363- * newBgColor.contrast(newFg1Color) > COLOR_CONTRAST_THRESHOLD_AA &&
364- * newBgColor.contrast(newFg1Color) < COLOR_CONTRAST_THRESHOLD_AAA ){
369+ * newBgColor.contrast(newFg2Color) >= COLOR_CONTRAST_MINIMUM_TEXT &&
370+ * newBgColor.contrast(newFg1Color) >= COLOR_CONTRAST_MINIMUM_GRAPHICS &&
371+ * newBgColor.contrast(newFg1Color) < COLOR_CONTRAST_MINIMUM_TEXT ){
365372 *
366373 * bgColor = newBgColor;
367374 * fg1Color = newFg1Color;
0 commit comments