-
Notifications
You must be signed in to change notification settings - Fork 0
/
host-variable.scss
71 lines (59 loc) · 1.59 KB
/
host-variable.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
@function trip-initial($str) {
@return str-slice($str, 2);
}
$str: "0123456789abcdefghijklmnopqrstuvwxyz";
$chars: ();
@for $i from 1 through 36 {
$char: str-slice($str, $i, $i);
$chars: append($chars, $char);
}
@function random-char($n: 1) {
$res: "";
@for $i from 1 through $n{
$c: nth($chars, random(36));
$res: $res + $c;
}
@return $res;
}
@function host($name, $suffix: "@@@@", $len: 4) {
@if $suffix == "@@@@" {
$suffix: random_char($len);
}
@return "--" + $name + "-" + $suffix;
}
@mixin host-variable($args...) {
$host: $host;
$variable: false;
$default: false;
@if length($args) == 2 {
$variable: nth($args, 1);
$default: nth($args, 2);
} @else if length($args) == 3 {
$host: nth($args, 1);
$variable: nth($args, 2);
$default: nth($args, 3);
} @else {
@warn "length of host-var mixin $args must be 2 or 3!";
}
#{$variable}: $default;
#{$host}#{trip-initial($variable)}: var(#{$variable});
// #{$host}#{$variable}: var(#{$variable});
}
@function host-variable($args...) {
$host: $host;
$variable: false;
@if length($args) == 1 {
$variable: nth($args, 1);
} @else if length($args) == 2 {
$host: nth($args, 1);
$variable: nth($args, 2);
} @else {
@warn "length of host-var mixin $args must be 1 or 2!";
}
@return var(#{$host}#{trip-initial($variable)});
}
// Alias
@mixin host-var($args...) { @include host-variable($args...); }
@mixin hvar($args...) { @include host-variable($args...); }
@function host-var($args...) { @return host-variable($args...); }
@function hvar($args...) { @return host-variable($args...); }