diff options
Diffstat (limited to 'src/_functions.scss')
| -rw-r--r-- | src/_functions.scss | 71 |
1 files changed, 37 insertions, 34 deletions
diff --git a/src/_functions.scss b/src/_functions.scss index 9dd14b1..7d4a695 100644 --- a/src/_functions.scss +++ b/src/_functions.scss | |||
| @@ -10,7 +10,10 @@ | |||
| 10 | //// | 10 | //// |
| 11 | 11 | ||
| 12 | @use 'sass:map'; | 12 | @use 'sass:map'; |
| 13 | @use 'sass:list'; | ||
| 13 | @use 'sass:math'; | 14 | @use 'sass:math'; |
| 15 | @use 'sass:string'; | ||
| 16 | @use 'sass:meta'; | ||
| 14 | @use './vars'; | 17 | @use './vars'; |
| 15 | 18 | ||
| 16 | /// | 19 | /// |
| @@ -23,10 +26,10 @@ | |||
| 23 | /// @return {string} A string with all instances of $search replaced with $replace | 26 | /// @return {string} A string with all instances of $search replaced with $replace |
| 24 | /// | 27 | /// |
| 25 | @function str-replace($string, $search, $replace) { | 28 | @function str-replace($string, $search, $replace) { |
| 26 | $index: str-index($string, $search); | 29 | $index: string.index($string, $search); |
| 27 | 30 | ||
| 28 | @if $index { | 31 | @if $index { |
| 29 | @return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace); | 32 | @return string.slice($string, 1, $index - 1) + $replace + str-replace(string.slice($string, $index + string.length($search)), $search, $replace); |
| 30 | } | 33 | } |
| 31 | 34 | ||
| 32 | @return $string; | 35 | @return $string; |
| @@ -44,9 +47,9 @@ | |||
| 44 | $result: ''; | 47 | $result: ''; |
| 45 | 48 | ||
| 46 | @each $item in $list { | 49 | @each $item in $list { |
| 47 | $result: $result + if(length($item) > 1, str-implode($item, $glue), $item); | 50 | $result: $result + if(list.length($item) > 1, str-implode($item, $glue), $item); |
| 48 | 51 | ||
| 49 | @if $item != nth($list, length($list)) { | 52 | @if $item != list.nth($list, list.length($list)) { |
| 50 | $result: $result + $glue; | 53 | $result: $result + $glue; |
| 51 | } | 54 | } |
| 52 | } | 55 | } |
| @@ -63,13 +66,13 @@ | |||
| 63 | /// | 66 | /// |
| 64 | /// @return {list} A slice of the list | 67 | /// @return {list} A slice of the list |
| 65 | /// | 68 | /// |
| 66 | @function list-slice($list, $start: 1, $end: length($list)) { | 69 | @function list-slice($list, $start: 1, $end: list.length($list)) { |
| 67 | $result: (); | 70 | $result: (); |
| 68 | 71 | ||
| 69 | @if $end >= $start { | 72 | @if $end >= $start { |
| 70 | @for $i from $start through $end { | 73 | @for $i from $start through $end { |
| 71 | @if $i != 0 { | 74 | @if $i != 0 { |
| 72 | $result: append($result, nth($list, $i), list-separator($list)); | 75 | $result: list.append($result, list.nth($list, $i), list.separator($list)); |
| 73 | } | 76 | } |
| 74 | } | 77 | } |
| 75 | } | 78 | } |
| @@ -86,11 +89,11 @@ | |||
| 86 | /// @return {list} A list with $value at the beginning, followed by the other items | 89 | /// @return {list} A list with $value at the beginning, followed by the other items |
| 87 | /// | 90 | /// |
| 88 | @function list-prepend($list, $value) { | 91 | @function list-prepend($list, $value) { |
| 89 | $result: append((), $value, list-separator($list)); | 92 | $result: list.append((), $value, list.separator($list)); |
| 90 | 93 | ||
| 91 | @if length($list) > 0 { | 94 | @if list.length($list) > 0 { |
| 92 | @for $i from 1 through length($list) { | 95 | @for $i from 1 through list.length($list) { |
| 93 | $result: append($result, nth($list, $i), list-separator($list)); | 96 | $result: list.append($result, list.nth($list, $i), list.separator($list)); |
| 94 | } | 97 | } |
| 95 | } | 98 | } |
| 96 | 99 | ||
| @@ -105,13 +108,13 @@ | |||
| 105 | /// @return {list} Teh reversed list | 108 | /// @return {list} Teh reversed list |
| 106 | /// | 109 | /// |
| 107 | @function list-reverse($list) { | 110 | @function list-reverse($list) { |
| 108 | @if length($list) == 0 { | 111 | @if list.length($list) == 0 { |
| 109 | @return $list; | 112 | @return $list; |
| 110 | } | 113 | } |
| 111 | 114 | ||
| 112 | $result: (); | 115 | $result: (); |
| 113 | @for $i from length($list) * -1 through -1 { | 116 | @for $i from list.length($list) * -1 through -1 { |
| 114 | $result: append($result, nth($list, abs($i))); | 117 | $result: list.append($result, list.nth($list, math.abs($i))); |
| 115 | } | 118 | } |
| 116 | @return $result; | 119 | @return $result; |
| 117 | } | 120 | } |
| @@ -126,11 +129,11 @@ | |||
| 126 | /// | 129 | /// |
| 127 | /// @return {list} Sorted list | 130 | /// @return {list} Sorted list |
| 128 | /// | 131 | /// |
| 129 | @function quicksort($l, $left: 1, $right: length($l)) { | 132 | @function quicksort($l, $left: 1, $right: list.length($l)) { |
| 130 | @if $left < $right { | 133 | @if $left < $right { |
| 131 | $pvr: quicksort-partition($l, $left, $right); | 134 | $pvr: quicksort-partition($l, $left, $right); |
| 132 | $pivot: nth($pvr, 1); | 135 | $pivot: list.nth($pvr, 1); |
| 133 | $l: nth($pvr, 2); | 136 | $l: list.nth($pvr, 2); |
| 134 | $l: quicksort($l, $left, $pivot); | 137 | $l: quicksort($l, $left, $pivot); |
| 135 | $l: quicksort($l, $pivot + 1, $right); | 138 | $l: quicksort($l, $pivot + 1, $right); |
| 136 | } | 139 | } |
| @@ -145,30 +148,30 @@ | |||
| 145 | $start: true; | 148 | $start: true; |
| 146 | $i: $left; | 149 | $i: $left; |
| 147 | $j: $right - 1; | 150 | $j: $right - 1; |
| 148 | $pivot: nth($l, $right); | 151 | $pivot: list.nth($l, $right); |
| 149 | 152 | ||
| 150 | @while ($i < $j) or $start { | 153 | @while ($i < $j) or $start { |
| 151 | @while (nth($l, $i) < $pivot) and ($i < $right - 1) { | 154 | @while (list.nth($l, $i) < $pivot) and ($i < $right - 1) { |
| 152 | $i: $i + 1; | 155 | $i: $i + 1; |
| 153 | } | 156 | } |
| 154 | 157 | ||
| 155 | @while (nth($l, $j)>= $pivot) and ($j > $left) { | 158 | @while (list.nth($l, $j)>= $pivot) and ($j > $left) { |
| 156 | $j: $j - 1; | 159 | $j: $j - 1; |
| 157 | } | 160 | } |
| 158 | 161 | ||
| 159 | @if $i < $j { | 162 | @if $i < $j { |
| 160 | $i-val: nth($l, $i); | 163 | $i-val: list.nth($l, $i); |
| 161 | $l: set-nth($l, $i, nth($l, $j)); | 164 | $l: list.set-nth($l, $i, list.nth($l, $j)); |
| 162 | $l: set-nth($l, $j, $i-val); | 165 | $l: list.set-nth($l, $j, $i-val); |
| 163 | } | 166 | } |
| 164 | 167 | ||
| 165 | $start: false; | 168 | $start: false; |
| 166 | } | 169 | } |
| 167 | 170 | ||
| 168 | @if nth($l, $i) > $pivot { | 171 | @if list.nth($l, $i) > $pivot { |
| 169 | $i-val: nth($l, $i); | 172 | $i-val: list.nth($l, $i); |
| 170 | $l: set-nth($l, $i, nth($l, $right)); | 173 | $l: list.set-nth($l, $i, list.nth($l, $right)); |
| 171 | $l: set-nth($l, $right, $i-val); | 174 | $l: list.set-nth($l, $right, $i-val); |
| 172 | } | 175 | } |
| 173 | 176 | ||
| 174 | @return $i $l; | 177 | @return $i $l; |
| @@ -185,10 +188,10 @@ | |||
| 185 | /// @return {any} Either the value assigned to $key or $default | 188 | /// @return {any} Either the value assigned to $key or $default |
| 186 | /// | 189 | /// |
| 187 | @function map-get-default($map, $key, $keys...) { | 190 | @function map-get-default($map, $key, $keys...) { |
| 188 | $default: nth($keys, length($keys)); | 191 | $default: list.nth($keys, list.length($keys)); |
| 189 | $keys: list-slice($keys, 1, length($keys) - 1); | 192 | $keys: list-slice($keys, 1, list.length($keys) - 1); |
| 190 | 193 | ||
| 191 | @return if(map-has-key($map, $key, $keys...), map-get($map, $key, $keys...), $default); | 194 | @return if(map.has-key($map, $key, $keys...), map.get($map, $key, $keys...), $default); |
| 192 | } | 195 | } |
| 193 | 196 | ||
| 194 | /// | 197 | /// |
| @@ -204,11 +207,11 @@ | |||
| 204 | @each $key, $value in $map { | 207 | @each $key, $value in $map { |
| 205 | $value-str: ''; | 208 | $value-str: ''; |
| 206 | 209 | ||
| 207 | @if type-of($value) == map { | 210 | @if meta.type-of($value) == map { |
| 208 | $value-str: '[ ' + map-print($value) + ' ]'; | 211 | $value-str: '[ ' + map-print($value) + ' ]'; |
| 209 | } @else if type-of($value) == list { | 212 | } @else if meta.type-of($value) == list { |
| 210 | $value-str: '[ ' + str-implode($value, ', ') + ' ]'; | 213 | $value-str: '[ ' + str-implode($value, ', ') + ' ]'; |
| 211 | } @else if type-of($value) == string { | 214 | } @else if meta.type-of($value) == string { |
| 212 | $value-str: '\'' + $value + '\''; | 215 | $value-str: '\'' + $value + '\''; |
| 213 | } @else { | 216 | } @else { |
| 214 | $value-str: $value; | 217 | $value-str: $value; |
| @@ -243,8 +246,8 @@ | |||
| 243 | @if not $sel-match { | 246 | @if not $sel-match { |
| 244 | $suf-match: true; | 247 | $suf-match: true; |
| 245 | 248 | ||
| 246 | @for $i from 1 through length($suffix) { | 249 | @for $i from 1 through list.length($suffix) { |
| 247 | @if $suf-match and (nth($sel, -$i) != nth($suffix, -$i)) { | 250 | @if $suf-match and (list.nth($sel, -$i) != list.nth($suffix, -$i)) { |
| 248 | $suf-match: false; | 251 | $suf-match: false; |
| 249 | } | 252 | } |
| 250 | } | 253 | } |
