aboutsummaryrefslogtreecommitdiffstats
path: root/src/_easing.scss
diff options
context:
space:
mode:
Diffstat (limited to 'src/_easing.scss')
-rw-r--r--src/_easing.scss27
1 files changed, 20 insertions, 7 deletions
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 @@
10//// 10////
11 11
12@use 'sass:math'; 12@use 'sass:math';
13@use 'sass:map';
14@use 'sass:list';
13 15
14/// 16///
15/// @access private 17/// @access private
@@ -73,14 +75,14 @@ $cubic-bezier-subdiv-max-iters: 10 !default;
73 75
74 $sample-pool-key: $x1 + '_' + $x2; 76 $sample-pool-key: $x1 + '_' + $x2;
75 77
76 @if not map-has-key($cubic-bezier-sample-pool, $sample-pool-key) { 78 @if not map.has-key($cubic-bezier-sample-pool, $sample-pool-key) {
77 $samples: (); 79 $samples: ();
78 80
79 @for $i from 0 through $cubic-bezier-sample-pool-size { 81 @for $i from 0 through $cubic-bezier-sample-pool-size {
80 $samples: append($samples, cubic-bezier-func($x1, $x2, math.div($i, $cubic-bezier-sample-pool-size))); 82 $samples: list.append($samples, cubic-bezier-func($x1, $x2, math.div($i, $cubic-bezier-sample-pool-size)));
81 } 83 }
82 84
83 $cubic-bezier-sample-pool: map-merge($cubic-bezier-sample-pool, ($sample-pool-key: $samples)) !global; 85 $cubic-bezier-sample-pool: map.merge($cubic-bezier-sample-pool, ($sample-pool-key: $samples)) !global;
84 } 86 }
85 87
86 // 88 //
@@ -169,7 +171,7 @@ $cubic-bezier-subdiv-max-iters: 10 !default;
169 $a: $cur-t; 171 $a: $cur-t;
170 } 172 }
171 173
172 @if abs($cur-x) < $cubic-bezier-subdiv-precision { 174 @if math.abs($cur-x) < $cubic-bezier-subdiv-precision {
173 @return $cur-t; 175 @return $cur-t;
174 } 176 }
175 } 177 }
@@ -184,19 +186,19 @@ $cubic-bezier-subdiv-max-iters: 10 !default;
184/// 186///
185@function cubic-bezier-t-for-x($x1, $x2, $x) { 187@function cubic-bezier-t-for-x($x1, $x2, $x) {
186 $sample-pool-key: $x1 + '_' + $x2; 188 $sample-pool-key: $x1 + '_' + $x2;
187 $samples: map-get($cubic-bezier-sample-pool, $sample-pool-key); 189 $samples: map.get($cubic-bezier-sample-pool, $sample-pool-key);
188 190
189 $intv-start: 0; 191 $intv-start: 0;
190 $cur-sample: 1; 192 $cur-sample: 1;
191 $last-sample: $cubic-bezier-sample-pool-size; 193 $last-sample: $cubic-bezier-sample-pool-size;
192 194
193 @while ($cur-sample != $last-sample) and (nth($samples, $cur-sample) <= $x) { 195 @while ($cur-sample != $last-sample) and (list.nth($samples, $cur-sample) <= $x) {
194 $intv-start: $intv-start + math.div(1, $cubic-bezier-sample-pool-size); 196 $intv-start: $intv-start + math.div(1, $cubic-bezier-sample-pool-size);
195 $cur-sample: $cur-sample + 1; 197 $cur-sample: $cur-sample + 1;
196 } 198 }
197 $cur-sample: $cur-sample - 1; 199 $cur-sample: $cur-sample - 1;
198 200
199 $dist: math.div($x - nth($samples, $cur-sample), nth($samples, $cur-sample + 1) - nth($samples, $cur-sample)); 201 $dist: math.div($x - list.nth($samples, $cur-sample), list.nth($samples, $cur-sample + 1) - list.nth($samples, $cur-sample));
200 $guess-t: $intv-start + math.div($dist, $cubic-bezier-sample-pool-size); 202 $guess-t: $intv-start + math.div($dist, $cubic-bezier-sample-pool-size);
201 203
202 $init-slope: cubic-bezier-func-slope($x1, $x2, $guess-t); 204 $init-slope: cubic-bezier-func-slope($x1, $x2, $guess-t);
@@ -210,6 +212,17 @@ $cubic-bezier-subdiv-max-iters: 10 !default;
210} 212}
211 213
212/// 214///
215/// Linear easing function.
216///
217/// @param {number} $x - Progress between 0 and 1 inclusive
218///
219/// @return {number}
220///
221@function linear($x) {
222 @return $x;
223}
224
225///
213/// Sinusoidal easing function (in direction). 226/// Sinusoidal easing function (in direction).
214/// 227///
215/// @param {number} $x - Progress between 0 and 1 inclusive 228/// @param {number} $x - Progress between 0 and 1 inclusive