import { Inject , Injectable , Optional } from '@angular/core' ; import { Icon , IconSettings , ICON_SETTINGS } from './icon-settings' ; @ Injectable ( { providedIn : 'root' , } ) export class IconRegistryService { private iconRegistry = new Map < string , string > ( ) ; constructor ( @ Optional ( ) @ Inject ( ICON_SETTINGS ) iconSettings ? ) { if ( iconSettings ) { this . addIcons ( iconSettings . icons ) ; console . warn ( `Use of IconSettings is deprecated, use IconRegistryService instead` ) ; } } public addIcon ( iconName , svgPath ) { if ( ! this . iconRegistry . has ( iconName ) ) { this . iconRegistry . set ( iconName , svgPath ) ; } else { console . warn ( `Icon with name: "${ iconName }" already exists` ) ; } } public addIcons ( icons ) { if ( ! icons ) { console . error ( 'Icons not defined' ) ; return ; } icons . forEach ( ( icon ) => { this . addIcon ( icon . name , icon . svg ) ; } ) ; } getIcons ( ) { return [ ... this . iconRegistry ] . map ( ( keyValPair ) => ( { name : keyValPair [ 0 ] , svg : keyValPair [ 1 ] } as Icon ) ) ; } getIcon ( name ) { const svg = this . iconRegistry . get ( name ) ; return svg ? { name , svg } : undefined ; } }