[d565449] | 1 | import prefixProperty from './utils/prefixProperty';
|
---|
| 2 | import prefixValue from './utils/prefixValue';
|
---|
| 3 |
|
---|
| 4 | import addNewValuesOnly from './utils/addNewValuesOnly';
|
---|
| 5 | import isObject from './utils/isObject';
|
---|
| 6 |
|
---|
| 7 | export default function createPrefixer(_ref) {
|
---|
| 8 | var prefixMap = _ref.prefixMap,
|
---|
| 9 | plugins = _ref.plugins;
|
---|
| 10 |
|
---|
| 11 | return function prefix(style) {
|
---|
| 12 | for (var property in style) {
|
---|
| 13 | var value = style[property];
|
---|
| 14 |
|
---|
| 15 | // handle nested objects
|
---|
| 16 | if (isObject(value)) {
|
---|
| 17 | style[property] = prefix(value);
|
---|
| 18 | // handle array values
|
---|
| 19 | } else if (Array.isArray(value)) {
|
---|
| 20 | var combinedValue = [];
|
---|
| 21 |
|
---|
| 22 | for (var i = 0, len = value.length; i < len; ++i) {
|
---|
| 23 | var processedValue = prefixValue(plugins, property, value[i], style, prefixMap);
|
---|
| 24 |
|
---|
| 25 | addNewValuesOnly(combinedValue, processedValue || value[i]);
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | // only modify the value if it was touched
|
---|
| 29 | // by any plugin to prevent unnecessary mutations
|
---|
| 30 | if (combinedValue.length > 0) {
|
---|
| 31 | style[property] = combinedValue;
|
---|
| 32 | }
|
---|
| 33 | } else {
|
---|
| 34 | var _processedValue = prefixValue(plugins, property, value, style, prefixMap);
|
---|
| 35 |
|
---|
| 36 | // only modify the value if it was touched
|
---|
| 37 | // by any plugin to prevent unnecessary mutations
|
---|
| 38 | if (_processedValue) {
|
---|
| 39 | style[property] = _processedValue;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | style = prefixProperty(prefixMap, property, style);
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | return style;
|
---|
| 47 | };
|
---|
| 48 | } |
---|