Last change
on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
788 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | var utils = require('../utils');
|
---|
| 2 |
|
---|
| 3 | /**
|
---|
| 4 | * Adjust HSL `color` `prop` by `amount`.
|
---|
| 5 | *
|
---|
| 6 | * @param {RGBA|HSLA} color
|
---|
| 7 | * @param {String} prop
|
---|
| 8 | * @param {Unit} amount
|
---|
| 9 | * @return {RGBA}
|
---|
| 10 | * @api private
|
---|
| 11 | */
|
---|
| 12 |
|
---|
| 13 | function adjust(color, prop, amount){
|
---|
| 14 | utils.assertColor(color, 'color');
|
---|
| 15 | utils.assertString(prop, 'prop');
|
---|
| 16 | utils.assertType(amount, 'unit', 'amount');
|
---|
| 17 | var hsl = color.hsla.clone();
|
---|
| 18 | prop = { hue: 'h', saturation: 's', lightness: 'l' }[prop.string];
|
---|
| 19 | if (!prop) throw new Error('invalid adjustment property');
|
---|
| 20 | var val = amount.val;
|
---|
| 21 | if ('%' == amount.type){
|
---|
| 22 | val = 'l' == prop && val > 0
|
---|
| 23 | ? (100 - hsl[prop]) * val / 100
|
---|
| 24 | : hsl[prop] * (val / 100);
|
---|
| 25 | }
|
---|
| 26 | hsl[prop] += val;
|
---|
| 27 | return hsl.rgba;
|
---|
| 28 | };
|
---|
| 29 | adjust.params = ['color', 'prop', 'amount'];
|
---|
| 30 | module.exports = adjust;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.