Merge pull request #1604 from derekcicerone/patch-36

Create jquery.color.d.ts
This commit is contained in:
Igorbek
2014-01-28 05:39:29 -08:00
2 changed files with 214 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
/// <reference path="../jquery/jquery.d.ts"/>
/// <reference path="jquery.color.d.ts"/>
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);
+168
View File
@@ -0,0 +1,168 @@
// Type definitions for jquery.color.js v2.1.2
// Project: https://github.com/jquery/jquery-color
// Definitions by: Derek Cicerone <https://github.com/derekcicerone/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jquery/jquery.d.ts"/>
interface JQueryColor {
/**
* 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 {
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;
}