|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 'use strict';
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports['default'] = camelCase;
-
- var _hyphenateStyleName = require('hyphenate-style-name');
-
- var _hyphenateStyleName2 = _interopRequireDefault(_hyphenateStyleName);
-
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
-
- /**
- * Convert camel cased property names to dash separated.
- *
- * @param {Object} style
- * @return {Object}
- */
- function convertCase(style) {
- var converted = {};
-
- for (var prop in style) {
- converted[(0, _hyphenateStyleName2['default'])(prop)] = style[prop];
- }
-
- if (style.fallbacks) {
- if (Array.isArray(style.fallbacks)) converted.fallbacks = style.fallbacks.map(convertCase);else converted.fallbacks = convertCase(style.fallbacks);
- }
-
- return converted;
- }
-
- /**
- * Allow camel cased property names by converting them back to dasherized.
- *
- * @param {Rule} rule
- */
- function camelCase() {
- function onProcessStyle(style) {
- if (Array.isArray(style)) {
- // Handle rules like @font-face, which can have multiple styles in an array
- for (var index = 0; index < style.length; index++) {
- style[index] = convertCase(style[index]);
- }
- return style;
- }
-
- return convertCase(style);
- }
-
- function onChangeValue(value, prop, rule) {
- var hyphenatedProp = (0, _hyphenateStyleName2['default'])(prop);
-
- // There was no camel case in place
- if (prop === hyphenatedProp) return value;
-
- rule.prop(hyphenatedProp, value);
-
- // Core will ignore that property value we set the proper one above.
- return null;
- }
-
- return { onProcessStyle: onProcessStyle, onChangeValue: onChangeValue };
- }
|