-
-
Notifications
You must be signed in to change notification settings - Fork 216
/
stylus.styl
251 lines (201 loc) · 6.61 KB
/
stylus.styl
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// Stylus RFS mixin
//
// Automated responsive values for font sizes, paddings, margins and much more
//
// Licensed under MIT (https://github.com/twbs/rfs/blob/main/LICENSE)
// Configuration
// Base value
$rfs-base-value ?= 1.25rem
$rfs-unit ?= rem
// Breakpoint at where values start decreasing if screen width is smaller
$rfs-breakpoint ?= 1200px
$rfs-breakpoint-unit ?= px
// Resize values based on screen height and width
$rfs-two-dimensional ?= false
// Factor of decrease
$rfs-factor ?= 10
// Mode. Possibilities: "min-media-query", "max-media-query"
$rfs-mode ?= "min-media-query"
// Generate enable or disable classes. Possibilities: false, "enable" or "disable"
$rfs-class ?= false
// 1 rem = $rfs-rem-value px
$rfs-rem-value ?= 16
// Safari iframe resize bug: https://github.com/twbs/rfs/issues/14
$rfs-safari-iframe-resize-bug-fix ?= false
// Disable RFS by setting $enable-rfs to false
$enable-rfs ?= true
// Cache $rfs-base-value unit
$rfs-base-value-unit = unit($rfs-base-value)
// Remove px-unit from $rfs-base-value for calculations
if $rfs-base-value-unit == "px"
$rfs-base-value = unit($rfs-base-value, "")
else if $rfs-base-value-unit == "rem"
$rfs-base-value = unit($rfs-base-value * $rfs-rem-value, "")
// Cache $rfs-breakpoint unit to prevent multiple calls
$rfs-breakpoint-unit-cache = unit($rfs-breakpoint)
// Remove unit from $rfs-breakpoint for calculations
if $rfs-breakpoint-unit-cache == "px"
$rfs-breakpoint = unit($rfs-breakpoint, "")
else if $rfs-breakpoint-unit-cache == "rem" or $rfs-breakpoint-unit-cache == "em"
$rfs-breakpoint = unit($rfs-breakpoint * $rfs-rem-value, "")
if $rfs-breakpoint-unit == px
$rfs-mq-value = unit($rfs-breakpoint, px)
else
$rfs-mq-value = unit($rfs-breakpoint / $rfs-rem-value, $rfs-breakpoint-unit)
if $rfs-mode == min-media-query
$rfs-mq-property-width = min-width
else
$rfs-mq-property-width = max-width
if $rfs-mode == min-media-query
$rfs-mq-property-height = min-height
else
$rfs-mq-property-height = max-height
_rfs-rule()
if $rfs-class == "disable" and $rfs-mode == max-media-query
&,
.disable-rfs &,
&.disable-rfs
{block}
else if $rfs-class == "enable" and $rfs-mode == min-media-query
.enable-rfs &,
&.enable-rfs
{block}
else
{block}
_rfs-media-query-rule()
if $rfs-class == "enable"
if $rfs-mode == min-media-query
{block}
+_rfs-media-query()
.enable-rfs &,
&.enable-rfs
{block}
else
if $rfs-class == disable and $rfs-mode == min-media-query
.disable-rfs &,
&.disable-rfs
{block}
+_rfs-media-query()
{block}
// Internal mixin used to determine which media query needs to be used
_rfs-media-query()
if $rfs-two-dimensional
if $rfs-mode == min-media-query
@media ({$rfs-mq-property-width}: $rfs-mq-value) and ({$rfs-mq-property-height}: $rfs-mq-value)
{block}
else
@media ({$rfs-mq-property-width}: $rfs-mq-value), ({$rfs-mq-property-height}: $rfs-mq-value)
{block}
else
@media ({$rfs-mq-property-width}: $rfs-mq-value)
{block}
// Helper function to get the formatted non-responsive value
rfs-value($value)
if $value == 0
0
else if type-of($value) != "unit"
$value
else
$unit = unit($value)
if $unit == "px"
if $rfs-unit == "rem"
unit($value / $rfs-rem-value, rem)
else
unit($value, px)
else if $unit == "rem"
if $rfs-unit == "rem"
unit($value, rem)
else
unit($value * $rfs-rem-value, px)
else
$value
// Helper function to get the responsive value calculated by RFS
rfs-fluid-value($value)
if $value == 0
0
else if type-of($value) != "unit"
$value
else if unit($value) != "px" and unit($value) != "rem"
$value
else
if unit($value) == "rem"
$value = unit($value * $rfs-rem-value, "")
else
$value = unit($value, "")
// Only add the media query if the value is greater than the minimum value
if abs($value) <= $rfs-base-value or !$enable-rfs
if $rfs-unit == "rem"
unit($value / $rfs-rem-value, rem)
else
unit($value, px)
else
// Calculate the minimum value
$value-min = $rfs-base-value + (abs($value) - $rfs-base-value) / $rfs-factor;
// Calculate difference between $value and the minimum value
$value-diff = abs($value) - $value-min;
// Base value formatting
if $rfs-unit == rem
$min-width = unit($value-min / $rfs-rem-value, rem)
else
$min-width = unit($value-min, px)
// Use `vmin` if two-dimensional is enabled
if $rfs-two-dimensional
$variable-unit = vmin
else
$variable-unit = vw
// Calculate the variable width between 0 and $rfs-breakpoint
$variable-width = unit(round($value-diff * 100) / $rfs-breakpoint, $variable-unit)
// Return the calculated value
if $value != abs($value)
unquote("calc(-" + $min-width + " - " + $variable-width + ")")
else
unquote("calc(" + $min-width + " + " + $variable-width + ")")
// RFS mixin
rfs($values, $property = font-size)
$val = ''
$fluidVal = ''
// Loop over each value and calculate responsive & non-responsive values
for $value in $values
$val+= ' ' + rfs-value($value)
$fluidVal+= ' ' + rfs-fluid-value($value)
// Remove first space
$val = unquote(slice($val, 1))
$fluidVal = unquote(slice($fluidVal, 1))
// Do not print the media query if responsive & non-responsive values are the same
if $val == $fluidVal
{$property}: $val
else
+_rfs-rule()
if $rfs-mode == "min-media-query"
{$property}: $fluidVal
else
{$property}: $val
if $rfs-safari-iframe-resize-bug-fix and $rfs-mode == "min-media-query"
min-width: 0vw
+_rfs-media-query-rule()
if $rfs-mode == "min-media-query"
{$property}: $val
else
{$property}: $fluidVal
rfs-font-size($value)
rfs($value)
rfs-padding($value, $property = padding)
rfs($value, $property)
rfs-padding-top($value, $property = padding-top)
rfs($value, $property)
rfs-padding-right($value, $property = padding-right)
rfs($value, $property)
rfs-padding-bottom($value, $property = padding-bottom)
rfs($value, $property)
rfs-padding-left($value, $property = padding-left)
rfs($value, $property)
rfs-margin($value, $property = margin)
rfs($value, $property)
rfs-margin-top($value, $property = margin-top)
rfs($value, $property)
rfs-margin-right($value, $property = margin-right)
rfs($value, $property)
rfs-margin-bottom($value, $property = margin-bottom)
rfs($value, $property)
rfs-margin-left($value, $property = margin-left)
rfs($value, $property)