1 |
|
2 |
|
3 | import appendPxIfNeeded from './append-px-if-needed';
|
4 | import camelCasePropsToDashCase from './camel-case-props-to-dash-case';
|
5 | import mapObject from './map-object';
|
6 | import {getPrefixedStyle} from './prefixer';
|
7 |
|
8 | function createMarkupForStyles(style: Object): string {
|
9 | return Object.keys(style)
|
10 | .map(property => {
|
11 | return property + ': ' + style[property] + ';';
|
12 | })
|
13 | .join('\n');
|
14 | }
|
15 |
|
16 | export default function cssRuleSetToString(
|
17 | selector: string,
|
18 | rules: Object,
|
19 | userAgent: ?string
|
20 | ): string {
|
21 | if (!rules) {
|
22 | return '';
|
23 | }
|
24 |
|
25 | const rulesWithPx = mapObject(rules, (value, key) =>
|
26 | appendPxIfNeeded(key, value));
|
27 | const prefixedRules = getPrefixedStyle(rulesWithPx, userAgent);
|
28 | const cssPrefixedRules = camelCasePropsToDashCase(prefixedRules);
|
29 | const serializedRules = createMarkupForStyles(cssPrefixedRules);
|
30 | return selector + '{' + serializedRules + '}';
|
31 | }
|