From 55dbfec2ebcae6de09f253f41c69b72adada3277 Mon Sep 17 00:00:00 2001 From: Vanya Date: Sat, 26 Jan 2019 23:08:12 +0400 Subject: [PATCH] Add definitions for color-diff (#32516) --- types/color-diff/color-diff-tests.ts | 17 +++++++ types/color-diff/index.d.ts | 67 ++++++++++++++++++++++++++++ types/color-diff/tsconfig.json | 17 +++++++ types/color-diff/tslint.json | 1 + 4 files changed, 102 insertions(+) create mode 100644 types/color-diff/color-diff-tests.ts create mode 100644 types/color-diff/index.d.ts create mode 100644 types/color-diff/tsconfig.json create mode 100644 types/color-diff/tslint.json diff --git a/types/color-diff/color-diff-tests.ts b/types/color-diff/color-diff-tests.ts new file mode 100644 index 0000000000..684858c203 --- /dev/null +++ b/types/color-diff/color-diff-tests.ts @@ -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 diff --git a/types/color-diff/index.d.ts b/types/color-diff/index.d.ts new file mode 100644 index 0000000000..f331b7203c --- /dev/null +++ b/types/color-diff/index.d.ts @@ -0,0 +1,67 @@ +// Type definitions for color-diff 1.1 +// Project: https://github.com/markusn/color-diff#readme +// Definitions by: 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, + backgroundColor?: RGBColor +): RGBColor; + +export function furthest( + color: RGBColor, + palette: ReadonlyArray, + backgroundColor?: RGBColor +): RGBColor; + +export function map_palette( + a: ReadonlyArray, + b: ReadonlyArray, + 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; + +export function furthest_lab( + color: LabColor, + palette: ReadonlyArray +): LabColor; + +export function map_palette_lab( + p1: ReadonlyArray, + p2: ReadonlyArray +): { [key: string]: LabColor }; + +export function lab_palette_map_key(c: LabColor): string; + +export function match_palette_lab( + target_color: LabColor, + palette: ReadonlyArray, + find_furthest: boolean +): LabColor; diff --git a/types/color-diff/tsconfig.json b/types/color-diff/tsconfig.json new file mode 100644 index 0000000000..b8a60d5c99 --- /dev/null +++ b/types/color-diff/tsconfig.json @@ -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"] +} diff --git a/types/color-diff/tslint.json b/types/color-diff/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/color-diff/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }