'use strict' ; import { ICSSDataProvider , IPropertyData , IAtDirectiveData , IPseudoClassData , IPseudoElementData , } from '../cssLanguageTypes' ; import * as objects from '../utils/objects' ; import { cssData } from '../data/webCustomData' ; import { CSSDataProvider } from './dataProvider' ; export class CSSDataManager { private dataProviders : ICSSDataProvider [ ] = [ ] ; private _propertySet : { [ k ] : IPropertyData ; } = { } ; private _atDirectiveSet : { [ k ] : IAtDirectiveData ; } = { } ; private _pseudoClassSet : { [ k ] : IPseudoClassData ; } = { } ; private _pseudoElementSet : { [ k ] : IPseudoElementData ; } = { } ; private _properties : IPropertyData [ ] = [ ] ; private _atDirectives : IAtDirectiveData [ ] = [ ] ; private _pseudoClasses : IPseudoClassData [ ] = [ ] ; private _pseudoElements : IPseudoElementData [ ] = [ ] ; constructor ( options ? ) { this . setDataProviders ( options ?. useDefaultDataProvider !== false , options ?. customDataProviders || [ ] ) ; } setDataProviders ( builtIn , providers ) { this . dataProviders = [ ] ; if ( builtIn ) { this . dataProviders . push ( new CSSDataProvider ( cssData ) ) ; } this . dataProviders . push ( ... providers ) ; this . collectData ( ) ; } /**
     * Collect all data  & handle duplicates
     */ private collectData ( ) { this . _propertySet = { } ; this . _atDirectiveSet = { } ; this . _pseudoClassSet = { } ; this . _pseudoElementSet = { } ; this . dataProviders . forEach ( provider => { provider . provideProperties ( ) . forEach ( p => { if ( ! this . _propertySet [ p . name ] ) { this . _propertySet [ p . name ] = p ; } } ) ; provider . provideAtDirectives ( ) . forEach ( p => { if ( ! this . _atDirectiveSet [ p . name ] ) { this . _atDirectiveSet [ p . name ] = p ; } } ) ; provider . providePseudoClasses ( ) . forEach ( p => { if ( ! this . _pseudoClassSet [ p . name ] ) { this . _pseudoClassSet [ p . name ] = p ; } } ) ; provider . providePseudoElements ( ) . forEach ( p => { if ( ! this . _pseudoElementSet [ p . name ] ) { this . _pseudoElementSet [ p . name ] = p ; } } ) ; } ) ; this . _properties = objects . values ( this . _propertySet ) ; this . _atDirectives = objects . values ( this . _atDirectiveSet ) ; this . _pseudoClasses = objects . values ( this . _pseudoClassSet ) ; this . _pseudoElements = objects . values ( this . _pseudoElementSet ) ; } getProperty ( name ) { return this . _propertySet [ name ] ; } getAtDirective ( name ) { return this . _atDirectiveSet [ name ] ; } getPseudoClass ( name ) { return this . _pseudoClassSet [ name ] ; } getPseudoElement ( name ) { return this . _pseudoElementSet [ name ] ; } getProperties ( ) { return this . _properties ; } getAtDirectives ( ) { return this . _atDirectives ; } getPseudoClasses ( ) { return this . _pseudoClasses ; } getPseudoElements ( ) { return this . _pseudoElements ; } isKnownProperty ( name ) { return name . toLowerCase ( ) in this . _propertySet ; } isStandardProperty ( name ) { return this . isKnownProperty ( name ) && ( ! this . _propertySet [ name . toLowerCase ( ) ] . status || this . _propertySet [ name . toLowerCase ( ) ] . status === 'standard' ) ; } }