animate-value
Version:
🏃 animates a numeric value
63 lines (49 loc) • 1.99 kB
JavaScript
'use strict';
exports.__esModule = true;
var _tick = require('./lib/tick');
var _tick2 = _interopRequireDefault(_tick);
var _calcStartEnd = require('./lib/calc/calcStartEnd');
var _calcStartEnd2 = _interopRequireDefault(_calcStartEnd);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return new Promise(function (resolve) {
var _options$from = options.from,
from = _options$from === undefined ? 0 : _options$from,
_options$to = options.to,
to = _options$to === undefined ? 1 : _options$to,
_options$easing = options.easing,
easing = _options$easing === undefined ? 'easeInQuad' : _options$easing,
_options$duration = options.duration,
duration = _options$duration === undefined ? 600 : _options$duration,
_options$delay = options.delay,
delay = _options$delay === undefined ? 0 : _options$delay,
_options$loopDelay = options.loopDelay,
loopDelay = _options$loopDelay === undefined ? 0 : _options$loopDelay,
_options$rewind = options.rewind,
rewind = _options$rewind === undefined ? false : _options$rewind,
change = options.change,
done = options.done;
var _options$loop = options.loop,
loop = _options$loop === undefined ? 1 : _options$loop;
if (loop === false) loop = 1;
var data = {
from: from,
to: to,
duration: duration,
delay: delay,
loopDelay: loopDelay,
loop: loop,
easing: easing,
rewind: rewind,
change: change,
done: done
};
data = Object.assign({}, data, (0, _calcStartEnd2.default)(delay, duration));
data.iteration = 1;
var raf = requestAnimationFrame(function () {
return (0, _tick2.default)(data, raf, resolve);
});
});
};
module.exports = exports['default'];