-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.scss
76 lines (70 loc) · 1.67 KB
/
index.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
69
70
71
72
73
74
75
76
@use 'sass:map';
@use 'sass:string';
@use 'sass:list';
@use './map' as *;
@use './utils';
// Transform query to class
@function query-transform($keys) {
// Combine (:)
@if string.index($keys, ':') {
$cls: ();
@each $class in utils.split($keys, ':') {
@if $class != '' {
$cls: list.append($cls, utils.get-class($classmap, $class));
}
}
@return utils.join-list($cls);
}
// Direct descandant (>)
@if string.index($keys, '>') {
@return utils.css-selector($keys, '>');
}
// Sibling selector (~)
@if string.index($keys, '~') {
@return utils.css-selector($keys, '~');
}
// Direct sibling selector
@if string.index($keys, '+') {
@return utils.css-selector($keys, '+');
}
@return utils.get-class($classmap, $keys);
}
@function format($keys) {
$not: null;
@if string.index($keys, '!') {
$classes: utils.split($keys, '!');
$first: if(list.nth($classes, 1) != '', query-transform(list.nth($classes, 1)), '');
$rest: null;
@each $class in utils.remove-nth($classes, 1) {
@if $rest == null {
$rest: query-transform($class);
} @else {
$rest: $rest + ',' + query-transform($class);
}
}
$not: $first + ':not(' + $rest + ')';
}
@return if($not == null, query-transform($keys), $not);
}
@function cls($keys) {
$A: ();
$B: ();
$C: ();
// Split group (,)
@each $group in utils.split($keys, ',') {
$A: list.append($A, $group);
}
// Split space
@each $query in $A {
$B: list.append($B, utils.split($query, ' '));
}
// Format and join
@each $group in $B {
$_A: ();
@each $query in $group {
$_A: list.append($_A, format($query));
}
$C: list.append($C, utils.str-trim(utils.join-list($_A, ' ')));
}
@return utils.join-list($C, ',');
}