7
7
import { AXObjects , AXObjectRoles , elementAXObjects } from 'axobject-query' ;
8
8
import Attribute from '../nodes/Attribute' ;
9
9
10
- const non_abstract_roles = [ ...roles_map . keys ( ) ] . filter ( ( name ) => ! roles_map . get ( name ) . abstract && name !== 'generic' ) ;
10
+ const aria_roles = roles_map . keys ( ) ;
11
+ const abstract_roles = new Set ( aria_roles . filter ( role => roles_map . get ( role ) . abstract ) ) ;
12
+ const non_abstract_roles = aria_roles . filter ( ( name ) => ! abstract_roles . has ( name ) ) ;
11
13
12
14
const non_interactive_roles = new Set (
13
15
non_abstract_roles
@@ -32,12 +34,23 @@ const interactive_roles = new Set(
32
34
non_abstract_roles . filter ( ( name ) => ! non_interactive_roles . has ( name ) )
33
35
) ;
34
36
35
- export function is_non_interactive_roles ( role : ARIARoleDefintionKey ) {
36
- return non_interactive_roles . has ( role ) ;
37
+ export enum RoleType {
38
+ Interactive = 'interactive' ,
39
+ NonInteractive = 'non-interactive' ,
40
+ Abstract = 'abstract' ,
41
+ Invalid = 'invalid' ,
37
42
}
38
43
39
- export function is_interactive_roles ( role : ARIARoleDefintionKey ) {
40
- return interactive_roles . has ( role ) ;
44
+ export function role_type ( role : ARIARoleDefintionKey ) : RoleType {
45
+ if ( interactive_roles . has ( role ) ) {
46
+ return RoleType . Interactive ;
47
+ } else if ( non_interactive_roles . has ( role ) ) {
48
+ return RoleType . NonInteractive ;
49
+ } else if ( abstract_roles . has ( role ) ) {
50
+ return RoleType . Abstract ;
51
+ } else {
52
+ return RoleType . Invalid ;
53
+ }
41
54
}
42
55
43
56
const presentation_roles = new Set ( [ 'presentation' , 'none' ] ) ;
@@ -65,7 +78,7 @@ export function is_hidden_from_screen_reader(tag_name: string, attribute_map: Ma
65
78
const non_interactive_element_role_schemas : ARIARoleRelationConcept [ ] = [ ] ;
66
79
67
80
elementRoles . entries ( ) . forEach ( ( [ schema , roles ] ) => {
68
- if ( [ ...roles ] . every ( ( role ) => non_interactive_roles . has ( role ) ) ) {
81
+ if ( [ ...roles ] . every ( ( role ) => role !== 'generic' && non_interactive_roles . has ( role ) ) ) {
69
82
non_interactive_element_role_schemas . push ( schema ) ;
70
83
}
71
84
} ) ;
@@ -102,7 +115,6 @@ elementAXObjects.entries().forEach(([schema, ax_object]) => {
102
115
}
103
116
} ) ;
104
117
105
-
106
118
function match_schema (
107
119
schema : ARIARoleRelationConcept ,
108
120
tag_name : string ,
@@ -123,70 +135,50 @@ function match_schema(
123
135
} ) ;
124
136
}
125
137
126
- export function is_interactive_element (
127
- tag_name : string ,
128
- attribute_map : Map < string , Attribute >
129
- ) : boolean {
130
- if (
138
+ export enum ElementInteractivity {
139
+ Interactive = 'interactive' ,
140
+ NonInteractive = 'non-interactive' ,
141
+ Static = 'static' ,
142
+ }
143
+
144
+ export function element_interactivity (
145
+ tag_name : string ,
146
+ attribute_map : Map < string , Attribute >
147
+ ) : ElementInteractivity {
148
+ if (
131
149
interactive_element_role_schemas . some ( ( schema ) =>
132
150
match_schema ( schema , tag_name , attribute_map )
133
151
)
134
152
) {
135
- return true ;
153
+ return ElementInteractivity . Interactive ;
136
154
}
137
155
138
- if (
156
+ if (
157
+ tag_name !== 'header' &&
139
158
non_interactive_element_role_schemas . some ( ( schema ) =>
140
159
match_schema ( schema , tag_name , attribute_map )
141
160
)
142
161
) {
143
- return false ;
162
+ return ElementInteractivity . NonInteractive ;
144
163
}
145
164
146
- if (
165
+ if (
147
166
interactive_element_ax_object_schemas . some ( ( schema ) =>
148
167
match_schema ( schema , tag_name , attribute_map )
149
168
)
150
169
) {
151
- return true ;
170
+ return ElementInteractivity . Interactive ;
152
171
}
153
172
154
- return false ;
155
- }
156
-
157
- export function is_non_interactive_element (
158
- tag_name : string ,
159
- attribute_map : Map < string , Attribute >
160
- ) : boolean {
161
- if ( tag_name === 'header' ) {
162
- return false ;
163
- }
164
-
165
173
if (
166
- non_interactive_element_role_schemas . some ( ( schema ) =>
167
- match_schema ( schema , tag_name , attribute_map )
168
- )
169
- ) {
170
- return true ;
171
- }
172
-
173
- if (
174
- interactive_element_role_schemas . some ( ( schema ) =>
175
- match_schema ( schema , tag_name , attribute_map )
176
- )
177
- ) {
178
- return false ;
179
- }
180
-
181
- if (
182
174
non_interactive_element_ax_object_schemas . some ( ( schema ) =>
183
175
match_schema ( schema , tag_name , attribute_map )
184
176
)
185
177
) {
186
- return true ;
178
+ return ElementInteractivity . NonInteractive ;
187
179
}
188
180
189
- return false ;
181
+ return ElementInteractivity . Static ;
190
182
}
191
183
192
184
export function is_semantic_role_element ( role : ARIARoleDefintionKey , tag_name : string , attribute_map : Map < string , Attribute > ) {
0 commit comments