import { equals } from 'ramda' ; import { IRegularAttr } from '../../typings' ; import { parseColor } from '../color/parse' ; import { parseAlpha } from '../math/parse-alpha' ; import { parseNumberList } from '../utils/parse-numberlist' ; export const valueIsEqual = ( attrDefine , value1 , value2 ) : boolean => { if ( value1 === value2 ) { return true ; } if ( attrDefine . maybeColor ) { const color1 = parseColor ( value1 ) ; const color2 = parseColor ( value2 ) ; if ( ! color1 . valid || ! color2 . valid ) return false ; color1 . origin = '' ; color2 . origin = '' ; if ( equals ( color1 , color2 ) ) { return true ; } } if ( attrDefine . maybeSizeNumber || attrDefine . maybeAccurateNumber ) { const nums2 = parseNumberList ( value2 ) ; if ( nums2 . length > 0 && equals ( parseNumberList ( value1 ) , nums2 ) ) { return true ; } if ( /^0[a-z]*$/i . test ( value1 ) && /^0[a-z]*$/i . test ( value2 ) ) { return true ; } } if ( attrDefine . maybeAlpha ) { if ( parseAlpha ( value1 ) === parseAlpha ( value2 ) ) { return true ; } } return false ; } ; export const attrIsEqual = ( attrDefine , value , nodeName ) : boolean => { if ( typeof attrDefine . initValue === 'string' ) { return valueIsEqual ( attrDefine , value , attrDefine . initValue ) ; } else { const initValue = attrDefine . initValue ; for ( let ii = 0 , il = initValue . length ; ii < il ; ii ++ ) { if ( initValue [ ii ] . tag . includes ( nodeName ) && valueIsEqual ( attrDefine , value , initValue [ ii ] . val ) ) { return true ; } } } return false ; } ;