@ -28,7 +28,7 @@ import type { VueNode } from '../../type';
const isClientSide = canUseDom ( ) ;
const isClientSide = canUseDom ( ) ;
const SKIP _CHECK = '_skip_check_' ;
const SKIP _CHECK = '_skip_check_' ;
const MULTI _VALUE = '_multi_value_' ;
export type CSSProperties = Omit < CSS .PropertiesFallback < number | string > , 'animationName' > & {
export type CSSProperties = Omit < CSS .PropertiesFallback < number | string > , 'animationName' > & {
animationName ? : CSS . PropertiesFallback < number | string > [ 'animationName' ] | Keyframes ;
animationName ? : CSS . PropertiesFallback < number | string > [ 'animationName' ] | Keyframes ;
} ;
} ;
@ -39,6 +39,7 @@ export type CSSPropertiesWithMultiValues = {
| Extract < CSSProperties [ K ] , string > [ ]
| Extract < CSSProperties [ K ] , string > [ ]
| {
| {
[ SKIP _CHECK ] : boolean ;
[ SKIP _CHECK ] : boolean ;
[ MULTI _VALUE ] ? : boolean ;
value : CSSProperties [ K ] | Extract < CSSProperties [ K ] , string > [ ] ;
value : CSSProperties [ K ] | Extract < CSSProperties [ K ] , string > [ ] ;
} ;
} ;
} ;
} ;
@ -65,7 +66,7 @@ export function normalizeStyle(styleStr: string) {
}
}
function isCompoundCSSProperty ( value : CSSObject [ 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 值
/ / 注 入 h a s h 值
@ -224,32 +225,45 @@ export const parseStyle = (
styleStr += ` ${ mergedKey } ${ parsedStr } ` ;
styleStr += ` ${ mergedKey } ${ parsedStr } ` ;
} else {
} else {
const actualValue = ( value as any ) ? . value ? ? value ;
function appendStyle ( cssKey : string , cssValue : any ) {
if (
if (
process . env . NODE _ENV !== 'production' &&
process . env . NODE _ENV !== 'production' &&
( typeof value !== 'object' || ! ( value as any ) ? . [ SKIP _CHECK ] )
( typeof value !== 'object' || ! ( value as any ) ? . [ SKIP _CHECK ] )
) {
) {
[ contentQuotesLinter , hashedAnimationLinter , ... linters ] . forEach ( linter =>
[ 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
/ / A u t o s u f f i x w i t h p x
let formatValue = actual Value;
let formatValue = css Value;
if ( ! unitless [ k ey] && typeof formatValue === 'number' && formatValue !== 0 ) {
if ( ! unitless [ cssK ey] && typeof formatValue === 'number' && formatValue !== 0 ) {
formatValue = ` ${ formatValue } px ` ;
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
/ / 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 ( k ey === 'animationName' && ( v alue as Keyframes ) ? . _keyframe ) {
if ( cssK ey === 'animationName' && ( cssV alue as Keyframes ) ? . _keyframe ) {
parseKeyframes ( v alue as Keyframes ) ;
parseKeyframes ( cssV alue as Keyframes ) ;
formatValue = ( v alue as Keyframes ) . getName ( hashId ) ;
formatValue = ( cssV alue as Keyframes ) . getName ( hashId ) ;
}
}
styleStr += ` ${ styleName } : ${ formatValue } ; ` ;
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 ) ;
}
}
}
} ) ;
} ) ;
}
}