npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pexip-engage-public/color-utils

v1.0.24

Published

**Warning**: This is a [pure ESM package](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)

Downloads

542

Readme

Color generator

Warning: This is a pure ESM package

ARIA-compliant for WCAG 2.0

The purpose of this color calculator is guarding the WCAG 2.0 rules when being provided with a foreground color (text color) and background-color (brand color) by calculating a shade that meets the requirements.

WAI-ARIA, the Accessible Rich Internet Applications Suite, defines a way to make Web content and Web applications more accessible to everyone. It especially helps with dynamic content and advanced user interface controls developed with HTML, JavaScript, and related technologies.

Contrast and color use are vital to accessibility. Users, including users with visual disabilities, must be able to perceive content on the page. It is important that all content on the page is legible to everyone.

Levels

There are 3 levels in Accessibility rules: A, AA, AAA. The more A's the more compliant it is.

  • A: Minimal compliance, mostly focuses on keyboard navigation and non-text alternatives.
  • AA: This is the most used rule and legally required level in multiple countries.
  • AAA: Though not a hard legal requirement (as of writing), this is the ideal conformance level which ensures that a page's or site's web content is accessible.

Understanding WCAG Contrast and Color Requirements

color contrast: In WCAG 2, contrast is a measure of the difference in perceived "luminance" or brightness between two colors (the phrase "color contrast" is never used). This brightness difference is expressed as a ratio ranging from 1:1 (e.g. white on white) to 21:1 (e.g., black on a white). To give a frame of reference, on a white background.

  • A or lowest: Does not focus on color contrast.
  • AA or midrange: The visual presentation of text and images of text has a contrast ratio of at least 4.5:1.
  • AAA or highest: The visual presentation of text and images of text has a contrast ratio of at least 7:1.

Installation

The color generator can be installed as an npm package:

$ npm install --save @pexip-engage-public/color-utils

or

$ yarn install @pexip-engage-public/color-utils

or

$ pnpm install @pexip-engage-public/color-utils

Basic usage

In this basic example, we pass our brandHex to the calculateColor

import { calculateColor } from "@pexip-engage-public/color-utils";

const brandHex = "#6366F1";
const newColor = calculateColor({ brandHex });

Parameters

interface Params {
  brandHex: string;
  textColor?: "FFF" | "000" | undefined;
  accessibilityLevel?: "midrange" | "highest" | undefined;
}

Where the accessibilitylevel is: AA = midrange AAA = highest

Example:

import { calculateColor } from "@pexip-engage-public/color-utils";

const brandHex = "#6366F1";
const newColor = calculateColor({ brandHex, textColor="000", accessibilityLevel = "midrange"  });