Lint and format src/runtime/motion/tweened.js

pull/8569/head
S. Elliott Johnson 3 years ago
parent 28240a5486
commit 4b294516a3

@ -4,8 +4,7 @@ import { linear } from '../easing';
import { is_date } from './utils';
/** @returns {(t: any) => any} */
function get_interpolator(a, b) {
if (a === b || a !== a)
return () => a;
if (a === b || a !== a) return () => a;
const type = typeof a;
if (type !== typeof b || Array.isArray(a) !== Array.isArray(b)) {
throw new Error('Cannot interpolate values of different type');
@ -17,8 +16,7 @@ function get_interpolator(a, b) {
return (t) => arr.map((fn) => fn(t));
}
if (type === 'object') {
if (!a || !b)
throw new Error('Object cannot be null');
if (!a || !b) throw new Error('Object cannot be null');
if (is_date(a) && is_date(b)) {
a = a.getTime();
b = b.getTime();
@ -65,7 +63,12 @@ export function tweened(value, defaults = {}) {
target_value = new_value;
let previous_task = task;
let started = false;
let { delay = 0, duration = 400, easing = linear, interpolate = get_interpolator } = assign(assign({}, defaults), opts);
let {
delay = 0,
duration = 400,
easing = linear,
interpolate = get_interpolator
} = assign(assign({}, defaults), opts);
if (duration === 0) {
if (previous_task) {
previous_task.abort();
@ -77,12 +80,10 @@ export function tweened(value, defaults = {}) {
const start = now() + delay;
let fn;
task = loop((now) => {
if (now < start)
return true;
if (now < start) return true;
if (!started) {
fn = interpolate(value, new_value);
if (typeof duration === 'function')
duration = duration(value, new_value);
if (typeof duration === 'function') duration = duration(value, new_value);
started = true;
}
if (previous_task) {
@ -107,7 +108,6 @@ export function tweened(value, defaults = {}) {
};
}
/**
* @typedef {(target_value: T, value: T) => T} Updater
* @template T

Loading…
Cancel
Save