@@ -9,6 +9,7 @@ let isIncrementReqForColor = /ahsv|ahsl|argb/g
9
9
const numRegExp =
10
10
/ \s + | ( [ A - Z a - z ? ( ) . , { } : " " [ \] # ] + ) | ( [ - + / * % ] + = ) ? ( [ - + * / % ] + ) ? (?: \d + \. ? \d * | \. ? \d + ) (?: [ e E ] [ - + ] ? \d + ) ? / g
11
11
let hexColor = / ^ # ( [ 0 - 9 a - f ] { 6 } | [ 0 - 9 a - f ] { 3 } ) $ / i
12
+ let trimRegExp = / \n | \r | \t / g
12
13
let hexReplace = ( all , hex ) => {
13
14
let r
14
15
let g
@@ -25,12 +26,13 @@ let hexReplace = (all, hex) => {
25
26
26
27
return `rgb(${ r } ,${ g } ,${ b } `
27
28
}
29
+ let trim = str => typeof str === 'string' ? str . replace ( trimRegExp , '' ) : str
28
30
29
31
const SubTween = ( start , end , roundv = 10000 ) => {
30
32
if ( Array . isArray ( start ) ) {
31
33
let isColorPropsExist = null
32
34
let startIndex = null
33
- end = end . map ( ( v , i ) => colorMatch . test ( v ) ? ( ( isColorPropsExist = v ) , ( startIndex = i ) , null ) : v === start [ i ] ? null : typeof v === 'number' ? ( v - start [ i ] ) : SubTween ( start [ i ] , v ) )
35
+ end = end . map ( ( v , i ) => colorMatch . test ( v ) ? ( ( isColorPropsExist = v ) , ( startIndex = i ) , null ) : v === start [ i ] ? null : typeof v === 'number' ? ( v - start [ i ] ) : numRegExp . test ( v ) ? SubTween ( trim ( start [ i ] ) , trim ( v ) ) : v )
34
36
let endIndex = startIndex !== null ? startIndex + 6 : null
35
37
if ( isColorPropsExist && isIncrementReqForColor . test ( isColorPropsExist ) ) {
36
38
startIndex ++
@@ -60,7 +62,7 @@ const SubTween = (start, end, roundv = 10000) => {
60
62
end [ property ] = null
61
63
} else if ( typeof start [ property ] === 'number' ) {
62
64
end [ property ] -= start [ property ]
63
- } else if ( typeof end [ property ] === 'object' || typeof [ end ] === 'string' ) {
65
+ } else if ( typeof end [ property ] === 'object' || ( typeof end [ property ] === 'string' && numRegExp . test ( end [ property ] ) ) ) {
64
66
end [ property ] = SubTween ( start [ property ] , end [ property ] )
65
67
}
66
68
}
@@ -84,9 +86,9 @@ const SubTween = (start, end, roundv = 10000) => {
84
86
return ( t ) => {
85
87
return isSame ? end : ( ( ( start + end * t ) * roundv ) | 0 ) / roundv
86
88
}
87
- } else if ( typeof start === 'string' ) {
88
- let _startMap = start . replace ( hexColor , hexReplace ) . match ( numRegExp ) . map ( toNumber )
89
- let _endMap = end . replace ( hexColor , hexReplace ) . match ( numRegExp ) . map ( toNumber )
89
+ } else if ( typeof start === 'string' && numRegExp . test ( start ) && numRegExp . test ( end ) ) {
90
+ let _startMap = trim ( start ) . replace ( hexColor , hexReplace ) . match ( numRegExp ) . map ( toNumber )
91
+ let _endMap = trim ( end ) . replace ( hexColor , hexReplace ) . match ( numRegExp ) . map ( toNumber )
90
92
let _tween = SubTween ( _startMap , _endMap )
91
93
return ( t ) => {
92
94
let _t = _tween ( t )
0 commit comments