diff options
author | Volpeon <git@volpeon.ink> | 2022-02-05 07:52:13 +0100 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2022-02-05 07:52:13 +0100 |
commit | dd5f3c463fab336d694f426dcad11a1783590fc9 (patch) | |
tree | faebf738a9556eaa393371852ed86550d4adf66a /src/_functions.scss | |
parent | Fix errors from transition from node-sass to sass (diff) | |
download | iro-sass-dd5f3c463fab336d694f426dcad11a1783590fc9.tar.gz iro-sass-dd5f3c463fab336d694f426dcad11a1783590fc9.tar.bz2 iro-sass-dd5f3c463fab336d694f426dcad11a1783590fc9.zip |
Ported from import syntax to modules
Diffstat (limited to 'src/_functions.scss')
-rw-r--r-- | src/_functions.scss | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/_functions.scss b/src/_functions.scss index 92ee262..d091afa 100644 --- a/src/_functions.scss +++ b/src/_functions.scss | |||
@@ -10,6 +10,7 @@ | |||
10 | //// | 10 | //// |
11 | 11 | ||
12 | @use 'sass:math'; | 12 | @use 'sass:math'; |
13 | @use './vars'; | ||
13 | 14 | ||
14 | /// | 15 | /// |
15 | /// Replace a substring with a new string. | 16 | /// Replace a substring with a new string. |
@@ -20,11 +21,11 @@ | |||
20 | /// | 21 | /// |
21 | /// @return {string} A string with all instances of $search replaced with $replace | 22 | /// @return {string} A string with all instances of $search replaced with $replace |
22 | /// | 23 | /// |
23 | @function iro-str-replace($string, $search, $replace) { | 24 | @function str-replace($string, $search, $replace) { |
24 | $index: str-index($string, $search); | 25 | $index: str-index($string, $search); |
25 | 26 | ||
26 | @if $index { | 27 | @if $index { |
27 | @return str-slice($string, 1, $index - 1) + $replace + iro-str-replace(str-slice($string, $index + str-length($search)), $search, $replace); | 28 | @return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace); |
28 | } | 29 | } |
29 | 30 | ||
30 | @return $string; | 31 | @return $string; |
@@ -38,11 +39,11 @@ | |||
38 | /// | 39 | /// |
39 | /// @return {string} | 40 | /// @return {string} |
40 | /// | 41 | /// |
41 | @function iro-str-implode($list, $glue: '') { | 42 | @function str-implode($list, $glue: '') { |
42 | $result: ''; | 43 | $result: ''; |
43 | 44 | ||
44 | @each $item in $list { | 45 | @each $item in $list { |
45 | $result: $result + if(length($item) > 1, iro-str-implode($item, $glue), $item); | 46 | $result: $result + if(length($item) > 1, str-implode($item, $glue), $item); |
46 | 47 | ||
47 | @if $item != nth($list, length($list)) { | 48 | @if $item != nth($list, length($list)) { |
48 | $result: $result + $glue; | 49 | $result: $result + $glue; |
@@ -61,7 +62,7 @@ | |||
61 | /// | 62 | /// |
62 | /// @return {list} A slice of the list | 63 | /// @return {list} A slice of the list |
63 | /// | 64 | /// |
64 | @function iro-list-slice($list, $start: 1, $end: length($list)) { | 65 | @function list-slice($list, $start: 1, $end: length($list)) { |
65 | $result: (); | 66 | $result: (); |
66 | 67 | ||
67 | @for $i from $start through $end { | 68 | @for $i from $start through $end { |
@@ -81,7 +82,7 @@ | |||
81 | /// | 82 | /// |
82 | /// @return {list} A list with $value at the beginning, followed by the other items | 83 | /// @return {list} A list with $value at the beginning, followed by the other items |
83 | /// | 84 | /// |
84 | @function iro-list-prepend($list, $value) { | 85 | @function list-prepend($list, $value) { |
85 | $result: append((), $value, list-separator($list)); | 86 | $result: append((), $value, list-separator($list)); |
86 | 87 | ||
87 | @if length($list) > 0 { | 88 | @if length($list) > 0 { |
@@ -103,13 +104,13 @@ | |||
103 | /// | 104 | /// |
104 | /// @return {list} Sorted list | 105 | /// @return {list} Sorted list |
105 | /// | 106 | /// |
106 | @function iro-quicksort($l, $left: 1, $right: length($l)) { | 107 | @function quicksort($l, $left: 1, $right: length($l)) { |
107 | @if $left < $right { | 108 | @if $left < $right { |
108 | $pvr: iro-quicksort-partition($l, $left, $right); | 109 | $pvr: quicksort-partition($l, $left, $right); |
109 | $pivot: nth($pvr, 1); | 110 | $pivot: nth($pvr, 1); |
110 | $l: nth($pvr, 2); | 111 | $l: nth($pvr, 2); |
111 | $l: iro-quicksort($l, $left, $pivot); | 112 | $l: quicksort($l, $left, $pivot); |
112 | $l: iro-quicksort($l, $pivot + 1, $right); | 113 | $l: quicksort($l, $pivot + 1, $right); |
113 | } | 114 | } |
114 | 115 | ||
115 | @return $l; | 116 | @return $l; |
@@ -118,7 +119,7 @@ | |||
118 | /// | 119 | /// |
119 | /// @access private | 120 | /// @access private |
120 | /// | 121 | /// |
121 | @function iro-quicksort-partition($l, $left, $right) { | 122 | @function quicksort-partition($l, $left, $right) { |
122 | $start: true; | 123 | $start: true; |
123 | $i: $left; | 124 | $i: $left; |
124 | $j: $right - 1; | 125 | $j: $right - 1; |
@@ -161,7 +162,7 @@ | |||
161 | /// | 162 | /// |
162 | /// @return {any} Either the value assigned to $key or $default | 163 | /// @return {any} Either the value assigned to $key or $default |
163 | /// | 164 | /// |
164 | @function iro-map-get-default($map, $key, $default) { | 165 | @function map-get-default($map, $key, $default) { |
165 | @return if(map-has-key($map, $key), map-get($map, $key), $default); | 166 | @return if(map-has-key($map, $key), map-get($map, $key), $default); |
166 | } | 167 | } |
167 | 168 | ||
@@ -174,7 +175,7 @@ | |||
174 | /// | 175 | /// |
175 | /// @return {any} Either the value assigned to $key or $default | 176 | /// @return {any} Either the value assigned to $key or $default |
176 | /// | 177 | /// |
177 | @function iro-map-get-deep($map, $key, $default: null) { | 178 | @function map-get-deep($map, $key, $default: null) { |
178 | $value: null; | 179 | $value: null; |
179 | 180 | ||
180 | @if type-of($key) == list { | 181 | @if type-of($key) == list { |
@@ -206,7 +207,7 @@ | |||
206 | /// | 207 | /// |
207 | /// @return {map} The result of a recursive merge of $map1 and $map2 | 208 | /// @return {map} The result of a recursive merge of $map1 and $map2 |
208 | /// | 209 | /// |
209 | @function iro-map-merge-recursive($map1, $map2) { | 210 | @function map-merge-recursive($map1, $map2) { |
210 | @if type-of($map1) != map or type-of($map2) != map { | 211 | @if type-of($map1) != map or type-of($map2) != map { |
211 | @error 'Two maps expected.'; | 212 | @error 'Two maps expected.'; |
212 | } | 213 | } |
@@ -215,7 +216,7 @@ | |||
215 | 216 | ||
216 | @each $key, $value in $map2 { | 217 | @each $key, $value in $map2 { |
217 | @if type-of(map-get($result, $key)) == map and type-of($value) == map { | 218 | @if type-of(map-get($result, $key)) == map and type-of($value) == map { |
218 | $result: map-merge($result, ($key: iro-map-merge-recursive(map-get($result, $key), $value))); | 219 | $result: map-merge($result, ($key: map-merge-recursive(map-get($result, $key), $value))); |
219 | } @else { | 220 | } @else { |
220 | $result: map-merge($result, ($key: $value)); | 221 | $result: map-merge($result, ($key: $value)); |
221 | } | 222 | } |
@@ -231,16 +232,16 @@ | |||
231 | /// | 232 | /// |
232 | /// @return {string} | 233 | /// @return {string} |
233 | /// | 234 | /// |
234 | @function iro-map-print($map) { | 235 | @function map-print($map) { |
235 | $output: ''; | 236 | $output: ''; |
236 | 237 | ||
237 | @each $key, $value in $map { | 238 | @each $key, $value in $map { |
238 | $value-str: ''; | 239 | $value-str: ''; |
239 | 240 | ||
240 | @if type-of($value) == map { | 241 | @if type-of($value) == map { |
241 | $value-str: '[ ' + iro-map-print($value) + ' ]'; | 242 | $value-str: '[ ' + map-print($value) + ' ]'; |
242 | } @else if type-of($value) == list { | 243 | } @else if type-of($value) == list { |
243 | $value-str: '[ ' + iro-str-implode($value, ', ') + ' ]'; | 244 | $value-str: '[ ' + str-implode($value, ', ') + ' ]'; |
244 | } @else if type-of($value) == string { | 245 | } @else if type-of($value) == string { |
245 | $value-str: '\'' + $value + '\''; | 246 | $value-str: '\'' + $value + '\''; |
246 | } @else { | 247 | } @else { |
@@ -265,7 +266,7 @@ | |||
265 | /// | 266 | /// |
266 | /// @return {bool} `true` if the selector matches at least one suffix, otherwise `false`. | 267 | /// @return {bool} `true` if the selector matches at least one suffix, otherwise `false`. |
267 | /// | 268 | /// |
268 | @function iro-selector-suffix-match($selector, $suffixes) { | 269 | @function selector-suffix-match($selector, $suffixes) { |
269 | $match: true; | 270 | $match: true; |
270 | 271 | ||
271 | @each $sel in $selector { | 272 | @each $sel in $selector { |
@@ -304,19 +305,19 @@ | |||
304 | /// | 305 | /// |
305 | /// @return {number} Unit-less variable | 306 | /// @return {number} Unit-less variable |
306 | /// | 307 | /// |
307 | @function iro-strip-unit($n) { | 308 | @function strip-unit($n) { |
308 | @return math.div($n, $n * 0 + 1); | 309 | @return math.div($n, $n * 0 + 1); |
309 | } | 310 | } |
310 | 311 | ||
311 | /// | 312 | /// |
312 | /// Convert a pixel value to a rem value. | 313 | /// Convert a pixel value to a rem value. |
313 | /// | 314 | /// |
314 | /// @param {number} $size - Pixel value to convert | 315 | /// @param {number} $size - Pixel value to convert |
315 | /// @param {number} $base [$iro-root-size] - Reference base font size used for conversion | 316 | /// @param {number} $base [vars.$root-size] - Reference base font size used for conversion |
316 | /// | 317 | /// |
317 | /// @return {number} Pixel value converted to rem | 318 | /// @return {number} Pixel value converted to rem |
318 | /// | 319 | /// |
319 | @function iro-px-to-rem($size, $base: $iro-root-size) { | 320 | @function px-to-rem($size, $base: vars.$root-size) { |
320 | @return math.div($size, $base) * 1rem; | 321 | @return math.div($size, $base) * 1rem; |
321 | } | 322 | } |
322 | 323 | ||
@@ -325,6 +326,6 @@ | |||
325 | /// | 326 | /// |
326 | /// @content | 327 | /// @content |
327 | /// | 328 | /// |
328 | @mixin iro-execute { | 329 | @mixin execute { |
329 | @content; | 330 | @content; |
330 | } | 331 | } |