UNPKG

@atlaskit/motion

Version:

A set of utilities to apply motion in your application.

42 lines (40 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getComputedAnimationDurationMs = void 0; var _convertToMs = require("./convert-to-ms"); var cssTimePattern = /^-?(?:\d+\.?\d*|\.\d+)(?:ms|s)$/; var toCssList = function toCssList(value) { return value.split(',').map(function (item) { return item.trim(); }).filter(Boolean); }; var toTimeList = function toTimeList(value) { return toCssList(value).filter(function (time) { return cssTimePattern.test(time); }).map(_convertToMs.convertToMs); }; /** * Returns the longest total runtime from computed CSS animation name, duration, and delay lists. * `animation-name` determines the number of animations. CSS repeats shorter duration and delay * lists and ignores timing values that do not correspond to an animation name. */ var getComputedAnimationDurationMs = exports.getComputedAnimationDurationMs = function getComputedAnimationDurationMs(animationName, animationDuration, animationDelay) { var names = toCssList(animationName); var durations = toTimeList(animationDuration); var delays = toTimeList(animationDelay); if (names.length === 0 || durations.length === 0) { return 0; } var longestDuration = 0; for (var index = 0; index < names.length; index++) { if (names[index] === 'none') { continue; } var duration = durations[index % durations.length]; var delay = delays.length > 0 ? delays[index % delays.length] : 0; longestDuration = Math.max(longestDuration, duration + delay); } return longestDuration; };