-
Notifications
You must be signed in to change notification settings - Fork 4k
/
index.js
42 lines (37 loc) · 1014 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* External dependencies
*/
import { map } from 'lodash';
/**
* WordPress dependencies
*/
import { compose } from '@wordpress/compose';
/**
* Internal dependencies
*/
import traverse from './traverse';
import urlRewrite from './transforms/url-rewrite';
import wrap from './transforms/wrap';
/**
* Applies a series of CSS rule transforms to wrap selectors inside a given class and/or rewrite URLs depending on the parameters passed.
*
* @param {Array} styles CSS rules.
* @param {string} wrapperClassName Wrapper Class Name.
* @return {Array} converted rules.
*/
const transformStyles = ( styles, wrapperClassName = '' ) => {
return map( styles, ( { css, baseURL } ) => {
const transforms = [];
if ( wrapperClassName ) {
transforms.push( wrap( wrapperClassName ) );
}
if ( baseURL ) {
transforms.push( urlRewrite( baseURL ) );
}
if ( transforms.length ) {
return traverse( css, compose( transforms ) );
}
return css;
} );
};
export default transformStyles;