|
| 1 | +@use 'sass:color'; |
| 2 | +@use 'sass:list'; |
| 3 | +@use 'sass:meta'; |
| 4 | +@use 'sass:selector'; |
| 5 | +@use 'sass:string'; |
| 6 | +@use 'sass:math'; |
| 7 | + |
1 | 8 | /// Strip the unit from a number. |
2 | 9 | /// |
3 | 10 | /// @group number |
|
9 | 16 | /// @debug strip-unit(5px); |
10 | 17 | /// //=> 5 |
11 | 18 | @function strip-unit($number) { |
12 | | - @return $number / ($number * 0 + 1); |
| 19 | + @return math.div($number, $number * 0 + 1); |
13 | 20 | } |
14 | 21 |
|
15 | 22 | /// Clamp `$number` between `$min` and `$max`. |
|
54 | 61 | /// @debug string-contains('foo bar baz', $substring: 'bar'); |
55 | 62 | /// //=> true |
56 | 63 | @function string-contains($string, $substring) { |
57 | | - @return str-index($string, $substring) != null; |
| 64 | + @return string.index($string, $substring) != null; |
58 | 65 | } |
59 | 66 |
|
60 | 67 | /// Check if `$string` starts with the given `$substring`. |
|
69 | 76 | /// @debug string-starts-with('foo bar', $substring: 'foo'); |
70 | 77 | /// //=> true |
71 | 78 | @function string-starts-with($string, $substring) { |
72 | | - @return str-index($string, $substring) == 1; |
| 79 | + @return string.index($string, $substring) == 1; |
73 | 80 | } |
74 | 81 |
|
75 | 82 | /// Check if `$string` ends with the given `$substring`. |
|
86 | 93 | @function string-ends-with($string, $substring) { |
87 | 94 | // This crashes libsass… |
88 | 95 | // @return str-slice($string, str-length($substring) * -1) == $substring; |
89 | | - @return str-slice($string, (str-length($string) - str-length($substring) + 1)) == $substring; |
| 96 | + @return string.slice($string, (string.length($string) - string.length($substring) + 1)) == $substring; |
90 | 97 | } |
91 | 98 |
|
92 | 99 | /// Replace substring `$search` in `$string` with `$replacement`. |
|
102 | 109 | /// @debug string-replace('foo bar baz', $search: 'bar', $replacement: 'unicorn'); |
103 | 110 | /// //=> 'foo unicorn baz' |
104 | 111 | @function string-replace($string, $search, $replacement: '') { |
105 | | - $index: str-index($string: $string, $substring: $search); |
| 112 | + $index: string.index($string: $string, $substring: $search); |
106 | 113 |
|
107 | 114 | @if $index { |
108 | 115 | @return |
109 | | - str-slice($string, $start-at: 1, $end-at: $index - 1) |
| 116 | + string.slice($string, $start-at: 1, $end-at: $index - 1) |
110 | 117 | + $replacement |
111 | | - + string-replace(str-slice($string, $start-at: $index + str-length($search)), $search, $replacement); |
| 118 | + + string-replace(string.slice($string, $start-at: $index + string.length($search)), $search, $replacement); |
112 | 119 | } |
113 | 120 |
|
114 | 121 | @return $string; |
|
125 | 132 | /// @debug list-first((1, 2, 3)); |
126 | 133 | /// //=> 1 |
127 | 134 | @function list-first($list) { |
128 | | - @return nth($list, 1); |
| 135 | + @return list.nth($list, 1); |
129 | 136 | } |
130 | 137 |
|
131 | 138 | /// Get the last element of `$list`. |
|
139 | 146 | /// @debug list-last((1, 2, 3)); |
140 | 147 | /// //=> 3 |
141 | 148 | @function list-last($list) { |
142 | | - @return nth($list, -1); |
| 149 | + @return list.nth($list, -1); |
143 | 150 | } |
144 | 151 |
|
145 | 152 | /// Generate a pseudorandom integer. |
|
181 | 188 | @function seed-random-float($seed) { |
182 | 189 | $max-int32: 2147483647; |
183 | 190 | $integer: seed-random-integer($seed); |
184 | | - @return ($integer - 1) / ($max-int32 - 1); |
| 191 | + @return math.div($integer - 1, $max-int32 - 1); |
185 | 192 | } |
186 | 193 |
|
187 | 194 | /// Generate a pseudorandom boolean. |
|
219 | 226 | @function random-color($saturation: 0.5, $lightness: 0.5) { |
220 | 227 | /* stylelint-disable-next-line number-max-precision */ |
221 | 228 | $golden-ratio-conjugate: 0.618033988749895; |
222 | | - $hue: (random() + $golden-ratio-conjugate) % 1; |
223 | | - @return hsl($hue * 360, $saturation * 100, $lightness * 100); |
| 229 | + $hue: (math.random() + $golden-ratio-conjugate) % 1; |
| 230 | + @return hsl($hue * 360, $saturation * 100%, $lightness * 100%); |
224 | 231 | } |
225 | 232 |
|
226 | 233 | /// Encode URL-unsafe characters in `$string`. |
|
282 | 289 | /// color: #ffc6d0; |
283 | 290 | /// } |
284 | 291 | @function tint($color, $percentage) { |
285 | | - @return mix(#fff, $color, $percentage); |
| 292 | + @return color.mix(#fff, $color, $percentage); |
286 | 293 | } |
287 | 294 |
|
288 | 295 | /// Darken a color by mixing it with black. |
|
303 | 310 | /// color: #e6adb7; |
304 | 311 | /// } |
305 | 312 | @function shade($color, $percentage) { |
306 | | - @return mix(#000, $color, $percentage); |
| 313 | + @return color.mix(#000, $color, $percentage); |
307 | 314 | } |
308 | 315 |
|
309 | 316 | /// Get the color black with a given `$opacity`. |
|
323 | 330 | /// color: rgba(0, 0, 0, 0.1); |
324 | 331 | /// } |
325 | 332 | @function black($opacity) { |
326 | | - @return rgba(0, 0, 0, $opacity / 100%); |
| 333 | + @return rgba(0, 0, 0, math.div($opacity, 100%)); |
327 | 334 | } |
328 | 335 |
|
329 | 336 | /// Get the color white with a given `$opacity`. |
|
343 | 350 | /// color: rgba(255, 255, 255, 0.1); |
344 | 351 | /// } |
345 | 352 | @function white($opacity) { |
346 | | - @return rgba(255, 255, 255, $opacity / 100%); |
| 353 | + @return rgba(255, 255, 255, math.div($opacity, 100%)); |
347 | 354 | } |
348 | 355 |
|
349 | 356 | /// Use SVG anywhere a `url()` is accepted, like in a `background` property. |
|
357 | 364 | @function svg-url($svg) { |
358 | 365 | // Add missing namespace |
359 | 366 | $namespace: 'xmlns="http://www.w3.org/2000/svg"'; |
360 | | - @if not str-index($string: $svg, $substring: $namespace) { |
| 367 | + @if not string.index($string: $svg, $substring: $namespace) { |
361 | 368 | $svg: string-replace($string: $svg, $search: '<svg', $replacement: '<svg #{$namespace}'); |
362 | 369 | } |
363 | 370 |
|
|
407 | 414 | /// color: blue; |
408 | 415 | /// } |
409 | 416 | @mixin context($changed, $to) { |
410 | | - @at-root #{selector-replace(&, $changed, $to)} { |
| 417 | + @at-root #{selector.replace(&, $changed, $to)} { |
411 | 418 | @content; |
412 | 419 | } |
413 | 420 | } |
|
0 commit comments