Add definitions for color-diff (#32516)

This commit is contained in:
Vanya
2019-01-26 23:08:12 +04:00
committed by Pranav Senthilnathan
parent 2a76edab65
commit 55dbfec2eb
4 changed files with 102 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
import diff from "color-diff";
const color = { R: 255, G: 1, B: 30 };
// red, green, blue
const palette = [
{ R: 255, G: 0, B: 0 },
{ R: 0, G: 255, B: 0 },
{ R: 0, G: 0, B: 255 }
];
diff.closest(color, palette); // {R: 255, G: 0, B: 0 }, red
const color1 = { R: 255, G: 255, B: 255 };
// black, white
const palette1 = [{ R: 0, G: 0, B: 0 }, { R: 255, G: 255, B: 255 }];
diff.furthest(color1, palette1); // {R: 0, G: 0, B: 0 }, black

67
types/color-diff/index.d.ts vendored Normal file
View File

@@ -0,0 +1,67 @@
// Type definitions for color-diff 1.1
// Project: https://github.com/markusn/color-diff#readme
// Definitions by: katsanva <https://github.com/katsanva>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.7
export interface RGBColor {
R: number;
G: number;
B: number;
A?: number;
}
export interface LabColor {
L: number;
a: number;
b: number;
}
export function diff(c1: LabColor, c2: LabColor): number;
export function rgb_to_lab(c: RGBColor): LabColor;
export function rgba_to_lab(c: RGBColor, bc?: RGBColor): LabColor;
export function closest(
color: RGBColor,
palette: ReadonlyArray<RGBColor>,
backgroundColor?: RGBColor
): RGBColor;
export function furthest(
color: RGBColor,
palette: ReadonlyArray<RGBColor>,
backgroundColor?: RGBColor
): RGBColor;
export function map_palette(
a: ReadonlyArray<RGBColor>,
b: ReadonlyArray<RGBColor>,
type?: "closest" | "furthest",
backgroundColor?: RGBColor
): { [key: string]: RGBColor };
export function palette_map_key(c: RGBColor): string;
export function closest_lab(
color: LabColor,
palette: ReadonlyArray<LabColor>
): LabColor;
export function furthest_lab(
color: LabColor,
palette: ReadonlyArray<LabColor>
): LabColor;
export function map_palette_lab(
p1: ReadonlyArray<LabColor>,
p2: ReadonlyArray<LabColor>
): { [key: string]: LabColor };
export function lab_palette_map_key(c: LabColor): string;
export function match_palette_lab(
target_color: LabColor,
palette: ReadonlyArray<LabColor>,
find_furthest: boolean
): LabColor;

View File

@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"strictFunctionTypes": true
},
"files": ["index.d.ts", "color-diff-tests.ts"]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }