import { Injectable } from '@angular/core' ; import { convertClass } from './convert-class.util' ; @ Injectable ( { providedIn : 'root' } ) export class IconRegistryService { private _defaultFontSetClass = 'ngx' ; private _iconMap : Map < string , string [ ] > = new Map ( ) ; setDefaultFontSetClass ( iconSet ) { this . _defaultFontSetClass = iconSet ; return this . _defaultFontSetClass ; } get ( keys , set ? ) { return this . lookup ( keys , set ) . map ( k => convertClass ( k ) ) ; } lookup ( keys , set ? ) { return ( Array . isArray ( keys ) ? keys : [ keys ] ) . reduce ( ( p , k ) => { k = this . _expandKeys ( k , set ) . map ( kk => { const x = this . _iconMap . get ( kk ) ; return x && x . length === 1 ? x [ 0 ] : kk ; } ) . join ( ' ' ) ; return p . concat ( this . _iconMap . get ( k ) || [ k ] ) ; } , [ ] ) ; } add ( key , icon ) { const k = this . _expandKeys ( key ) . join ( ' ' ) ; const v = this . lookup ( icon ) ; this . _iconMap . set ( k , v ) ; } private _expandKeys ( key , set = this . _defaultFontSetClass ) { return key . split ( ' ' ) . map ( k => { if ( k . includes ( ':' ) ) return k ; return `${ set }:${ k }` ; } ) ; } }