_various.colors.scss 2.0 KB

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