Skip to content

Commit

Permalink
Use apca-w3 and colorparsley to calculate APCA values
Browse files Browse the repository at this point in the history
  • Loading branch information
sondr3 committed Jul 24, 2022
1 parent a20efc3 commit b21b93c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 206 deletions.
5 changes: 4 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"type": "module",
"dependencies": {
"@types/chroma-js": "2.1.4",
"apca-w3": "0.1.9",
"chroma-js": "^2.4.2",
"colorparsley": "0.1.8",
"nanoid": "^3.3.3"
}
}
10 changes: 3 additions & 7 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { BaseColor } from './stores';
import chroma, { Color } from 'chroma-js';
import { APCAcontrast } from './vendor/APCAonly.98e_d12e';
import { calcAPCA } from 'apca-w3';
import { colorParsley } from 'colorparsley';

const roundTo = (num: number, multiplier: number): number => Math.round(num * multiplier) / multiplier;

Expand Down Expand Up @@ -33,14 +34,9 @@ export function sortBaseColors(a: BaseColor, b: BaseColor): number {
}
}

export const colorStringToHex = (color: string): number => {
color = color.replace('#', '0x');
return parseInt(color, 16);
};

export const getWcag2CR = (fg: string, bg: string): number => roundTo10th(chroma.contrast(fg, bg));

export const getWcag3CR = (fg: string, bg: string): number =>
roundToWhole(APCAcontrast(colorStringToHex(bg), colorStringToHex(fg)));
roundToWhole(calcAPCA(colorParsley(fg), colorParsley(bg)));

export const useProperMinus = (num: number): string => num.toString().replace('-', '\u2212');
198 changes: 0 additions & 198 deletions src/vendor/APCAonly.98e_d12e.ts

This file was deleted.

0 comments on commit b21b93c

Please sign in to comment.