1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _keys = require('babel-runtime/core-js/object/keys');
|
8 |
|
9 | var _keys2 = _interopRequireDefault(_keys);
|
10 |
|
11 | exports.default = rtl;
|
12 |
|
13 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14 |
|
15 | var reTranslate = /((^|\s)translate(3d|X)?\()(\-?[\d]+)/;
|
16 | var reSkew = /((^|\s)skew(x|y)?\()\s*(\-?[\d]+)(deg|rad|grad)(,\s*(\-?[\d]+)(deg|rad|grad))?/;
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function rtl(muiTheme) {
|
24 | if (muiTheme.isRtl) {
|
25 | return function (style) {
|
26 | if (style.directionInvariant === true) {
|
27 | return style;
|
28 | }
|
29 |
|
30 | var flippedAttributes = {
|
31 |
|
32 | right: 'left',
|
33 | left: 'right',
|
34 | marginRight: 'marginLeft',
|
35 | marginLeft: 'marginRight',
|
36 | paddingRight: 'paddingLeft',
|
37 | paddingLeft: 'paddingRight',
|
38 | borderRight: 'borderLeft',
|
39 | borderLeft: 'borderRight'
|
40 | };
|
41 |
|
42 | var newStyle = {};
|
43 |
|
44 | (0, _keys2.default)(style).forEach(function (attribute) {
|
45 | var value = style[attribute];
|
46 | var key = attribute;
|
47 |
|
48 | if (flippedAttributes.hasOwnProperty(attribute)) {
|
49 | key = flippedAttributes[attribute];
|
50 | }
|
51 |
|
52 | switch (attribute) {
|
53 | case 'float':
|
54 | case 'textAlign':
|
55 | if (value === 'right') {
|
56 | value = 'left';
|
57 | } else if (value === 'left') {
|
58 | value = 'right';
|
59 | }
|
60 | break;
|
61 |
|
62 | case 'direction':
|
63 | if (value === 'ltr') {
|
64 | value = 'rtl';
|
65 | } else if (value === 'rtl') {
|
66 | value = 'ltr';
|
67 | }
|
68 | break;
|
69 |
|
70 | case 'transform':
|
71 | if (!value) break;
|
72 | var matches = void 0;
|
73 | if (matches = value.match(reTranslate)) {
|
74 | value = value.replace(matches[0], matches[1] + -parseFloat(matches[4]));
|
75 | }
|
76 | if (matches = value.match(reSkew)) {
|
77 | value = value.replace(matches[0], matches[1] + -parseFloat(matches[4]) + matches[5] + matches[6] ? ', ' + (-parseFloat(matches[7]) + matches[8]) : '');
|
78 | }
|
79 | break;
|
80 |
|
81 | case 'transformOrigin':
|
82 | if (!value) break;
|
83 | if (value.indexOf('right') > -1) {
|
84 | value = value.replace('right', 'left');
|
85 | } else if (value.indexOf('left') > -1) {
|
86 | value = value.replace('left', 'right');
|
87 | }
|
88 | break;
|
89 | }
|
90 |
|
91 | newStyle[key] = value;
|
92 | });
|
93 |
|
94 | return newStyle;
|
95 | };
|
96 | }
|
97 | } |
\ | No newline at end of file |