import { IColor } from './color' ; import { LineExtraction , DocumentLine , flattenLineExtractionsFlatten } from '../util/color-util' ; import { Extractor , IStrategy } from '../extractor-mixin' ; export interface IColorStrategy extends IStrategy { extractColors ( fileLines ) : Promise < LineExtraction [ ] > ; extractColor ( text ) : IColor ; } class ColorExtractor extends Extractor { public async extract ( fileLines ) { const colors = await Promise . all ( this . enabledStrategies . map ( strategy => ( < IColorStrategy > strategy ) . extractColors ( fileLines ) ) ) ; return flattenLineExtractionsFlatten ( colors ) ; } public extractOneColor ( text ) { const colors = this . enabledStrategies . map ( strategy => ( < IColorStrategy > strategy ) . extractColor ( text ) ) ; return colors . find ( color => color !== null ) ; } } const instance = new ColorExtractor ( ) ; export default instance ;