1
- import { ScrollAxis , ValidScrollAxis } from '..' ;
1
+ import { CSSEffect , ScrollAxis , ValidScrollAxis } from '..' ;
2
2
import {
3
3
ParsedValueEffect ,
4
4
ValidCSSEffects ,
@@ -37,14 +37,14 @@ export function parseElementTransitionEffects(
37
37
const parsedEffects : { [ key : string ] : ParsedValueEffect } = { } ;
38
38
39
39
PARALLAX_EFFECTS . forEach ( ( key : keyof typeof ValidCSSEffects ) => {
40
- const value = props ?. [ key ] ;
41
40
const defaultValue : AllValidUnits = MAP_EFFECT_TO_DEFAULT_UNIT [ key ] ;
42
41
43
42
// If the provided type is a number, this must be the speed prop
44
43
// in which case we need to construct the proper translate config
45
- if ( typeof value === 'number' ) {
46
- const startSpeed = `${ ( props . speed || 0 ) * 10 } px` ;
47
- const endSpeed = `${ ( props . speed || 0 ) * - 10 } px` ;
44
+ if ( typeof props ?. [ key ] === 'number' ) {
45
+ const value = props ?. [ key ] as number ;
46
+ const startSpeed = `${ ( value || 0 ) * 10 } px` ;
47
+ const endSpeed = `${ ( value || 0 ) * - 10 } px` ;
48
48
49
49
const startParsed = parseValueAndUnit ( startSpeed ) ;
50
50
const endParsed = parseValueAndUnit ( endSpeed ) ;
@@ -67,28 +67,27 @@ export function parseElementTransitionEffects(
67
67
}
68
68
69
69
// The rest are standard effect being parsed
70
- const shouldParseEffect =
71
- Array . isArray ( value ) &&
72
- typeof value ?. [ 0 ] !== 'undefined' &&
73
- typeof value ?. [ 1 ] !== 'undefined' ;
70
+ if ( Array . isArray ( props ?. [ key ] ) ) {
71
+ const value = props ?. [ key ] as CSSEffect ;
74
72
75
- if ( shouldParseEffect ) {
76
- const startParsed = parseValueAndUnit ( value ?. [ 0 ] , defaultValue ) ;
77
- const endParsed = parseValueAndUnit ( value ?. [ 1 ] , defaultValue ) ;
73
+ if ( typeof value [ 0 ] !== 'undefined' && typeof value [ 1 ] !== 'undefined' ) {
74
+ const startParsed = parseValueAndUnit ( value ?. [ 0 ] , defaultValue ) ;
75
+ const endParsed = parseValueAndUnit ( value ?. [ 1 ] , defaultValue ) ;
78
76
79
- const easing = createEasingFunction ( value ?. [ 2 ] ) ;
77
+ const easing = createEasingFunction ( value ?. [ 2 ] ) ;
80
78
81
- parsedEffects [ key ] = {
82
- start : startParsed . value ,
83
- end : endParsed . value ,
84
- unit : startParsed . unit ,
85
- easing,
86
- } ;
79
+ parsedEffects [ key ] = {
80
+ start : startParsed . value ,
81
+ end : endParsed . value ,
82
+ unit : startParsed . unit ,
83
+ easing,
84
+ } ;
87
85
88
- if ( startParsed . unit !== endParsed . unit ) {
89
- throw new Error (
90
- 'Must provide matching units for the min and max offset values of each axis.'
91
- ) ;
86
+ if ( startParsed . unit !== endParsed . unit ) {
87
+ throw new Error (
88
+ 'Must provide matching units for the min and max offset values of each axis.'
89
+ ) ;
90
+ }
92
91
}
93
92
}
94
93
} ) ;
0 commit comments