Add document ready & linear-gradient (#27367)

* Add document-ready

* Add linear-gradient
This commit is contained in:
Jack Works 2018-07-24 02:20:34 +08:00 committed by Andy
parent ed33c9ae20
commit 655e4406d0
8 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,4 @@
import ready = require("document-ready");
ready(() => {
// on load
});

7
types/document-ready/index.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
// Type definitions for document-ready 2.0
// Project: https://github.com/bendrucker/document-ready#readme
// Definitions by: Jack Works <https://github.com/Jack-Works>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare function ready(callback: () => void): void;
export = ready;

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"strictFunctionTypes": true,
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"document-ready-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

18
types/linear-gradient/index.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
// Type definitions for linear-gradient 1.0
// Project: https://github.com/karmadata/linear-gradient#readme
// Definitions by: Jack Works <https://github.com/Jack-Works>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
type Color = [number, number, number];
declare class Gradient {
constructor(colors: Color[]);
/**
* the input value should be normalized to the range between 0 and 1
*/
calcArray(normalizedPercent: number): Color;
/**
* the input value should be normalized to the range between 0 and 1
*/
calcHex(normalizedPrecent: number): string;
}
export = Gradient;

View File

@ -0,0 +1,23 @@
import Gradient = require("linear-gradient");
// instantiate with an RGB palette
const grad1 = new Gradient([
[0, 0, 0],
[0, 80, 0],
[0, 160, 80],
[80, 80, 80],
[160, 40, 40],
[255, 0, 0]
]);
// now we are ready to calculate the colors
// the input value should be normalized to the range between 0 and 1
(grad1.calcArray(0)); // -> [0,0,0] (0 -> first color of the palette)
(grad1.calcArray(1)); // -> [255,0,0] (1 -> last color of the palette)
(grad1.calcArray(0.25)); // -> [0,100,20] (weighted average between [0,80,0] and [0,160,80])
(grad1.calcArray(0.5));
(grad1.calcArray(0.75));
(grad1.calcHex(1)); // -> '#ffffff'
(grad1.calcHex(0.25)); // -> '#006416'

View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"strictFunctionTypes": true,
"esModuleInterop": true,
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"linear-gradient-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }