-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_testi.scss
126 lines (117 loc) · 3.58 KB
/
_testi.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
$testi_debug: false;
// returns a copy of the array with all falsy values removed
@function _testi_compact($list) {
@each $key, $value in $list {
@if $value == null or $value == "" {
$list: map-remove($list, $key);
}
}
@return $list;
}
// merge recursively two lists
@function _testi_merge($parent-map, $child-map) {
$result: $parent-map;
@each $key, $value in $child-map {
@if (not map-has-key($result, $key)) or (type-of(map-get($result, $key)) != type-of($value)) or (not (type-of(map-get($result, $key)) == map and type-of($value) == map)) {
$result: map-merge($result, ($key: $value));
} @else {
$result: map-merge($result, ($key: _testi_merge(map-get($result, $key), $value)));
}
}
@return $result;
}
// return a preset object according to the given key
@function _testi_getPreset($key) {
@if map-has-key($testi, $key) {
@return map-get($testi, $key);
}
@return null;
}
// return the style object according to the given key
@function _tetsi_getStyle($presetKey) {
$style: _testi_getPreset($presetKey);
@if $style != null {
$extend: _tetsi_getStyle(map-get($style, "extend"));
$style: map-remove($style, "extend");
$style: map-merge((
antialiased: true
), _testi_merge($extend, $style));
@return $style;
} @else {
@return ();
}
}
// apply a list of css rules
@mixin applyStyle($style) {
@each $key, $value in $style {
@if $key == 'antialiased' {
@if $value == true {
-webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased;
-o-font-smoothing: antialiased;
font-smoothing: antialiased;
}
} @else if $key == 'mq' {
@each $breakpoint, $style in map-get($style, 'mq') {
@if mixin-exists('respond-to') and map-has-key(get-breakpoint(), $breakpoint) {
@include respond-to(#{$breakpoint}) {
@include applyStyle($style);
}
} @else if mixin-exists('mq') and map-has-key($mq-breakpoints, $breakpoint) {
@include mq($from: #{$breakpoint}) {
@include applyStyle($style);
}
} @else {
@media #{$breakpoint} {
@include applyStyle($style);
}
}
}
} @else {
#{$key}: $value;
}
}
}
@mixin testi($a:null, $b:null, $c:null, $d:null, $e:null) {
@if global-variable-exists(testi) AND type-of($testi) == 'map' {
@if type-of($a) == 'string' {
@if map-has-key($testi, $a) {
// extend default style with a preset
$style: _tetsi_getStyle($a);
// extend style with the given arguments
$style: map-merge($style, _testi_compact((
font-size: $b,
line-height: $c,
font-weight: $d,
letter-spacing: $e
)));
// set style
@include applyStyle($style);
@if $testi_debug == true {
&:before {
content: '#{$a}';
display: block;
max-width: 300px;
font-family: Arial;
font-weight: bold;
padding: 2px;
font-size: 10px;
line-height: 9px;
color: black;
background: #00ff30;
font-family: Arial;
position: relative;
text-transform: uppercase;
letter-spacing: 0em;
}
}
} @else {
@warn 'Preset "#{$a}" not found; available presets: #{map-keys($testi)}';
}
} @else {
@warn 'Text mixin require a preset name as first argument; available presets: #{map-keys($testi)}';
}
} @else {
@warn '"$testi" variable not found';
}
}