Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

97 righe
2.7 KiB

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