@@ -3,7 +3,6 @@ export const UNSAFE_NAME = /[\s\n\\/='"\0<>]/;
3
3
export const XLINK = / ^ x l i n k : ? ./ ;
4
4
5
5
// DOM properties that should NOT have "px" added when numeric
6
- const IS_NON_DIMENSIONAL = / a c i t | e x (?: s | g | n | p | $ ) | r p h | g r i d | o w s | m n c | n t w | i n e [ c h ] | z o o | ^ o r d | ^ - - / ;
7
6
const ENCODED_ENTITIES = / [ " & < ] / ;
8
7
9
8
/** @param {string } str */
@@ -50,9 +49,45 @@ export let isLargeString = (s, length, ignoreLines) =>
50
49
String ( s ) . indexOf ( '<' ) !== - 1 ;
51
50
52
51
const JS_TO_CSS = { } ;
53
- const SUFFIX_CACHE = { } ;
54
52
55
- const CSS_REGEX = / ( [ A - Z ] ) / g;
53
+ const IS_NON_DIMENSIONAL = new Set ( [
54
+ 'animation-iteration-count' ,
55
+ 'border-image-outset' ,
56
+ 'border-image-slice' ,
57
+ 'border-image-width' ,
58
+ 'box-flex' ,
59
+ 'box-flex-group' ,
60
+ 'box-ordinal-group' ,
61
+ 'column-count' ,
62
+ 'fill-opacity' ,
63
+ 'flex' ,
64
+ 'flex-grow' ,
65
+ 'flex-negative' ,
66
+ 'flex-order' ,
67
+ 'flex-positive' ,
68
+ 'flex-shrink' ,
69
+ 'flood-opacity' ,
70
+ 'font-weight' ,
71
+ 'grid-column' ,
72
+ 'grid-row' ,
73
+ 'line-clamp' ,
74
+ 'line-height' ,
75
+ 'opacity' ,
76
+ 'order' ,
77
+ 'orphans' ,
78
+ 'stop-opacity' ,
79
+ 'stroke-dasharray' ,
80
+ 'stroke-dashoffset' ,
81
+ 'stroke-miterlimit' ,
82
+ 'stroke-opacity' ,
83
+ 'stroke-width' ,
84
+ 'tab-size' ,
85
+ 'widows' ,
86
+ 'z-index' ,
87
+ 'zoom'
88
+ ] ) ;
89
+
90
+ const CSS_REGEX = / [ A - Z ] / g;
56
91
// Convert an Object style to a CSSText string
57
92
export function styleObjToCss ( s ) {
58
93
let str = '' ;
@@ -63,17 +98,15 @@ export function styleObjToCss(s) {
63
98
prop [ 0 ] == '-'
64
99
? prop
65
100
: JS_TO_CSS [ prop ] ||
66
- ( JS_TO_CSS [ prop ] = prop . replace ( CSS_REGEX , '-$1 ' ) . toLowerCase ( ) ) ;
101
+ ( JS_TO_CSS [ prop ] = prop . replace ( CSS_REGEX , '-$& ' ) . toLowerCase ( ) ) ;
67
102
68
103
let suffix = ';' ;
69
- let isNumber = typeof val === 'number' ;
70
- if ( isNumber && SUFFIX_CACHE [ name ] ) {
71
- suffix = 'px;' ;
72
- } else if (
73
- isNumber &&
74
- IS_NON_DIMENSIONAL . test ( prop . toLowerCase ( ) ) === false
104
+ if (
105
+ typeof val === 'number' &&
106
+ // Exclude custom-attributes
107
+ ! name . startsWith ( '--' ) &&
108
+ ! IS_NON_DIMENSIONAL . has ( name )
75
109
) {
76
- SUFFIX_CACHE [ name ] = true ;
77
110
suffix = 'px;' ;
78
111
}
79
112
str = str + name + ':' + val + suffix ;
0 commit comments