From f0f84513f8efe533b6ee670a6f1a0c074387b2ec Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 13 Aug 2025 12:01:46 +0200 Subject: Make use of SASS modules --- src/_functions.scss | 356 ++++++++++++++++++++++++++-------------------------- 1 file changed, 178 insertions(+), 178 deletions(-) (limited to 'src/_functions.scss') diff --git a/src/_functions.scss b/src/_functions.scss index 0d139b4..74cc1b5 100644 --- a/src/_functions.scss +++ b/src/_functions.scss @@ -19,21 +19,21 @@ $numbers: ('0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9); $units: ( - 'px': 1px, - 'cm': 1cm, - 'mm': 1mm, - '%': 1%, - 'ch': 1ch, - 'pc': 1pc, - 'in': 1in, - 'em': 1em, - 'rem': 1rem, - 'pt': 1pt, - 'ex': 1ex, - 'vw': 1vw, - 'vh': 1vh, - 'vmin': 1vmin, - 'vmax': 1vmax + 'px': 1px, + 'cm': 1cm, + 'mm': 1mm, + '%': 1%, + 'ch': 1ch, + 'pc': 1pc, + 'in': 1in, + 'em': 1em, + 'rem': 1rem, + 'pt': 1pt, + 'ex': 1ex, + 'vw': 1vw, + 'vh': 1vh, + 'vmin': 1vmin, + 'vmax': 1vmax ); /// @@ -46,13 +46,13 @@ $units: ( /// @return {string} A string with all instances of $search replaced with $replace /// @function str-replace($string, $search, $replace) { - $index: string.index($string, $search); + $index: string.index($string, $search); - @if $index { - @return string.slice($string, 1, $index - 1) + $replace + str-replace(string.slice($string, $index + string.length($search)), $search, $replace); - } + @if $index { + @return string.slice($string, 1, $index - 1) + $replace + str-replace(string.slice($string, $index + string.length($search)), $search, $replace); + } - @return $string; + @return $string; } /// @@ -64,17 +64,17 @@ $units: ( /// @return {string} /// @function str-implode($list, $glue: '') { - $result: ''; + $result: ''; - @each $item in $list { - $result: $result + if(list.length($item) > 1, str-implode($item, $glue), $item); + @each $item in $list { + $result: $result + if(list.length($item) > 1, str-implode($item, $glue), $item); - @if $item != list.nth($list, list.length($list)) { - $result: $result + $glue; - } - } + @if $item != list.nth($list, list.length($list)) { + $result: $result + $glue; + } + } - @return $result; + @return $result; } /// @@ -87,17 +87,17 @@ $units: ( /// @return {list} A slice of the list /// @function list-slice($list, $start: 1, $end: list.length($list)) { - $result: (); + $result: (); - @if $end >= $start { - @for $i from $start through $end { - @if $i != 0 { - $result: list.append($result, list.nth($list, $i), list.separator($list)); - } - } - } + @if $end >= $start { + @for $i from $start through $end { + @if $i != 0 { + $result: list.append($result, list.nth($list, $i), list.separator($list)); + } + } + } - @return $result; + @return $result; } /// @@ -109,15 +109,15 @@ $units: ( /// @return {list} A list with $value at the beginning, followed by the other items /// @function list-prepend($list, $value) { - $result: list.append((), $value, list.separator($list)); + $result: list.append((), $value, list.separator($list)); - @if list.length($list) > 0 { - @for $i from 1 through list.length($list) { - $result: list.append($result, list.nth($list, $i), list.separator($list)); - } - } + @if list.length($list) > 0 { + @for $i from 1 through list.length($list) { + $result: list.append($result, list.nth($list, $i), list.separator($list)); + } + } - @return $result; + @return $result; } /// @@ -128,15 +128,15 @@ $units: ( /// @return {list} Teh reversed list /// @function list-reverse($list) { - @if list.length($list) == 0 { - @return $list; - } - - $result: (); - @for $i from list.length($list) * -1 through -1 { - $result: list.append($result, list.nth($list, math.abs($i))); - } - @return $result; + @if list.length($list) == 0 { + @return $list; + } + + $result: (); + @for $i from list.length($list) * -1 through -1 { + $result: list.append($result, list.nth($list, math.abs($i))); + } + @return $result; } /// @@ -150,51 +150,51 @@ $units: ( /// @return {list} Sorted list /// @function quicksort($l, $left: 1, $right: list.length($l)) { - @if $left < $right { - $pvr: quicksort-partition($l, $left, $right); - $pivot: list.nth($pvr, 1); - $l: list.nth($pvr, 2); - $l: quicksort($l, $left, $pivot); - $l: quicksort($l, $pivot + 1, $right); - } - - @return $l; + @if $left < $right { + $pvr: quicksort-partition($l, $left, $right); + $pivot: list.nth($pvr, 1); + $l: list.nth($pvr, 2); + $l: quicksort($l, $left, $pivot); + $l: quicksort($l, $pivot + 1, $right); + } + + @return $l; } /// /// @access private /// @function quicksort-partition($l, $left, $right) { - $start: true; - $i: $left; - $j: $right - 1; - $pivot: list.nth($l, $right); - - @while ($i < $j) or $start { - @while (list.nth($l, $i) < $pivot) and ($i < $right - 1) { - $i: $i + 1; - } - - @while (list.nth($l, $j)>= $pivot) and ($j > $left) { - $j: $j - 1; - } - - @if $i < $j { - $i-val: list.nth($l, $i); - $l: list.set-nth($l, $i, list.nth($l, $j)); - $l: list.set-nth($l, $j, $i-val); - } - - $start: false; - } - - @if list.nth($l, $i) > $pivot { - $i-val: list.nth($l, $i); - $l: list.set-nth($l, $i, list.nth($l, $right)); - $l: list.set-nth($l, $right, $i-val); - } - - @return $i $l; + $start: true; + $i: $left; + $j: $right - 1; + $pivot: list.nth($l, $right); + + @while ($i < $j) or $start { + @while (list.nth($l, $i) < $pivot) and ($i < $right - 1) { + $i: $i + 1; + } + + @while (list.nth($l, $j)>= $pivot) and ($j > $left) { + $j: $j - 1; + } + + @if $i < $j { + $i-val: list.nth($l, $i); + $l: list.set-nth($l, $i, list.nth($l, $j)); + $l: list.set-nth($l, $j, $i-val); + } + + $start: false; + } + + @if list.nth($l, $i) > $pivot { + $i-val: list.nth($l, $i); + $l: list.set-nth($l, $i, list.nth($l, $right)); + $l: list.set-nth($l, $right, $i-val); + } + + @return $i $l; } /// @@ -208,10 +208,10 @@ $units: ( /// @return {any} Either the value assigned to $key or $default /// @function map-get-default($map, $key, $keys...) { - $default: list.nth($keys, list.length($keys)); - $keys: list-slice($keys, 1, list.length($keys) - 1); + $default: list.nth($keys, list.length($keys)); + $keys: list-slice($keys, 1, list.length($keys) - 1); - @return if(map.has-key($map, $key, $keys...), map.get($map, $key, $keys...), $default); + @return if(map.has-key($map, $key, $keys...), map.get($map, $key, $keys...), $default); } /// @@ -222,29 +222,29 @@ $units: ( /// @return {string} /// @function map-print($map) { - $output: ''; - - @each $key, $value in $map { - $value-str: ''; - - @if meta.type-of($value) == map { - $value-str: '[ ' + map-print($value) + ' ]'; - } @else if meta.type-of($value) == list { - $value-str: '[ ' + str-implode($value, ', ') + ' ]'; - } @else if meta.type-of($value) == string { - $value-str: '\'' + $value + '\''; - } @else { - $value-str: $value; - } - - @if $output == '' { - $output: $key + ': ' + $value-str; - } @else { - $output: $output + ', ' + $key + ': ' + $value-str; - } - } - - @return $output; + $output: ''; + + @each $key, $value in $map { + $value-str: ''; + + @if meta.type-of($value) == map { + $value-str: '[ ' + map-print($value) + ' ]'; + } @else if meta.type-of($value) == list { + $value-str: '[ ' + str-implode($value, ', ') + ' ]'; + } @else if meta.type-of($value) == string { + $value-str: '\'' + $value + '\''; + } @else { + $value-str: $value; + } + + @if $output == '' { + $output: $key + ': ' + $value-str; + } @else { + $output: $output + ', ' + $key + ': ' + $value-str; + } + } + + @return $output; } /// @@ -256,35 +256,35 @@ $units: ( /// @return {bool} `true` if the selector matches at least one suffix, otherwise `false`. /// @function selector-suffix-match($selector, $suffixes) { - $match: true; - - @each $sel in $selector { - @if $match { - $sel-match: false; - - @each $suffix in $suffixes { - @if not $sel-match { - $suf-match: true; - - @for $i from 1 through list.length($suffix) { - @if $suf-match and (list.nth($sel, -$i) != list.nth($suffix, -$i)) { - $suf-match: false; - } - } - - @if $suf-match { - $sel-match: true; - } - } - } - - @if not $sel-match { - $match: false; - } - } - } - - @return $match; + $match: true; + + @each $sel in $selector { + @if $match { + $sel-match: false; + + @each $suffix in $suffixes { + @if not $sel-match { + $suf-match: true; + + @for $i from 1 through list.length($suffix) { + @if $suf-match and (list.nth($sel, -$i) != list.nth($suffix, -$i)) { + $suf-match: false; + } + } + + @if $suf-match { + $sel-match: true; + } + } + } + + @if not $sel-match { + $match: false; + } + } + } + + @return $match; } /// @@ -295,7 +295,7 @@ $units: ( /// @return {number} Unit-less variable /// @function strip-unit($n) { - @return math.div($n, $n * 0 + 1); + @return math.div($n, $n * 0 + 1); } /// @@ -307,7 +307,7 @@ $units: ( /// @return {number} Pixel value converted to rem /// @function px-to-rem($size, $base: vars.$root-size) { - @return math.div($size, $base) * 1rem; + @return math.div($size, $base) * 1rem; } /// @@ -318,35 +318,35 @@ $units: ( /// @return {number} /// @function to-number($value) { - @if meta.type-of($value) == 'number' { - @return $value; - } - @if meta.type-of($value) != 'string' { - @error 'Value for `to-number` should be a number or a string.'; - } + @if meta.type-of($value) == 'number' { + @return $value; + } + @if meta.type-of($value) != 'string' { + @error 'Value for `to-number` should be a number or a string.'; + } - $result: 0; - $digits: 0; - $minus: string.slice($value, 1, 1) == '-'; + $result: 0; + $digits: 0; + $minus: string.slice($value, 1, 1) == '-'; - @for $i from if($minus, 2, 1) through string.length($value) { - $character: string.slice($value, $i, $i); + @for $i from if($minus, 2, 1) through string.length($value) { + $character: string.slice($value, $i, $i); - @if not list.index(map.keys($numbers), $character) and $character != '.' { - @return to-length(if($minus, -$result, $result), string.slice($value, $i)); - } + @if not list.index(map.keys($numbers), $character) and $character != '.' { + @return to-length(if($minus, -$result, $result), string.slice($value, $i)); + } - @if $character == '.' { - $digits: 1; - } @else if $digits == 0 { - $result: $result * 10 + map.get($numbers, $character); - } @else { - $digits: $digits * 10; - $result: $result + math.div(map.get($numbers, $character), $digits); - } - } + @if $character == '.' { + $digits: 1; + } @else if $digits == 0 { + $result: $result * 10 + map.get($numbers, $character); + } @else { + $digits: $digits * 10; + $result: $result + math.div(map.get($numbers, $character), $digits); + } + } - @return if($minus, -$result, $result); + @return if($minus, -$result, $result); } /// @@ -358,11 +358,11 @@ $units: ( /// @return {number} $value expressed in $unit /// @function to-length($value, $unit) { - @if not list.index(map.keys($units), $unit) { - @error 'Invalid unit `#{$unit}`.'; - } + @if not list.index(map.keys($units), $unit) { + @error 'Invalid unit `#{$unit}`.'; + } - @return $value * map.get($units, $unit); + @return $value * map.get($units, $unit); } /// @@ -371,5 +371,5 @@ $units: ( /// @content /// @mixin execute { - @content; + @content; } -- cgit v1.2.3-70-g09d2