@@ -20,16 +20,18 @@ export type ClassEntry = [string, ClassMetadata]
20
20
const IS_FRACTION = / ^ \d + \/ \d + $ /
21
21
22
22
export function getClassList ( design : DesignSystem ) : ClassEntry [ ] {
23
- let list : ClassItem [ ] = [ ]
23
+ let items = new DefaultMap < string , ClassItem > ( ( utility ) => ( {
24
+ name : utility ,
25
+ utility,
26
+ fraction : false ,
27
+ modifiers : [ ] ,
28
+ } ) )
24
29
25
30
// Static utilities only work as-is
26
31
for ( let utility of design . utilities . keys ( 'static' ) ) {
27
- list . push ( {
28
- name : utility ,
29
- utility,
30
- fraction : false ,
31
- modifiers : [ ] ,
32
- } )
32
+ let item = items . get ( utility )
33
+ item . fraction = false
34
+ item . modifiers = [ ]
33
35
}
34
36
35
37
// Functional utilities have their own list of completions
@@ -42,28 +44,25 @@ export function getClassList(design: DesignSystem): ClassEntry[] {
42
44
43
45
let name = value === null ? utility : `${ utility } -${ value } `
44
46
45
- list . push ( {
46
- name,
47
- utility,
48
- fraction,
49
- modifiers : group . modifiers ,
50
- } )
47
+ let item = items . get ( name )
48
+ item . utility = utility
49
+ item . fraction ||= fraction
50
+ item . modifiers . push ( ...group . modifiers )
51
51
52
52
if ( group . supportsNegative ) {
53
- list . push ( {
54
- name : `-${ name } ` ,
55
- utility : `-${ utility } ` ,
56
- fraction,
57
- modifiers : group . modifiers ,
58
- } )
53
+ let item = items . get ( `-${ name } ` )
54
+ item . utility = `-${ utility } `
55
+ item . fraction ||= fraction
56
+ item . modifiers . push ( ...group . modifiers )
59
57
}
60
58
}
61
59
}
62
60
}
63
61
64
- if ( list . length === 0 ) return [ ]
62
+ if ( items . size === 0 ) return [ ]
65
63
66
64
// Sort utilities by their class name
65
+ let list = Array . from ( items . values ( ) )
67
66
list . sort ( ( a , b ) => compare ( a . name , b . name ) )
68
67
69
68
let entries = sortFractionsLast ( list )
0 commit comments