1
1
// DOM properties that should NOT have "px" added when numeric
2
- export const NON_DIMENSION_PROPS = {
3
- boxFlex :1 , boxFlexGroup :1 , columnCount :1 , fillOpacity :1 , flex :1 , flexGrow :1 ,
4
- flexPositive :1 , flexShrink :1 , flexNegative :1 , fontWeight :1 , lineClamp :1 , lineHeight :1 ,
5
- opacity :1 , order :1 , orphans :1 , strokeOpacity :1 , widows :1 , zIndex :1 , zoom :1
6
- } ;
7
-
8
- const ESC = {
9
- '<' : '<' ,
10
- '>' : '>' ,
11
- '"' : '"' ,
12
- '&' : '&'
13
- } ;
2
+ export const IS_NON_DIMENSIONAL = / a c i t | e x (?: s | g | n | p | $ ) | r p h | o w s | m n c | n t w | i n e [ c h ] | z o o | ^ o r d / i;
14
3
15
4
export const objectKeys = Object . keys || ( obj => {
16
5
let keys = [ ] ;
17
6
for ( let i in obj ) if ( obj . hasOwnProperty ( i ) ) keys . push ( i ) ;
18
7
return keys ;
19
8
} ) ;
20
9
21
- export let encodeEntities = s => String ( s ) . replace ( / [ < > " & ] / g, escapeChar ) ;
22
-
23
- let escapeChar = a => ESC [ a ] || a ;
24
-
25
- export let falsey = v => v == null || v === false ;
26
-
27
- export let memoize = ( fn , mem = { } ) => v => mem [ v ] || ( mem [ v ] = fn ( v ) ) ;
10
+ export let encodeEntities = s => String ( s )
11
+ . replace ( / < / g, '<' )
12
+ . replace ( / > / g, '>' )
13
+ . replace ( / " / g, '"' )
14
+ . replace ( / & / g, '&' ) ;
28
15
29
16
export let indent = ( s , char ) => String ( s ) . replace ( / ( \n + ) / g, '$1' + ( char || '\t' ) ) ;
30
17
31
18
export let isLargeString = ( s , length , ignoreLines ) => ( String ( s ) . length > ( length || 40 ) || ( ! ignoreLines && String ( s ) . indexOf ( '\n' ) !== - 1 ) || String ( s ) . indexOf ( '<' ) !== - 1 ) ;
32
19
20
+ const JS_TO_CSS = { } ;
21
+
33
22
// Convert an Object style to a CSSText string
34
23
export function styleObjToCss ( s ) {
35
24
let str = '' ;
36
25
for ( let prop in s ) {
37
26
let val = s [ prop ] ;
38
27
if ( val != null ) {
39
28
if ( str ) str += ' ' ;
40
- str += jsToCss ( prop ) ;
29
+ // str += jsToCss(prop);
30
+ str += JS_TO_CSS [ prop ] || ( JS_TO_CSS [ prop ] = prop . replace ( / ( [ A - Z ] ) / g, '-$1' ) . toLowerCase ( ) ) ;
41
31
str += ': ' ;
42
32
str += val ;
43
- if ( typeof val === 'number' && ! NON_DIMENSION_PROPS [ prop ] ) {
33
+ if ( typeof val === 'number' && IS_NON_DIMENSIONAL . test ( prop ) === false ) {
44
34
str += 'px' ;
45
35
}
46
36
str += ';' ;
@@ -49,22 +39,6 @@ export function styleObjToCss(s) {
49
39
return str || undefined ;
50
40
}
51
41
52
-
53
- // See https://github.com/developit/preact/blob/master/src/util.js#L61
54
- export function hashToClassName ( c ) {
55
- let str = '' ;
56
- for ( let prop in c ) {
57
- if ( c [ prop ] ) {
58
- if ( str ) str += ' ' ;
59
- str += prop ;
60
- }
61
- }
62
- return str ;
63
- }
64
-
65
- // Convert a JavaScript camel-case CSS property name to a CSS property name
66
- export let jsToCss = memoize ( s => s . replace ( / ( [ A - Z ] ) / g, '-$1' ) . toLowerCase ( ) ) ;
67
-
68
42
export function assign ( obj , props ) {
69
43
for ( let i in props ) obj [ i ] = props [ i ] ;
70
44
return obj ;
0 commit comments