-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·38 lines (33 loc) · 1.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
var render = require('./utils/render.js');
var colorFunctions = require('./utils/color.js');
var parseColorFunction = require('./utils/parse-color-function.js');
var Color = require('./utils/tree/color.js');
var calcColorValue = require('./utils/calc-color-function.js');
var exportObj = {
render: render,
};
Object.keys(colorFunctions).forEach(function (funcName) {
exportObj[funcName] = function () {
return parseColorFunction(colorFunctions[funcName], arguments, funcName);
};
});
exportObj.color = function (value) {
if (value instanceof Color) {
return value;
}
if (value && typeof value === 'string') {
value = calcColorValue(value);
}
if (value && typeof value === 'string') {
var funcNameMatches = value.match(/^\s*([a-zA-Z]+?)\((.+)\)/);
if (funcNameMatches) {
var funcName = funcNameMatches[1];
if (exportObj[funcName]) {
return exportObj[funcName].apply(null, funcNameMatches[2].split(','));
}
}
}
return new Color(value);
};
module.exports = exportObj;