1
- if ( ! axe . commons . dom . isVisible ( node , false ) ) {
1
+ const { dom, color, text } = axe . commons ;
2
+
3
+ if ( ! dom . isVisible ( node , false ) ) {
2
4
return true ;
3
5
}
4
6
5
- var noScroll = ! ! ( options || { } ) . noScroll ;
6
- var bgNodes = [ ] ,
7
- bgColor = axe . commons . color . getBackgroundColor ( node , bgNodes , noScroll ) ,
8
- fgColor = axe . commons . color . getForegroundColor ( node , noScroll ) ;
7
+ const noScroll = ! ! ( options || { } ) . noScroll ;
8
+ const bgNodes = [ ] ;
9
+ const bgColor = color . getBackgroundColor ( node , bgNodes , noScroll ) ;
10
+ const fgColor = color . getForegroundColor ( node , noScroll ) ;
9
11
10
- var nodeStyle = window . getComputedStyle ( node ) ;
11
- var fontSize = parseFloat ( nodeStyle . getPropertyValue ( 'font-size' ) ) ;
12
- var fontWeight = nodeStyle . getPropertyValue ( 'font-weight' ) ;
13
- var bold =
12
+ const nodeStyle = window . getComputedStyle ( node ) ;
13
+ const fontSize = parseFloat ( nodeStyle . getPropertyValue ( 'font-size' ) ) ;
14
+ const fontWeight = nodeStyle . getPropertyValue ( 'font-weight' ) ;
15
+ const bold =
14
16
[ 'bold' , 'bolder' , '600' , '700' , '800' , '900' ] . indexOf ( fontWeight ) !== - 1 ;
15
17
16
- var cr = axe . commons . color . hasValidContrastRatio (
17
- bgColor ,
18
- fgColor ,
19
- fontSize ,
20
- bold
21
- ) ;
18
+ const cr = color . hasValidContrastRatio ( bgColor , fgColor , fontSize , bold ) ;
22
19
23
20
// truncate ratio to three digits while rounding down
24
21
// 4.499 = 4.49, 4.019 = 4.01
25
- var truncatedResult = Math . floor ( cr . contrastRatio * 100 ) / 100 ;
22
+ const truncatedResult = Math . floor ( cr . contrastRatio * 100 ) / 100 ;
26
23
27
24
// if fgColor or bgColor are missing, get more information.
28
- var missing ;
25
+ let missing ;
29
26
if ( bgColor === null ) {
30
- missing = axe . commons . color . incompleteData . get ( 'bgColor' ) ;
27
+ missing = color . incompleteData . get ( 'bgColor' ) ;
31
28
}
32
29
33
- let equalRatio = false ;
34
- if ( truncatedResult === 1 ) {
35
- equalRatio = true ;
36
- missing = axe . commons . color . incompleteData . set ( 'bgColor' , 'equalRatio' ) ;
30
+ const equalRatio = truncatedResult === 1 ;
31
+ const shortTextContent =
32
+ text . visibleVirtual ( virtualNode , false , true ) . length === 1 ;
33
+ if ( equalRatio ) {
34
+ missing = color . incompleteData . set ( 'bgColor' , 'equalRatio' ) ;
35
+ } else if ( shortTextContent ) {
36
+ // Check that the text content is a single character long
37
+ missing = 'shortTextContent' ;
37
38
}
39
+
38
40
// need both independently in case both are missing
39
- var data = {
41
+ const data = {
40
42
fgColor : fgColor ? fgColor . toHexString ( ) : undefined ,
41
43
bgColor : bgColor ? bgColor . toHexString ( ) : undefined ,
42
44
contrastRatio : cr ? truncatedResult : undefined ,
@@ -48,13 +50,21 @@ var data = {
48
50
49
51
this . data ( data ) ;
50
52
51
- //We don't know, so we'll put it into Can't Tell
52
- if ( fgColor === null || bgColor === null || equalRatio ) {
53
+ // We don't know, so we'll put it into Can't Tell
54
+ if (
55
+ fgColor === null ||
56
+ bgColor === null ||
57
+ equalRatio ||
58
+ ( shortTextContent && ! cr . isValid )
59
+ ) {
53
60
missing = null ;
54
- axe . commons . color . incompleteData . clear ( ) ;
61
+ color . incompleteData . clear ( ) ;
55
62
this . relatedNodes ( bgNodes ) ;
56
63
return undefined ;
57
- } else if ( ! cr . isValid ) {
64
+ }
65
+
66
+ if ( ! cr . isValid ) {
58
67
this . relatedNodes ( bgNodes ) ;
59
68
}
69
+
60
70
return cr . isValid ;
0 commit comments