UNPKG

@atlaskit/motion

Version:

A set of utilities to apply motion in your application.

40 lines (39 loc) 1.38 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.getDurationMs = void 0; var _toConsumableArray2 = _interopRequireDefault(require("@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. */ var getDurationMs = exports.getDurationMs = function getDurationMs(animation) { var animations = animation.split(/,(?![^()]*\))/).map(function (value) { return (0, _toConsumableArray2.default)(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 }); };