Skip to content

Commit

Permalink
add type definition (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
74th authored and mistic100 committed Jul 8, 2018
1 parent 9415fa8 commit dd32237
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"license": "MIT",
"homepage": "https://github.com/mistic100/tinygradient",
"main": "tinygradient.js",
"types": "tinygradient.d.ts",
"dependencies": {
"@types/tinycolor2": "^1.4.0",
"tinycolor2": "^1.0.0"
},
"devDependencies": {
Expand Down
119 changes: 119 additions & 0 deletions tinygradient.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*!
* TinyGradient 0.4.0
* Copyright 2014-2018 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
* Licensed under MIT (http://opensource.org/licenses/MIT)
*/

declare var tinygradient: tinygradient;

type ArcMode = boolean | 'short' | 'long';

interface TinyGradient {

/**
* Return new instance with reversed stops
* @return {tinygradient}
*/
reverse(): tinygradient;

/**
* Generate gradient with RGBa interpolation
* @param {int} steps
* @return {tinycolorInstance[]}
*/
rgb(steps: number): tinycolorInstance[];

/**
* Generate gradient with HSVa interpolation
* @param {int} steps
* @param {Boolean|String} [mode=false]
* - false to step in clockwise
* - true to step in trigonometric order
* - 'short' to use the shortest way
* - 'long' to use the longest way
* @return {tinycolorInstance[]}
*/
hsv(steps: number, mode: ArcMode): tinycolorInstance[];

/**
* Generate CSS3 command (no prefix) for this gradient
* @param {String} [mode=linear] - 'linear' or 'radial'
* @param {String} [direction] - default is 'to right' or 'ellipse at center'
* @return {String}
*/
css(mode?: 'linear' | 'radial', direction?: string): string;

/**
* Returns the color at specific position with RGBa interpolation
* @param {float} pos, between 0 and 1
* @return {tinycolorInstance}
*/
rgbAt(pos: number): tinycolorInstance;

/**
* Returns the color at specific position with HSVa interpolation
* @param {float} pos, between 0 and 1
* @return {tinycolorInstance}
*/
hsvAt(pos: number): tinycolorInstance;

}

interface tinygradient {
/**
* @class tinygradient
* @param {ColorInput[]} stops
*/
(stops: ColorInput[]): TinyGradient;

/**
* Generate gradient with RGBa interpolation
* @param {ColorInput[]} stops
* @param {int} steps
* @return {tinycolorInstance[]}
*/
rgb(stops: ColorInput[], steps: number): tinycolorInstance[];

/**
* Generate gradient with HSVa interpolation
* @param {ColorInput[]} stops
* @param {int} steps
* @param {Boolean|String} [mode=false]
* - false to step in clockwise
* - true to step in trigonometric order
* - 'short' to use the shortest way
* - 'long' to use the longest way
* @return {tinycolorInstance[]}
*/
hsv(stops: ColorInput[], steps: number, mode: ArcMode): tinycolorInstance[];

/**
* Generate CSS3 command (no prefix) for this gradient
* @param {ColorInput[]} stops
* @param {String} [mode=linear] - 'linear' or 'radial'
* @param {String} [direction] - default is 'to right' or 'ellipse at center'
* @return {String}
*/
css(stops: ColorInput[], mode?: 'linear' | 'radial', direction?: string): string;

/**
* Returns the color at specific position with RGBa interpolation
* @param {ColorInput[]} stops
* @param {float} pos, between 0 and 1
* @return {tinycolorInstance}
*/
rgbAt(stops: ColorInput[], pos: number): tinycolorInstance;

/**
* Returns the color at specific position with HSVa interpolation
* @param {ColorInput[]} stops
* @param {float} pos, between 0 and 1
* @return {tinycolorInstance}
*/
hsvAt(stops: ColorInput[], pos: number): tinycolorInstance;
}

// export default tinygradient;
declare module 'tinygradient' {
export = tinygradient;
}

0 comments on commit dd32237

Please sign in to comment.