Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
@adobe/leonardo-contrast-colors
Advanced tools
Generate colors based on a desired contrast ratio
@adobe/leonardo-contrast-colors
This package contains all the functions for generating colors by target contrast ratio.
npm i @adobe/leonardo-contrast-colors
Pass your colors and desired ratios. See additional options below.
import { generateContrastColors } from '@adobe/leonardo-contrast-colors';
// returns rgb value
let colors = generateContrastColors({colorKeys: ["#ff00ff"], base: "#ffffff", ratios: [4.5]});
Primary function used to generate colors based on target contrast ratios. Parameters are destructured and need to be explicitly called, such as colorKeys: ["#f26322"]
.
generateContrastColors({colorKeys, base, ratios, colorspace})
colorKeys [array]: list of colors referenced to generate a lightness scale. Much like key frames, key colors are single points by which additional colors will be interpolated between.
base string: references the color value that the color is to be generated from.
ratios [array]: list of numbers to be used as target contrast ratios.
colorspace string: the colorspace in which the key colors will be interpolated within. Below are the available options:
You may notice the tool takes an input (target ratio) but most often outputs a contrast ratio slightly higher. This has to do with the available colors in the RGB color space, and the math associated with calculating these ratios.
For example let's look at blue and white. Blue: rgb(0, 0, 255) White: rgb(255, 255, 255) Contrast ratio: 8.59:1
If we change any one value in the RGB channel for either color, the ratio changes: Blue: rgb(0, 1, 255) White: rgb(255, 255, 255) Contrast ratio: 8.57:1
If 8.58 is input as the target ratio with the starting color of blue, the output will not be exact. This is exaggerated by the various colorspace interpolations.
Since the WCAG requirement is defined as a minimum contrast requirement, it should be fine to generate colors that are a little more accessible than the minimum.
This project is currently built using D3 color. Although functionality is comparable to Chroma.js, the choice of D3 color is based on the additional modules available for state-of-the-art color appearance models, such as CIE CAM02.
The createScale()
function is basically a wrapper function for creating a d3 linear scale for colors, with a few enhancements that aid in the generateContrastColors()
function.
The Leonardo web app leverages d3 for additional features such as generating 2d and 3d charts.
Contributions are welcomed! Read the Contributing Guide for more information.
You can run tests and watch for changes with:
yarn dev
This project is licensed under the Apache V2 License. See LICENSE for more information.
FAQs
Generate colors based on a desired contrast ratio
We found that @adobe/leonardo-contrast-colors demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 22 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.