-
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
Lucas Wojciechowski
committed
Jan 14, 2016
1 parent
c1d8e06
commit 27e0443
Showing
11 changed files
with
197 additions
and
91 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,47 @@ | ||
'use strict'; | ||
|
||
var parseCSSColor = require('csscolorparser').parseCSSColor; | ||
var util = require('../util/util'); | ||
|
||
var colorCache = {}; | ||
|
||
function parseColor(input) { | ||
|
||
if (colorCache[input]) { | ||
return colorCache[input]; | ||
|
||
// RGBA array | ||
} else if (Array.isArray(input)) { | ||
return input; | ||
|
||
// style function | ||
} else if (input && input.range) { | ||
return util.extend({}, input, { | ||
range: input.range.map(parseColor) | ||
}); | ||
|
||
// legacy style function | ||
} else if (input && input.stops) { | ||
return util.extend({}, input, { | ||
stops: input.stops.map(function(step) { | ||
return [step[0], parseColor(step[1])]; | ||
}) | ||
}); | ||
|
||
// Color string | ||
} else if (typeof input === 'string') { | ||
var output = colorDowngrade(parseCSSColor(input)); | ||
colorCache[input] = output; | ||
return output; | ||
|
||
} else { | ||
throw new Error('Invalid color ' + input); | ||
} | ||
|
||
} | ||
|
||
function colorDowngrade(color) { | ||
return [color[0] / 255, color[1] / 255, color[2] / 255, color[3]]; | ||
} | ||
|
||
module.exports = parseColor; |
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
Oops, something went wrong.