mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-30 00:50:47 +03:00
1 parent
2b77e593cd
commit
4da56575c2
1 file changed
+2
-2
@@ -60,7 +60,7 @@ function getContrastColor(hue: number, saturation: number, lightness: number): s
|
||||
const m = l - c / 2;
|
||||
|
||||
// Compact RGB calculation using array indexing
|
||||
const hueSegment = Math.floor(h * 6);
|
||||
const hueSegment = Math.floor(Math.abs(h) * 6);
|
||||
const rgbValues = [
|
||||
[c, x, 0], // 0-60°
|
||||
[x, c, 0], // 60-120°
|
||||
@@ -70,7 +70,7 @@ function getContrastColor(hue: number, saturation: number, lightness: number): s
|
||||
[c, 0, x], // 300-360°
|
||||
];
|
||||
|
||||
const [r, g, b] = rgbValues[hueSegment].map((val) => (val + m) * 255);
|
||||
const [r, g, b] = rgbValues[hueSegment % 6].map((val) => (val + m) * 255);
|
||||
|
||||
// Calculate relative luminance and return appropriate contrast color
|
||||
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
||||
|
||||
Reference in new issue
Block a user