1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports["default"] = void 0;
|
5 | function rgbToHsl(color) {
|
6 |
|
7 | var red = color.red / 255;
|
8 | var green = color.green / 255;
|
9 | var blue = color.blue / 255;
|
10 | var max = Math.max(red, green, blue);
|
11 | var min = Math.min(red, green, blue);
|
12 | var lightness = (max + min) / 2;
|
13 | if (max === min) {
|
14 |
|
15 | if (color.alpha !== undefined) {
|
16 | return {
|
17 | hue: 0,
|
18 | saturation: 0,
|
19 | lightness: lightness,
|
20 | alpha: color.alpha
|
21 | };
|
22 | } else {
|
23 | return {
|
24 | hue: 0,
|
25 | saturation: 0,
|
26 | lightness: lightness
|
27 | };
|
28 | }
|
29 | }
|
30 | var hue;
|
31 | var delta = max - min;
|
32 | var saturation = lightness > 0.5 ? delta / (2 - max - min) : delta / (max + min);
|
33 | switch (max) {
|
34 | case red:
|
35 | hue = (green - blue) / delta + (green < blue ? 6 : 0);
|
36 | break;
|
37 | case green:
|
38 | hue = (blue - red) / delta + 2;
|
39 | break;
|
40 | default:
|
41 |
|
42 | hue = (red - green) / delta + 4;
|
43 | break;
|
44 | }
|
45 | hue *= 60;
|
46 | if (color.alpha !== undefined) {
|
47 | return {
|
48 | hue: hue,
|
49 | saturation: saturation,
|
50 | lightness: lightness,
|
51 | alpha: color.alpha
|
52 | };
|
53 | }
|
54 | return {
|
55 | hue: hue,
|
56 | saturation: saturation,
|
57 | lightness: lightness
|
58 | };
|
59 | }
|
60 | var _default = exports["default"] = rgbToHsl;
|
61 | module.exports = exports.default; |
\ | No newline at end of file |