-
Notifications
You must be signed in to change notification settings - Fork 1
/
hsluv-stylus.js
29 lines (26 loc) · 974 Bytes
/
hsluv-stylus.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
var hsluv = require('hsluv');
var stylus = require('stylus');
module.exports = function () {
// convert [0-1] (rgb) values to [0-255] (stylus) values
function floatToInt(f) {
return Math.round(f * 255);
}
return function (style) {
style.define('hsluv', function (H, S, L, A) {
var rgb = hsluv.hsluvToRgb([H.val, S.val, L.val]);
var r = floatToInt(rgb[0]);
var g = floatToInt(rgb[1]);
var b = floatToInt(rgb[2]);
var a = (A !== undefined ? A.val : 1);
return new stylus.nodes.RGBA(r, g, b, a);
});
style.define('hpluv', function (H, S, L, A) {
var rgb = hsluv.hpluvToRgb([H.val, S.val, L.val]);
var r = floatToInt(rgb[0]);
var g = floatToInt(rgb[1]);
var b = floatToInt(rgb[2]);
var a = (A !== undefined ? A.val : 1);
return new stylus.nodes.RGBA(r, g, b, a);
});
}
}