MCPcopy Create free account
hub / github.com/apitable/apitable / rgba2hex

Function rgba2hex

packages/core/src/model/color.ts:27–38  ·  view source on GitHub ↗
(foregroundColor: string, backgroundColor = '#FFFFFF')

Source from the content-addressed store, hash-verified

25const COLOR_LEVEL_ALPHA = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8, 1];
26
27const rgba2hex = (foregroundColor: string, backgroundColor = '#FFFFFF') => {
28 const getAdjustedChannel = (fValue: number, bValue: number, opacity: number) => opacity * fValue + (1 - opacity) * bValue;
29 const fc = Color(foregroundColor);
30 const bc = Color(backgroundColor);
31 const opacity = fc.alpha();
32 const adjustedColor = Color([
33 getAdjustedChannel(fc.red(), bc.red(), opacity),
34 getAdjustedChannel(fc.green(), bc.green(), opacity),
35 getAdjustedChannel(fc.blue(), bc.blue(), opacity),
36 ]);
37 return adjustedColor.hex();
38};
39
40export const getColorValue = (color: string, alpha: number) => {
41 return rgba2hex(Color(color).alpha(alpha).string());

Callers 1

getColorValueFunction · 0.70

Calls 2

getAdjustedChannelFunction · 0.70
ColorClass · 0.50

Tested by

no test coverage detected