@@ -28,7 +28,7 @@ import type { VueNode } from '../../type';
28
28
const isClientSide = canUseDom ( ) ;
29
29
30
30
const SKIP_CHECK = '_skip_check_' ;
31
-
31
+ const MULTI_VALUE = '_multi_value_' ;
32
32
export type CSSProperties = Omit < CSS . PropertiesFallback < number | string > , 'animationName' > & {
33
33
animationName ?: CSS . PropertiesFallback < number | string > [ 'animationName' ] | Keyframes ;
34
34
} ;
@@ -39,6 +39,7 @@ export type CSSPropertiesWithMultiValues = {
39
39
| Extract < CSSProperties [ K ] , string > [ ]
40
40
| {
41
41
[ SKIP_CHECK ] : boolean ;
42
+ [ MULTI_VALUE ] ?: boolean ;
42
43
value : CSSProperties [ K ] | Extract < CSSProperties [ K ] , string > [ ] ;
43
44
} ;
44
45
} ;
@@ -65,7 +66,7 @@ export function normalizeStyle(styleStr: string) {
65
66
}
66
67
67
68
function isCompoundCSSProperty ( value : CSSObject [ string ] ) {
68
- return typeof value === 'object' && value && SKIP_CHECK in value ;
69
+ return typeof value === 'object' && value && ( SKIP_CHECK in value || MULTI_VALUE in value ) ;
69
70
}
70
71
71
72
// 注入 hash 值
@@ -224,32 +225,45 @@ export const parseStyle = (
224
225
225
226
styleStr += `${ mergedKey } ${ parsedStr } ` ;
226
227
} else {
227
- const actualValue = ( value as any ) ?. value ?? value ;
228
- if (
229
- process . env . NODE_ENV !== 'production' &&
230
- ( typeof value !== 'object' || ! ( value as any ) ?. [ SKIP_CHECK ] )
231
- ) {
232
- [ contentQuotesLinter , hashedAnimationLinter , ...linters ] . forEach ( linter =>
233
- linter ( key , actualValue , { path, hashId, parentSelectors } ) ,
234
- ) ;
235
- }
228
+ function appendStyle ( cssKey : string , cssValue : any ) {
229
+ if (
230
+ process . env . NODE_ENV !== 'production' &&
231
+ ( typeof value !== 'object' || ! ( value as any ) ?. [ SKIP_CHECK ] )
232
+ ) {
233
+ [ contentQuotesLinter , hashedAnimationLinter , ...linters ] . forEach ( linter =>
234
+ linter ( cssKey , cssValue , { path, hashId, parentSelectors } ) ,
235
+ ) ;
236
+ }
236
237
237
- // 如果是样式则直接插入
238
- const styleName = key . replace ( / [ A - Z ] / g, match => `-${ match . toLowerCase ( ) } ` ) ;
238
+ // 如果是样式则直接插入
239
+ const styleName = cssKey . replace ( / [ A - Z ] / g, match => `-${ match . toLowerCase ( ) } ` ) ;
239
240
240
- // Auto suffix with px
241
- let formatValue = actualValue ;
242
- if ( ! unitless [ key ] && typeof formatValue === 'number' && formatValue !== 0 ) {
243
- formatValue = `${ formatValue } px` ;
244
- }
241
+ // Auto suffix with px
242
+ let formatValue = cssValue ;
243
+ if ( ! unitless [ cssKey ] && typeof formatValue === 'number' && formatValue !== 0 ) {
244
+ formatValue = `${ formatValue } px` ;
245
+ }
245
246
246
- // handle animationName & Keyframe value
247
- if ( key === 'animationName' && ( value as Keyframes ) ?. _keyframe ) {
248
- parseKeyframes ( value as Keyframes ) ;
249
- formatValue = ( value as Keyframes ) . getName ( hashId ) ;
250
- }
247
+ // handle animationName & Keyframe value
248
+ if ( cssKey === 'animationName' && ( cssValue as Keyframes ) ?. _keyframe ) {
249
+ parseKeyframes ( cssValue as Keyframes ) ;
250
+ formatValue = ( cssValue as Keyframes ) . getName ( hashId ) ;
251
+ }
251
252
252
- styleStr += `${ styleName } :${ formatValue } ;` ;
253
+ styleStr += `${ styleName } :${ formatValue } ;` ;
254
+ }
255
+ const actualValue = ( value as any ) ?. value ?? value ;
256
+ if (
257
+ typeof value === 'object' &&
258
+ ( value as any ) ?. [ MULTI_VALUE ] &&
259
+ Array . isArray ( actualValue )
260
+ ) {
261
+ actualValue . forEach ( item => {
262
+ appendStyle ( key , item ) ;
263
+ } ) ;
264
+ } else {
265
+ appendStyle ( key , actualValue ) ;
266
+ }
253
267
}
254
268
} ) ;
255
269
}
0 commit comments