import { colorIn, colorOut } from './color'
import match from './match'
import { unitsIn, unitsOut } from './units'

const middleware = [
  { name: 'color', i: colorIn, o: colorOut },
  { name: 'units', i: unitsIn, o: unitsOut }
]

export default (shape1, shape2, time, duration, easing) => {
  const tween = (from, to) => {
    if (from === to) {
      return from
    }

    if (typeof from === 'number' && typeof to === 'number') {
      return easing(time, from, to, duration)
    }

    let f = from
    let t = to

    middleware.map(({ i }) => {
      if (typeof f === 'string' && typeof t === 'string') {
        f = i(f)
        t = i(t)
      }
    })

    if (typeof f === 'object' && typeof t === 'object') {
      for (let i in middleware) {
        const { name, o } = middleware[ i ]

        if (name === f.middleware && name === t.middleware) {
          return o(match(f, t, tween))
        }
      }
    }

    return from
  }

  return match(shape1, shape2, tween)
}

@@ -110,16 +110,61 @@
 units'%0A%0A
+/** Middleware to apply to tweened values */%0A
 const mi
@@ -274,68 +274,875 @@
 %0A%5D%0A%0A
-export default (shape1, shape2, time, duration, easing) =%3E %7B
+/**%0A * Find current shape given a from shape, a to shape and tween data.%0A *%0A * @param %7Bobject%7D fromShape - The shape object to tween from.%0A * @param %7Bobject%7D toShape - The shape object to tween to.%0A * @param %7Bnumber%7D time - Current time in milliseconds since the start of the tween.%0A * @param %7Bnumber%7D duration - Total duration of the tween in milliseconds.%0A * @param %7Bfunction%7D easing - The easing function.%0A *%0A * @returns %7Bobject%7D%0A *%0A * @example%0A * func(circle, square, 100, 200, easeInOutQuad)%0A */%0Aexport default (fromShape, toShape, time, duration, easing) =%3E %7B%0A  /**%0A   * Find current value given a from value and a to value and the%0A   * enclosed tween data.%0A   *%0A   * @param %7B(number%7Cstring)%7D from - The value to tween from.%0A   * @param %7B(number%7Cstring)%7D to - The value to tween to.%0A   *%0A   * @returns %7B(number%7Cstring)%7D%0A   *%0A   * @example%0A   * tween(1, 2)%0A   */
 %0A  c
@@ -1811,22 +1811,26 @@
 tch(
-s
+fromS
 hape
-1
 , 
-s
+toS
 hape
-2
 , tw

add tween helper functions comments