namespace svg { export function addClass ( el , cls ) { if ( el . classList ) { el . classList . add ( cls ) ; } else if ( el . className . baseVal . indexOf ( cls ) < 0 ) { el . className . baseVal += " " + cls ; } } export function removeClass ( el , cls ) { if ( el . classList ) { el . classList . remove ( cls ) ; } else { el . className . baseVal = el . className . baseVal . replace ( cls , "" ) . replace ( /\s{2,}/ , " " ) ; } } export function hydrate ( el , props ) { for ( const k in props ) { if ( k == "title" ) { svg . title ( el , props [ k ] ) ; } else { el . setAttributeNS ( null , k , props [ k ] ) ; } } } export function createElement ( name , props ? ) { const newElement = document . createElementNS ( "http://www.w3.org/2000/svg" , name ) ; if ( props ) { svg . hydrate ( newElement , props ) ; } return newElement ; } export function child ( parent , name , props ? ) { const childElement = svg . createElement ( name , props ) ; parent . appendChild ( childElement ) ; return childElement ; } export function fill ( el , c ) { el . style . fill = c ; } export function filter ( el , c ) { el . style . filter = c ; } export function fills ( els , c ) { els . forEach ( el => ( el . style . fill = c ) ) ; } export function mkTitle ( txt ) { const t = svg . createElement ( "title" ) as SVGTitleElement ; t . textContent = txt ; return t ; } export function title ( el , txt ) { const t = mkTitle ( txt ) ; el . appendChild ( t ) ; return t ; } export function setLed ( ledStatus , offColor , onColor , ledElement , gradientStopElement ) { if ( ledStatus ) { ledElement ?. setAttribute ( "fill" , onColor ) ; gradientStopElement ?. setAttribute ( "stop-opacity" , "1" ) ; } else { ledElement ?. setAttribute ( "fill" , offColor ) ; gradientStopElement ?. setAttribute ( "stop-opacity" , "0" ) ; } } } export default svg ;