import { ITagNode } from 'svg-vdom' ; import { IAnimateAttr } from '../../typings' ; import { animationAttrElements } from '../const/definitions' ; export const getAnimateAttr = ( node ) => { const result = [ ] ; node . children . forEach ( childNode => { if ( animationAttrElements . includes ( childNode . nodeName ) ) { const attributeName = childNode . getAttribute ( 'attributeName' ) ; if ( attributeName ) { if ( childNode . nodeName !== 'animateTransform' || attributeName === 'tranform' || attributeName === 'patternTransform' ) { const value = [ ] ; const from = childNode . getAttribute ( 'from' ) ; const to = childNode . getAttribute ( 'to' ) ; const by = childNode . getAttribute ( 'by' ) ; const values = childNode . getAttribute ( 'values' ) ; const key = [ ] ; if ( from ) { value . push ( from ) ; key . push ( 'from' ) ; } if ( to ) { value . push ( to ) ; key . push ( 'to' ) ; } if ( by ) { value . push ( by ) ; key . push ( 'by' ) ; } if ( values ) { value . push ( ... values . split ( ';' ) . map ( val => val . trim ( ) ) . filter ( val => ! ! val ) ) ; key . push ( 'values' ) ; } result . push ( { node : childNode , attributeName , keys : key , values : value , } ) ; } } } } ) ; return result ; } ; export const checkAnimateAttr = ( animateAttrs , name , condition = ( ) => true ) => animateAttrs . some ( item => item . attributeName === name && item . values . some ( condition ) ) ; export const findAnimateAttr = ( animateAttrs , name ) => animateAttrs . filter ( item => item . attributeName === name ) ;