export function addClass ( el , list = [ ] ) { if ( ! Array . isArray ( list ) ) list = [ list ] ; list . forEach ( clz => ( ! el . classList . contains ( clz ) && el . classList . add ( clz ) ) ) ; } export function removeClass ( el , list = [ ] ) { if ( ! Array . isArray ( list ) ) list = [ list ] ; list . forEach ( clz => ( el . classList . contains ( clz ) && el . classList . remove ( clz ) ) ) ; } export function attachListener ( el , evtName , handler , opts ? ) { el . addEventListener ( evtName , handler , opts ) ; } export function detachListener ( el , evtName , handler ) { el . removeEventListener ( evtName , handler ) ; } export function removeAttr ( el , attr ) { el . removeAttribute ( attr ) ; } export function setAttr ( el , attr , value = '' ) { el . setAttribute ( attr , value ) ; return el ; } export function setStyle ( el , style , forceRender ? ) { Object . keys ( style ) . forEach ( prop => { el . style [ prop as any ] = style [ prop ] ; } ) ; forceRender && getComputedStyle ( el ) ; return el ; } export function getTranslate ( el , isHorizontal ) { const matrix = getComputedStyle ( el ) . transform . replace ( /[a-z]|\(|\)|\s/g , '' ) . split ( ',' ) . map ( parseFloat ) ; let arr = [ ] ; if ( matrix . length === 16 ) { arr = matrix . slice ( 12 , 14 ) ; } else if ( matrix . length === 6 ) { arr = matrix . slice ( 4 , 6 ) ; } return ( < Array < number > > arr ) [ isHorizontal ? 0 : 1 ] || 0 ; } export function stringToElement ( string ) { const wrapper = document . createElement ( 'div' ) ; wrapper . innerHTML = string ; return wrapper . firstChild as HTMLElement ; }