{"version":3,"file":"keyframes.mjs","sources":["../../../../src/animation/generators/keyframes.ts"],"sourcesContent":["import {\n    easeInOut,\n    easingDefinitionToFunction,\n    EasingFunction,\n    isEasingArray,\n} from \"motion-utils\"\nimport { interpolate } from \"../../utils/interpolate\"\nimport { defaultOffset } from \"../keyframes/offsets/default\"\nimport { convertOffsetToTimes } from \"../keyframes/offsets/time\"\nimport {\n    AnimationState,\n    AnyResolvedKeyframe,\n    KeyframeGenerator,\n    ValueAnimationOptions,\n} from \"../types\"\n\nexport function defaultEasing(\n    values: any[],\n    easing?: EasingFunction\n): EasingFunction[] {\n    return values.map(() => easing || easeInOut).splice(0, values.length - 1)\n}\n\nexport function keyframes<T extends AnyResolvedKeyframe>({\n    duration = 300,\n    keyframes: keyframeValues,\n    times,\n    ease = \"easeInOut\",\n}: ValueAnimationOptions<T>): KeyframeGenerator<T> {\n    /**\n     * Easing functions can be externally defined as strings. Here we convert them\n     * into actual functions.\n     */\n    const easingFunctions = isEasingArray(ease)\n        ? ease.map(easingDefinitionToFunction)\n        : easingDefinitionToFunction(ease)\n\n    /**\n     * This is the Iterator-spec return value. We ensure it's mutable rather than using a generator\n     * to reduce GC during animation.\n     */\n    const state: AnimationState<T> = {\n        done: false,\n        value: keyframeValues[0],\n    }\n\n    /**\n     * Create a times array based on the provided 0-1 offsets\n     */\n    const absoluteTimes = convertOffsetToTimes(\n        // Only use the provided offsets if they're the correct length\n        // TODO Maybe we should warn here if there's a length mismatch\n        times && times.length === keyframeValues.length\n            ? times\n            : defaultOffset(keyframeValues),\n        duration\n    )\n\n    const mapTimeToKeyframe = interpolate<T>(absoluteTimes, keyframeValues, {\n        ease: Array.isArray(easingFunctions)\n            ? easingFunctions\n            : defaultEasing(keyframeValues, easingFunctions),\n    })\n\n    return {\n        calculatedDuration: duration,\n        next: (t: number) => {\n            state.value = mapTimeToKeyframe(t)\n            state.done = t >= duration\n            return state\n        },\n    }\n}\n"],"names":[],"mappings":";;;;;AAgBM,SAAU,aAAa,C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