d2-ui
Version:
82 lines (60 loc) • 2.8 kB
JavaScript
Object.defineProperty(exports, '__esModule', {
value: true
});
exports['default'] = transition;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var _utilsCamelToDashCase = require('../utils/camelToDashCase');
var _utilsCamelToDashCase2 = _interopRequireDefault(_utilsCamelToDashCase);
var _utilsCapitalizeString = require('../utils/capitalizeString');
var _utilsCapitalizeString2 = _interopRequireDefault(_utilsCapitalizeString);
var _utilsIsPrefixedValue = require('../utils/isPrefixedValue');
var _utilsIsPrefixedValue2 = _interopRequireDefault(_utilsIsPrefixedValue);
var _prefixProps = require('../prefixProps');
var _prefixProps2 = _interopRequireDefault(_prefixProps);
var properties = {
transition: true,
transitionProperty: true,
WebkitTransition: true,
WebkitTransitionProperty: true
};
function transition(property, value) {
// also check for already prefixed transitions
if (typeof value === 'string' && properties[property]) {
var _ref2;
var outputValue = prefixValue(value);
var webkitOutput = outputValue.split(',').filter(function (value) {
return value.match(/-moz-|-ms-/) === null;
}).join(',');
// if the property is already prefixed
if (property.indexOf('Webkit') > -1) {
return _defineProperty({}, property, webkitOutput);
}
return _ref2 = {}, _defineProperty(_ref2, 'Webkit' + (0, _utilsCapitalizeString2['default'])(property), webkitOutput), _defineProperty(_ref2, property, outputValue), _ref2;
}
}
function prefixValue(value) {
if ((0, _utilsIsPrefixedValue2['default'])(value)) {
return value;
}
// only split multi values, not cubic beziers
var multipleValues = value.split(/,(?![^()]*(?:\([^()]*\))?\))/g);
// iterate each single value and check for transitioned properties
// that need to be prefixed as well
multipleValues.forEach(function (val, index) {
multipleValues[index] = Object.keys(_prefixProps2['default']).reduce(function (out, prefix) {
var dashCasePrefix = '-' + prefix.toLowerCase() + '-';
Object.keys(_prefixProps2['default'][prefix]).forEach(function (prop) {
var dashCaseProperty = (0, _utilsCamelToDashCase2['default'])(prop);
if (val.indexOf(dashCaseProperty) > -1) {
// join all prefixes and create a new value
out = val.replace(dashCaseProperty, dashCasePrefix + dashCaseProperty) + ',' + out;
}
});
return out;
}, val);
});
return multipleValues.join(',');
}
module.exports = exports['default'];
;