colorizr
Version:
Manipulate colors like a boss
84 lines (80 loc) • 3.32 kB
text/typescript
import { ColorKeysTuple, ColorModelKey } from '~/types';
export const COLOR_KEYS: Record<ColorModelKey, ColorKeysTuple> = {
hsl: ['h', 's', 'l'],
oklab: ['l', 'a', 'b'],
oklch: ['l', 'c', 'h'],
rgb: ['r', 'g', 'b'],
};
export const CLMS_TO_OKLAB: number[][] = [
[],
[],
[],
];
export const DEG2RAD = Math.PI / 180;
export const LMS_TO_LRGB: number[][] = [
[],
[-1.2684380046, 2.6097574011, -0.3413193965],
[-0.0041960863, -0.7034186147, 1.707614701],
];
export const LRGB_TO_LMS: number[][] = [
[],
[],
[],
];
export const OKLAB_TO_CLMS: number[][] = [
[],
[],
[],
];
export const P3_TO_SRGB: number[][] = [
[],
[-0.042056954709688121, 1.0420569547096883, 0],
[-0.019637554590334422, -0.078636045550631792, 1.0982736001409665],
];
export const P3_TO_XYZ: number[][] = [
[],
[],
[],
];
export const SRGB_TO_P3: number[][] = [
[],
[],
[],
];
export const XYZ_TO_SRGB: number[][] = [
[],
[-0.9692436362808796, 1.8759675015077202, 0.0415550574071756],
[],
];
export const GAMUT_EPSILON = 0.000001;
export const PRECISION = 5;
export const RAD2DEG = 180 / Math.PI;
export const MESSAGES = {
alpha: 'alpha must be a number between 0 and 1',
alphaAdjustment: 'alpha must be a number between -1 and 1',
amount: 'amount must be a number between 0 and 100',
colorRequired: 'color is required',
degreesRange: 'degrees must be a number between -360 and 360',
hueArgs: 'point, chroma and h are required',
hueRange: 'hue must be a number between 0 and 360',
input: 'input is required',
inputHex: 'input is required and must be a hex',
inputNumber: 'input is required and must be a number',
inputString: 'input is required and must be a string',
invalid: 'invalid input',
invalidColor: 'invalid color',
invalidCSS: 'invalid CSS string',
invalidHex: 'invalid hex',
invalidKey: 'invalid key',
invalidModel: 'invalid model',
invalidRange: 'color value out of range',
left: 'left is required and must be a string',
lightnessRange: 'lightness must be a number between 0 and 1',
options: 'invalid options',
paletteSize: 'palette size must be at least 2',
ratioRange: 'ratio must be a number between 0 and 1',
right: 'right is required and must be a string',
threshold: 'threshold must be a number between 0 and 255',
thresholdNormalized: 'threshold must be a number between 0 and 1',
} as const;
export const MONOCHROMATIC_LIGHTNESS_MAX = 80;