From 6731dd1aec1c17183cf39aeeb7ecb688955d96b5 Mon Sep 17 00:00:00 2001 From: Derek Cicerone Date: Thu, 23 Jan 2014 19:07:01 -0500 Subject: [PATCH 1/3] Create jquery.color.d.ts --- jquery.color/jquery.color.d.ts | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 jquery.color/jquery.color.d.ts diff --git a/jquery.color/jquery.color.d.ts b/jquery.color/jquery.color.d.ts new file mode 100644 index 000000000..427890a41 --- /dev/null +++ b/jquery.color/jquery.color.d.ts @@ -0,0 +1,64 @@ +// Type definitions for jquery.color.js v2.1.2 +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface JQueryColor { + /** + * Returns the alpha value of this color. + */ + alpha(): number; + + /** + * Returns the hexadecimal representation. + */ + toHexString(): string; + + /** + * Returns a CSS string like "rgba(255, 255, 255, 0.4)". + */ + toRgbaString(): string; + + /** + * The color distance (0.0 - 1.0) of the way between this color and othercolor. + */ + transition(othercolor: JQueryColor, distance: number): JQueryColor; + + /** + * Checks if two colors are equal. + */ + is(otherColor: JQueryColor): boolean; + + /** + * Returns the red component of the color (integer from 0 - 255). + */ + red(): number; + + /** + * Returns the green component of the color (integer from 0 - 255). + */ + green(): number; + + /** + * Returns the blue component of the color (integer from 0 - 255). + */ + blue(): number; +} + +interface HslaColor { + hue?: number; + saturation?: number; + lightness?: number; + alpha?: number; +} + +interface RgbaColor { + red?: number; + green?: number; + blue?: number; + alpha?: number; +} + +interface JQueryStatic { + Color(color: HslaColor): JQueryColor; + Color(color: RgbaColor): JQueryColor; + Color(color: string): JQueryColor; +} From def4da160bde7430d5d4f3b4a4e77318c1a9b4d8 Mon Sep 17 00:00:00 2001 From: Derek Cicerone Date: Mon, 27 Jan 2014 14:16:20 -0500 Subject: [PATCH 2/3] Update jquery.color.d.ts --- jquery.color/jquery.color.d.ts | 154 +++++++++++++++++++++++++++------ 1 file changed, 129 insertions(+), 25 deletions(-) diff --git a/jquery.color/jquery.color.d.ts b/jquery.color/jquery.color.d.ts index 427890a41..8d5000a6c 100644 --- a/jquery.color/jquery.color.d.ts +++ b/jquery.color/jquery.color.d.ts @@ -1,46 +1,150 @@ // Type definitions for jquery.color.js v2.1.2 +// Project: https://github.com/jquery/jquery-color +// Definitions by: Derek Cicerone // Definitions: https://github.com/borisyankov/DefinitelyTyped +/// + interface JQueryColor { - /** - * Returns the alpha value of this color. - */ - alpha(): number; - - /** - * Returns the hexadecimal representation. - */ - toHexString(): string; - - /** - * Returns a CSS string like "rgba(255, 255, 255, 0.4)". - */ - toRgbaString(): string; - - /** - * The color distance (0.0 - 1.0) of the way between this color and othercolor. - */ - transition(othercolor: JQueryColor, distance: number): JQueryColor; - - /** - * Checks if two colors are equal. - */ - is(otherColor: JQueryColor): boolean; - /** * Returns the red component of the color (integer from 0 - 255). */ red(): number; + /** + * Returns a copy of the color object with the red set to val. + */ + red(val: number): JQueryColor; + /** * Returns the green component of the color (integer from 0 - 255). */ green(): number; + /** + * Returns a copy of the color object with the green set to val. + */ + green(val: number): JQueryColor; + /** * Returns the blue component of the color (integer from 0 - 255). */ blue(): number; + + /** + * Returns a copy of the color object with the blue set to val. + */ + blue(val: number): JQueryColor; + + /** + * Returns the alpha value of this color (float from 0.0 - 1.0). + */ + alpha(): number; + + /** + * Returns a copy of the color object with the alpha set to val. + */ + alpha(val: number): JQueryColor; + + /** + * Returns the hue component of the color (integer from 0 - 359). + */ + hue(): number; + + /** + * Returns a copy of the color object with the hue set to val. + */ + hue(val: number): JQueryColor; + + /** + * Returns the saturation component of the color (float from 0.0 - 1.0). + */ + saturation(): number; + + /** + * Returns a copy of the color object with the saturation set to val. + */ + saturation(val: number): JQueryColor; + + /** + * Returns the lightness component of the color (float from 0.0 - 1.0). + */ + lightness(): number; + + /** + * Returns a copy of the color object with the lightness set to val. + */ + lightness(val: number): JQueryColor; + + /** + * Returns a rgba "tuple" [ red, green, blue, alpha ]. + */ + rgba(): number[]; + + /** + * Returns a copy of the color with any defined values set to the new value. + */ + rgba(red: number, green: number, blue: number, alpha?: number): JQueryColor; + + /** + * Returns a copy of the color with any defined values set to the new value. + */ + rgba(val: RgbaColor): JQueryColor; + + /** + * Returns a copy of the color with any defined values set to the new value. + */ + rgba(vals: number[]): JQueryColor; + + /** + * Returns a HSL tuple [ hue, saturation, lightness, alpha ]. + */ + hsla(): number[]; + + /** + * Returns a copy of the color with any defined values set to the new value. + */ + hsla(hue: number, saturation: number, lightness: number, alpha?: number): JQueryColor; + + /** + * Returns a copy of the color with any defined values set to the new value. + */ + hsla(val: HslaColor): JQueryColor; + + /** + * Returns a copy of the color with any defined values set to the new value. + */ + hsla(vals: number[]): JQueryColor; + + /** + * Returns a CSS string "rgba(255, 255, 255, 0.4)". + */ + toRgbaString(): string; + + /** + * Returns a css string "hsla(330, 75%, 25%, 0.4)". + */ + toHslaString(): string; + + /** + * Returns a css string "#abcdef", with "includeAlpha" uses "#rrggbbaa" (alpha *= 255). + */ + toHexString(includeAlpha?: boolean): string; + + /** + * The color distance (0.0 - 1.0) of the way between this color and othercolor. + */ + transition(othercolor: JQueryColor, distance: number): JQueryColor; + + /** + * Will apply this color on top of the other color using alpha blending. + */ + blend(othercolor: JQueryColor): void; + + /** + * Checks if two colors are equal. + */ + is(otherColor: JQueryColor): boolean; } interface HslaColor { From b7e1c8b53ece9f0772f0c1a361df5dcf6cca2f6a Mon Sep 17 00:00:00 2001 From: Derek Cicerone Date: Mon, 27 Jan 2014 14:16:46 -0500 Subject: [PATCH 3/3] Create jquery.color-tests.ts --- jquery.color/jquery.color-tests.ts | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 jquery.color/jquery.color-tests.ts diff --git a/jquery.color/jquery.color-tests.ts b/jquery.color/jquery.color-tests.ts new file mode 100644 index 000000000..267ee3b63 --- /dev/null +++ b/jquery.color/jquery.color-tests.ts @@ -0,0 +1,46 @@ +/// +/// + +var color = $.Color("rgba(255, 255, 255, 0.4)"); +var color1 = $.Color({red: 255, green: 255, blue: 255}); +var color2 = $.Color({hue: 359, saturation: 0.5, lightness: 0.5}); + +// getters +var red = color.red(); +var green = color.green(); +var blue = color.blue(); +var alpha = color.alpha(); +var hue = color.hue(); +var saturation = color.saturation(); +var lightness = color.lightness(); + +// setters +var newRed = color.red(20); +var newGreen = color.green(20); +var newBlue = color.blue(20); +var newAlpha = color.alpha(0.5); +var newHue = color.hue(20); +var newSaturation = color.saturation(0.5); +var newLightness = color.lightness(0.5); + +// rgba methods +var rgba = color.rgba(); +var newRgba1 = color.rgba(255, 255, 255, 0.5); +var newRgba2 = color.rgba({red: 255, green: 255, blue: 255}); +var newRgba3 = color.rgba(rgba); + +// hsla methods +var hsla = color.hsla(); +var newHsla1 = color.hsla(359, 0.5, 0.5, 0.5); +var newHsla2 = color.hsla({hue: 359, saturation: 0.5, lightness: 0.5}); +var newHsla3 = color.hsla(hsla); + +// string methods +var rgbaString = color.toRgbaString(); +var hslaString = color.toHslaString(); +var hexString = color.toHexString(); + +// other colors +var transitionedColor = color.transition(newRed, 0.5); +var blendedColor = color.blend(newRed); +var isEqual = color.is(newRed);