import type { IconifyIcon } from '@iconify/types' ; import type { FullIconCustomisations } from '@iconify/utils/lib/customisations' ; import { defaults , mergeCustomisations , } from '@iconify/utils/lib/customisations' ; import { flipFromString , alignmentFromString , } from '@iconify/utils/lib/customisations/shorthand' ; import { rotateFromString } from '@iconify/utils/lib/customisations/rotate' ; import { iconToSVG } from '@iconify/utils/lib/svg/build' ; import { replaceIDs } from '@iconify/utils/lib/svg/id' ; import type { IconifyIconCustomisations , IconifyIconProps } from './props' ; /**
 * Render result
 */ export interface RenderResult { width : string | number ; height : string | number ; viewBox : string ; preserveAspectRatio : string ; style ? : string ; className : string ; body : string ; } /**
 * Render icon
 */ export const render = ( icon , props , className ) : RenderResult => { const customisations = mergeCustomisations ( defaults , props as IconifyIconCustomisations ) as FullIconCustomisations ; let style = '' ; for ( let key in props ) { const value = props [ key ] ; if ( value === void 0 ) { continue ; } switch ( key ) { case 'icon' : case 'onLoad' : break ; case 'inline' : case 'hFlip' : case 'vFlip' : customisations [ key ] = value === true || value === 'true' || value === 1 ; break ; case 'flip' : if ( typeof value === 'string' ) { flipFromString ( customisations , value ) ; } break ; case 'align' : if ( typeof value === 'string' ) { alignmentFromString ( customisations , value ) ; } break ; case 'color' : style += 'color: ' + value + ';' ; break ; case 'rotate' : if ( typeof value === 'string' ) { customisations [ key ] = rotateFromString ( value ) ; } else if ( typeof value === 'number' ) { customisations [ key ] = value ; } break ; } } const item = iconToSVG ( icon , customisations ) ; let localCounter = 0 ; const id = props . id ; const body = replaceIDs ( item . body , id ? ( ) => id + 'ID' + localCounter ++ : 'iconifyEmber' ) ; if ( item . inline ) { style += 'vertical-align: -0.125em;' ; } return { ... item . attributes , style : style === '' ? void 0 : style , className , body , } ; } ;