Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

65 строки
1.7 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports['default'] = camelCase;
  6. var _hyphenateStyleName = require('hyphenate-style-name');
  7. var _hyphenateStyleName2 = _interopRequireDefault(_hyphenateStyleName);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  9. /**
  10. * Convert camel cased property names to dash separated.
  11. *
  12. * @param {Object} style
  13. * @return {Object}
  14. */
  15. function convertCase(style) {
  16. var converted = {};
  17. for (var prop in style) {
  18. converted[(0, _hyphenateStyleName2['default'])(prop)] = style[prop];
  19. }
  20. if (style.fallbacks) {
  21. if (Array.isArray(style.fallbacks)) converted.fallbacks = style.fallbacks.map(convertCase);else converted.fallbacks = convertCase(style.fallbacks);
  22. }
  23. return converted;
  24. }
  25. /**
  26. * Allow camel cased property names by converting them back to dasherized.
  27. *
  28. * @param {Rule} rule
  29. */
  30. function camelCase() {
  31. function onProcessStyle(style) {
  32. if (Array.isArray(style)) {
  33. // Handle rules like @font-face, which can have multiple styles in an array
  34. for (var index = 0; index < style.length; index++) {
  35. style[index] = convertCase(style[index]);
  36. }
  37. return style;
  38. }
  39. return convertCase(style);
  40. }
  41. function onChangeValue(value, prop, rule) {
  42. var hyphenatedProp = (0, _hyphenateStyleName2['default'])(prop);
  43. // There was no camel case in place
  44. if (prop === hyphenatedProp) return value;
  45. rule.prop(hyphenatedProp, value);
  46. // Core will ignore that property value we set the proper one above.
  47. return null;
  48. }
  49. return { onProcessStyle: onProcessStyle, onChangeValue: onChangeValue };
  50. }