import { isString , hyphenate , capitalize , isArray } from '@vue/shared' ; import { camelize } from '@vue/runtime-core' ; type Style = string | Record < string , string | string [ ] > | null ; export function patchStyle ( el , prev , next ) { const style = ( el as HTMLElement ) . style ; if ( ! next ) { el . removeAttribute ( 'style' ) ; } else if ( isString ( next ) ) { if ( prev !== next ) { const current = style . display ; style . cssText = next ; if ( '_vod' in el ) { style . display = current ; } } } else { for ( const key in next ) { setStyle ( style , key , next [ key ] ) ; } if ( prev && ! isString ( prev ) ) { for ( const key in prev ) { if ( next [ key ] == null ) { setStyle ( style , key , '' ) ; } } } } } const importantRE = /\s*!important$/ ; function setStyle ( style , name , val ) { if ( isArray ( val ) ) { val . forEach ( v => setStyle ( style , name , v ) ) ; } else { if ( name . startsWith ( '--' ) ) { style . setProperty ( name , val ) ; } else { const prefixed = autoPrefix ( style , name ) ; if ( importantRE . test ( val ) ) { style . setProperty ( hyphenate ( prefixed ) , val . replace ( importantRE , '' ) , 'important' ) ; } else { style [ prefixed as any ] = val ; } } } } const prefixes = [ 'Webkit' , 'Moz' , 'ms' ] ; const prefixCache = { } ; function autoPrefix ( style , rawName ) { const cached = prefixCache [ rawName ] ; if ( cached ) { return cached ; } let name = camelize ( rawName ) ; if ( name !== 'filter' && name in style ) { return ( prefixCache [ rawName ] = name ) ; } name = capitalize ( name ) ; for ( let i = 0 ; i < prefixes . length ; i ++ ) { const prefixed = prefixes [ i ] + name ; if ( prefixed in style ) { return ( prefixCache [ rawName ] = prefixed ) ; } } return rawName ; }