import { Inject , Injectable , Optional } from '@angular/core' ; import { MatIconRegistry } from '@angular/material/icon' ; import { DomSanitizer } from '@angular/platform-browser' ; import { ObIconConfig , ObTIconConfig } from './icon.model' ; import { iconSet } from '../../assets/oblique-icons' ; @ Injectable ( { providedIn : 'root' } ) export class ObIconService { constructor ( private readonly registry , private readonly domSanitizer , @ Optional ( ) @ Inject ( ObTIconConfig ) private readonly config ) { } registerOnAppInit ( ) { this . getIconSets ( this . config ) . forEach ( config => this . registerSvg ( config ) ) ; this . registerFontClass ( this . config ?. fontClass ) ; } registerIconSetsAsync ( ... urls ) { urls . forEach ( iconSet => this . registry . addSvgIconSet ( this . domSanitizer . bypassSecurityTrustResourceUrl ( iconSet ) ) ) ; } registerIconSets ( ... iconSets ) { iconSets . forEach ( iconSet => this . registry . addSvgIconSetLiteral ( this . domSanitizer . bypassSecurityTrustHtml ( iconSet ) ) ) ; } registerIconsAsync ( ... icons ) { icons . forEach ( icon => this . registry . addSvgIcon ( icon . name , this . domSanitizer . bypassSecurityTrustResourceUrl ( icon . url ) ) ) ; } registerIcons ( ... icons ) { icons . forEach ( icon => this . registry . addSvgIconLiteral ( icon . name , this . domSanitizer . bypassSecurityTrustHtml ( icon . svg ) ) ) ; } private getIconSets ( config ) { const iconSets = config ?. additionalIcons || [ ] ; if ( config . registerObliqueIcons ) { iconSets . unshift ( iconSet ) ; } return iconSets ; } private registerSvg ( iconSet ) { this . registry . addSvgIconSetLiteral ( this . domSanitizer . bypassSecurityTrustHtml ( iconSet ) ) ; } private registerFontClass ( fontClass ) { if ( fontClass ) { this . registry . setDefaultFontSetClass ( fontClass ) ; } } }