@@ -28,69 +28,32 @@ function getAttributes(serializedAXNodeRoot: TextSnapshotNode): string[] {
2828 `"${ serializedAXNodeRoot . name || '' } "` , // Corrected: Added quotes around name
2929 ] ;
3030
31- // Value properties
32- const valueProperties = [
33- 'value' ,
34- 'valuetext' ,
35- 'valuemin' ,
36- 'valuemax' ,
37- 'level' ,
38- 'autocomplete' ,
39- 'haspopup' ,
40- 'invalid' ,
41- 'orientation' ,
42- 'description' ,
43- 'keyshortcuts' ,
44- 'roledescription' ,
45- ] as const ;
46- for ( const property of valueProperties ) {
47- if (
48- property in serializedAXNodeRoot &&
49- serializedAXNodeRoot [ property ] !== undefined
50- ) {
51- attributes . push ( `${ property } ="${ serializedAXNodeRoot [ property ] } "` ) ;
52- }
53- }
31+ const excluded = new Set ( [ 'id' , 'role' , 'name' , 'elementHandle' , 'children' ] ) ;
5432
55- // Boolean properties that also have an 'able' attribute
56- const booleanPropertyMap = {
33+ const booleanPropertyMap : Record < string , string > = {
5734 disabled : 'disableable' ,
5835 expanded : 'expandable' ,
5936 focused : 'focusable' ,
6037 selected : 'selectable' ,
6138 } ;
62- for ( const [ property , ableAttribute ] of Object . entries ( booleanPropertyMap ) ) {
63- if ( property in serializedAXNodeRoot ) {
64- attributes . push ( ableAttribute ) ;
65- if ( serializedAXNodeRoot [ property as keyof typeof booleanPropertyMap ] ) {
66- attributes . push ( property ) ;
67- }
68- }
69- }
7039
71- const booleanProperties = [
72- 'modal' ,
73- 'multiline' ,
74- 'readonly' ,
75- 'required' ,
76- 'multiselectable' ,
77- ] as const ;
78-
79- for ( const property of booleanProperties ) {
80- if ( property in serializedAXNodeRoot && serializedAXNodeRoot [ property ] ) {
81- attributes . push ( property ) ;
40+ for ( const attr of Object . keys ( serializedAXNodeRoot ) . sort ( ) ) {
41+ if ( excluded . has ( attr ) ) {
42+ continue ;
8243 }
83- }
84-
85- // Mixed boolean/string attributes
86- for ( const property of [ 'pressed' , 'checked' ] as const ) {
87- if ( property in serializedAXNodeRoot ) {
88- attributes . push ( property ) ;
89- if ( serializedAXNodeRoot [ property ] ) {
90- attributes . push ( `${ property } ="${ serializedAXNodeRoot [ property ] } "` ) ;
44+ const value = ( serializedAXNodeRoot as unknown as Record < string , unknown > ) [
45+ attr
46+ ] ;
47+ if ( typeof value === 'boolean' ) {
48+ if ( booleanPropertyMap [ attr ] ) {
49+ attributes . push ( booleanPropertyMap [ attr ] ) ;
9150 }
51+ if ( value ) {
52+ attributes . push ( attr ) ;
53+ }
54+ } else if ( typeof value === 'string' || typeof value === 'number' ) {
55+ attributes . push ( `${ attr } ="${ value } "` ) ;
9256 }
9357 }
94-
9558 return attributes ;
9659}
0 commit comments