@use 'sass:color'; @use 'sass:math'; @use 'sass:map'; @use 'sass:list'; @use 'sass:meta'; @use 'iro-sass/src/easing'; @use 'apca'; @function palette($base-color, $levels, $ref-color: $base-color) { $base-lch: color.to-space($base-color, oklch); $ref-lch: color.to-space($ref-color, oklch); $ref-l: color.channel($ref-lch, 'lightness'); $ref-y: apca.sRGB_to_Y($ref-lch); $black-y: apca.sRGB_to_Y(#000); $white-y: apca.sRGB_to_Y(#fff); $palette: (); @each $key, $level in $levels { $color: list.nth($level, 1); $y: 0; $c: 1; $h: 0deg; @if list.length($level) > 1 { $c: list.nth($level, 2); } @if list.length($level) > 2 { $h: list.nth($level, 3); } @if meta.type-of($color) != 'color' { $y: apca.reverse($color, $ref-y); $l: color.channel($base-lch, 'lightness'); @if $y != false { $l: color.channel(apca.Y_to_sRGB($y), 'lightness', oklch); } @else { $y: $ref-y; } $color: oklch($l ($c * color.channel($base-lch, 'chroma')) ($h + color.channel($base-lch, 'hue'))); } @else { $y: apca.sRGB_to_Y($color); } $contrast-black: apca.contrast($black-y, $y); $contrast-white: apca.contrast($white-y, $y); $palette: map.set($palette, $key, $color); $palette: map.set($palette, #{$key}-text, if(math.abs($contrast-black) > math.abs($contrast-white), #000, #fff)); } @return $palette; } @function transparent-palette($color, $text, $alphas) { $palette: ( --text: $text, ); @each $key, $alpha in $alphas { $palette: map.set($palette, $key, rgba($color, $alpha)); } @return $palette; }