@aotearoan/neon
Version:
Neon is a lightweight design library of Vue 3 components with minimal dependencies.
124 lines (123 loc) • 4.19 kB
TypeScript
import type { NeonContrastAccessibility } from '@/common/models/NeonContrastAccessibility';
/**
* Utility class with helpers for calculating relative contrast & determining accessibility.
* @ignore INTERNAL USE ONLY. This logic is specifically for the palette generator & is not intended for use elsewhere.
*/
export declare class NeonColorUtils {
private static red;
private static green;
private static blue;
private static labXn;
private static labYn;
private static labZn;
private static labT0;
private static labT1;
private static labT2;
private static labT3;
private static degreesToRadians;
private static radiansToDegrees;
private static gamma;
/**
* Calculate luminance from RGB color Array.
*
* @param r Red value 0-255.
* @param g Green value 0-255.
* @param b Blue value 0-255.
*
* @returns The luminance.
*/
static luminance([r, g, b]: Array<number>): number;
/**
* Hex color string to RGB Array.
*
* @param hexString Hex color string to transform.
*
* @returns RGB color array.
*/
static toRgb(hexString: string): Array<number>;
/**
* Convert RGB color array to xyz color space.
*
* @param r Red value 0-255.
* @param g Green value 0-255.
* @param b Blue value 0-255.
*
* @returns xyz color value.
*/
static rgbToXyz(rgb: Array<number>): Array<number>;
/**
* Convert RGB color array to Lab color space.
*
* @param r Red value 0-255.
* @param g Green value 0-255.
* @param b Blue value 0-255.
*
* @returns Lab color value.
*/
static rgbToLab(rgb: Array<number>): Array<number>;
/**
* Convert RGB color array to Hcl color space.
*
* @param r Red value 0-255.
* @param g Green value 0-255.
* @param b Blue value 0-255.
*
* @returns Hcl color value.
*/
static rgbToHcl(rgb: Array<number>): Array<number>;
/**
* Check two hex colors for their contrast accessibility.
*
* @param hex1 Hex color 1.
* @param hex2 Hex color 2.
*
* @returns {NeonContrastAccessibility} Accessibility data.
*/
static isAccessible(rgb1: string, rgb2: string): NeonContrastAccessibility;
/**
* Calculate the contrast ratio between two colors.
*
* @param rgb1 First color.
* @param rgb2 Second color.
*
* @returns The contrast ratio (x:1).
*/
static contrast(rgb1: Array<number>, rgb2: Array<number>): number;
/**
* Convert RGB color array to hex color string.
*
* @param r Red value 0-255.
* @param g Green value 0-255.
* @param b Blue value 0-255.
*
* @returns hex color string.
*/
static rgbToHex(rgb: Array<number>): string;
/**
* Generate a Neon color palette with 5 light & 5 dark steps (l1-l5 & d1-d5) from a reference color. For both L1 & D1
* steps this will search for the closest match to the reference color that meets at least AA contrast requirements.
* The L2-L5 & D2-D5 steps are then generated based on a Hcl curve.
*
* @param referenceColor Hex string of the reference color from which to generate the palette.
* @param darkTextHex The dark text color hex string for calculating the contrast ratio for L1-L5 steps.
* @param lightTextHex The light text color hex string for calculating the contrast ratio for D1-D5 steps.
*
* @returns A map of the palette's color steps to hex values.
*/
static generatePalette(referenceColor: string, darkTextHex: string, lightTextHex: string): Record<string, string>;
private static generateChromaCurve;
private static generateLuminanceCurve;
private static xyzToLab;
private static rgbValueToXyz;
private static labToHcl;
private static luminanceByChannel;
private static relativeLuminance;
private static contrastRatio;
private static labToXyz;
private static xyzToRgb;
private static labToRgb;
private static hclToLab;
private static hclToRgb;
private static lightReferenceColor;
private static darkReferenceColor;
}