2021-01-05 10:52:05 +00:00
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
|
|
const toHSL = require('hex-to-hsl');
|
|
|
|
|
2021-02-17 15:44:17 +00:00
|
|
|
// untested TODO - test
|
|
|
|
function defineHSL(mixin, name, hue, sat, light) {
|
2021-01-05 10:52:05 +00:00
|
|
|
const obj = {};
|
2021-02-17 15:44:17 +00:00
|
|
|
obj[name] = name;
|
|
|
|
// need to ensure hue is a string otherwise postcss (is it postcss?) appends
|
|
|
|
// 'px' to the property's value.
|
|
|
|
obj[`${name}__h`] = hue.toString();
|
|
|
|
obj[`${name}__s`] = `${sat}%`;
|
|
|
|
obj[`${name}__l`] = `${light}%`;
|
|
|
|
return obj;
|
2021-01-05 10:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// defines a custom property with identifier name, along with individual hue,
|
2021-02-17 15:44:17 +00:00
|
|
|
// saturation and lightness components
|
|
|
|
function defineHex(mixin, name, hex) {
|
|
|
|
const [hue, sat, light] = toHSL(hex);
|
|
|
|
return defineHSL(name, hue, sat, light)
|
2021-01-05 10:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const postcssMixins = {
|
2021-02-17 15:44:17 +00:00
|
|
|
defineHSL,
|
|
|
|
defineHex,
|
2021-01-05 10:52:05 +00:00
|
|
|
};
|
|
|
|
|
2021-02-17 15:44:17 +00:00
|
|
|
module.exports = postcssMixins;
|