'use strict';

var calcDuration = require('./calc-duration.js');
var timeConversion = require('../../../../../../../../motion-utils@12.36.0/node_modules/motion-utils/dist/es/time-conversion.js');

/**
 * Create a progress => progress easing function from a generator.
 */
function createGeneratorEasing(options, scale = 100, createGenerator) {
    const generator = createGenerator({ ...options, keyframes: [0, scale] });
    const duration = Math.min(calcDuration.calcGeneratorDuration(generator), calcDuration.maxGeneratorDuration);
    return {
        type: "keyframes",
        ease: (progress) => {
            return generator.next(duration * progress).value / scale;
        },
        duration: timeConversion.millisecondsToSeconds(duration),
    };
}

exports.createGeneratorEasing = createGeneratorEasing;
