/*!
 * tweensy - Copyright (c) 2017 Jacob Buck
 * https://github.com/jacobbuck/tweensy
 * Licensed under the terms of the MIT license.
 */
import now from "performance-now";
import rafq from "rafq";

const queue = rafq();

const lerp = (v0, v1, t) => (1 - t) * v0 + t * v1;

const tween = options => {
  const {
    duration = 0,
    easing = t => t,
    from,
    onComplete = () => {},
    onProgress = () => {},
    to,
  } = options;

  let isFinished = false;
  let startTime = null;

  const tick = () => {
    const time = now();

    if (startTime === null) {
      startTime = time;
    }

    const progress = isFinished
      ? 1
      : Math.min((time - startTime) / options.duration, 1);

    const t = options.easing(progress);

    if (typeof from === "number") {
      options.onProgress(lerp(from, to, t));
    } else if (Array.isArray(from)) {
      options.onProgress(from.map((v, i) => lerp(v, to[i], t)));
    } else if (typeof from === "object") {
      options.onProgress(
        Object.keys(from).reduce((memo, i) => {
          memo[i] = lerp(from[i], to[i], t);
          return memo;
        }, {})
      );
    }

    if (progress === 1) {
      options.onComplete(time);
    } else {
      queue.add(tick);
    }
  };

  const stop = finish => {
    isFinished = true;

    if (!finish) {
      queue.remove(tick);
    }
  };

  tick();

  return stop;
};

@@ -268,16 +268,416 @@
  * v1;%0A%0A
+const createInterpolate = (v0, v1) =%3E %7B%0A  if (typeof from === %22number%22) %7B%0A    return t =%3E lerp(v0, v1, t);%0A  %7D else if (Array.isArray(v0)) %7B%0A    return t =%3E v0.map((v, i) =%3E lerp(v, v1%5Bi%5D, t));%0A  %7D else if (typeof v0 === %22object%22) %7B%0A    const keys = Object.keys(v0);%0A    return t =%3E%0A      keys.reduce((memo, i) =%3E %7B%0A        memo%5Bi%5D = lerp(v0%5Bi%5D, v1%5Bi%5D, t);%0A        return memo;%0A      %7D, %7B%7D);%0A  %7D%0A%7D;%0A%0A
 const tw
@@ -695,16 +695,16 @@
 ns =%3E %7B%0A
-
   const 
@@ -883,16 +883,68 @@
  null;%0A%0A
+  const interpolate = createInterpolate(from, to);%0A%0A
   const 
@@ -1155,443 +1155,66 @@
     
-const t = options.easing(progress);%0A%0A    if (typeof from === %22number%22) %7B%0A      options.onProgress(lerp(from, to, t));%0A    %7D else if (Array.isArray(from)) %7B%0A      options.onProgress(from.map((v, i) =%3E lerp(v, to%5Bi%5D, t)));%0A    %7D else if (typeof from === %22object%22) %7B%0A      options.onProgress(%0A        Object.keys(from).reduce((memo, i) =%3E %7B%0A          memo%5Bi%5D = lerp(from%5Bi%5D, to%5Bi%5D, t);%0A          return memo;%0A        %7D, %7B%7D)%0A      );%0A    %7D
+options.onProgress(interpolate(options.easing(progress)));
 %0A%0A  

Move interpolate out for better performance