cleanup
This commit is contained in:
@@ -93,6 +93,19 @@ const srgbChannelToLinear = (value: number) => {
|
||||
return ((normalized + 0.055) / 1.055) ** 2.4;
|
||||
};
|
||||
|
||||
export const hexToRgb = (input?: string): (RgbColor & { hex: string }) | null => {
|
||||
if (!input) return null;
|
||||
const match = HEX_COLOR_PATTERN.exec(input.trim());
|
||||
if (!match) return null;
|
||||
const value = parseInt(match[1], 16);
|
||||
return {
|
||||
r: (value >> 16) & 0xff,
|
||||
g: (value >> 8) & 0xff,
|
||||
b: value & 0xff,
|
||||
hex: `#${match[1].toLowerCase()}`,
|
||||
};
|
||||
};
|
||||
|
||||
const hexToOklch = (input?: string) => {
|
||||
const rgb = hexToRgb(input);
|
||||
if (!rgb) {
|
||||
@@ -150,19 +163,6 @@ const buildTagStyle = (backgroundHex: string) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const hexToRgb = (input?: string): (RgbColor & { hex: string }) | null => {
|
||||
if (!input) return null;
|
||||
const match = HEX_COLOR_PATTERN.exec(input.trim());
|
||||
if (!match) return null;
|
||||
const value = parseInt(match[1], 16);
|
||||
return {
|
||||
r: (value >> 16) & 0xff,
|
||||
g: (value >> 8) & 0xff,
|
||||
b: value & 0xff,
|
||||
hex: `#${match[1].toLowerCase()}`,
|
||||
};
|
||||
};
|
||||
|
||||
export const relativeLuminance = ({ r, g, b }: RgbColor): number => {
|
||||
const toLinear = (channel) => {
|
||||
const normalized = channel / 255;
|
||||
@@ -295,7 +295,6 @@ export const getTagColorStyle = (hex) => {
|
||||
adjustments.forEach((delta) => registerCandidate(baseHsl.l + delta));
|
||||
|
||||
let bestBackground = baseHex;
|
||||
let bestText = baseText;
|
||||
let bestRatio = baseRatio;
|
||||
|
||||
if (bestRatio >= TARGET_RATIO) {
|
||||
@@ -303,7 +302,6 @@ export const getTagColorStyle = (hex) => {
|
||||
}
|
||||
|
||||
let compliantBackground = null;
|
||||
let compliantText = null;
|
||||
let compliantDelta = Infinity;
|
||||
let compliantRatio = -Infinity;
|
||||
|
||||
@@ -314,7 +312,6 @@ export const getTagColorStyle = (hex) => {
|
||||
|
||||
if (ratio > bestRatio) {
|
||||
bestBackground = candidateHex;
|
||||
bestText = textHex;
|
||||
bestRatio = ratio;
|
||||
}
|
||||
|
||||
@@ -330,7 +327,6 @@ export const getTagColorStyle = (hex) => {
|
||||
|| (isSimilarDistance && improvesRatio)
|
||||
) {
|
||||
compliantBackground = candidateHex;
|
||||
compliantText = textHex;
|
||||
compliantDelta = delta;
|
||||
compliantRatio = ratio;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user