[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.default = transition;
|
---|
| 7 |
|
---|
| 8 | var _hyphenateProperty = require('css-in-js-utils/lib/hyphenateProperty');
|
---|
| 9 |
|
---|
| 10 | var _hyphenateProperty2 = _interopRequireDefault(_hyphenateProperty);
|
---|
| 11 |
|
---|
| 12 | var _isPrefixedValue = require('css-in-js-utils/lib/isPrefixedValue');
|
---|
| 13 |
|
---|
| 14 | var _isPrefixedValue2 = _interopRequireDefault(_isPrefixedValue);
|
---|
| 15 |
|
---|
| 16 | var _capitalizeString = require('../utils/capitalizeString');
|
---|
| 17 |
|
---|
| 18 | var _capitalizeString2 = _interopRequireDefault(_capitalizeString);
|
---|
| 19 |
|
---|
| 20 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
| 21 |
|
---|
| 22 | var properties = {
|
---|
| 23 | transition: true,
|
---|
| 24 | transitionProperty: true,
|
---|
| 25 | WebkitTransition: true,
|
---|
| 26 | WebkitTransitionProperty: true,
|
---|
| 27 | MozTransition: true,
|
---|
| 28 | MozTransitionProperty: true
|
---|
| 29 | };
|
---|
| 30 |
|
---|
| 31 | var prefixMapping = {
|
---|
| 32 | Webkit: '-webkit-',
|
---|
| 33 | Moz: '-moz-',
|
---|
| 34 | ms: '-ms-'
|
---|
| 35 | };
|
---|
| 36 |
|
---|
| 37 | function prefixValue(value, propertyPrefixMap) {
|
---|
| 38 | if ((0, _isPrefixedValue2.default)(value)) {
|
---|
| 39 | return value;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | // only split multi values, not cubic beziers
|
---|
| 43 | var multipleValues = value.split(/,(?![^()]*(?:\([^()]*\))?\))/g);
|
---|
| 44 |
|
---|
| 45 | for (var i = 0, len = multipleValues.length; i < len; ++i) {
|
---|
| 46 | var singleValue = multipleValues[i];
|
---|
| 47 | var values = [singleValue];
|
---|
| 48 | for (var property in propertyPrefixMap) {
|
---|
| 49 | var dashCaseProperty = (0, _hyphenateProperty2.default)(property);
|
---|
| 50 |
|
---|
| 51 | if (singleValue.indexOf(dashCaseProperty) > -1 && dashCaseProperty !== 'order') {
|
---|
| 52 | var prefixes = propertyPrefixMap[property];
|
---|
| 53 | for (var j = 0, pLen = prefixes.length; j < pLen; ++j) {
|
---|
| 54 | // join all prefixes and create a new value
|
---|
| 55 | values.unshift(singleValue.replace(dashCaseProperty, prefixMapping[prefixes[j]] + dashCaseProperty));
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | multipleValues[i] = values.join(',');
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | return multipleValues.join(',');
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | function transition(property, value, style, propertyPrefixMap) {
|
---|
| 67 | // also check for already prefixed transitions
|
---|
| 68 | if (typeof value === 'string' && properties.hasOwnProperty(property)) {
|
---|
| 69 | var outputValue = prefixValue(value, propertyPrefixMap);
|
---|
| 70 | // if the property is already prefixed
|
---|
| 71 | var webkitOutput = outputValue.split(/,(?![^()]*(?:\([^()]*\))?\))/g).filter(function (val) {
|
---|
| 72 | return !/-moz-|-ms-/.test(val);
|
---|
| 73 | }).join(',');
|
---|
| 74 |
|
---|
| 75 | if (property.indexOf('Webkit') > -1) {
|
---|
| 76 | return webkitOutput;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | var mozOutput = outputValue.split(/,(?![^()]*(?:\([^()]*\))?\))/g).filter(function (val) {
|
---|
| 80 | return !/-webkit-|-ms-/.test(val);
|
---|
| 81 | }).join(',');
|
---|
| 82 |
|
---|
| 83 | if (property.indexOf('Moz') > -1) {
|
---|
| 84 | return mozOutput;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | style['Webkit' + (0, _capitalizeString2.default)(property)] = webkitOutput;
|
---|
| 88 | style['Moz' + (0, _capitalizeString2.default)(property)] = mozOutput;
|
---|
| 89 | return outputValue;
|
---|
| 90 | }
|
---|
| 91 | } |
---|