summaryrefslogtreecommitdiffstats
path: root/src/_functions.scss
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2022-02-13 10:15:46 +0100
committerVolpeon <git@volpeon.ink>2022-02-13 10:15:46 +0100
commit1c7272be54be8783d81dd25900c6c7dc9beca09d (patch)
tree941216fd904303222b73e9ffb5fb1fd6e68dd045 /src/_functions.scss
parentCalculate gray palette via contrast automatically (diff)
downloadiro-design-1c7272be54be8783d81dd25900c6c7dc9beca09d.tar.gz
iro-design-1c7272be54be8783d81dd25900c6c7dc9beca09d.tar.bz2
iro-design-1c7272be54be8783d81dd25900c6c7dc9beca09d.zip
Better palette generation algorithm
Diffstat (limited to 'src/_functions.scss')
-rw-r--r--src/_functions.scss45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/_functions.scss b/src/_functions.scss
index 9425413..73a1ec9 100644
--- a/src/_functions.scss
+++ b/src/_functions.scss
@@ -1,4 +1,7 @@
1@use 'sass:math';
1@use 'iro-sass/src/index' as iro; 2@use 'iro-sass/src/index' as iro;
3@use '@oddbird/blend';
4@use '@oddbird/blend/sass/convert' as blend-convert;
2 5
3@function color($key, $tree: 'colors', $default: null, $global: false) { 6@function color($key, $tree: 'colors', $default: null, $global: false) {
4 @return iro.props-get(join(--colors, $key), $tree, $default, $global); 7 @return iro.props-get(join(--colors, $key), $tree, $default, $global);
@@ -59,3 +62,45 @@
59 } 62 }
60 } 63 }
61} 64}
65
66@function multi-contrast($base-color, $colors, $wanted-contrasts) {
67 $dir: if(lightness($base-color) >= 50%, -1, 1);
68 $base-lum: nth(blend-convert.lin_sRGB_to_XYZ(blend-convert.lin_sRGB(blend-convert.sassToRgb($base-color))), 2) + .05;
69
70 $result: ();
71 $colors-len: length($colors);
72 $colors-idx: if($dir == -1, $colors-len, 1);
73 $wanted-len: length($wanted-contrasts);
74 $wanted-idx: 1;
75
76 @while $colors-idx >= 1 and $colors-idx <= $colors-len and $wanted-idx <= $wanted-len {
77 $color: nth($colors, $colors-idx);
78 $lum: nth(blend-convert.lin_sRGB_to_XYZ(blend-convert.lin_sRGB(blend-convert.sassToRgb($color))), 2) + .05;
79 $contrast: math.div(math.max($base-lum, $lum), math.min($lum, $base-lum));
80
81 @if $contrast != 1 {
82 $contrast: $dir * $contrast;
83
84 @if $lum <= $base-lum {
85 $contrast: -1 * $contrast;
86 }
87 }
88
89 $wanted-contrast: nth($wanted-contrasts, $wanted-idx);
90
91 @if $contrast >= $wanted-contrast {
92 $result: append($result, $color);
93 $wanted-idx: $wanted-idx + 1;
94 } @else {
95 $colors-idx: $colors-idx + $dir * 1;
96 }
97 }
98
99 $last-color: nth($colors, if($dir == -1, 1, $colors-len));
100
101 @for $i from $wanted-idx through $wanted-len {
102 $result: append($result, $last-color);
103 }
104
105 @return $result;
106}