import { IAttr } from 'svg-vdom' ; import { IRegularAttr , TLegalValueItem } from '../../typings' ; import { CSSDefault } from '../const/enum' ; import { regularAttr } from '../const/regular-attr' ; import { useEnum } from './use-enum' ; import { useFunc } from './use-func' ; import { useMix } from './use-mix' ; import { useReg } from './use-reg' ; const checkLegal = ( legalRule , value ) => { switch ( legalRule . type ) { case 'reg' : if ( useReg ( legalRule . value , value ) ) { return true ; } break ; case 'enum' : if ( useEnum ( legalRule . value , value ) ) { return true ; } break ; case 'mix' : if ( useMix ( legalRule . value , value ) ) { return true ; } break ; case 'func' : if ( useFunc ( legalRule . value , value ) ) { return true ; } break ; default : if ( ( legalRule as { type : 'string' ; value : string ; } ) . value === value ) { return true ; } break ; } return false ; } ; export const legalValue = ( attrDefine , attr , nodeName = '' ) : boolean => { if ( attrDefine . legalValues . length ) { let noMatchRule = true ; for ( const legalRule of attrDefine . legalValues ) { const legalTag = ! legalRule . tag || ! nodeName || legalRule . tag . includes ( nodeName ) ; if ( legalTag ) { noMatchRule = false ; if ( legalRule . type === 'attr' ) { if ( ! regularAttr [ attr . value ] . isUndef && attr . fullname !== attr . value ) { return true ; } } else if ( checkLegal ( legalRule , attr . value ) ) { return true ; } if ( attrDefine . couldBeStyle && useEnum ( CSSDefault , attr . value ) ) { return true ; } } } return noMatchRule ; } return ! attrDefine . isUndef ; } ;