UNPKG

1.52 kBJavaScriptView Raw
1Object.defineProperty(exports, "__esModule", {
2 value: true
3});
4exports['default'] = resolveRTL;
5
6var _arrayFlatten = require('array-flatten');
7
8var _rtlCssJs = require('rtl-css-js');
9
10var _rtlCssJs2 = _interopRequireDefault(_rtlCssJs);
11
12var _separateStyles2 = require('./separateStyles');
13
14var _separateStyles3 = _interopRequireDefault(_separateStyles2);
15
16function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
17
18function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
19
20// Styles is an array of properties returned by `create()`, a POJO, or an
21// array thereof. POJOs are treated as inline styles. This version of the
22// resolve function explicitly flips inline styles for an RTL context.
23// This function returns an object to be spread onto an element.
24function resolveRTL(css, styles) {
25 var flattenedStyles = (0, _arrayFlatten.from)(styles);
26
27 var _separateStyles = (0, _separateStyles3['default'])(flattenedStyles),
28 aphroditeStyles = _separateStyles.aphroditeStyles,
29 hasInlineStyles = _separateStyles.hasInlineStyles,
30 inlineStyles = _separateStyles.inlineStyles;
31
32 var result = {};
33 if (aphroditeStyles.length > 0) {
34 result.className = css.apply(undefined, _toConsumableArray(aphroditeStyles));
35 }
36
37 if (hasInlineStyles) {
38 result.style = (0, _rtlCssJs2['default'])(inlineStyles);
39 }
40
41 return result;
42}
\No newline at end of file