From dd5f3c463fab336d694f426dcad11a1783590fc9 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sat, 5 Feb 2022 07:52:13 +0100 Subject: Ported from import syntax to modules --- src/_gradients.scss | 127 +++++++++++++++++++++++++--------------------------- 1 file changed, 62 insertions(+), 65 deletions(-) (limited to 'src/_gradients.scss') diff --git a/src/_gradients.scss b/src/_gradients.scss index 657efa2..6575482 100644 --- a/src/_gradients.scss +++ b/src/_gradients.scss @@ -17,6 +17,8 @@ @use 'sass:math'; @use 'sass:meta'; +@use './functions'; +@use './easing'; /// /// Number of intermediate color stops generated to achieve easing. @@ -24,7 +26,7 @@ /// /// @type number /// -$iro-easing-gradient-steps: 10 !default; +$easing-gradient-steps: 10 !default; /// /// Generate a new easing background gradient. @@ -44,7 +46,7 @@ $iro-easing-gradient-steps: 10 !default; /// /// @example scss - A smoother linear gradient /// .background { -/// background-image: iro-easing-gradient( +/// background-image: easing-gradient( /// linear, /// to top, /// #000, @@ -74,7 +76,7 @@ $iro-easing-gradient-steps: 10 !default; /// /// @example scss - A smoother radial gradient /// .background { -/// background-image: iro-easing-gradient( +/// background-image: easing-gradient( /// radial, /// 50em 16em at 0 0, /// #000, @@ -104,7 +106,7 @@ $iro-easing-gradient-steps: 10 !default; /// /// @example scss - A smoother linear gradient with complex color positions /// .background { -/// background-image: iro-easing-gradient( +/// background-image: easing-gradient( /// linear, /// to top, /// #000 20%, @@ -132,9 +134,9 @@ $iro-easing-gradient-steps: 10 !default; /// ); /// } /// -@function iro-easing-gradient($type, $dir, $stop, $stops...) { +@function easing-gradient($type, $dir, $stop, $stops...) { $pos-template: null; - $stops: iro-list-prepend($stops, $stop); + $stops: functions.list-prepend($stops, $stop); $last-positioned-stop: 1; $generated-stops: (); @@ -147,7 +149,7 @@ $iro-easing-gradient-steps: 10 !default; $stop: nth($stops, $i); @if $i == 1 { - @if not iro-easing-gradient-is-color-stop($stop) { + @if not easing-gradient-is-color-stop($stop) { @error 'The first color stop argument must be a color stop.'; } @@ -161,9 +163,9 @@ $iro-easing-gradient-steps: 10 !default; $stops: set-nth($stops, $i, $stop); } - $generated-stops: append($generated-stops, iro-str-implode($stop, ' ')); - } @else if iro-easing-gradient-is-positioned-color-stop($stop) or ($i == length($stops)) { - @if not iro-easing-gradient-is-color-stop($stop) { + $generated-stops: append($generated-stops, functions.str-implode($stop, ' ')); + } @else if easing-gradient-is-positioned-color-stop($stop) or ($i == length($stops)) { + @if not easing-gradient-is-color-stop($stop) { @error 'The last color stop argument must be a color stop.'; } @@ -194,19 +196,19 @@ $iro-easing-gradient-steps: 10 !default; // the positions of all stops list items that are color stops. // - $interpolated-stops: iro-easing-gradient-interpolate-stop-positions( + $interpolated-stops: easing-gradient-interpolate-stop-positions( nth($stops, $last-positioned-stop), - iro-list-slice($stops, $last-positioned-stop + 1, $i - 1), + functions.list-slice($stops, $last-positioned-stop + 1, $i - 1), $stop ); $new-stops: join( - iro-list-slice($stops, 1, $last-positioned-stop), + functions.list-slice($stops, 1, $last-positioned-stop), $interpolated-stops ); $new-stops: join( $new-stops, - iro-list-slice($stops, $i) + functions.list-slice($stops, $i) ); $stops: $new-stops; } @@ -225,13 +227,13 @@ $iro-easing-gradient-steps: 10 !default; $prev-stop: nth($stops, $j - 1); $next-stop: nth($stops, $j); - @if not iro-easing-gradient-is-color-stop($next-stop) { + @if not easing-gradient-is-color-stop($next-stop) { $j: $j + 1; $easing: $next-stop; $next-stop: nth($stops, $j); - @if not iro-easing-gradient-is-color-stop($next-stop) { + @if not easing-gradient-is-color-stop($next-stop) { @error 'There can be at most one interpolation hint between to color stops.'; } } @@ -245,16 +247,16 @@ $iro-easing-gradient-steps: 10 !default; $easing-args: (); @if type-of($easing) == list { - $easing-args: iro-list-slice($easing, 2); + $easing-args: functions.list-slice($easing, 2); $easing: nth($easing, 1); } $generated-stops: join( $generated-stops, - iro-easing-gradient-ease-stops($prev-stop, $next-stop, $easing, $easing-args) + easing-gradient-ease-stops($prev-stop, $next-stop, $easing, $easing-args) ); } @else { - $generated-stops: append($generated-stops, iro-str-implode($next-stop, ' ')); + $generated-stops: append($generated-stops, functions.str-implode($next-stop, ' ')); } $j: $j + 1; @@ -265,30 +267,30 @@ $iro-easing-gradient-steps: 10 !default; } @if $type == 'linear' { - @return linear-gradient($dir, unquote(iro-str-implode($generated-stops, ', '))); + @return linear-gradient($dir, unquote(functions.str-implode($generated-stops, ', '))); } @else if $type == 'radial' { - @return radial-gradient($dir, unquote(iro-str-implode($generated-stops, ', '))); + @return radial-gradient($dir, unquote(functions.str-implode($generated-stops, ', '))); } @else { @error 'Invalid gradient type: #{inspect($type)}.'; } } /// -/// Alias for iro-easing-gradient('linear',...) +/// Alias for easing-gradient('linear',...) /// -/// @see {function} iro-easing-gradient +/// @see {function} easing-gradient /// -@function iro-easing-linear-gradient($dir, $stop, $stops...) { - @return iro-easing-gradient('linear', $dir, $stop, $stops...); +@function easing-linear-gradient($dir, $stop, $stops...) { + @return easing-gradient('linear', $dir, $stop, $stops...); } /// -/// Alias for iro-easing-gradient('radial',...) +/// Alias for easing-gradient('radial',...) /// -/// @see {function} iro-easing-gradient +/// @see {function} easing-gradient /// -@function iro-easing-radial-gradient($dir, $stop, $stops...) { - @return iro-easing-gradient('radial', $dir, $stop, $stops...); +@function easing-radial-gradient($dir, $stop, $stops...) { + @return easing-gradient('radial', $dir, $stop, $stops...); } /// @@ -296,7 +298,7 @@ $iro-easing-gradient-steps: 10 !default; /// /// @access private /// -@function iro-easing-gradient-ease-stops($prev-stop, $next-stop, $easing, $easing-args: ()) { +@function easing-gradient-ease-stops($prev-stop, $next-stop, $easing, $easing-args: ()) { @if $easing == 'steps' { $steps: null; $jump: null; @@ -309,16 +311,11 @@ $iro-easing-gradient-steps: 10 !default; $jump: jump-end; } - @return iro-easing-gradient-steps-stops($prev-stop, $next-stop, $steps, $jump); + @return easing-gradient-steps-stops($prev-stop, $next-stop, $steps, $jump); } @else { - $easing-func: null; - @if function-exists('iro-' + $easing) { - $easing-func: get-function('iro-' + $easing); - } @else { - $easing-func: get-function($easing); - } + $easing-func: get-function($easing, $module: easing); - @return iro-easing-gradient-bezier-stops($prev-stop, $next-stop, $easing-func, $easing-args); + @return easing-gradient-bezier-stops($prev-stop, $next-stop, $easing-func, $easing-args); } } @@ -327,7 +324,7 @@ $iro-easing-gradient-steps: 10 !default; /// /// @access private /// -@function iro-easing-gradient-bezier-stops($prev-stop, $next-stop, $easing-func, $easing-args: ()) { +@function easing-gradient-bezier-stops($prev-stop, $next-stop, $easing-func, $easing-args: ()) { $prev-stop-color: nth($prev-stop, 1); $prev-stop-pos: nth($prev-stop, 2); $next-stop-color: nth($next-stop, 1); @@ -342,8 +339,8 @@ $iro-easing-gradient-steps: 10 !default; $distance: $next-stop-pos - $prev-stop-pos; - @for $i from 1 through $iro-easing-gradient-steps { - $perc: math.div($i, $iro-easing-gradient-steps); + @for $i from 1 through $easing-gradient-steps { + $perc: math.div($i, $easing-gradient-steps); $color: null; $pos: $prev-stop-pos + $perc * $distance; @@ -378,8 +375,8 @@ $iro-easing-gradient-steps: 10 !default; $next-stop-pos: meta.calc-args($next-stop-pos); } - @for $i from 1 through $iro-easing-gradient-steps { - $perc: $i / $iro-easing-gradient-steps; + @for $i from 1 through $easing-gradient-steps { + $perc: math.div($i, $easing-gradient-steps); $color: null; $pos: null; @@ -403,7 +400,7 @@ $iro-easing-gradient-steps: 10 !default; /// /// @access private /// -@function iro-easing-gradient-steps-stops($prev-stop, $next-stop, $steps, $jump: jump-end) { +@function easing-gradient-steps-stops($prev-stop, $next-stop, $steps, $jump: jump-end) { $prev-stop-color: nth($prev-stop, 1); $prev-stop-pos: nth($prev-stop, 2); $next-stop-color: nth($next-stop, 1); @@ -419,18 +416,18 @@ $iro-easing-gradient-steps: 10 !default; $distance: $next-stop-pos - $prev-stop-pos; @for $i from 1 through $steps { - $x1: ($i - 1) / $steps; - $x2: $i / $steps; + $x1: math.div($i - 1, $steps); + $x2: math.div($i, $steps); $y: null; @if $jump == jump-start { - $y: $i / $steps; + $y: math.div($i, $steps); } @else if $jump == jump-end { - $y: ($i - 1) / $steps; + $y: math.div($i - 1, $steps); } @else if $jump == jump-both { - $y: $i / ($steps + 1); + $y: math.div($i, $steps + 1); } @else if $jump == jump-none { - $y: ($i - 1) / ($steps - 1); + $y: math.div($i - 1, $steps - 1); } @else { @error 'Invalid $jump: #{inspect($jump)}'; } @@ -474,18 +471,18 @@ $iro-easing-gradient-steps: 10 !default; } @for $i from 1 through $steps { - $x1: ($i - 1) / $steps; - $x2: $i / $steps; + $x1: math.div($i - 1, $steps); + $x2: math.div($i, $steps); $y: null; @if $jump == jump-start { - $y: $i / $steps; + $y: math.div($i, $steps); } @else if $jump == jump-end { - $y: ($i - 1) / $steps; + $y: math.div($i - 1, $steps); } @else if $jump == jump-both { - $y: $i / ($steps + 1); + $y: math.div($i, $steps + 1); } @else if $jump == jump-none { - $y: ($i - 1) / ($steps - 1); + $y: math.div($i - 1, $steps - 1); } @else { @error 'Invalid $jump: #{inspect($jump)}'; } @@ -515,14 +512,14 @@ $iro-easing-gradient-steps: 10 !default; /// /// @access private /// -@function iro-easing-gradient-interpolate-stop-positions($prev-stop, $stops, $next-stop) { +@function easing-gradient-interpolate-stop-positions($prev-stop, $stops, $next-stop) { $prev-stop-pos: nth($prev-stop, 2); $next-stop-pos: nth($next-stop, 2); $stops-num: 0; @for $i from 1 through length($stops) { $stop: nth($stops, $i); - @if iro-easing-gradient-is-color-stop($stop) { + @if easing-gradient-is-color-stop($stop) { $stops-num: $stops-num + 1; } } @@ -539,8 +536,8 @@ $iro-easing-gradient-steps: 10 !default; @for $i from 1 through length($stops) { $stop: nth($stops, $i); - @if iro-easing-gradient-is-color-stop($stop) { - $pos: $prev-stop-pos + $distance / ($stops-num + 1) * $cur-stop-num; + @if easing-gradient-is-color-stop($stop) { + $pos: $prev-stop-pos + math.div($distance, $stops-num + 1) * $cur-stop-num; $stops: set-nth($stops, $i, $stop $pos); $cur-stop-num: $cur-stop-num + 1; @@ -571,8 +568,8 @@ $iro-easing-gradient-steps: 10 !default; @for $i from 1 through length($stops) { $stop: nth($stops, $i); - @if iro-easing-gradient-is-color-stop($stop) { - $perc: $cur-stop-num / ($stops-num + 1); + @if easing-gradient-is-color-stop($stop) { + $perc: math.div($cur-stop-num, $stops-num + 1); $pos: calc(#{$prev-stop-pos} + (#{$next-stop-pos} - #{$prev-stop-pos}) * #{$perc}); $stops: set-nth($stops, $i, $stop $pos); @@ -589,8 +586,8 @@ $iro-easing-gradient-steps: 10 !default; /// /// @access private /// -@function iro-easing-gradient-is-color-stop($input) { - @return (type-of($input) == color) or iro-easing-gradient-is-positioned-color-stop($input); +@function easing-gradient-is-color-stop($input) { + @return (type-of($input) == color) or easing-gradient-is-positioned-color-stop($input); } /// @@ -598,6 +595,6 @@ $iro-easing-gradient-steps: 10 !default; /// /// @access private /// -@function iro-easing-gradient-is-positioned-color-stop($input) { +@function easing-gradient-is-positioned-color-stop($input) { @return (type-of($input) == list) and (type-of(nth($input, 1)) == color); } -- cgit v1.2.3-54-g00ecf