import { Inject, Injectable } from '../decorators' import { RGB, RGBAStyles } from '../style-typings/styles' import ThemeService from '../theme/theme.service' import { ThemeTextColor } from '../theme/theme.typings' @Injectable('colorUtilsService') export default class ColorUtilsService { constructor( @Inject('themeService') private themeService: ThemeService, ) {} hexToRgb(hex: string): RGB | undefined { const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16) } : undefined } initRGBAStyles(themeTextColor: ThemeTextColor = 'light', themeColor: string = '#535353', opacity: number = 1): RGBAStyles { const bgRGBA = this.hexToRgb(this.themeService.getBackgroundColor(themeColor)['background-color']) const colorRGBA = this.hexToRgb(this.themeService.getIconColorStyle(themeTextColor, themeColor).color) return { backgroundColor: bgRGBA ? `rgba(${bgRGBA.r}, ${bgRGBA.g}, ${bgRGBA.b}, ${opacity})` : undefined, color: colorRGBA ? `rgba(${colorRGBA.r}, ${colorRGBA.g}, ${colorRGBA.b}, ${opacity})` : undefined, } } }