@atlaskit/motion
Version:
A set of utilities to apply motion in your application.
28 lines • 895 B
JavaScript
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
/**
* Gets the duration in milliseconds for an animation property.
* @param animation - The animation property to get the duration for.
* @returns The duration in milliseconds.
*/
export var getDurationMs = function getDurationMs(animation) {
var match = _toConsumableArray(animation.trim().matchAll(/(-?\d*\.?\d+)(ms|s)\b/g));
if (match.length === 0) {
return {
duration: 0,
delay: 0
};
}
var durationValue = parseFloat(match[0][1]);
var durationUnit = match[0][2];
var duration = durationUnit === 's' ? durationValue * 1000 : durationValue;
var delay = 0;
if (match[1]) {
var delayValue = parseFloat(match[1][1]);
var delayUnit = match[1][2];
delay = delayUnit === 's' ? delayValue * 1000 : delayValue;
}
return {
duration: duration,
delay: delay
};
};