-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.scss
68 lines (57 loc) · 1.44 KB
/
library.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@use "sass:color";
@use "sass:map";
@use "sass:math";
@use "sass:meta";
@use "sass:string";
$theme: () !default;
@function split($string, $separator) {
$split-arr: ();
$index : string.index($string, $separator);
@while $index != null {
$item: string.slice($string, 1, $index - 1);
$split-arr: append($split-arr, $item);
$string: string.slice($string, $index + 1);
$index : string.index($string, $separator);
}
$split-arr: append($split-arr, $string);
@return $split-arr;
}
@function get($path) {
$result: $theme;
@each $key in split($path, ".") {
$result: map.get($result, $key);
}
@return $result;
}
@function use($color, $alpha: null) {
@if meta.type-of($color) == 'string' {
$color: get($color);
}
@if $alpha != null {
@return color.change($color, $alpha: $alpha);
}
@return $color;
}
@function blend($color, $background, $alpha: null) {
$color: use($color);
$background: use($background);
@if $alpha == null {
$alpha: color.alpha($color);
}
@if ($alpha == 1) {
@return $color;
}
$color: color.change($color, $alpha: 1);
$background: color.change($background, $alpha: 1);
@return color.mix($color, $background, $alpha * 100%);
}
@function raw($color) {
$red: math.div(color.red($color), 255);
$green: math.div(color.green($color), 255);
$blue: math.div(color.blue($color), 255);
$alpha: color.alpha($color);
@return $red, $green, $blue, $alpha;
}
@function array($color) {
@return [#{raw($color)}];
}