File tree Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Original file line number Diff line number Diff line change 5
5
*/
6
6
var utilities = require ( './utilities' ) ;
7
7
var propertyConfig = require ( './property-config' ) ;
8
- var cssToReactNative = require ( 'css-to-react-native ' ) ;
8
+ var csstree = require ( 'css-tree ' ) ;
9
9
var config = propertyConfig . config ;
10
10
var isCustomAttribute = propertyConfig . HTMLDOMPropertyConfig . isCustomAttribute ;
11
11
@@ -64,16 +64,21 @@ function cssToJs(style) {
64
64
throw new Error ( '`cssToJs`: first argument must be a string. ' ) ;
65
65
}
66
66
67
- var styles = style . split ( ';' ) ;
68
- styles = styles . map ( function ( style ) {
69
- var parts = style . split ( ':' ) ;
70
- var propName = parts [ 0 ] ;
71
- parts . shift ( ) ;
72
- var propValue = parts . join ( ':' ) ;
73
- return [ propName . trim ( ) , propValue . trim ( ) ] ;
67
+ var styleObj = { } ;
68
+
69
+ var ast = csstree . parse ( style , {
70
+ context : 'declarationList' ,
71
+ parseValue : false
72
+ } ) ;
73
+
74
+ csstree . walk ( ast , function ( node ) {
75
+ if ( node . type === 'Declaration' ) {
76
+ var propertyCamelCase = node . property . replace ( / - ( [ a - z ] ) / g, function ( g ) { return g [ 1 ] . toUpperCase ( ) ; } ) ;
77
+ styleObj [ propertyCamelCase ] = node . value . value ;
78
+ }
74
79
} ) ;
75
80
76
- return cssToReactNative . default ( styles ) ;
81
+ return styleObj ;
77
82
}
78
83
79
84
/**
Original file line number Diff line number Diff line change 29
29
" converter"
30
30
],
31
31
"dependencies" : {
32
- "css-to-react-native " : " ^2 .0.4 " ,
32
+ "css-tree " : " ^1 .0.0-alpha.26 " ,
33
33
"html-dom-parser" : " 0.1.2" ,
34
34
"react-dom-core" : " 0.0.2"
35
35
},
You can’t perform that action at this time.
0 commit comments