33Object . defineProperty ( exports , "__esModule" , {
44 value : true
55} ) ;
6- exports . getPostcss = exports . objectify = exports . toES5Config = exports . toConfig = undefined ;
6+ exports . getPostcss = exports . toES5Config = exports . toConfig = undefined ;
77
88var _stringify = require ( 'babel-runtime/core-js/json/stringify' ) ;
99
1010var _stringify2 = _interopRequireDefault ( _stringify ) ;
1111
12- var _keys = require ( 'babel-runtime/core-js/object/keys' ) ;
13-
14- var _keys2 = _interopRequireDefault ( _keys ) ;
15-
16- var _postcssJs = require ( 'postcss-js' ) ;
17-
18- var _postcssJs2 = _interopRequireDefault ( _postcssJs ) ;
19-
2012var _compose = require ( 'lodash/fp/compose' ) ;
2113
2214var _compose2 = _interopRequireDefault ( _compose ) ;
2315
24- var _get = require ( 'lodash/fp/get' ) ;
25-
26- var _get2 = _interopRequireDefault ( _get ) ;
27-
2816var _cond = require ( 'lodash/fp/cond' ) ;
2917
3018var _cond2 = _interopRequireDefault ( _cond ) ;
3119
32- var _lowerFirst = require ( 'lodash/lowerFirst' ) ;
33-
34- var _lowerFirst2 = _interopRequireDefault ( _lowerFirst ) ;
35-
3620var _postcss = require ( 'postcss' ) ;
3721
3822var _postcss2 = _interopRequireDefault ( _postcss ) ;
@@ -54,25 +38,11 @@ var isProd = function isProd() {
5438 return ! isDev ( ) ;
5539} ;
5640
57- var transform = function transform ( data ) {
58- if ( ! data ) {
59- return { } ;
60- }
61- return ( 0 , _keys2 . default ) ( data ) . reduce ( function ( acc , k ) {
62- var v = data [ k ] ;
63-
64- k = k . replace ( / ^ - + / , '' ) ; // strips '-'
65- k = ( 0 , _lowerFirst2 . default ) ( k ) ;
66- acc [ k ] = v . endsWith ( 'px' ) ? parseInt ( v , 10 ) : v ;
67- return acc ;
68- } , { } ) ;
69- } ;
70-
7141var toProdExport = function toProdExport ( code ) {
7242 return 'export default ' + code ;
7343} ;
7444var toDevExport = function toDevExport ( code ) {
75- return 'let config = ' + code + ';\nif (typeof global. Proxy !== \'undefined\') {\n config = new Proxy(config, {\n get(target, key) {\n if (key !== \'__esModule\' && !target[key]) {\n console.error(`No variable found, check variable key: ["${key.toString()}"]`);\n }\n \n return target[key];\n },\n \n set(target, key) {\n throw new Error(\'Config variables are immutable \' + key);\n }\n });\n}\nexport default config' ;
45+ return 'let config = ' + code + ';\nif (typeof Proxy !== \'undefined\') {\n config = new Proxy(config, {\n get(target, key) {\n if (key !== \'__esModule\' && !target[key]) {\n console.error(`No variable found, check variable key: ["${key.toString()}"]`);\n }\n \n return target[key];\n },\n \n set(target, key) {\n throw new Error(\'Config variables are immutable \' + key);\n }\n });\n}\nexport default config' ;
7646} ;
7747var toES5Export = function toES5Export ( code ) {
7848 return 'module.exports = ' + code ;
@@ -83,21 +53,31 @@ var toExport = (0, _cond2.default)([[isDev, toDevExport], [isProd, toProdExport]
8353var toString = function toString ( data ) {
8454 return '' + ( 0 , _stringify2 . default ) ( data , null , '\t' ) ;
8555} ;
86- var toData = ( 0 , _compose2 . default ) ( transform , ( 0 , _get2 . default ) ( ':root' ) ) ;
8756
88- var toConfig = exports . toConfig = ( 0 , _compose2 . default ) ( toExport , toString , toData ) ;
89- var toES5Config = exports . toES5Config = ( 0 , _compose2 . default ) ( toES5Export , toString , toData ) ;
57+ var objectify = function objectify ( root , filepath ) {
58+ var result = { } ;
59+
60+ if ( ! root ) {
61+ return result ;
62+ }
63+
64+ root . walkDecls ( function ( rule ) {
65+ if ( rule . source . input . file !== filepath ) {
66+ return ;
67+ }
68+ if ( rule . parent && rule . parent . selectors . find ( function ( sel ) {
69+ return sel === ':root' ;
70+ } ) ) {
71+ var v = rule . value ; // replace "--"
9072
91- var objectify = exports . objectify = function objectify ( root , filepath ) {
92- // removes imported rules, so we have only computed output
93- root . walkRules ( function ( r ) {
94- if ( r . source . input . file !== filepath ) {
95- r . remove ( ) ;
73+ result [ rule . prop . replace ( / ^ - + / , '' ) ] = v . endsWith ( 'px' ) ? parseInt ( v , 10 ) : v ;
9674 }
9775 } ) ;
98- return _postcssJs2 . default . objectify ( root ) ;
76+ return result ;
9977} ;
10078
79+ var toConfig = exports . toConfig = ( 0 , _compose2 . default ) ( toExport , toString , objectify ) ;
80+ var toES5Config = exports . toES5Config = ( 0 , _compose2 . default ) ( toES5Export , toString , objectify ) ;
10181var getPostcss = exports . getPostcss = function getPostcss ( async ) {
10282 return ( 0 , _postcss2 . default ) ( ) . use ( ( 0 , _postcssImport2 . default ) ( { async : async } ) ) . use ( ( 0 , _postcssCssnext2 . default ) ( { features : { customProperties : { preserve : 'computed' } } } ) ) ;
10383} ;
0 commit comments