-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
57 lines (53 loc) · 1.76 KB
/
utils.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* @typedef {import('color')} Color
*/
module.exports = {
/**
* Convert a pixel value to rem
* @param {String|Number} pixel - the value to convert in pixels
* @param {String|Number?} context - the base font-size value in pixels
*/
calcRem(pixel, context = 16) {
return parseFloat(pixel) / parseFloat(context) + 'rem';
},
/**
* Replacement for Sass's lighten function
* https://sass-lang.com/documentation/modules/color#lighten
* @param {Color} color
* @param {Number} amount - the percent to increase the lightness by e.g. `3` will increase a lightness of 40% to 43%
* @return {Color}
*/
lighten(color, amount) {
return color.lightness(color.lightness() + amount);
},
/**
* Replacement for Sass's darken function
* https://sass-lang.com/documentation/modules/color#darken
* @param {Color} color
* @param {Number} amount - the percent to decrease the lightness by e.g. `3` will decrease a lightness of 43% to 40%
* @return {Color}
*/
darken(color, amount) {
return color.lightness(color.lightness() - amount);
},
/**
* Replacement for Sass's mix function
* https://sass-lang.com/documentation/modules/color#mix
* @param {Color} firstColor
* @param {Color} secondColor
* @param {Number} weight - the weight from 0-100 of the first color in the mix
* @return {Color}
*/
mix(firstColor, secondColor, weight) {
return firstColor.mix(secondColor, weight / 100);
},
/**
* Utility to use @apply within Tailwind plugins
* @param {Array<String>} classes - the classes to apply
*/
apply(classes) {
return {
[`@apply ${classes.join(' ')}`]: {},
};
},
};