import * as vscode from 'vscode' ; import { ColorValueExtractorType } from './color_extractor' ; interface UserLanguageConfiguration { selector : string | Record < string , unknown > ; colors : string | string [ ] ; } class LanguageConfiguration { public static fromUser ( user ) { const types = new Set ( ) ; const userColors = Array . isArray ( user . colors ) ? user . colors : [ user . colors ] ; for ( const t of userColors . map ( ( x ) => ( '' + x ) . toLowerCase ( ) ) ) { switch ( t ) { case 'css' : types . add ( 'rgb' ) ; types . add ( 'hsl' ) ; types . add ( 'hex' ) ; types . add ( 'hex+alpha' ) ; types . add ( 'css-color-names' ) ; break ; case 'rgb' : case 'hsl' : case 'hex' : case 'hex+alpha' : case 'css-color-names' : types . add ( t ) ; break ; } } const selector = typeof user . selector === 'string' ? [ { language : user . selector } ] : user . selector ; return new LanguageConfiguration ( selector , types ) ; } private constructor ( public readonly selector , public readonly colorExtractors ) { } } /**
 * Configures
 */ export class LanguagesConfiguration { public static load ( config ) { const user = config . get < UserLanguageConfiguration [ ] > ( 'languages' ) || [ ] ; const lang = new LanguagesConfiguration ( user . map ( ( x ) => LanguageConfiguration . fromUser ( x ) ) . filter ( ( x ) => x !== null ) ) ; return lang ; } public languages : LanguageConfiguration [ ] ; private constructor ( languages ) { this . languages = languages ; } }