MCPcopy Create free account
hub / github.com/alephdata/aleph / reduceTranslucentColor

Function reduceTranslucentColor

ui/src/util/reduceTranslucentColor.ts:27–42  ·  view source on GitHub ↗
(hex: string, opacity: number)

Source from the content-addressed store, hash-verified

25// Calculate the HEX representation for a color as if
26// it was rendered on a white background
27export function reduceTranslucentColor(hex: string, opacity: number) {
28 const color = hexToRgb(hex);
29 const white = { r: 255, g: 255, b: 255 };
30
31 if (!color) {
32 return undefined;
33 }
34
35 const reducedRgb = {
36 r: Math.round(opacity * color.r + (1 - opacity) * white.r),
37 g: Math.round(opacity * color.g + (1 - opacity) * white.g),
38 b: Math.round(opacity * color.b + (1 - opacity) * white.b),
39 };
40
41 return rgbToHex(reducedRgb);
42}

Callers 3

getColorMethod · 0.90

Calls 2

hexToRgbFunction · 0.85
rgbToHexFunction · 0.85

Tested by

no test coverage detected