3 function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
5 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7 function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
9 function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
11 var Prefixer = require('./prefixer');
12 var OldValue = require('./old-value');
13 var utils = require('./utils');
15 var vendor = require('postcss').vendor;
17 var Value = function (_Prefixer) {
18 _inherits(Value, _Prefixer);
21 _classCallCheck(this, Value);
23 return _possibleConstructorReturn(this, _Prefixer.apply(this, arguments));
27 * Clone decl for each prefixed values
29 Value.save = function save(prefixes, decl) {
35 var _loop = function _loop(prefix) {
36 var value = decl._autoprefixerValues[prefix];
38 if (value === decl.value) {
43 var propPrefix = vendor.prefix(prop);
45 if (propPrefix === '-pie-') {
49 if (propPrefix === prefix) {
50 item = decl.value = value;
55 var prefixed = prefixes.prefixed(prop, prefix);
56 var rule = decl.parent;
58 if (!rule.every(function (i) {
59 return i.prop !== prefixed;
65 var trimmed = value.replace(/\s+/, ' ');
66 var already = rule.some(function (i) {
67 return i.prop === decl.prop && i.value.replace(/\s+/, ' ') === trimmed;
75 var cloned = _this2.clone(decl, { value: value });
76 item = decl.parent.insertBefore(decl, cloned);
81 for (var prefix in decl._autoprefixerValues) {
82 var _ret = _loop(prefix);
84 if (_ret === 'continue') continue;
91 * Is declaration need to be prefixed
95 Value.prototype.check = function check(decl) {
96 var value = decl.value;
97 if (value.indexOf(this.name) === -1) {
101 return !!value.match(this.regexp());
105 * Lazy regexp loading
109 Value.prototype.regexp = function regexp() {
110 return this.regexpCache || (this.regexpCache = utils.regexp(this.name));
114 * Add prefix to values in string
118 Value.prototype.replace = function replace(string, prefix) {
119 return string.replace(this.regexp(), '$1' + prefix + '$2');
123 * Get value with comments if it was not changed
127 Value.prototype.value = function value(decl) {
128 if (decl.raws.value && decl.raws.value.value === decl.value) {
129 return decl.raws.value.raw;
136 * Save values with next prefixed token
140 Value.prototype.add = function add(decl, prefix) {
141 if (!decl._autoprefixerValues) {
142 decl._autoprefixerValues = {};
144 var value = decl._autoprefixerValues[prefix] || this.value(decl);
149 value = this.replace(value, prefix);
150 if (value === false) return;
151 } while (value !== before);
153 decl._autoprefixerValues[prefix] = value;
157 * Return function to fast find prefixed value
161 Value.prototype.old = function old(prefix) {
162 return new OldValue(this.name, prefix + this.name);
168 module.exports = Value;