.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / autoprefixer / lib / value.js
1 'use strict';
2
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; }
4
5 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
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; }
8
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); }
10
11 var Prefixer = require('./prefixer');
12 var OldValue = require('./old-value');
13 var utils = require('./utils');
14
15 var vendor = require('postcss').vendor;
16
17 var Value = function (_Prefixer) {
18     _inherits(Value, _Prefixer);
19
20     function Value() {
21         _classCallCheck(this, Value);
22
23         return _possibleConstructorReturn(this, _Prefixer.apply(this, arguments));
24     }
25
26     /**
27      * Clone decl for each prefixed values
28      */
29     Value.save = function save(prefixes, decl) {
30         var _this2 = this;
31
32         var prop = decl.prop;
33         var result = [];
34
35         var _loop = function _loop(prefix) {
36             var value = decl._autoprefixerValues[prefix];
37
38             if (value === decl.value) {
39                 return 'continue';
40             }
41
42             var item = void 0;
43             var propPrefix = vendor.prefix(prop);
44
45             if (propPrefix === '-pie-') {
46                 return 'continue';
47             }
48
49             if (propPrefix === prefix) {
50                 item = decl.value = value;
51                 result.push(item);
52                 return 'continue';
53             }
54
55             var prefixed = prefixes.prefixed(prop, prefix);
56             var rule = decl.parent;
57
58             if (!rule.every(function (i) {
59                 return i.prop !== prefixed;
60             })) {
61                 result.push(item);
62                 return 'continue';
63             }
64
65             var trimmed = value.replace(/\s+/, ' ');
66             var already = rule.some(function (i) {
67                 return i.prop === decl.prop && i.value.replace(/\s+/, ' ') === trimmed;
68             });
69
70             if (already) {
71                 result.push(item);
72                 return 'continue';
73             }
74
75             var cloned = _this2.clone(decl, { value: value });
76             item = decl.parent.insertBefore(decl, cloned);
77
78             result.push(item);
79         };
80
81         for (var prefix in decl._autoprefixerValues) {
82             var _ret = _loop(prefix);
83
84             if (_ret === 'continue') continue;
85         }
86
87         return result;
88     };
89
90     /**
91      * Is declaration need to be prefixed
92      */
93
94
95     Value.prototype.check = function check(decl) {
96         var value = decl.value;
97         if (value.indexOf(this.name) === -1) {
98             return false;
99         }
100
101         return !!value.match(this.regexp());
102     };
103
104     /**
105      * Lazy regexp loading
106      */
107
108
109     Value.prototype.regexp = function regexp() {
110         return this.regexpCache || (this.regexpCache = utils.regexp(this.name));
111     };
112
113     /**
114      * Add prefix to values in string
115      */
116
117
118     Value.prototype.replace = function replace(string, prefix) {
119         return string.replace(this.regexp(), '$1' + prefix + '$2');
120     };
121
122     /**
123      * Get value with comments if it was not changed
124      */
125
126
127     Value.prototype.value = function value(decl) {
128         if (decl.raws.value && decl.raws.value.value === decl.value) {
129             return decl.raws.value.raw;
130         } else {
131             return decl.value;
132         }
133     };
134
135     /**
136      * Save values with next prefixed token
137      */
138
139
140     Value.prototype.add = function add(decl, prefix) {
141         if (!decl._autoprefixerValues) {
142             decl._autoprefixerValues = {};
143         }
144         var value = decl._autoprefixerValues[prefix] || this.value(decl);
145
146         var before = void 0;
147         do {
148             before = value;
149             value = this.replace(value, prefix);
150             if (value === false) return;
151         } while (value !== before);
152
153         decl._autoprefixerValues[prefix] = value;
154     };
155
156     /**
157      * Return function to fast find prefixed value
158      */
159
160
161     Value.prototype.old = function old(prefix) {
162         return new OldValue(this.name, prefix + this.name);
163     };
164
165     return Value;
166 }(Prefixer);
167
168 module.exports = Value;