🚨 Fixed DeepSource issues

This commit is contained in:
Mawoka
2023-06-14 16:33:44 +02:00
parent 6673a77b8a
commit db26082a00
28 changed files with 47 additions and 68 deletions
+10 -9
View File
@@ -10,8 +10,8 @@ export const invertColor = (hexTripletColor: string): string => {
let color_int = parseInt(color, 16); // convert to integer
color_int = 0xffffff ^ color_int; // invert three bytes
color = color_int.toString(16); // convert to hex
color = ('000000' + color).slice(-6); // pad with leading zeros
color = '#' + color; // prepend #
color = `000000${color}`.slice(-6); // pad with leading zeros
color = `#${color}`; // prepend #
return color;
};
@@ -20,13 +20,6 @@ export const calculate_score = (q_time: number, time_taken: number): number => {
};
export type RGB = [number, number, number];
export const getContrast = (foregroundColor: RGB, backgroundColor: RGB) => {
const foregroundLuminance = getLuminance(foregroundColor);
const backgroundLuminance = getLuminance(backgroundColor);
return backgroundLuminance < foregroundLuminance
? (backgroundLuminance + 0.05) / (foregroundLuminance + 0.05)
: (foregroundLuminance + 0.05) / (backgroundLuminance + 0.05);
};
export const getLuminance = (rgb: RGB): number => {
const [r, g, b] = rgb.map((v) => {
@@ -36,6 +29,14 @@ export const getLuminance = (rgb: RGB): number => {
return r * 0.2126 + g * 0.7152 + b * 0.0722;
};
export const getContrast = (foregroundColor: RGB, backgroundColor: RGB) => {
const foregroundLuminance = getLuminance(foregroundColor);
const backgroundLuminance = getLuminance(backgroundColor);
return backgroundLuminance < foregroundLuminance
? (backgroundLuminance + 0.05) / (foregroundLuminance + 0.05)
: (foregroundLuminance + 0.05) / (backgroundLuminance + 0.05);
};
export const getRgbColorFromHex = (hex: string): RGB => {
hex = hex.slice(1);
const value = parseInt(hex, 16);