From 08c8d70405344c32ceba508faa903289adb6c295 Mon Sep 17 00:00:00 2001 From: Roman Vaughan Date: Thu, 17 Sep 2015 16:33:46 +1200 Subject: [PATCH 1/2] Add TypeScript typings file for inclusion of TypeScript projects Created a typings file based on the exposed functions defined in README.md The functions are not annotated with JSDoc yet, this was just enough to compile and run in a RequireJS environment --- tinycolor.d.ts | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100755 tinycolor.d.ts diff --git a/tinycolor.d.ts b/tinycolor.d.ts new file mode 100755 index 0000000..a5841b4 --- /dev/null +++ b/tinycolor.d.ts @@ -0,0 +1,113 @@ + +interface Rgb { + r: number|string; + g: number|string; + b: number|string; +} + +interface Rgba extends Rgb { + a: number; +} + +interface Hsv { + h: number; + s: number; + v: number; +} + +interface Hsl { + h: number; + s: number; + l: number; +} + +interface WCAG2 { + level: string; + size: string; +} + +declare module "tinycolor" { + + function tinycolor(value: tinycolor | string| Rgb | Rgba | Hsv | Hsl): tinycolor; + + interface tinycolor { + fromRatio(value: string| Rgb | Rgba | Hsv | Hsl): void; + + getFormat(): string; + getOriginalInput(): string; + + getBrightness(): number; + getLuminance(): number; + getAlpha(): number; + + setAlpha(alpha: number): void; + + isLight(): boolean; + isDark(): boolean; + isValid(): boolean; + + toString(): string; + + toHex(): string; + toHexString(): string; + + toHex8(): string; + toHex8String(): string; + + toHsv(): Hsv; + toHsvString(): string; + + toHsl(): Hsl; + toHslString(): string; + + toRgb(): Rgb|Rgba; + toRgbString(): string; + + toPercentageRgb(): Rgb|Rgba; + toPercentageRgbString(): string; + + toName(): string; + + toFilter(): string; + + lighten(value?: number): tinycolor; + brighten(value?: number): tinycolor; + darken(value?: number): tinycolor; + desaturate(value?: number): tinycolor; + saturate(value?: number): tinycolor; + greyscale(): tinycolor; + spin(value: number): tinycolor; + + analogous(results?: number, slices?: number): tinycolor[]; + monochromatic(results?: number): tinycolor[]; + splitcomplement(): tinycolor[]; + triad(): tinycolor[]; + tetrad(): tinycolor[]; + complement(): tinycolor; + + equals(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor | string | Rgb | Rgba | Hsv | Hsl): boolean; + mix(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor | string | Rgb | Rgba | Hsv | Hsl, amount: number): tinycolor; + random(): tinycolor; + + readability(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor | string | Rgb | Rgba | Hsv | Hsl): number; + isReadable(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor | string | Rgb | Rgba | Hsv | Hsl, wcag2?: WCAG2): boolean; + mostReadable(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor[]| string[]| Rgb[]| Rgba[]| Hsv[]| Hsl[], wcag2?: WCAG2): boolean|tinycolor; + } + + function lighten(color: tinycolor | string | Rgb | Rgba | Hsv | Hsl, value?: number): tinycolor; + function brighten(color: tinycolor | string | Rgb | Rgba | Hsv | Hsl, value?: number): tinycolor; + function darken(color: tinycolor | string | Rgb | Rgba | Hsv | Hsl, value?: number): tinycolor; + function desaturate(color: tinycolor | string | Rgb | Rgba | Hsv | Hsl, value?: number): tinycolor; + function saturate(color: tinycolor | string | Rgb | Rgba | Hsv | Hsl, value?: number): tinycolor; + function greyscale(color: tinycolor | string | Rgb | Rgba | Hsv | Hsl): tinycolor; + function spin(color: tinycolor | string | Rgb | Rgba | Hsv | Hsl, value: number): tinycolor; + + function analogous(color: tinycolor | string | Rgb | Rgba | Hsv | Hsl, results?: number, slices?: number): tinycolor[]; + function monochromatic(color: tinycolor | string | Rgb | Rgba | Hsv | Hsl, results?: number): tinycolor[]; + function splitcomplement(color: tinycolor | string | Rgb | Rgba | Hsv | Hsl): tinycolor[]; + function triad(color: tinycolor | string | Rgb | Rgba | Hsv | Hsl): tinycolor[]; + function tetrad(color: tinycolor | string | Rgb | Rgba | Hsv | Hsl): tinycolor[]; + function complement(color: tinycolor | string | Rgb | Rgba | Hsv | Hsl): tinycolor; + + export = tinycolor; +} \ No newline at end of file From c39808eb874c8fa102ac5e8fa97bf809b053aead Mon Sep 17 00:00:00 2001 From: Roman Vaughan Date: Thu, 17 Sep 2015 23:03:13 +1200 Subject: [PATCH 2/2] Move prototype functions to declared var along with "new" --- tinycolor.d.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) mode change 100755 => 100644 tinycolor.d.ts diff --git a/tinycolor.d.ts b/tinycolor.d.ts old mode 100755 new mode 100644 index a5841b4..624bdc6 --- a/tinycolor.d.ts +++ b/tinycolor.d.ts @@ -28,10 +28,21 @@ interface WCAG2 { declare module "tinycolor" { - function tinycolor(value: tinycolor | string| Rgb | Rgba | Hsv | Hsl): tinycolor; + var tinycolor : { + new (value: tinycolor | string | Rgb | Rgba | Hsv | Hsl): tinycolor; + + fromRatio(value: string| Rgb | Rgba | Hsv | Hsl): tinycolor; + + equals(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor | string | Rgb | Rgba | Hsv | Hsl): boolean; + mix(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor | string | Rgb | Rgba | Hsv | Hsl, amount: number): tinycolor; + random(): tinycolor; + + isReadable(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor | string | Rgb | Rgba | Hsv | Hsl, wcag2?: WCAG2): boolean; + mostReadable(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor[]| string[]| Rgb[]| Rgba[]| Hsv[]| Hsl[], wcag2?: WCAG2): boolean|tinycolor; + readability(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor | string | Rgb | Rgba | Hsv | Hsl): number; + } interface tinycolor { - fromRatio(value: string| Rgb | Rgba | Hsv | Hsl): void; getFormat(): string; getOriginalInput(): string; @@ -84,14 +95,6 @@ declare module "tinycolor" { triad(): tinycolor[]; tetrad(): tinycolor[]; complement(): tinycolor; - - equals(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor | string | Rgb | Rgba | Hsv | Hsl): boolean; - mix(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor | string | Rgb | Rgba | Hsv | Hsl, amount: number): tinycolor; - random(): tinycolor; - - readability(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor | string | Rgb | Rgba | Hsv | Hsl): number; - isReadable(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor | string | Rgb | Rgba | Hsv | Hsl, wcag2?: WCAG2): boolean; - mostReadable(color1: tinycolor | string | Rgb | Rgba | Hsv | Hsl, color2: tinycolor[]| string[]| Rgb[]| Rgba[]| Hsv[]| Hsl[], wcag2?: WCAG2): boolean|tinycolor; } function lighten(color: tinycolor | string | Rgb | Rgba | Hsv | Hsl, value?: number): tinycolor;