export const getUsedSelectors = ( elm ) => { const usedSelectors = { attrs : new Set ( ) , classNames : new Set ( ) , ids : new Set ( ) , tags : new Set ( ) , } ; collectUsedSelectors ( usedSelectors , elm ) ; return usedSelectors ; } ; const collectUsedSelectors = ( usedSelectors , elm ) => { if ( elm != null && elm . nodeType === 1 ) { const children = elm . children ; const tagName = elm . nodeName . toLowerCase ( ) ; usedSelectors . tags . add ( tagName ) ; const attributes = elm . attributes ; for ( let i = 0 , l = attributes . length ; i < l ; i ++ ) { const attr = attributes . item ( i ) ; const attrName = attr . name . toLowerCase ( ) ; usedSelectors . attrs . add ( attrName ) ; if ( attrName === 'class' ) { const classList = elm . classList ; for ( let i = 0 , l = classList . length ; i < l ; i ++ ) { usedSelectors . classNames . add ( classList . item ( i ) ) ; } } else if ( attrName === 'id' ) { usedSelectors . ids . add ( attr . value ) ; } } if ( children ) { for ( let i = 0 , l = children . length ; i < l ; i ++ ) { collectUsedSelectors ( usedSelectors , children [ i ] ) ; } } } } ; export interface UsedSelectors { tags : Set < string > ; classNames : Set < string > ; ids : Set < string > ; attrs : Set < string > ; }