ismx-nexo-node-app 0.4.120 → 0.4.121
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -12,6 +12,49 @@ class ColorUtils {
|
|
|
12
12
|
static rgbToHex(r, g, b) {
|
|
13
13
|
return `#${((1 << 24) | (r << 16) | (g << 8) | b).toString(16).slice(1)}`;
|
|
14
14
|
}
|
|
15
|
+
static hvsToHex(h, s, v) {
|
|
16
|
+
h = ((h % 360) + 360) % 360;
|
|
17
|
+
s = Math.max(0, Math.min(100, s)) / 100;
|
|
18
|
+
v = Math.max(0, Math.min(100, v)) / 100;
|
|
19
|
+
const c = v * s;
|
|
20
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
21
|
+
const m = v - c;
|
|
22
|
+
let rPrime = 0, gPrime = 0, bPrime = 0;
|
|
23
|
+
if (h < 60) {
|
|
24
|
+
rPrime = c;
|
|
25
|
+
gPrime = x;
|
|
26
|
+
bPrime = 0;
|
|
27
|
+
}
|
|
28
|
+
else if (h < 120) {
|
|
29
|
+
rPrime = x;
|
|
30
|
+
gPrime = c;
|
|
31
|
+
bPrime = 0;
|
|
32
|
+
}
|
|
33
|
+
else if (h < 180) {
|
|
34
|
+
rPrime = 0;
|
|
35
|
+
gPrime = c;
|
|
36
|
+
bPrime = x;
|
|
37
|
+
}
|
|
38
|
+
else if (h < 240) {
|
|
39
|
+
rPrime = 0;
|
|
40
|
+
gPrime = x;
|
|
41
|
+
bPrime = c;
|
|
42
|
+
}
|
|
43
|
+
else if (h < 300) {
|
|
44
|
+
rPrime = x;
|
|
45
|
+
gPrime = 0;
|
|
46
|
+
bPrime = c;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
rPrime = c;
|
|
50
|
+
gPrime = 0;
|
|
51
|
+
bPrime = x;
|
|
52
|
+
}
|
|
53
|
+
const r = Math.round((rPrime + m) * 255);
|
|
54
|
+
const g = Math.round((gPrime + m) * 255);
|
|
55
|
+
const b = Math.round((bPrime + m) * 255);
|
|
56
|
+
return ColorUtils.rgbToHex(r, g, b);
|
|
57
|
+
}
|
|
15
58
|
static interpolate(color1, color2, ratio) {
|
|
16
59
|
const color1Rgb = ColorUtils.hexToRgb(color1);
|
|
17
60
|
const color2Rgb = ColorUtils.hexToRgb(color2);
|
|
@@ -5,6 +5,7 @@ export default abstract class ColorUtils {
|
|
|
5
5
|
b: number;
|
|
6
6
|
};
|
|
7
7
|
static rgbToHex(r: number, g: number, b: number): string;
|
|
8
|
+
static hvsToHex(h: number, s: number, v: number): string;
|
|
8
9
|
static interpolate(color1: string, color2: string, ratio: number): string;
|
|
9
10
|
static contrast(color: string): string;
|
|
10
11
|
static transparency(color: string, transparency: number): string;
|
package/package.json
CHANGED
|
@@ -15,6 +15,31 @@ export default abstract class ColorUtils {
|
|
|
15
15
|
return `#${((1 << 24) | (r << 16) | (g << 8) | b).toString(16).slice(1)}`;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
static hvsToHex(h: number, s: number, v: number): string
|
|
19
|
+
{
|
|
20
|
+
h = ((h % 360) + 360) % 360;
|
|
21
|
+
s = Math.max(0, Math.min(100, s)) / 100;
|
|
22
|
+
v = Math.max(0, Math.min(100, v)) / 100;
|
|
23
|
+
|
|
24
|
+
const c = v * s;
|
|
25
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
26
|
+
const m = v - c;
|
|
27
|
+
|
|
28
|
+
let rPrime = 0, gPrime = 0, bPrime = 0;
|
|
29
|
+
if (h < 60) { rPrime = c; gPrime = x; bPrime = 0; }
|
|
30
|
+
else if (h < 120) { rPrime = x; gPrime = c; bPrime = 0; }
|
|
31
|
+
else if (h < 180) { rPrime = 0; gPrime = c; bPrime = x; }
|
|
32
|
+
else if (h < 240) { rPrime = 0; gPrime = x; bPrime = c; }
|
|
33
|
+
else if (h < 300) { rPrime = x; gPrime = 0; bPrime = c; }
|
|
34
|
+
else { rPrime = c; gPrime = 0; bPrime = x; }
|
|
35
|
+
|
|
36
|
+
const r = Math.round((rPrime + m) * 255);
|
|
37
|
+
const g = Math.round((gPrime + m) * 255);
|
|
38
|
+
const b = Math.round((bPrime + m) * 255);
|
|
39
|
+
|
|
40
|
+
return ColorUtils.rgbToHex(r, g, b);
|
|
41
|
+
}
|
|
42
|
+
|
|
18
43
|
static interpolate(color1: string, color2: string, ratio: number) {
|
|
19
44
|
const color1Rgb = ColorUtils.hexToRgb(color1);
|
|
20
45
|
const color2Rgb = ColorUtils.hexToRgb(color2);
|