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 55 */
66var utilities = require ( './utilities' ) ;
77var propertyConfig = require ( './property-config' ) ;
8- var cssToReactNative = require ( 'css-to-react-native ' ) ;
8+ var csstree = require ( 'css-tree ' ) ;
99var config = propertyConfig . config ;
1010var isCustomAttribute = propertyConfig . HTMLDOMPropertyConfig . isCustomAttribute ;
1111
@@ -64,16 +64,21 @@ function cssToJs(style) {
6464 throw new Error ( '`cssToJs`: first argument must be a string. ' ) ;
6565 }
6666
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+ }
7479 } ) ;
7580
76- return cssToReactNative . default ( styles ) ;
81+ return styleObj ;
7782}
7883
7984/**
Original file line number Diff line number Diff line change 2929 " converter"
3030 ],
3131 "dependencies" : {
32- "css-to-react-native " : " ^2 .0.4 " ,
32+ "css-tree " : " ^1 .0.0-alpha.26 " ,
3333 "html-dom-parser" : " 0.1.2" ,
3434 "react-dom-core" : " 0.0.2"
3535 },
You can’t perform that action at this time.
0 commit comments