From 9e2321a1730506c1973226fc254fa96df4f0dac9 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Mon, 24 Jun 2024 08:55:42 +0200 Subject: Add linear easing func --- src/_easing.scss | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/_easing.scss b/src/_easing.scss index 8bcfd39..6d66ea7 100644 --- a/src/_easing.scss +++ b/src/_easing.scss @@ -10,6 +10,8 @@ //// @use 'sass:math'; +@use 'sass:map'; +@use 'sass:list'; /// /// @access private @@ -73,14 +75,14 @@ $cubic-bezier-subdiv-max-iters: 10 !default; $sample-pool-key: $x1 + '_' + $x2; - @if not map-has-key($cubic-bezier-sample-pool, $sample-pool-key) { + @if not map.has-key($cubic-bezier-sample-pool, $sample-pool-key) { $samples: (); @for $i from 0 through $cubic-bezier-sample-pool-size { - $samples: append($samples, cubic-bezier-func($x1, $x2, math.div($i, $cubic-bezier-sample-pool-size))); + $samples: list.append($samples, cubic-bezier-func($x1, $x2, math.div($i, $cubic-bezier-sample-pool-size))); } - $cubic-bezier-sample-pool: map-merge($cubic-bezier-sample-pool, ($sample-pool-key: $samples)) !global; + $cubic-bezier-sample-pool: map.merge($cubic-bezier-sample-pool, ($sample-pool-key: $samples)) !global; } // @@ -169,7 +171,7 @@ $cubic-bezier-subdiv-max-iters: 10 !default; $a: $cur-t; } - @if abs($cur-x) < $cubic-bezier-subdiv-precision { + @if math.abs($cur-x) < $cubic-bezier-subdiv-precision { @return $cur-t; } } @@ -184,19 +186,19 @@ $cubic-bezier-subdiv-max-iters: 10 !default; /// @function cubic-bezier-t-for-x($x1, $x2, $x) { $sample-pool-key: $x1 + '_' + $x2; - $samples: map-get($cubic-bezier-sample-pool, $sample-pool-key); + $samples: map.get($cubic-bezier-sample-pool, $sample-pool-key); $intv-start: 0; $cur-sample: 1; $last-sample: $cubic-bezier-sample-pool-size; - @while ($cur-sample != $last-sample) and (nth($samples, $cur-sample) <= $x) { + @while ($cur-sample != $last-sample) and (list.nth($samples, $cur-sample) <= $x) { $intv-start: $intv-start + math.div(1, $cubic-bezier-sample-pool-size); $cur-sample: $cur-sample + 1; } $cur-sample: $cur-sample - 1; - $dist: math.div($x - nth($samples, $cur-sample), nth($samples, $cur-sample + 1) - nth($samples, $cur-sample)); + $dist: math.div($x - list.nth($samples, $cur-sample), list.nth($samples, $cur-sample + 1) - list.nth($samples, $cur-sample)); $guess-t: $intv-start + math.div($dist, $cubic-bezier-sample-pool-size); $init-slope: cubic-bezier-func-slope($x1, $x2, $guess-t); @@ -209,6 +211,17 @@ $cubic-bezier-subdiv-max-iters: 10 !default; } } +/// +/// Linear easing function. +/// +/// @param {number} $x - Progress between 0 and 1 inclusive +/// +/// @return {number} +/// +@function linear($x) { + @return $x; +} + /// /// Sinusoidal easing function (in direction). /// -- cgit v1.2.3-70-g09d2