UNPKG

@atlaskit/motion

Version:

A set of utilities to apply motion in your application.

33 lines 1.12 kB
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 animations = animation.split(/,(?![^()]*\))/).map(function (value) { return _toConsumableArray(value.trim().matchAll(/(-?\d*\.?\d+)(ms|s)\b/g)); }).filter(function (matches) { return matches.length > 0; }); if (animations.length === 0) { return { duration: 0, delay: 0 }; } return animations.reduce(function (longest, matches) { var toMilliseconds = function toMilliseconds(match) { var value = parseFloat(match[1]); return match[2] === 's' ? value * 1000 : value; }; var timing = { duration: toMilliseconds(matches[0]), delay: matches[1] ? toMilliseconds(matches[1]) : 0 }; return timing.duration + timing.delay > longest.duration + longest.delay ? timing : longest; }, { duration: 0, delay: 0 }); };