1
- import { isString , hyphenate , capitalize } from '@vue/shared'
1
+ import { isString , hyphenate , capitalize , isArray } from '@vue/shared'
2
2
import { camelize } from '@vue/runtime-core'
3
3
4
- type Style = string | Partial < CSSStyleDeclaration > | null
4
+ type Style = string | Record < string , string | string [ ] > | null
5
5
6
6
export function patchStyle ( el : Element , prev : Style , next : Style ) {
7
7
const style = ( el as HTMLElement ) . style
@@ -13,7 +13,7 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
13
13
}
14
14
} else {
15
15
for ( const key in next ) {
16
- setStyle ( style , key , next [ key ] as string )
16
+ setStyle ( style , key , next [ key ] )
17
17
}
18
18
if ( prev && ! isString ( prev ) ) {
19
19
for ( const key in prev ) {
@@ -27,21 +27,29 @@ export function patchStyle(el: Element, prev: Style, next: Style) {
27
27
28
28
const importantRE = / \s * ! i m p o r t a n t $ /
29
29
30
- function setStyle ( style : CSSStyleDeclaration , name : string , val : string ) {
31
- if ( name . startsWith ( '--' ) ) {
32
- // custom property definition
33
- style . setProperty ( name , val )
30
+ function setStyle (
31
+ style : CSSStyleDeclaration ,
32
+ name : string ,
33
+ val : string | string [ ]
34
+ ) {
35
+ if ( isArray ( val ) ) {
36
+ val . forEach ( v => setStyle ( style , name , v ) )
34
37
} else {
35
- const prefixed = autoPrefix ( style , name )
36
- if ( importantRE . test ( val ) ) {
37
- // !important
38
- style . setProperty (
39
- hyphenate ( prefixed ) ,
40
- val . replace ( importantRE , '' ) ,
41
- 'important'
42
- )
38
+ if ( name . startsWith ( '--' ) ) {
39
+ // custom property definition
40
+ style . setProperty ( name , val )
43
41
} else {
44
- style [ prefixed as any ] = val
42
+ const prefixed = autoPrefix ( style , name )
43
+ if ( importantRE . test ( val ) ) {
44
+ // !important
45
+ style . setProperty (
46
+ hyphenate ( prefixed ) ,
47
+ val . replace ( importantRE , '' ) ,
48
+ 'important'
49
+ )
50
+ } else {
51
+ style [ prefixed as any ] = val
52
+ }
45
53
}
46
54
}
47
55
}
0 commit comments