-
Notifications
You must be signed in to change notification settings - Fork 0
/
_functions.scss
86 lines (81 loc) · 2.06 KB
/
_functions.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
//
// Checks the type of a variable against the given type.
//
// @param {string} $type
// @param {mixed} $var
// @return {boolean}
//
@function is-type($type, $var) {
@return type-of($var) == #{$type};
}
//
// Checks if a number is a fraction.
//
// @param {number} $number
// @return {boolean}
//
@function is-fraction($number) {
@return $number != floor($number);
}
//
// Return a list or map of percentages of a list of map of fraction.
//
// @param {map|list} $map-or-list
// @param {boolean} $negative-values
// @return {map|list}
//
@function percentages($map-or-list, $negative-values: false) {
$returnValue: ();
@if is-type('map', $map-or-list) {
@each $key, $value in $map-or-list {
$pair: ($key: percentage(if($negative-values == true, -1 * $value, $value)));
$returnValue: map-merge($returnValue, $pair);
}
}
@else if (is-type('list', $map-or-list)) {
@each $value in $map-or-list {
$item: percentage(if($negative-values == true, -1 * $value, $value));
$returnValue: append($returnValue, $item, comma);
}
}
@return $returnValue;
}
//
// Returns a value of cubic-bezier in reverse.
//
// @param {number} $arg1
// @param {number} $arg2
// @param {number} $arg3
// @param {number} $arg4
// @return {string}
//
@function reverse-cubic-bezier($arg1, $arg2, $arg3, $arg4) {
@return 1 - ($arg3), 1 - ($arg4), 1 - ($arg1), 1 - ($arg2);
}
//
// Replace the occurrence of the search with the replace.
//
// @param {string} $subject
// @param {string} $search
// @param {string} $replace
// @return {string}
//
@function str-replace($subject, $search, $replace: '') {
$index: str-index($subject, $search);
@if $index {
@return str-slice($subject, 1, $index - 1) + $replace + str-replace(str-slice($subject, $index + str-length($search)), $search, $replace);
}
@return $subject;
}
//
// Strips the unit of a number with unit.
//
// @param {number} $number
// @return {number}
//
@function strip-unit($number) {
@if is-type('number', $number) and not unitless($number) {
@return $number / ($number * 0 + 1);
}
@return $number;
}