@@ -38,17 +38,24 @@ const { isNativeElement } = require('../utils/is-native-element');
3838
3939const interactiveRoleSet = INTERACTIVE_ROLES ;
4040
41- const elementRoleEntries = [ ...elementRoles ] ;
42-
43- // Schemas (element name + attribute constraints) whose role list contains at
44- // least one interactive role.
45- const interactiveElementRoleSchemas = elementRoleEntries
46- . filter ( ( [ , rolesArr ] ) => [ ...rolesArr ] . some ( ( r ) => interactiveRoleSet . has ( r ) ) )
47- . map ( ( [ schema ] ) => schema ) ;
41+ // Pre-index interactive element schemas by tag name at module load. aria-query's
42+ // elementRoles is static data; bucketing by tag turns the per-node O(N) scan
43+ // over all schemas into a direct O(1) Map lookup followed by checking only the
44+ // 1–5 schemas for that specific tag.
45+ const INTERACTIVE_SCHEMAS_BY_TAG = ( ( ) => {
46+ const index = new Map ( ) ;
47+ for ( const [ schema , rolesArr ] of elementRoles ) {
48+ if ( [ ...rolesArr ] . some ( ( r ) => interactiveRoleSet . has ( r ) ) ) {
49+ if ( ! index . has ( schema . name ) ) {
50+ index . set ( schema . name , [ ] ) ;
51+ }
52+ index . get ( schema . name ) . push ( schema ) ;
53+ }
54+ }
55+ return index ;
56+ } ) ( ) ;
4857
49- const tagsWithInteractiveElementRoleEntry = new Set (
50- interactiveElementRoleSchemas . map ( ( schema ) => schema . name )
51- ) ;
58+ const tagsWithInteractiveElementRoleEntry = new Set ( INTERACTIVE_SCHEMAS_BY_TAG . keys ( ) ) ;
5259
5360// AX-fallback tag set — tags whose AXObject list is entirely widget AND which
5461// have no interactive `elementRoles` entry. Excludes `canvas` per rationale
@@ -162,10 +169,7 @@ function isInteractiveElement(node) {
162169
163170 // Primary signal: elementRoles with at least one interactive role + schema
164171 // constraints match the node's attributes.
165- for ( const schema of interactiveElementRoleSchemas ) {
166- if ( schema . name !== tag ) {
167- continue ;
168- }
172+ for ( const schema of INTERACTIVE_SCHEMAS_BY_TAG . get ( tag ) ?? [ ] ) {
169173 if ( ! attributesMatchSchema ( schema , node ) ) {
170174 continue ;
171175 }
0 commit comments