From 4c88538c4d267de7cd21cc29c07e7c8360145441 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Fri, 25 Oct 2024 19:04:07 +0200 Subject: New palette generation --- src/_functions.scss | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) (limited to 'src/_functions.scss') diff --git a/src/_functions.scss b/src/_functions.scss index 27b850c..62caf8c 100644 --- a/src/_functions.scss +++ b/src/_functions.scss @@ -7,49 +7,41 @@ @use 'iro-sass/src/easing'; @use 'apca'; -@function palette($base-color, $contrasts, $chroma-range: 1, $ref-color: $base-color, $chroma-easing: 'ease') { +@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); - $cmax: math.max(map.values($contrasts)...); - $cmax: math.max($cmax, math.abs(math.min(map.values($contrasts)...))); - $black-y: apca.sRGB_to_Y(#000); $white-y: apca.sRGB_to_Y(#fff); - $chroma-inv: false; - @if $chroma-range < 0 { - $chroma-inv: true; - $chroma-range: -1 * $chroma-range; - } - $chroma-easing: meta.get-function($chroma-easing, $module: easing); - $palette: (); - @each $key, $contrast in $contrasts { - $y: apca.reverse($contrast, $ref-y); - $l: color.channel($base-lch, 'lightness'); + @each $key, $level in $levels { + $color: list.nth($level, 1); + $y: 0; $c: 1; - @if $y != false { - $l: color.channel(apca.Y_to_sRGB($y), 'lightness', oklch); - } @else { - $y: $ref-y; + @if list.length($level) > 1 { + $c: list.nth($level, 2); } - @if $chroma-range != 1 { - $c: if($ref-l > 50%, math.clamp(0, math.div($contrast, $cmax), 1), -1 * math.clamp(-1, math.div($contrast, $cmax), 0)); - @if $chroma-inv { - $c: 1 - $c; + @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; } - $c: meta.call($chroma-easing, $c); - $c: $chroma-range + (1 - $chroma-range) * $c; - } - $color: oklch($l ($c * color.channel($base-lch, 'chroma')) color.channel($base-lch, 'hue')); + $color: oklch($l ($c * color.channel($base-lch, 'chroma')) 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); -- cgit v1.2.3-70-g09d2