-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.scss
440 lines (411 loc) · 10.1 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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/// Strip the unit from a number.
///
/// @group number
///
/// @parameter {Number} $number
/// @return {Number}
///
/// @example
/// @debug strip-unit(5px);
/// //=> 5
@function strip-unit($number) {
@return $number / ($number * 0 + 1);
}
/// Clamp `$number` between `$min` and `$max`.
///
/// @group number
///
/// @parameter {Number} $number - Number to clamp
/// @parameter {Number} $min - Minimum number
/// @parameter {Number} $max - Maximum number
/// @return {Number}
///
/// @example
/// @debug math-clamp(1, 2, 4);
/// //=> 2
@function number-clamp($number, $min, $max) {
@return min(max($number, $min), $max);
}
/// Invert a number.
///
/// @group number
///
/// @parameter {Number} $number - Number to invert
/// @return {Number}
///
/// @example
/// @debug number-invert(5);
/// //=> -5
@function number-invert($number) {
@return $number * -1;
}
/// Check if `$string` contains the given `$substring`.
///
/// @group string
///
/// @parameter {String} $string - String to check
/// @parameter {String} $substring - Substring to search for in `$string`
/// @return {Boolean}
///
/// @example
/// @debug string-contains('foo bar baz', $substring: 'bar');
/// //=> true
@function string-contains($string, $substring) {
@return str-index($string, $substring) != null;
}
/// Check if `$string` starts with the given `$substring`.
///
/// @group string
///
/// @parameter {String} $string - String to check
/// @parameter {String} $substring - Substring to search for at the start of `$string`
/// @return {Boolean}
///
/// @example
/// @debug string-starts-with('foo bar', $substring: 'foo');
/// //=> true
@function string-starts-with($string, $substring) {
@return str-index($string, $substring) == 1;
}
/// Check if `$string` ends with the given `$substring`.
///
/// @group string
///
/// @parameter {String} $string - String to check
/// @parameter {String} $substring - Substring to search for at the end of `$string`
/// @return {Boolean}
///
/// @example
/// @debug string-ends-with('foo bar', $substring: 'bar');
/// //=> true
@function string-ends-with($string, $substring) {
// This crashes libsass…
// @return str-slice($string, str-length($substring) * -1) == $substring;
@return str-slice($string, (str-length($string) - str-length($substring) + 1)) == $substring;
}
/// Replace substring `$search` in `$string` with `$replacement`.
///
/// @group string
///
/// @parameter {String} $string - String to search
/// @parameter {String} $search - Substring to search for in `$string`
/// @parameter {String} $replacement - Replacement for `$search`
/// @return {String}
///
/// @example
/// @debug string-replace('foo bar baz', $search: 'bar', $replacement: 'unicorn');
/// //=> 'foo unicorn baz'
@function string-replace($string, $search, $replacement: '') {
$index: str-index($string: $string, $substring: $search);
@if $index {
@return
str-slice($string, $start-at: 1, $end-at: $index - 1)
+ $replacement
+ string-replace(str-slice($string, $start-at: $index + str-length($search)), $search, $replacement);
}
@return $string;
}
/// Get the first element of `$list`.
///
/// @group list
///
/// @parameter {List} $list
/// @return {*}
///
/// @example
/// @debug list-first((1, 2, 3));
/// //=> 1
@function list-first($list) {
@return nth($list, 1);
}
/// Get the last element of `$list`.
///
/// @group list
///
/// @parameter {List} $list
/// @return {*}
///
/// @example
/// @debug list-last((1, 2, 3));
/// //=> 3
@function list-last($list) {
@return nth($list, -1);
}
/// Generate a pseudorandom integer.
/// Uses the [`Park-Miller` algorithm](https://en.wikipedia.org/wiki/Lehmer_random_number_generator).
///
/// @group random
///
/// @parameter {Number} $seed - The same [`$seed`](https://en.wikipedia.org/wiki/Random_seed) will generate the same number
/// @return {Number}
///
/// @example
/// @debug seed-random-integer(5);
/// //=> 84035
@function seed-random-integer($seed) {
$max-int32: 2147483647;
$minstd: 16807;
$seed: $seed % $max-int32;
@if $seed <= 0 {
$seed: $seed + ($max-int32 - 1);
}
@return ($seed * $minstd) % $max-int32;
}
/// Generate a pseudorandom float.
/// Uses the [`Park-Miller` algorithm](https://en.wikipedia.org/wiki/Lehmer_random_number_generator).
///
/// Note: You'll need to increase the default Sass precision to at least 10 for this method to be useful.
///
/// @group random
///
/// @parameter {Number} $seed - The same [`$seed`](https://en.wikipedia.org/wiki/Random_seed) will generate the same number
/// @return {Number}
///
/// @example
/// @debug seed-random-float(5);
/// //=> 0.0000391314
@function seed-random-float($seed) {
$max-int32: 2147483647;
$integer: seed-random-integer($seed);
@return ($integer - 1) / ($max-int32 - 1);
}
/// Generate a pseudorandom boolean.
/// Uses the [`Park-Miller` algorithm](https://en.wikipedia.org/wiki/Lehmer_random_number_generator).
///
/// @group random
///
/// @parameter {Number} $seed - The same [`$seed`](https://en.wikipedia.org/wiki/Random_seed) will generate the same number
/// @return {Boolean}
///
/// @example
/// @debug seed-random-boolean(5);
/// //=> false
@function seed-random-boolean($seed) {
@return seed-random-integer($seed) % 2 == 0;
}
/// Get a random [aesthetically pleasing color](https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/).
///
/// @group random
///
/// @parameter {Number} $saturation [0.5] - Color saturation in the range `0...1`
/// @parameter {Number} $lightness [0.5] - Color lightness in the range `0...1`
/// @return {Color}
///
/// @example
/// .foo {
/// background-color: random-color();
/// }
///
/// @example css - Output CSS
/// .foo {
/// background-color: random-color();
/// }
@function random-color($saturation: 0.5, $lightness: 0.5) {
/* stylelint-disable-next-line number-max-precision */
$golden-ratio-conjugate: 0.618033988749895;
$hue: (random() + $golden-ratio-conjugate) % 1;
@return hsl($hue * 360, $saturation * 100, $lightness * 100);
}
/// Encode URL-unsafe characters in `$string`.
///
/// @parameter {String} $string
/// @return {String}
///
/// @example
/// @debug url-encode('#foo@bar');
/// //=> '%23foo%40bar'
@function url-encode($string) {
$map: (
// URL reserved characters
'!': '%21',
'#': '%23',
'$': '%24',
'&': '%26',
'\'': '%27',
'(': '%28',
')': '%29',
'*': '%2A',
'+': '%2B',
',': '%2C',
'/': '%2F',
':': '%3A',
';': '%3B',
'=': '%3D',
'?': '%3F',
'@': '%40',
'[': '%5B',
']': '%5D',
// In case the result is wrapped in double-quotes
'"': '%22'
);
$ret: $string;
@each $search, $replacement in $map {
$ret: string-replace($ret, $search, $replacement);
}
@return $ret;
}
/// Lighten a color by mixing it with white.
///
/// @group color
///
/// @parameter {Color} $color - Color to lighten
/// @parameter {Number} $percentage - Amount of white color to mix in
/// @return {Color}
///
/// @example
/// a {
/// color: tint(pink, 10%);
/// }
///
/// @example css - Output CSS
/// a {
/// color: #ffc6d0;
/// }
@function tint($color, $percentage) {
@return mix(#fff, $color, $percentage);
}
/// Darken a color by mixing it with black.
///
/// @group color
///
/// @parameter {Color} $color - Color to darken
/// @parameter {Number} $percentage - Amount of black color to mix in
/// @return {Color}
///
/// @example
/// a {
/// color: shade(pink, 10%);
/// }
///
/// @example css - Output CSS
/// a {
/// color: #e6adb7;
/// }
@function shade($color, $percentage) {
@return mix(#000, $color, $percentage);
}
/// Get the color black with a given `$opacity`.
///
/// @group color
///
/// @parameter {Number} $opacity - Opacity percentage
/// @return {Color}
///
/// @example
/// a {
/// color: black(10%);
/// }
///
/// @example css - Output CSS
/// a {
/// color: rgba(0, 0, 0, 0.1);
/// }
@function black($opacity) {
@return rgba(0, 0, 0, $opacity / 100%);
}
/// Get the color white with a given `$opacity`.
///
/// @group color
///
/// @parameter {Number} $opacity - Opacity percentage
/// @return {Color}
///
/// @example
/// a {
/// color: white(10%);
/// }
///
/// @example css - Output CSS
/// a {
/// color: rgba(255, 255, 255, 0.1);
/// }
@function white($opacity) {
@return rgba(255, 255, 255, $opacity / 100%);
}
/// Use SVG anywhere a `url()` is accepted, like in a `background` property.
///
/// @parameter {String} $svg - SVG string. The `xmlns` attribute is added for you.
///
/// @example
/// body {
/// background: svg-url('<svg>…</svg>');
/// }
@function svg-url($svg) {
// Add missing namespace
$namespace: 'xmlns="http://www.w3.org/2000/svg"';
@if not str-index($string: $svg, $substring: $namespace) {
$svg: string-replace($string: $svg, $search: '<svg', $replacement: '<svg #{$namespace}');
}
@return url('data:image/svg+xml;utf8,#{url-encode($svg)}');
}
/// Set SVG as `background-image`.
///
/// @parameter {String} $svg - SVG string. The `xmlns` attribute is added for you.
///
/// @example
/// body {
/// @include background-svg('<svg>…</svg>');
/// }
@mixin background-svg($svg) {
background-image: svg-url($svg);
}
/// Include a block with a changed context.
///
/// @parameter {String} $changed - Old parent selector. Any parent.
/// @parameter {String} $to - New parent selector. Any parent.
///
/// @example
/// .tabs {
/// .tab {
/// background: pink;
///
/// .icon {
/// color: gray;
///
/// @include context($changed: '.tab', $to: '.tab:hover') {
/// color: blue;
/// }
/// }
/// }
/// }
///
/// @example css - Output CSS
/// .tabs .tab {
/// background: pink;
/// }
/// .tabs .tab .icon {
/// color: gray;
/// }
/// .tabs .tab:hover .icon {
/// color: blue;
/// }
@mixin context($changed, $to) {
@at-root #{selector-replace(&, $changed, $to)} {
@content;
}
}
/// System font stack.
///
/// @type List
///
/// @example
/// body {
/// font-family: $system-fonts;
/// }
$system-fonts:
'system-ui',
'-apple-system',
'Segoe UI',
'Roboto',
'Helvetica',
'Arial',
'sans-serif',
'Apple Color Emoji',
'Segoe UI Emoji' !default;
$system-fonts-mono:
'ui-monospace',
'SFMono-Regular',
'Consolas',
'Liberation Mono',
'Menlo',
'monospace' !default;