import type { IconifyIcon } from '@iconify/types' ; 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 { IconProps } from './props' ; /**
 * Default SVG attributes
 */ const svgDefaults = { 'xmlns' : 'http://www.w3.org/2000/svg' , 'xmlns:xlink' : 'http://www.w3.org/1999/xlink' , 'aria-hidden' : true , 'role' : 'img' , } ; /**
 * Result
 */ export interface RenderResult { attributes : Record < string , unknown > ; body : string ; } /**
 * Generate icon from properties
 */ export function render ( icon , props ) { const customisations = mergeCustomisations ( defaults , props as typeof defaults ) ; const componentProps = { ... svgDefaults } as Record < string , unknown > ; let style = typeof props . style === 'string' ? props . style : '' ; for ( let key in props ) { const value = props [ key as keyof typeof props ] as unknown ; if ( value === void 0 ) { continue ; } switch ( key ) { case 'icon' : case 'style' : 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 = style + ( style . length > 0 && style . trim ( ) . slice ( - 1 ) !== ';' ? ';' : '' ) + 'color: ' + value + '; ' ; break ; case 'rotate' : if ( typeof value === 'string' ) { customisations [ key ] = rotateFromString ( value ) ; } else if ( typeof value === 'number' ) { customisations [ key ] = value ; } break ; case 'ariaHidden' : case 'aria-hidden' : if ( value !== true && value !== 'true' ) { delete componentProps [ 'aria-hidden' ] ; } break ; default : if ( key . slice ( 0 , 3 ) === 'on:' ) { break ; } if ( ( defaults as Record < string , unknown > ) [ key ] === void 0 ) { componentProps [ key ] = value ; } } } const item = iconToSVG ( icon , customisations ) ; for ( let key in item . attributes ) { componentProps [ key ] = item . attributes [ key as keyof typeof item . attributes ] ; } if ( item . inline ) { style = 'vertical-align: -0.125em; ' + style ; } if ( style !== '' ) { componentProps . style = style ; } let localCounter = 0 ; const id = props . id ; return { attributes : componentProps , body : replaceIDs ( item . body , id ? ( ) => id + 'ID' + localCounter ++ : 'iconifySvelte' ) , } ; }