File tree Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { isArray , isString , isObject , hyphenate } from './'
2
2
import { isNoUnitNumericStyleProp } from './domAttrConfig'
3
3
4
+ const hashedCustomProperty = / ^ [ 0 - 9 a - f ] { 8 } - / i;
5
+ const customPropertyPrefix = '--' ;
6
+
7
+ function normalizeCustomProperty ( value : Record < string , string > | string ) : Record < string , string > | string {
8
+ if ( isObject ( value ) ) {
9
+ const objectKeys = Object . keys ( value ) ;
10
+ const res : Record < string , string > = { } ;
11
+
12
+ for ( let i = 0 ; i < objectKeys . length ; i ++ ) {
13
+ const item = objectKeys [ i ] ;
14
+
15
+ if ( item . match ( hashedCustomProperty ) ) {
16
+ res [ `${ customPropertyPrefix } ${ item } ` ] = value [ item ] ;
17
+ continue ;
18
+ }
19
+
20
+ res [ item ] = value [ item ] ;
21
+ }
22
+
23
+ return res ;
24
+ }
25
+
26
+ if ( value . match ( hashedCustomProperty ) ) {
27
+ return `${ customPropertyPrefix } ${ value } ` ;
28
+ }
29
+
30
+ return value ;
31
+ }
32
+
4
33
export type NormalizedStyle = Record < string , string | number >
5
34
6
35
export function normalizeStyle (
@@ -21,9 +50,9 @@ export function normalizeStyle(
21
50
}
22
51
return res
23
52
} else if ( isString ( value ) ) {
24
- return value
53
+ return normalizeCustomProperty ( value ) ;
25
54
} else if ( isObject ( value ) ) {
26
- return value
55
+ return normalizeCustomProperty ( value ) ;
27
56
}
28
57
}
29
58
You can’t perform that action at this time.
0 commit comments