From 022c0e59af81b939101936c29f1412724b3b551b Mon Sep 17 00:00:00 2001 From: azurepolarbear Date: Sun, 2 Jun 2024 14:01:12 -0500 Subject: [PATCH] #14 #88 Update documentation. --- docs/release-notes/v0.6.0-notes.md | 12 ++++++++++++ src/main/color/palette/palette.ts | 12 ++++++++++++ src/test/shared/palette.ts | 25 +++++++++++++++++++------ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/docs/release-notes/v0.6.0-notes.md b/docs/release-notes/v0.6.0-notes.md index 81ea9a6..d0dc361 100644 --- a/docs/release-notes/v0.6.0-notes.md +++ b/docs/release-notes/v0.6.0-notes.md @@ -242,8 +242,20 @@ declare interface Palette { * palette, black (#000000), and white (#FFFFFF). */ readonly CONTRAST_MAP: { + /** + * The colors in the palette that pass the WCAG AA standard when + * compared to black (#000000). This list should NOT contain + * white (#FFFFFF) unless it is a color listed in the palette. + */ '#000000': string[], + + /** + * The colors in the palette that pass the WCAG AA standard when + * compared to white (#FFFFFF). This list should NOT contain + * black (#000000) unless it is a color listed in the palette. + */ '#FFFFFF': string[], + [HEX: string]: string[] }, diff --git a/src/main/color/palette/palette.ts b/src/main/color/palette/palette.ts index 0607bd7..7b6730a 100644 --- a/src/main/color/palette/palette.ts +++ b/src/main/color/palette/palette.ts @@ -52,8 +52,20 @@ export interface Palette { * palette, black (#000000), and white (#FFFFFF). */ readonly CONTRAST_MAP: { + /** + * The colors in the palette that pass the WCAG AA standard when + * compared to black (#000000). This list should NOT contain + * white (#FFFFFF) unless it is a color listed in the palette. + */ '#000000': string[], + + /** + * The colors in the palette that pass the WCAG AA standard when + * compared to white (#FFFFFF). This list should NOT contain + * black (#000000) unless it is a color listed in the palette. + */ '#FFFFFF': string[], + [HEX: string]: string[] }, diff --git a/src/test/shared/palette.ts b/src/test/shared/palette.ts index 2cc6235..496c753 100644 --- a/src/test/shared/palette.ts +++ b/src/test/shared/palette.ts @@ -62,14 +62,20 @@ export function checkForPaletteNameKeyMatch(map: StringMap): void { export function checkForValidContrastMap(palette: Palette): void { checkForValidPalette(palette); - expect(palette.CONTRAST_MAP['#000000']).not.toContain('#FFFFFF'); - expect(palette.CONTRAST_MAP['#FFFFFF']).not.toContain('#000000'); const validHexes: string[] = palette.COLORS.map((color: PaletteColor): string => { return color.HEX; }); - validHexes.push('#000000'); - validHexes.push('#FFFFFF'); + + if (validHexes.indexOf('#000000') < 0) { + expect(palette.CONTRAST_MAP['#FFFFFF']).not.toContain('#000000'); + validHexes.push('#000000'); + } + + if (validHexes.indexOf('#FFFFFF') < 0) { + expect(palette.CONTRAST_MAP['#000000']).not.toContain('#FFFFFF'); + validHexes.push('#FFFFFF'); + } for (const key in palette.CONTRAST_MAP) { checkForValidHexColorString(key); @@ -79,14 +85,21 @@ export function checkForValidContrastMap(palette: Palette): void { checkForValidHexColorString(hex); expect(validHexes).toContain(hex); - const meetsRatio: boolean = + const meetsNormalRatio: boolean = ColorContrastAssessor.meetsContrastStandard( key, hex, ContrastStandard.AA, ContrastFontSize.NORMAL ); - expect(meetsRatio).toBeTruthy(); + const meetsLargeRatio: boolean = + ColorContrastAssessor.meetsContrastStandard( + key, + hex, + ContrastStandard.AA, + ContrastFontSize.LARGE + ); + expect(meetsNormalRatio && meetsLargeRatio).toBeTruthy(); } } }