1 | /**
|
---|
2 | * @license
|
---|
3 | * Copyright Google LLC All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
6 | * found in the LICENSE file at https://angular.io/license
|
---|
7 | */
|
---|
8 | /** Parses a CSS time value to milliseconds. */
|
---|
9 | function parseCssTimeUnitsToMs(value) {
|
---|
10 | // Some browsers will return it in seconds, whereas others will return milliseconds.
|
---|
11 | const multiplier = value.toLowerCase().indexOf('ms') > -1 ? 1 : 1000;
|
---|
12 | return parseFloat(value) * multiplier;
|
---|
13 | }
|
---|
14 | /** Gets the transform transition duration, including the delay, of an element in milliseconds. */
|
---|
15 | export function getTransformTransitionDurationInMs(element) {
|
---|
16 | const computedStyle = getComputedStyle(element);
|
---|
17 | const transitionedProperties = parseCssPropertyValue(computedStyle, 'transition-property');
|
---|
18 | const property = transitionedProperties.find(prop => prop === 'transform' || prop === 'all');
|
---|
19 | // If there's no transition for `all` or `transform`, we shouldn't do anything.
|
---|
20 | if (!property) {
|
---|
21 | return 0;
|
---|
22 | }
|
---|
23 | // Get the index of the property that we're interested in and match
|
---|
24 | // it up to the same index in `transition-delay` and `transition-duration`.
|
---|
25 | const propertyIndex = transitionedProperties.indexOf(property);
|
---|
26 | const rawDurations = parseCssPropertyValue(computedStyle, 'transition-duration');
|
---|
27 | const rawDelays = parseCssPropertyValue(computedStyle, 'transition-delay');
|
---|
28 | return parseCssTimeUnitsToMs(rawDurations[propertyIndex]) +
|
---|
29 | parseCssTimeUnitsToMs(rawDelays[propertyIndex]);
|
---|
30 | }
|
---|
31 | /** Parses out multiple values from a computed style into an array. */
|
---|
32 | function parseCssPropertyValue(computedStyle, name) {
|
---|
33 | const value = computedStyle.getPropertyValue(name);
|
---|
34 | return value.split(',').map(part => part.trim());
|
---|
35 | }
|
---|
36 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJhbnNpdGlvbi1kdXJhdGlvbi5qcyIsInNvdXJjZV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