@ -28,7 +28,7 @@ import type { VueNode } from '../../type';
const isClientSide = canUseDom ( ) ;
const SKIP _CHECK = '_skip_check_' ;
const MULTI _VALUE = '_multi_value_' ;
export type CSSProperties = Omit < CSS .PropertiesFallback < number | string > , 'animationName' > & {
animationName ? : CSS . PropertiesFallback < number | string > [ 'animationName' ] | Keyframes ;
} ;
@ -39,6 +39,7 @@ export type CSSPropertiesWithMultiValues = {
| Extract < CSSProperties [ K ] , string > [ ]
| {
[ SKIP _CHECK ] : boolean ;
[ MULTI _VALUE ] ? : boolean ;
value : CSSProperties [ K ] | Extract < CSSProperties [ K ] , string > [ ] ;
} ;
} ;
@ -65,7 +66,7 @@ export function normalizeStyle(styleStr: string) {
}
function isCompoundCSSProperty ( value : CSSObject [ string ] ) {
return typeof value === 'object' && value && SKIP _CHECK in value ;
return typeof value === 'object' && value && ( SKIP _CHECK in value || MULTI _VALUE in value ) ;
}
/ / 注 入 h a s h 值
@ -224,33 +225,46 @@ export const parseStyle = (
styleStr += ` ${ mergedKey } ${ parsedStr } ` ;
} else {
const actualValue = ( value as any ) ? . value ? ? value ;
function appendStyle ( cssKey : string , cssValue : any ) {
if (
process . env . NODE _ENV !== 'production' &&
( typeof value !== 'object' || ! ( value as any ) ? . [ SKIP _CHECK ] )
) {
[ contentQuotesLinter , hashedAnimationLinter , ... linters ] . forEach ( linter =>
linter ( key , actual Value, { path , hashId , parentSelectors } ) ,
linter ( cssKey , css Value, { path , hashId , parentSelectors } ) ,
) ;
}
/ / 如 果 是 样 式 则 直 接 插 入
const styleName = k ey. replace ( /[A-Z]/g , match => ` - ${ match . toLowerCase ( ) } ` ) ;
const styleName = cssK ey. replace ( /[A-Z]/g , match => ` - ${ match . toLowerCase ( ) } ` ) ;
/ / A u t o s u f f i x w i t h p x
let formatValue = actual Value;
if ( ! unitless [ k ey] && typeof formatValue === 'number' && formatValue !== 0 ) {
let formatValue = css Value;
if ( ! unitless [ cssK ey] && typeof formatValue === 'number' && formatValue !== 0 ) {
formatValue = ` ${ formatValue } px ` ;
}
/ / h a n d l e a n i m a t i o n N a m e & K e y f r a m e v a l u e
if ( key === 'animationName' && ( v alue as Keyframes ) ? . _keyframe ) {
parseKeyframes ( v alue as Keyframes ) ;
formatValue = ( v alue as Keyframes ) . getName ( hashId ) ;
if ( cssKey === 'animationName' && ( cssV alue as Keyframes ) ? . _keyframe ) {
parseKeyframes ( cssV alue as Keyframes ) ;
formatValue = ( cssV alue as Keyframes ) . getName ( hashId ) ;
}
styleStr += ` ${ styleName } : ${ formatValue } ; ` ;
}
const actualValue = ( value as any ) ? . value ? ? value ;
if (
typeof value === 'object' &&
( value as any ) ? . [ MULTI _VALUE ] &&
Array . isArray ( actualValue )
) {
actualValue . forEach ( item => {
appendStyle ( key , item ) ;
} ) ;
} else {
appendStyle ( key , actualValue ) ;
}
}
} ) ;
}
} ) ;