@pexip-engage-public/color-utils 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,44 @@
1
+ # @pexip-engage-public/color-utils
2
+
3
+ ## 0.0.7
4
+
5
+ ### Patch Changes
6
+
7
+ - a17130f3: chore: fix publishing setup
8
+
9
+ ## 0.0.6
10
+
11
+ ### Patch Changes
12
+
13
+ - 48abc995: chore: cleanup monorepo setup
14
+ - 1681e3ed: chore: update "author" & "license" fields in package.json
15
+
16
+ ## 0.0.5
17
+
18
+ ### Patch Changes
19
+
20
+ - 8a214621: chore: add all peerDeps correctly to packages
21
+
22
+ ## 0.0.4
23
+
24
+ ### Patch Changes
25
+
26
+ - 6fabbfa5: chore: update minor deps
27
+
28
+ ## 0.0.3
29
+
30
+ ### Patch Changes
31
+
32
+ - c36e435a: dependencies: update non-major dependencies
33
+
34
+ ## 0.0.2
35
+
36
+ ### Patch Changes
37
+
38
+ - 09cf3c2a: fix public npm publishes
39
+
40
+ ## 0.0.1
41
+
42
+ ### Patch Changes
43
+
44
+ - b3f6785b: chore: extract out package for color generation
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Color generator
2
+
3
+ ## ARIA-compliant for WCAG 2.0
4
+
5
+ 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.
6
+
7
+ 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.
8
+
9
+ 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.
10
+
11
+ ### Levels
12
+
13
+ There are 3 levels in Accessibility rules: A, AA, AAA. The more A's the more compliant it is.
14
+
15
+ - `A`: Minimal compliance, mostly focuses on keyboard navigation and non-text alternatives.
16
+ - `AA`: This is the most used rule and legally required level in multiple countries.
17
+ - `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.
18
+
19
+ ### Understanding WCAG Contrast and Color Requirements
20
+
21
+ `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.
22
+
23
+ - `A` or `lowest`: Does not focus on color contrast.
24
+ - `AA` or `midrange`: The visual presentation of text and images of text has a contrast ratio of at least 4.5:1.
25
+ - `AAA` or `highest`: The visual presentation of text and images of text has a contrast ratio of at least 7:1.
26
+
27
+ ## Installation
28
+
29
+ The color generator can be installed as an [npm package](https://github.com/skedify/frontend-mono/tree/develop/packages/color-utils):
30
+
31
+ ```bash
32
+ $ npm install --save @pexip-engage-public/color-utils
33
+ ```
34
+
35
+ or
36
+
37
+ ```bash
38
+ $ yarn install @pexip-engage-public/color-utils
39
+ ```
40
+
41
+ or
42
+
43
+ ```bash
44
+ $ pnpm install @pexip-engage-public/color-utils
45
+ ```
46
+
47
+ ## Basic usage
48
+
49
+ In this basic example, we pass our brandHex to the `calculateColor`
50
+
51
+ ```js
52
+ import { calculateColor } from "@pexip-engage-public/color-utils";
53
+
54
+ const brandHex = "#6366F1";
55
+ const newColor = calculateColor({ brandHex });
56
+ ```
57
+
58
+ ## Parameters
59
+
60
+ ```ts
61
+ interface Params {
62
+ brandHex: string;
63
+ textColor?: "FFF" | "000" | undefined;
64
+ accessibilityLevel?: "midrange" | "highest" | undefined;
65
+ }
66
+ ```
67
+
68
+ Where the accessibilitylevel is:
69
+ `AA` = midrange
70
+ `AAA` = highest
71
+
72
+ Example:
73
+
74
+ ```js
75
+ import { calculateColor } from "@pexip-engage-public/color-utils";
76
+
77
+ const brandHex = "#6366F1";
78
+ const newColor = calculateColor({ brandHex, textColor="000", accessibilityLevel = "midrange" });
79
+ ```
package/dist/index.mjs ADDED
@@ -0,0 +1,94 @@
1
+ // src/color.ts
2
+ import { hex as convertHexTo2, hsl as convertHslTo } from "color-convert";
3
+ import warning from "tiny-warning";
4
+
5
+ // src/wcag.ts
6
+ import { hex as convertHexTo } from "color-convert";
7
+
8
+ // src/hexValidators.ts
9
+ import invariant from "tiny-invariant";
10
+ function isValidColorCode(hex) {
11
+ return isValidSixDigitColorCode(hex) || isValidThreeDigitColorCode(hex);
12
+ }
13
+ function isValidSixDigitColorCode(hex) {
14
+ return /^(#)?([0-9a-fA-F]{6})?$/.test(hex);
15
+ }
16
+ function isValidThreeDigitColorCode(hex) {
17
+ return /^(#)?([0-9a-fA-F]{3})?$/.test(hex);
18
+ }
19
+ function ensureSixDigitHex(hex) {
20
+ invariant(isValidColorCode(hex), `${hex} is not a valid hex code`);
21
+ const strippedHex = hex.replace("#", "");
22
+ if (isValidSixDigitColorCode(hex)) {
23
+ return `#${strippedHex}`;
24
+ }
25
+ return "#" + strippedHex[0] + strippedHex[0] + strippedHex[1] + strippedHex[1] + strippedHex[2] + strippedHex[2];
26
+ }
27
+
28
+ // src/wcag.ts
29
+ var WCAG_RATIO_AA_LG = 3;
30
+ var WCAG_RATIO_AA_SM = 4.5;
31
+ var WCAG_RATIO_AAA_LG = 4.5;
32
+ var WCAG_RATIO_AAA_SM = 7;
33
+ var WCAG_FONT_CUTOFF = 18;
34
+ function calculateAccessibilityLevel({
35
+ bgColor,
36
+ fontSize = 14,
37
+ textColor = "#FFFFFF"
38
+ }) {
39
+ const contrastRatio = calculateContrastRatio(
40
+ convertHexTo.rgb(ensureSixDigitHex(bgColor)),
41
+ convertHexTo.rgb(ensureSixDigitHex(textColor))
42
+ );
43
+ if (fontSize >= WCAG_FONT_CUTOFF) {
44
+ return contrastRatio >= WCAG_RATIO_AAA_LG ? "highest" /* WCAG_AAA */ : contrastRatio >= WCAG_RATIO_AA_LG ? "midrange" /* WCAG_AA */ : "lowest" /* WCAG_A */;
45
+ }
46
+ return contrastRatio >= WCAG_RATIO_AAA_SM ? "highest" /* WCAG_AAA */ : contrastRatio >= WCAG_RATIO_AA_SM ? "midrange" /* WCAG_AA */ : "lowest" /* WCAG_A */;
47
+ }
48
+ function calculateContrastRatio(rgb1, rgb2) {
49
+ const lum1 = calculateLuminance(rgb1[0], rgb1[1], rgb1[2]);
50
+ const lum2 = calculateLuminance(rgb2[0], rgb2[1], rgb2[2]);
51
+ const brightest = Math.max(lum1, lum2);
52
+ const darkest = Math.min(lum1, lum2);
53
+ return (brightest + 0.05) / (darkest + 0.05);
54
+ }
55
+ function calculateLuminance(r, g, b) {
56
+ const a = [r, g, b].map((v) => {
57
+ v /= 255;
58
+ return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
59
+ });
60
+ return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
61
+ }
62
+
63
+ // src/color.ts
64
+ var SHADE_SHIFT_AMOUNT = 1;
65
+ function calculateColor({
66
+ brandHex,
67
+ textColor,
68
+ accessibilityLevel = "midrange" /* WCAG_AA */
69
+ }) {
70
+ warning(
71
+ accessibilityLevel !== "highest" /* WCAG_AAA */,
72
+ "Currently WCAG_AAA is not required. Falling back to WCAG_AA"
73
+ );
74
+ const brandHexWCAG = calculateAccessibilityLevel({
75
+ bgColor: brandHex,
76
+ textColor
77
+ });
78
+ if (brandHexWCAG === "lowest" /* WCAG_A */) {
79
+ return calculateColor({
80
+ brandHex: darkenOrLightenShade(brandHex, textColor),
81
+ textColor,
82
+ accessibilityLevel
83
+ });
84
+ }
85
+ return brandHex;
86
+ }
87
+ function darkenOrLightenShade(color, textColor = "FFF" /* WHITE */) {
88
+ const hsl = convertHexTo2.hsl(color);
89
+ hsl[2] = textColor === "FFF" /* WHITE */ ? Math.max(hsl[2] - SHADE_SHIFT_AMOUNT, 0) : Math.min(hsl[2] + SHADE_SHIFT_AMOUNT, 1);
90
+ return "#" + convertHslTo.hex(hsl);
91
+ }
92
+ export {
93
+ calculateColor
94
+ };
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@pexip-engage-public/color-utils",
3
+ "version": "0.0.7",
4
+ "description": "",
5
+ "homepage": "https://github.com/skedify/frontend-mono/tree/develop/packages/color-utils#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/skedify/frontend-mono/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/skedify/frontend-mono.git",
12
+ "directory": "packages/color-utils"
13
+ },
14
+ "license": "UNLICENSED",
15
+ "author": {
16
+ "name": "Pexip Engage",
17
+ "email": "info@pexip.com",
18
+ "url": "https://engage.pexip.com"
19
+ },
20
+ "sideEffects": false,
21
+ "exports": {
22
+ ".": {
23
+ "import": "./dist/index.mjs"
24
+ },
25
+ "./src/index.ts": {
26
+ "import": "./src/index.ts"
27
+ }
28
+ },
29
+ "module": "./dist/index.mjs",
30
+ "types": "./typings/index.d.ts",
31
+ "files": [
32
+ "dist",
33
+ "CHANGELOG.md",
34
+ "typings",
35
+ "src"
36
+ ],
37
+ "jest": {
38
+ "preset": "@pexip-engage/scripts/jest/node"
39
+ },
40
+ "dependencies": {
41
+ "color-convert": "^2.0.1"
42
+ },
43
+ "devDependencies": {
44
+ "@pexip-engage/scripts": "0.0.17",
45
+ "@pexip-engage/tsconfig": "0.0.5",
46
+ "@types/color-convert": "^2.0.0",
47
+ "eslint-config-pexip-engage": "0.0.3",
48
+ "tiny-invariant": "^1.3.0",
49
+ "tiny-warning": "^1.0.3"
50
+ },
51
+ "peerDependencies": {
52
+ "tiny-invariant": "^1.3.0",
53
+ "tiny-warning": "^1.0.3"
54
+ },
55
+ "volta": {
56
+ "extends": "../../package.json"
57
+ },
58
+ "publishConfig": {
59
+ "access": "public",
60
+ "registry": "https://registry.npmjs.org"
61
+ },
62
+ "scripts": {
63
+ "build": "tsup",
64
+ "clean": "rm -rf .turbo node_modules dist typings",
65
+ "dev": "concurrently \"tsc -w\" \"tsup --watch\"",
66
+ "lint": "cross-env TIMING=1 eslint .",
67
+ "lint:fix": "pnpm lint --fix",
68
+ "test": "jest --passWithNoTests",
69
+ "typecheck": "tsc"
70
+ }
71
+ }
@@ -0,0 +1,48 @@
1
+ import { calculateColor } from "./color";
2
+
3
+ const WCAG_AA = [
4
+ { hex: "#000000", isAA: true, expected: "#000000" },
5
+ { hex: "#00008F", isAA: true, expected: "#00008F" },
6
+ { hex: "#5C5C5B", isAA: true, expected: "#5C5C5B" },
7
+ { hex: "#7843ab", isAA: true, expected: "#7843ab" },
8
+ { hex: "#ce0303", isAA: true, expected: "#ce0303" },
9
+ { hex: "#07488b", isAA: true, expected: "#07488b" },
10
+ { hex: "#000000", isAA: true, expected: "#000000" },
11
+ { hex: "#e20000", isAA: true, expected: "#e20000" },
12
+ { hex: "#d42e41", isAA: true, expected: "#d42e41" },
13
+ { hex: "#870930", isAA: true, expected: "#870930" },
14
+ { hex: "#080070", isAA: true, expected: "#080070" },
15
+ { hex: "#3a5c76", isAA: true, expected: "#3a5c76" },
16
+ { hex: "#d71e3c", isAA: true, expected: "#d71e3c" },
17
+ { hex: "#9e1c12", isAA: true, expected: "#9e1c12" },
18
+ { hex: "#007279", isAA: true, expected: "#007279" },
19
+ { hex: "#ae0247", isAA: true, expected: "#ae0247" },
20
+ { hex: "#003D78", isAA: true, expected: "#003D78" },
21
+ ];
22
+
23
+ const WCAG_A = [
24
+ { hex: "#21b7c5", isAA: false, expected: "#18828C" },
25
+ { hex: "#51b0a8", isAA: false, expected: "#397F7C" }, // TODO: double check me (why not 397F7B?)
26
+ { hex: "#2898cc", isAA: false, expected: "#217CA6" },
27
+ { hex: "#1DFF76", isAA: false, expected: "#008535" },
28
+ { hex: "#08c", isAA: false, expected: "#007AB8" },
29
+ { hex: "#00b287", isAA: false, expected: "#008566" },
30
+ { hex: "#79BB2B", isAA: false, expected: "#52811D" },
31
+ { hex: "#fbc7ab", isAA: false, expected: "#CD4A04" },
32
+ { hex: "#8dc63f", isAA: false, expected: "#597E26" },
33
+ { hex: "#a9937a", isAA: false, expected: "#887359" },
34
+ { hex: "#008dcd", isAA: false, expected: "#007DB8" },
35
+ ];
36
+
37
+ describe("calculateColor", () => {
38
+ it.each(WCAG_AA)("does not convert WCAG_AA hex codes", ({ hex: brandHex }) => {
39
+ expect(calculateColor({ brandHex })).toEqual(brandHex);
40
+ });
41
+
42
+ it.each(WCAG_A)(
43
+ "does convert non-WCAG_AA hex codes to WCAG_AA",
44
+ ({ expected, hex: brandHex }) => {
45
+ expect(calculateColor({ brandHex })).toEqual(expected);
46
+ }
47
+ );
48
+ });
package/src/color.ts ADDED
@@ -0,0 +1,65 @@
1
+ import { hex as convertHexTo, hsl as convertHslTo } from "color-convert";
2
+ import { HEX } from "color-convert/conversions";
3
+ import warning from "tiny-warning";
4
+
5
+ import { AccessibilityLevel, calculateAccessibilityLevel } from "./wcag";
6
+
7
+ enum TextColors {
8
+ WHITE = "FFF",
9
+ BLACK = "000",
10
+ }
11
+
12
+ interface Params {
13
+ brandHex: HEX;
14
+ textColor?: TextColors;
15
+ accessibilityLevel?: AccessibilityLevel.WCAG_AA | AccessibilityLevel.WCAG_AAA;
16
+ }
17
+
18
+ const SHADE_SHIFT_AMOUNT = 1;
19
+
20
+ // TODO @Ben: what does this mean and how can we implement this?
21
+ // if we would adapt text (white or black) on top of color:
22
+ // (we would also have to export the chosen textcolor)
23
+ // find whether color is on light side or dark side by finding ratio with both black and white
24
+ // const lightTextRatio = calculateContrastRatio({ bgColor: brandHex, textColor: "FFF" });
25
+ // const darkTextRatio = calculateContrastRatio({ bgColor: brandHex, textColor: "000" });
26
+ // const prefTextColor = lightTextRatio >= darkTextRatio ? textColors.WHITE : textColors.BLACK;
27
+
28
+ export function calculateColor({
29
+ brandHex,
30
+ textColor,
31
+ accessibilityLevel = AccessibilityLevel.WCAG_AA,
32
+ }: Params): HEX {
33
+ warning(
34
+ accessibilityLevel !== AccessibilityLevel.WCAG_AAA,
35
+ "Currently WCAG_AAA is not required. Falling back to WCAG_AA"
36
+ );
37
+
38
+ const brandHexWCAG = calculateAccessibilityLevel({
39
+ bgColor: brandHex,
40
+ textColor,
41
+ });
42
+
43
+ // If color is not WCAG_AAA or WCAG_AA calculate again
44
+ if (brandHexWCAG === AccessibilityLevel.WCAG_A) {
45
+ return calculateColor({
46
+ brandHex: darkenOrLightenShade(brandHex, textColor),
47
+ textColor,
48
+ accessibilityLevel,
49
+ });
50
+ }
51
+
52
+ return brandHex;
53
+ }
54
+
55
+ // Make brand shade darker / lighter
56
+ function darkenOrLightenShade(color: HEX, textColor: TextColors = TextColors.WHITE): HEX {
57
+ const hsl = convertHexTo.hsl(color);
58
+
59
+ hsl[2] =
60
+ textColor === TextColors.WHITE
61
+ ? Math.max(hsl[2] - SHADE_SHIFT_AMOUNT, 0)
62
+ : Math.min(hsl[2] + SHADE_SHIFT_AMOUNT, 1);
63
+
64
+ return "#" + convertHslTo.hex(hsl);
65
+ }
@@ -0,0 +1,79 @@
1
+ import {
2
+ ensureSixDigitHex,
3
+ isValidColorCode,
4
+ isValidSixDigitColorCode,
5
+ isValidThreeDigitColorCode,
6
+ } from "./hexValidators";
7
+
8
+ describe("isValidThreeDigitColorCode", () => {
9
+ it("returns false when a 6-digit hex code is passed", () => {
10
+ expect(isValidThreeDigitColorCode("#FFFFFF")).toBeFalsy();
11
+ });
12
+
13
+ it("returns false when a random-digit hex code is passed", () => {
14
+ expect(isValidThreeDigitColorCode("#FFFF")).toBeFalsy();
15
+ });
16
+
17
+ it("returns true when a string without '#' is passed", () => {
18
+ expect(isValidThreeDigitColorCode("FFF")).toBeTruthy();
19
+ });
20
+
21
+ it("returns true when a valid 3-digit hex code is passed", () => {
22
+ expect(isValidThreeDigitColorCode("#FFF")).toBeTruthy();
23
+ });
24
+ });
25
+
26
+ describe("isValidSixDigitColorCode", () => {
27
+ it("returns false when a 3-digit hex code is passed", () => {
28
+ expect(isValidSixDigitColorCode("#FFF")).toBeFalsy();
29
+ });
30
+
31
+ it("returns false when a random-digit hex code is passed", () => {
32
+ expect(isValidSixDigitColorCode("#FFFF")).toBeFalsy();
33
+ });
34
+
35
+ it("returns true when a string without '#' is passed", () => {
36
+ expect(isValidSixDigitColorCode("FFFFFF")).toBeTruthy();
37
+ });
38
+
39
+ it("returns true when a valid 6-digit hex code is passed", () => {
40
+ expect(isValidSixDigitColorCode("#FFFFFF")).toBeTruthy();
41
+ });
42
+ });
43
+
44
+ describe("isValidColorCode", () => {
45
+ it("returns false when a random-digit hex code is passed", () => {
46
+ expect(isValidColorCode("#FFFF")).toBeFalsy();
47
+ });
48
+
49
+ it("returns false when a 6-digit string without '#' is passed", () => {
50
+ expect(isValidColorCode("FFFFFF")).toBeTruthy();
51
+ });
52
+
53
+ it("returns false when a 3-digit string without '#' is passed", () => {
54
+ expect(isValidColorCode("FFF")).toBeTruthy();
55
+ });
56
+
57
+ it("returns true when a valid 3-digit hex code is passed", () => {
58
+ expect(isValidColorCode("#FFF")).toBeTruthy();
59
+ });
60
+
61
+ it("returns true when a valid 6-digit hex code is passed", () => {
62
+ expect(isValidColorCode("#FFFFFF")).toBeTruthy();
63
+ });
64
+ });
65
+
66
+ describe("ensureSixDigitHex", () => {
67
+ it("throws an error when an invalid hex code is passed", () => {
68
+ expect(() => {
69
+ ensureSixDigitHex("FFFF");
70
+ }).toThrow();
71
+ });
72
+
73
+ it("returns a six-digit hex code with '#'", () => {
74
+ expect(ensureSixDigitHex("FFF")).toEqual("#FFFFFF");
75
+ expect(ensureSixDigitHex("#FFF")).toEqual("#FFFFFF");
76
+ expect(ensureSixDigitHex("FFFFFF")).toEqual("#FFFFFF");
77
+ expect(ensureSixDigitHex("#FFFFFF")).toEqual("#FFFFFF");
78
+ });
79
+ });
@@ -0,0 +1,33 @@
1
+ import invariant from "tiny-invariant";
2
+
3
+ export function isValidColorCode(hex: string): boolean {
4
+ return isValidSixDigitColorCode(hex) || isValidThreeDigitColorCode(hex);
5
+ }
6
+
7
+ export function isValidSixDigitColorCode(hex: string): boolean {
8
+ return /^(#)?([0-9a-fA-F]{6})?$/.test(hex);
9
+ }
10
+
11
+ export function isValidThreeDigitColorCode(hex: string): boolean {
12
+ return /^(#)?([0-9a-fA-F]{3})?$/.test(hex);
13
+ }
14
+
15
+ export function ensureSixDigitHex(hex: string): string {
16
+ invariant(isValidColorCode(hex), `${hex} is not a valid hex code`);
17
+
18
+ const strippedHex = hex.replace("#", "");
19
+
20
+ if (isValidSixDigitColorCode(hex)) {
21
+ return `#${strippedHex}`;
22
+ }
23
+
24
+ return (
25
+ "#" +
26
+ strippedHex[0] +
27
+ strippedHex[0] +
28
+ strippedHex[1] +
29
+ strippedHex[1] +
30
+ strippedHex[2] +
31
+ strippedHex[2]
32
+ );
33
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { calculateColor } from "./color";
package/src/wcag.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { hex as convertHexTo } from "color-convert";
2
+ import { RGB } from "color-convert/conversions";
3
+
4
+ import { ensureSixDigitHex } from "./hexValidators";
5
+
6
+ const WCAG_RATIO_AA_LG = 3.0;
7
+ const WCAG_RATIO_AA_SM = 4.5;
8
+ const WCAG_RATIO_AAA_LG = 4.5;
9
+ const WCAG_RATIO_AAA_SM = 7.0;
10
+ const WCAG_FONT_CUTOFF = 18;
11
+
12
+ type Params = {
13
+ bgColor: string;
14
+ textColor?: string;
15
+ fontSize?: number;
16
+ };
17
+
18
+ // There are 3 levels in Accessibility rules: A, AA, AAA. The more A's the more strict it is.
19
+ // We are meeting the AA levels because that's the level that is legally required for certain sites.
20
+ export enum AccessibilityLevel {
21
+ WCAG_A = "lowest",
22
+ WCAG_AA = "midrange",
23
+ WCAG_AAA = "highest",
24
+ }
25
+
26
+ export function calculateAccessibilityLevel({
27
+ bgColor,
28
+ fontSize = 14,
29
+ textColor = "#FFFFFF", // Text color depends on the theme. Skedify only has light for now.
30
+ }: Params): AccessibilityLevel {
31
+ const contrastRatio = calculateContrastRatio(
32
+ convertHexTo.rgb(ensureSixDigitHex(bgColor)),
33
+ convertHexTo.rgb(ensureSixDigitHex(textColor))
34
+ );
35
+
36
+ // TODO: improve me
37
+ if (fontSize >= WCAG_FONT_CUTOFF) {
38
+ return contrastRatio >= WCAG_RATIO_AAA_LG
39
+ ? AccessibilityLevel.WCAG_AAA
40
+ : contrastRatio >= WCAG_RATIO_AA_LG
41
+ ? AccessibilityLevel.WCAG_AA
42
+ : AccessibilityLevel.WCAG_A;
43
+ }
44
+
45
+ return contrastRatio >= WCAG_RATIO_AAA_SM
46
+ ? AccessibilityLevel.WCAG_AAA
47
+ : contrastRatio >= WCAG_RATIO_AA_SM
48
+ ? AccessibilityLevel.WCAG_AA
49
+ : AccessibilityLevel.WCAG_A;
50
+ }
51
+
52
+ // TODO: formula / documentation?
53
+ export function calculateContrastRatio(rgb1: RGB, rgb2: RGB): number {
54
+ const lum1 = calculateLuminance(rgb1[0], rgb1[1], rgb1[2]);
55
+ const lum2 = calculateLuminance(rgb2[0], rgb2[1], rgb2[2]);
56
+
57
+ const brightest = Math.max(lum1, lum2);
58
+ const darkest = Math.min(lum1, lum2);
59
+
60
+ return (brightest + 0.05) / (darkest + 0.05);
61
+ }
62
+
63
+ // See https://www.w3.org/TR/WCAG20-TECHS/G17.html for official formula
64
+ function calculateLuminance(r: number, g: number, b: number): number {
65
+ const a = [r, g, b].map((v) => {
66
+ v /= 255;
67
+
68
+ return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
69
+ });
70
+
71
+ return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
72
+ }
@@ -0,0 +1,14 @@
1
+ import { HEX } from "color-convert/conversions";
2
+ import { AccessibilityLevel } from "./wcag";
3
+ declare enum TextColors {
4
+ WHITE = "FFF",
5
+ BLACK = "000"
6
+ }
7
+ interface Params {
8
+ brandHex: HEX;
9
+ textColor?: TextColors;
10
+ accessibilityLevel?: AccessibilityLevel.WCAG_AA | AccessibilityLevel.WCAG_AAA;
11
+ }
12
+ export declare function calculateColor({ brandHex, textColor, accessibilityLevel, }: Params): HEX;
13
+ export {};
14
+ //# sourceMappingURL=color.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../src/color.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAGhD,OAAO,EAAE,kBAAkB,EAA+B,MAAM,QAAQ,CAAC;AAEzE,aAAK,UAAU;IACb,KAAK,QAAQ;IACb,KAAK,QAAQ;CACd;AAED,UAAU,MAAM;IACd,QAAQ,EAAE,GAAG,CAAC;IACd,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC,OAAO,GAAG,kBAAkB,CAAC,QAAQ,CAAC;CAC/E;AAYD,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,SAAS,EACT,kBAA+C,GAChD,EAAE,MAAM,GAAG,GAAG,CAqBd"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=color.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.test.d.ts","sourceRoot":"","sources":["../src/color.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export declare function isValidColorCode(hex: string): boolean;
2
+ export declare function isValidSixDigitColorCode(hex: string): boolean;
3
+ export declare function isValidThreeDigitColorCode(hex: string): boolean;
4
+ export declare function ensureSixDigitHex(hex: string): string;
5
+ //# sourceMappingURL=hexValidators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hexValidators.d.ts","sourceRoot":"","sources":["../src/hexValidators.ts"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/D;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAkBrD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=hexValidators.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hexValidators.test.d.ts","sourceRoot":"","sources":["../src/hexValidators.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export { calculateColor } from "./color";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1 @@
1
+ {"program":{"fileNames":["../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2021.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2022.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.esnext.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2021.string.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2022.array.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2022.error.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2022.object.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.es2022.string.d.ts","../../../node_modules/.pnpm/typescript@4.8.4/node_modules/typescript/lib/lib.esnext.intl.d.ts","../../../node_modules/.pnpm/@types+react@18.0.21/node_modules/@types/react/global.d.ts","../../../node_modules/.pnpm/csstype@3.1.0/node_modules/csstype/index.d.ts","../../../node_modules/.pnpm/@types+prop-types@15.7.5/node_modules/@types/prop-types/index.d.ts","../../../node_modules/.pnpm/@types+scheduler@0.16.2/node_modules/@types/scheduler/tracing.d.ts","../../../node_modules/.pnpm/@types+react@18.0.21/node_modules/@types/react/index.d.ts","../../../node_modules/.pnpm/@types+react@18.0.21/node_modules/@types/react/jsx-runtime.d.ts","../../../node_modules/.pnpm/@types+color-name@1.1.1/node_modules/@types/color-name/index.d.ts","../../../node_modules/.pnpm/@types+color-convert@2.0.0/node_modules/@types/color-convert/conversions.d.ts","../../../node_modules/.pnpm/@types+color-convert@2.0.0/node_modules/@types/color-convert/route.d.ts","../../../node_modules/.pnpm/@types+color-convert@2.0.0/node_modules/@types/color-convert/index.d.ts","../../../node_modules/.pnpm/tiny-warning@1.0.3/node_modules/tiny-warning/src/index.d.ts","../../../node_modules/.pnpm/tiny-invariant@1.3.0/node_modules/tiny-invariant/dist/tiny-invariant.d.ts","../src/hexValidators.ts","../src/wcag.ts","../src/color.ts","../src/color.test.ts","../src/hexValidators.test.ts","../src/index.ts","../../../node_modules/.pnpm/@types+eslint@8.4.3/node_modules/@types/eslint/helpers.d.ts","../../../node_modules/.pnpm/@types+estree@0.0.51/node_modules/@types/estree/index.d.ts","../../../node_modules/.pnpm/@types+json-schema@7.0.11/node_modules/@types/json-schema/index.d.ts","../../../node_modules/.pnpm/@types+eslint@8.4.3/node_modules/@types/eslint/index.d.ts","../../../node_modules/.pnpm/@types+eslint-scope@3.7.3/node_modules/@types/eslint-scope/index.d.ts","../../../node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/index.d.ts","../../../node_modules/.pnpm/jest-diff@27.5.1/node_modules/jest-diff/build/cleanupSemantic.d.ts","../../../node_modules/.pnpm/pretty-format@27.5.1/node_modules/pretty-format/build/types.d.ts","../../../node_modules/.pnpm/pretty-format@27.5.1/node_modules/pretty-format/build/index.d.ts","../../../node_modules/.pnpm/jest-diff@27.5.1/node_modules/jest-diff/build/types.d.ts","../../../node_modules/.pnpm/jest-diff@27.5.1/node_modules/jest-diff/build/diffLines.d.ts","../../../node_modules/.pnpm/jest-diff@27.5.1/node_modules/jest-diff/build/printDiffs.d.ts","../../../node_modules/.pnpm/jest-diff@27.5.1/node_modules/jest-diff/build/index.d.ts","../../../node_modules/.pnpm/jest-matcher-utils@27.5.1/node_modules/jest-matcher-utils/build/index.d.ts","../../../node_modules/.pnpm/@types+jest@27.5.2/node_modules/@types/jest/index.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/assert.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/assert/strict.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/globals.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/async_hooks.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/buffer.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/child_process.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/cluster.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/console.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/constants.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/crypto.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/dgram.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/dns.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/dns/promises.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/domain.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/events.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/fs.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/fs/promises.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/http.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/http2.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/https.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/inspector.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/module.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/net.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/os.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/path.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/perf_hooks.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/process.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/punycode.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/querystring.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/readline.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/repl.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/stream.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/stream/promises.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/stream/consumers.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/stream/web.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/string_decoder.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/test.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/timers.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/timers/promises.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/tls.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/trace_events.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/tty.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/url.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/util.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/v8.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/vm.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/wasi.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/worker_threads.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/zlib.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/globals.global.d.ts","../../../node_modules/.pnpm/@types+node@16.11.62/node_modules/@types/node/ts4.8/index.d.ts","../../../node_modules/.pnpm/@types+prettier@2.6.3/node_modules/@types/prettier/index.d.ts","../../../node_modules/.pnpm/@types+react-dom@18.0.6/node_modules/@types/react-dom/index.d.ts"],"fileInfos":[{"version":"f20c05dbfe50a208301d2a1da37b9931bce0466eb5a1f4fe240971b4ecc82b67","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","1fc5ab7a764205c68fa10d381b08417795fc73111d6dd16b5b1ed36badb743d9","746d62152361558ea6d6115cf0da4dd10ede041d14882ede3568bce5dc4b4f1f","d11a03592451da2d1065e09e61f4e2a9bf68f780f4f6623c18b57816a9679d17","aea179452def8a6152f98f63b191b84e7cbd69b0e248c91e61fb2e52328abe8c",{"version":"9b087de7268e4efc5f215347a62656663933d63c0b1d7b624913240367b999ea","affectsGlobalScope":true},{"version":"3260e3386d9535b804205bdddb5618a9a27735bd22927f48ad54363abcd23d45","affectsGlobalScope":true},{"version":"adb996790133eb33b33aadb9c09f15c2c575e71fb57a62de8bf74dbf59ec7dfb","affectsGlobalScope":true},{"version":"8cc8c5a3bac513368b0157f3d8b31cfdcfe78b56d3724f30f80ed9715e404af8","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"0d5f52b3174bee6edb81260ebcd792692c32c81fd55499d69531496f3f2b25e7","affectsGlobalScope":true},{"version":"55f400eec64d17e888e278f4def2f254b41b89515d3b88ad75d5e05f019daddd","affectsGlobalScope":true},{"version":"181f1784c6c10b751631b24ce60c7f78b20665db4550b335be179217bacc0d5f","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"81cac4cbc92c0c839c70f8ffb94eb61e2d32dc1c3cf6d95844ca099463cf37ea","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"09aa50414b80c023553090e2f53827f007a301bc34b0495bfb2c3c08ab9ad1eb","affectsGlobalScope":true},{"version":"d7f680a43f8cd12a6b6122c07c54ba40952b0c8aa140dcfcf32eb9e6cb028596","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"775d9c9fd150d5de79e0450f35bc8b8f94ae64e3eb5da12725ff2a649dccc777","affectsGlobalScope":true},{"version":"b248e32ca52e8f5571390a4142558ae4f203ae2f94d5bac38a3084d529ef4e58","affectsGlobalScope":true},{"version":"6c55633c733c8378db65ac3da7a767c3cf2cf3057f0565a9124a16a3a2019e87","affectsGlobalScope":true},{"version":"fb4416144c1bf0323ccbc9afb0ab289c07312214e8820ad17d709498c865a3fe","affectsGlobalScope":true},{"version":"5b0ca94ec819d68d33da516306c15297acec88efeb0ae9e2b39f71dbd9685ef7","affectsGlobalScope":true},{"version":"34c839eaaa6d78c8674ae2c37af2236dee6831b13db7b4ef4df3ec889a04d4f2","affectsGlobalScope":true},{"version":"34478567f8a80171f88f2f30808beb7da15eac0538ae91282dd33dce928d98ed","affectsGlobalScope":true},{"version":"ab7d58e6161a550ff92e5aff755dc37fe896245348332cd5f1e1203479fe0ed1","affectsGlobalScope":true},{"version":"6bda95ea27a59a276e46043b7065b55bd4b316c25e70e29b572958fa77565d43","affectsGlobalScope":true},{"version":"aedb8de1abb2ff1095c153854a6df7deae4a5709c37297f9d6e9948b6806fa66","affectsGlobalScope":true},{"version":"a4da0551fd39b90ca7ce5f68fb55d4dc0c1396d589b612e1902f68ee090aaada","affectsGlobalScope":true},{"version":"11ffe3c281f375fff9ffdde8bbec7669b4dd671905509079f866f2354a788064","affectsGlobalScope":true},{"version":"52d1bb7ab7a3306fd0375c8bff560feed26ed676a5b0457fa8027b563aecb9a4","affectsGlobalScope":true},{"version":"bbdf156fea2fabed31a569445835aeedcc33643d404fcbaa54541f06c109df3f","affectsGlobalScope":true},"ba7617784f6b9aeac5e20c5eea869bbc3ef31b905f59c796b0fd401dae17c111","6a386ff939f180ae8ef064699d8b7b6e62bc2731a62d7fbf5e02589383838dea","f5a8b384f182b3851cec3596ccc96cb7464f8d3469f48c74bf2befb782a19de5",{"version":"5917af4ff931b050dba49a1dedd9c00f15f7b3dc4345ad8491bfacd2ec68ed32","affectsGlobalScope":true},"af7fd2870746deed40e130fc0a3966de74e8f52a97ec114d0fbb35876ab05ca9","f0cb4b3ab88193e3e51e9e2622e4c375955003f1f81239d72c5b7a95415dad3e","92450d617e92f96354d281c8ed5613fd16cacea79eb60b1e9736494b3c057e69","8a9086357fe289efb682dc925358f30b6312c7219a5ca92212857a0a79612012","92bc42ed0e2d41559513fd457ee30d834c2f0fedb9ed5004c029cbf0ad2f8bd9","5771ec76e11a5e8303d8945e8050daee051436150d5285dc818c8df3239f45bb","274739c6c5cc94391cdf4acbbf72c7c6cd13429b48c6582ff9e111749fefa9fc",{"version":"06f2189d1099b5383f832b6f73610dfd6d90efb5a9a6c5d6f5579a6d7ca83855","signature":"5eb3187d0072362cda9cd18b219cf91e11c0420e5289c24bafa60c51ead12035"},{"version":"5ab2ad979c9d7cbc5cf5e1cc5b118db9403f80c0b79ed9778cff9cb27e09eac6","signature":"4ae6ed57fe60d465787326a28527c213aae329b6c9a8be7a43dc09d785f7e21c"},{"version":"f8c85d524a814d708c16baf2e19872608f1e9846fe507ceab99c162ce5577ed0","signature":"188176dd10a48d7d796f42e8e5ae41172d49512f2a6f939e2d4d7573584dae25"},{"version":"9c919e1c5c07a9f6ca1b59e34b9b8a05ff8020a642888b3767b0d35ae825a115","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},{"version":"14cd85b1a9aedb5591bdd1e25b7135cc358d17eeb125227369aa3dc5230a2679","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"},"d55408094a4b7c6318f88d18bca4718c68f14f75c7409143667893b6c49bde26",{"version":"64d4b35c5456adf258d2cf56c341e203a073253f229ef3208fc0d5020253b241","affectsGlobalScope":true},"a1c79f857f5c7754e14c93949dad8cfefcd7df2ecc0dc9dd79a30fd493e28449","f3e604694b624fa3f83f6684185452992088f5efb2cf136b62474aa106d6f1b6","2d474dfb84cd28ea43f27fe684da8c00382cbd40cee45e1dad4e9f41f6c437b6","dc33ce27fbeaf0ea3da556c80a6cc8af9d13eb443088c8f25cdc39fca8e756f6","0d14fa22c41fdc7277e6f71473b20ebc07f40f00e38875142335d5b63cdfc9d2","d8aab31ba8e618cc3eea10b0945de81cb93b7e8150a013a482332263b9305322","462bccdf75fcafc1ae8c30400c9425e1a4681db5d605d1a0edb4f990a54d8094","5923d8facbac6ecf7c84739a5c701a57af94a6f6648d6229a6c768cf28f0f8cb","7adecb2c3238794c378d336a8182d4c3dd2c4fa6fa1785e2797a3db550edea62","dc12dc0e5aa06f4e1a7692149b78f89116af823b9e1f1e4eae140cd3e0e674e6","1bfc6565b90c8771615cd8cfcf9b36efc0275e5e83ac7d9181307e96eb495161","8a8a96898906f065f296665e411f51010b51372fa260d5373bf9f64356703190","7f82ef88bdb67d9a850dd1c7cd2d690f33e0f0acd208e3c9eba086f3670d4f73",{"version":"ccfd8774cd9b929f63ff7dcf657977eb0652e3547f1fcac1b3a1dc5db22d4d58","affectsGlobalScope":true},"0d5a2ee1fdfa82740e0103389b9efd6bfe145a20018a2da3c02b89666181f4d9","a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a",{"version":"2f6c9750131d5d2fdaba85c164a930dc07d2d7e7e8970b89d32864aa6c72620c","affectsGlobalScope":true},"56d13f223ab40f71840795f5bef2552a397a70666ee60878222407f3893fb8d0",{"version":"aeeee3998c5a730f8689f04038d41cf4245c9edbf6ef29a698e45b36e399b8ed","affectsGlobalScope":true},"95843d5cfafced8f3f8a5ce57d2335f0bcd361b9483587d12a25e4bd403b8216","afc6e96061af46bcff47246158caee7e056f5288783f2d83d6858cd25be1c565",{"version":"34f5bcac12b36d70304b73de5f5aab3bb91bd9919f984be80579ebcad03a624e","affectsGlobalScope":true},"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","3a0c45fe95e8f0e2c5247d48acf3a522d2ef29f1ab0effb3c59a9c4fdd5edbcd","f50c975ab7b50e25a69e3d8a3773894125b44e9698924105f23b812bf7488baf","c993aac3b6d4a4620ef9651497069eb84806a131420e4f158ea9396fb8eb9b8c","76650408392bf49a8fbf3e2b6b302712a92d76af77b06e2da1cc8077359c4409","0af3121e68297b2247dd331c0d24dba599e50736a7517a5622d5591aae4a3122","06ccebc2c2db57d6bdbca63b71c4ae5e6ddc42d972fd8f122d4c1a28aa111b25",{"version":"81e8508d1e82278f5d3fee936f267e00c308af36219bfcee2631f9513c9c4017","affectsGlobalScope":true},"413a4be7f94f631235bbc83dad36c4d15e5a2ff02bca1efdbd03636d6454631b","20c468256fd68d3ef1fa53526e76d51d6aa91711e84d72c0343589b99238287e","a5f6d22760eef0178bebc5b5b5664a403109615a9c49da879ccd84438bd55223","8d4c16a26d59e3ce49741a7d4a6e8206b884e226cf308667c7778a0b2c0fee7f","ee3bad055a79f188626b1a7046f04ab151fdd3581e55c51d32face175bd9d06f","d61c7c41eb1960b1285e242fd102c162b65c0522985b839fadda59874308a170",{"version":"e8b18c6385ff784228a6f369694fcf1a6b475355ba89090a88de13587a9391d5","affectsGlobalScope":true},"11c8be5993cd30dbb5310d95ba6c54dbb8724221eed0c4b2e4a7d6a4f9a032dd","d10f4929cd610c26926d6784fc3f9f4120b789c03081b5d65fb2d2670a00fa04","fb0989383c6109f20281b3d31265293daefdd76d0d30551782c1654e93704f48","a4210a84a82b3e7a8cec5b2f3616e46d523f4f10cc1576d8f2fb89d0987b341e",{"version":"8207e7e6db9aa5fc7e61c8f17ba74cf9c115d26f51f91ee93f790815a7ea9dfb","affectsGlobalScope":true},"9f1069b9e2c051737b1f9b4f1baf50e4a63385a6a89c32235549ae87fc3d5492","ee18f2da7a037c6ceeb112a084e485aead9ea166980bf433474559eac1b46553","29c2706fa0cc49a2bd90c83234da33d08bb9554ecec675e91c1f85087f5a5324","0acbf26bf958f9e80c1ffa587b74749d2697b75b484062d36e103c137c562bc3","02b3239cf1b1ff8737e383ed5557f0247499d15f5bd21ab849b1a24687b6100c","1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff",{"version":"806ef4cac3b3d9fa4a48d849c8e084d7c72fcd7b16d76e06049a9ed742ff79c0","affectsGlobalScope":true},"33eee034727baf564056b4ea719075c23d3b4767d0b5f9c6933b81f3d77774d2","c33a6ea7147af60d8e98f1ac127047f4b0d4e2ce28b8f08ff3de07ca7cc00637","a4471d2bdba495b2a6a30b8765d5e0282fa7009d88345a9528f73c37869d3b93",{"version":"aee7013623e7632fba449d4df1da92925b27d9b816cb05546044dbfe54c88ef4","affectsGlobalScope":true},"664d8f2d59164f2e08c543981453893bc7e003e4dfd29651ce09db13e9457980","c9d70d3d7191a66a81cb554557f8ed1cf736ea8397c44a864fe52689de18865a","998a3de5237518c0b3ac00a11b3b4417affb008aa20aedee52f3fdae3cb86151","ad41008ffe077206e1811fc873f4d9005b5fd7f6ab52bb6118fef600815a5cb4",{"version":"1aad825534c73852a1f3275e527d729a2c0640f539198fdfdfeb83b839851910","affectsGlobalScope":true},"badae0df9a8016ac36994b0a0e7b82ba6aaa3528e175a8c3cb161e4683eec03e","c3db860bcaaaeb3bbc23f353bbda1f8ab82756c8d5e973bebb3953cb09ea68f2","235a53595bd20b0b0eeb1a29cb2887c67c48375e92f03749b2488fbd46d0b1a0","bc09393cd4cd13f69cf1366d4236fbae5359bb550f0de4e15767e9a91d63dfb1","9c266243b01545e11d2733a55ad02b4c00ecdbda99c561cd1674f96e89cdc958","c71155c05fc76ff948a4759abc1cb9feec036509f500174bc18dad4c7827a60c",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"e3685a8957b4e2af64c3f04a58289ee0858a649dbcd963a2b897fe85858ae18a","f1d8b21cdf08726021c8cce0cd6159486236cf1d633eeabbc435b5b2e5869c2e","e4dd91dd4789a109aab51d8a0569a282369fcda9ba6f2b2297bc61bacfb1a042"],"options":{"allowSyntheticDefaultImports":true,"composite":true,"declaration":true,"declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":true,"inlineSources":false,"jsx":4,"module":99,"noFallthroughCasesInSwitch":true,"noImplicitReturns":false,"noUnusedLocals":false,"noUnusedParameters":false,"outDir":"./","rootDir":"../src","skipLibCheck":true,"strict":true,"target":99,"tsBuildInfoFile":"./tsconfig.tsbuildinfo","useDefineForClassFields":true},"fileIdsList":[[62,133],[63,64,133],[63,133],[133],[75,77,133],[74,75,76,133],[82,87,133],[89,133],[92,133],[93,98,133],[94,104,105,112,121,132,133],[94,95,104,112,133],[96,133],[97,98,105,113,133],[98,121,129,133],[99,101,104,112,133],[100,133],[101,102,133],[103,104,133],[104,133],[104,105,106,121,132,133],[104,105,106,121,133],[107,112,121,132,133],[104,105,107,108,112,121,129,132,133],[107,109,121,129,132,133],[89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139],[104,110,133],[111,132,133],[101,104,112,121,133],[113,133],[114,133],[92,115,133],[116,131,133,137],[117,133],[118,133],[104,119,133],[119,120,133,135],[104,121,122,123,133],[121,123,133],[121,122,133],[124,133],[125,133],[104,127,128,133],[127,128,133],[98,112,129,133],[130,133],[112,131,133],[93,107,118,132,133],[98,133],[121,133,134],[133,135],[133,136],[93,98,104,106,115,121,132,133,135,137],[121,133,138],[60,133],[56,57,58,59,133],[80,83,133],[80,83,84,85,133],[82,133],[79,86,133],[81,133],[61,70,133],[61,63,65,66,69,133],[61,68,133],[61,67,133],[61,63,65,68,133],[63,69],[63]],"referencedMap":[[63,1],[65,2],[64,3],[62,4],[78,5],[74,4],[77,6],[75,4],[88,7],[76,4],[89,8],[90,8],[92,9],[93,10],[94,11],[95,12],[96,13],[97,14],[98,15],[99,16],[100,17],[101,18],[102,18],[103,19],[104,20],[105,21],[106,22],[91,4],[139,4],[107,23],[108,24],[109,25],[140,26],[110,27],[111,28],[112,29],[113,30],[114,31],[115,32],[116,33],[117,34],[118,35],[119,36],[120,37],[121,38],[123,39],[122,40],[124,41],[125,42],[126,4],[127,43],[128,44],[129,45],[130,46],[131,47],[132,48],[133,49],[134,50],[135,51],[136,52],[137,53],[138,54],[141,4],[58,4],[142,55],[56,4],[60,56],[61,55],[59,4],[79,4],[57,4],[80,4],[84,57],[86,58],[85,57],[83,59],[87,60],[82,61],[81,4],[67,4],[66,4],[11,4],[12,4],[14,4],[13,4],[2,4],[15,4],[16,4],[17,4],[18,4],[19,4],[20,4],[21,4],[22,4],[3,4],[4,4],[26,4],[23,4],[24,4],[25,4],[27,4],[28,4],[29,4],[5,4],[30,4],[31,4],[32,4],[33,4],[6,4],[34,4],[35,4],[36,4],[37,4],[7,4],[38,4],[43,4],[44,4],[39,4],[40,4],[41,4],[42,4],[8,4],[48,4],[45,4],[46,4],[47,4],[49,4],[9,4],[50,4],[51,4],[52,4],[53,4],[54,4],[1,4],[10,4],[55,4],[71,62],[70,63],[72,64],[68,65],[73,62],[69,66]],"exportedModulesMap":[[63,1],[65,2],[64,3],[62,4],[78,5],[74,4],[77,6],[75,4],[88,7],[76,4],[89,8],[90,8],[92,9],[93,10],[94,11],[95,12],[96,13],[97,14],[98,15],[99,16],[100,17],[101,18],[102,18],[103,19],[104,20],[105,21],[106,22],[91,4],[139,4],[107,23],[108,24],[109,25],[140,26],[110,27],[111,28],[112,29],[113,30],[114,31],[115,32],[116,33],[117,34],[118,35],[119,36],[120,37],[121,38],[123,39],[122,40],[124,41],[125,42],[126,4],[127,43],[128,44],[129,45],[130,46],[131,47],[132,48],[133,49],[134,50],[135,51],[136,52],[137,53],[138,54],[141,4],[58,4],[142,55],[56,4],[60,56],[61,55],[59,4],[79,4],[57,4],[80,4],[84,57],[86,58],[85,57],[83,59],[87,60],[82,61],[81,4],[67,4],[66,4],[11,4],[12,4],[14,4],[13,4],[2,4],[15,4],[16,4],[17,4],[18,4],[19,4],[20,4],[21,4],[22,4],[3,4],[4,4],[26,4],[23,4],[24,4],[25,4],[27,4],[28,4],[29,4],[5,4],[30,4],[31,4],[32,4],[33,4],[6,4],[34,4],[35,4],[36,4],[37,4],[7,4],[38,4],[43,4],[44,4],[39,4],[40,4],[41,4],[42,4],[8,4],[48,4],[45,4],[46,4],[47,4],[49,4],[9,4],[50,4],[51,4],[52,4],[53,4],[54,4],[1,4],[10,4],[55,4],[70,67],[73,62],[69,68]],"semanticDiagnosticsPerFile":[63,65,64,62,78,74,77,75,88,76,89,90,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,91,139,107,108,109,140,110,111,112,113,114,115,116,117,118,119,120,121,123,122,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,141,58,142,56,60,61,59,79,57,80,84,86,85,83,87,82,81,67,66,11,12,14,13,2,15,16,17,18,19,20,21,22,3,4,26,23,24,25,27,28,29,5,30,31,32,33,6,34,35,36,37,7,38,43,44,39,40,41,42,8,48,45,46,47,49,9,50,51,52,53,54,1,10,55,71,70,72,68,73,69],"latestChangedDtsFile":"./index.d.ts"},"version":"4.8.4"}
@@ -0,0 +1,15 @@
1
+ import { RGB } from "color-convert/conversions";
2
+ declare type Params = {
3
+ bgColor: string;
4
+ textColor?: string;
5
+ fontSize?: number;
6
+ };
7
+ export declare enum AccessibilityLevel {
8
+ WCAG_A = "lowest",
9
+ WCAG_AA = "midrange",
10
+ WCAG_AAA = "highest"
11
+ }
12
+ export declare function calculateAccessibilityLevel({ bgColor, fontSize, textColor, }: Params): AccessibilityLevel;
13
+ export declare function calculateContrastRatio(rgb1: RGB, rgb2: RGB): number;
14
+ export {};
15
+ //# sourceMappingURL=wcag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wcag.d.ts","sourceRoot":"","sources":["../src/wcag.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAUhD,aAAK,MAAM,GAAG;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAIF,oBAAY,kBAAkB;IAC5B,MAAM,WAAW;IACjB,OAAO,aAAa;IACpB,QAAQ,YAAY;CACrB;AAED,wBAAgB,2BAA2B,CAAC,EAC1C,OAAO,EACP,QAAa,EACb,SAAqB,GACtB,EAAE,MAAM,GAAG,kBAAkB,CAoB7B;AAGD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,MAAM,CAQnE"}