MCPcopy Create free account
hub / github.com/anomalyco/opencode / hexToRgb

Function hexToRgb

packages/ui/src/theme/color.ts:11–28  ·  view source on GitHub ↗
(hex: HexColor)

Source from the content-addressed store, hash-verified

9}
10
11export function hexToRgb(hex: HexColor): { r: number; g: number; b: number } {
12 const h = hex.replace("#", "")
13 const full =
14 h.length === 3 || h.length === 4
15 ? h
16 .split("")
17 .map((c) => c + c)
18 .join("")
19 : h
20 const rgb = full.length === 8 ? full.slice(0, 6) : full
21
22 const num = parseInt(rgb, 16)
23 return {
24 r: ((num >> 16) & 255) / 255,
25 g: ((num >> 8) & 255) / 255,
26 b: (num & 255) / 255,
27 }
28}
29
30export function rgbToHex(r: number, g: number, b: number): HexColor {
31 const toHex = (v: number) => {

Callers 6

lumFunction · 0.90
hexToOklchFunction · 0.70
generateAlphaScaleFunction · 0.70
luminanceFunction · 0.70
blendFunction · 0.70
withAlphaFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected