_various.colors.scss 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // $color is either a color or an hsl tuple
  2. @mixin define-color($name, $color) {
  3. $h: null;
  4. $s: null;
  5. $l: null;
  6. @if type-of($color) == color {
  7. $h: hue($color) / 1deg; // Cast to unitless
  8. $s: saturation($color);
  9. $l: lightness($color);
  10. } @else {
  11. $h: nth($color, 1);
  12. $s: nth($color, 2);
  13. $l: nth($color, 3);
  14. }
  15. --#{$name}-hue: #{$h};
  16. --#{$name}-saturation: #{$s};
  17. --#{$name}-lightness: #{$l};
  18. --#{$name}: hsl(#{ var(--#{$name}-hue), var(--#{$name}-saturation), var(--#{$name}-lightness) });
  19. }
  20. @function get-color($name) {
  21. @return (var(--#{$name}-hue), var(--#{$name}-saturation), var(--#{$name}-lightness));
  22. }
  23. @function css-darken($hsl-tuple, $darken-by) {
  24. $h: nth($hsl-tuple, 1);
  25. $s: nth($hsl-tuple, 2);
  26. $l: nth($hsl-tuple, 3);
  27. @return ($h, $s, calc(#{$l} - #{$darken-by + 0%}));
  28. }
  29. @function css-lighten($hsl-tuple, $lighten-by) {
  30. $h: nth($hsl-tuple, 1);
  31. $s: nth($hsl-tuple, 2);
  32. $l: nth($hsl-tuple, 3);
  33. @return ($h, $s, calc(#{$l} + #{$lighten-by + 0%}));
  34. }
  35. @function css-saturate($hsl-tuple, $saturate-by) {
  36. $h: nth($hsl-tuple, 1);
  37. $s: nth($hsl-tuple, 2);
  38. $l: nth($hsl-tuple, 3);
  39. @return ($h, calc(#{$s} + #{$saturate-by + 0%}), $l);
  40. }
  41. @function css-desaturate($hsl-tuple, $desaturate-by) {
  42. $h: nth($hsl-tuple, 1);
  43. $s: nth($hsl-tuple, 2);
  44. $l: nth($hsl-tuple, 3);
  45. @return ($h, calc(#{$s} - #{$desaturate-by + 0%}), $l);
  46. }
  47. @function css-adjust-hue($hsl-tuple, $adjust-by) {
  48. $h: nth($hsl-tuple, 1);
  49. $s: nth($hsl-tuple, 2);
  50. $l: nth($hsl-tuple, 3);
  51. @return (calc(#{$h} + #{$adjust-by}), $s, $l);
  52. }
  53. @function css-transparentize($hsl-tuple, $alpha) {
  54. $h: nth($hsl-tuple, 1);
  55. $s: nth($hsl-tuple, 2);
  56. $l: nth($hsl-tuple, 3);
  57. @return ($h, $s, $l, $alpha);
  58. }