-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6f3399
commit 670108d
Showing
29 changed files
with
229 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// @flow | ||
|
||
const {parseCSSColor} = require('csscolorparser'); | ||
|
||
/** | ||
* An RGBA color value. All components are in the range [0, 1] and R, B, and G are premultiplied by A. | ||
* @private | ||
*/ | ||
class Color { | ||
r: number; | ||
g: number; | ||
b: number; | ||
a: number; | ||
|
||
constructor(r: number, g: number, b: number, a: number = 1) { | ||
this.r = r; | ||
this.g = g; | ||
this.b = b; | ||
this.a = a; | ||
} | ||
|
||
static parse(input: ?string): Color | void { | ||
if (!input) { | ||
return undefined; | ||
} | ||
|
||
if (input instanceof Color) { | ||
return input; | ||
} | ||
|
||
if (typeof input !== 'string') { | ||
return undefined; | ||
} | ||
|
||
const rgba = parseCSSColor(input); | ||
if (!rgba) { | ||
return undefined; | ||
} | ||
|
||
return new Color( | ||
rgba[0] / 255 * rgba[3], | ||
rgba[1] / 255 * rgba[3], | ||
rgba[2] / 255 * rgba[3], | ||
rgba[3] | ||
); | ||
} | ||
} | ||
|
||
module.exports = Color; |
Oops, something went wrong.