Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
@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
The npm package @adobe/leonardo-contrast-colors receives a total of 3,148 weekly downloads. As such, @adobe/leonardo-contrast-colors popularity was classified as popular.
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.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.