"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const interpolate = require("../../utils/interpolate.js");
const index = require("../../easing/index.js");
function defaultEasing(values, easing) {
  return values.map(() => easing || index.easeInOut).splice(0, values.length - 1);
}
function defaultOffset(values) {
  const numValues = values.length;
  return values.map((_value, i) => i !== 0 ? i / (numValues - 1) : 0);
}
function convertOffsetToTimes(offset, duration) {
  return offset.map((o) => o * duration);
}
function keyframes({ from = 0, to = 1, ease, offset, duration = 300 }) {
  const state = { done: false, value: from };
  const values = Array.isArray(to) ? to : [from, to];
  const times = convertOffsetToTimes(offset && offset.length === values.length ? offset : defaultOffset(values), duration);
  function createInterpolator() {
    return interpolate.interpolate(times, values, {
      ease: Array.isArray(ease) ? ease : defaultEasing(values, ease)
    });
  }
  let interpolator = createInterpolator();
  return {
    next: (t) => {
      state.value = interpolator(t);
      state.done = t >= duration;
      return state;
    },
    flipTarget: () => {
      values.reverse();
      interpolator = createInterpolator();
    }
  };
}
exports.convertOffsetToTimes = convertOffsetToTimes;
exports.defaultEasing = defaultEasing;
exports.defaultOffset = defaultOffset;
exports.keyframes = keyframes;
//# sourceMappingURL=keyframes.js.map
