MCPcopy Create free account
hub / github.com/bernaferrari/FigmaToCode / htmlColor

Function htmlColor

packages/backend/src/html/builderImpl/htmlColor.ts:80–99  ·  view source on GitHub ↗
(color: RGB, alpha: number = 1)

Source from the content-addressed store, hash-verified

78 * Convert RGB color to CSS color string
79 */
80export const htmlColor = (color: RGB, alpha: number = 1): string => {
81 if (color.r === 1 && color.g === 1 && color.b === 1 && alpha === 1) {
82 return "white";
83 }
84 if (color.r === 0 && color.g === 0 && color.b === 0 && alpha === 1) {
85 return "black";
86 }
87 if (alpha === 1) {
88 const r = Math.round(color.r * 255);
89 const g = Math.round(color.g * 255);
90 const b = Math.round(color.b * 255);
91 const toHex = (num: number): string => num.toString(16).padStart(2, "0");
92 return `#${toHex(r)}${toHex(g)}${toHex(b)}`.toUpperCase();
93 }
94 const r = numberToFixedString(color.r * 255);
95 const g = numberToFixedString(color.g * 255);
96 const b = numberToFixedString(color.b * 255);
97 const a = numberToFixedString(alpha);
98 return `rgba(${r}, ${g}, ${b}, ${a})`;
99};
100
101/**
102 * Process a single gradient stop

Callers 2

htmlShadowFunction · 0.90
processColorWithVariableFunction · 0.85

Calls 2

numberToFixedStringFunction · 0.90
toHexFunction · 0.70

Tested by

no test coverage detected