color-helper.nix (535B)
1 lib: r: g: b: a: 2 let 3 s = toString; 4 toUnsignedInt = n: lib.toInt (builtins.head (builtins.match "^([0-9]*).*$" (builtins.toString n))); 5 toHex = n: builtins.head (builtins.match "^.*(.{2})$" "0${lib.toHexString (toUnsignedInt n)}"); 6 xr = toHex r; 7 xg = toHex g; 8 xb = toHex b; 9 xa = toHex (a * 255); 10 in 11 { 12 inherit 13 r 14 g 15 b 16 a 17 xr 18 xg 19 xb 20 xa 21 ; 22 rgba = "rgba(${s r},${s g},${s b},${s a})"; 23 rgbaHex = "rgba(${xr}${xg}${xb}${xa})"; 24 hex = "${xr}${xg}${xb}"; 25 hexRgba = "${xr}${xg}${xb}${xa}"; 26 }