.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / autoprefixer / lib / prefixer.js
1 'use strict';
2
3 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
4
5 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
7 var Browsers = require('./browsers');
8 var utils = require('./utils');
9
10 var vendor = require('postcss').vendor;
11
12 /**
13  * Recursivly clone objects
14  */
15 function _clone(obj, parent) {
16     var cloned = new obj.constructor();
17
18     for (var _iterator = Object.keys(obj || {}), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
19         var _ref;
20
21         if (_isArray) {
22             if (_i >= _iterator.length) break;
23             _ref = _iterator[_i++];
24         } else {
25             _i = _iterator.next();
26             if (_i.done) break;
27             _ref = _i.value;
28         }
29
30         var i = _ref;
31
32         var value = obj[i];
33         if (i === 'parent' && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
34             if (parent) {
35                 cloned[i] = parent;
36             }
37         } else if (i === 'source' || i === null) {
38             cloned[i] = value;
39         } else if (value instanceof Array) {
40             cloned[i] = value.map(function (x) {
41                 return _clone(x, cloned);
42             });
43         } else if (i !== '_autoprefixerPrefix' && i !== '_autoprefixerValues') {
44             if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null) {
45                 value = _clone(value, cloned);
46             }
47             cloned[i] = value;
48         }
49     }
50
51     return cloned;
52 }
53
54 var Prefixer = function () {
55
56     /**
57      * Add hack to selected names
58      */
59     Prefixer.hack = function hack(klass) {
60         var _this = this;
61
62         if (!this.hacks) {
63             this.hacks = {};
64         }
65         return klass.names.map(function (name) {
66             _this.hacks[name] = klass;
67             return _this.hacks[name];
68         });
69     };
70
71     /**
72      * Load hacks for some names
73      */
74
75
76     Prefixer.load = function load(name, prefixes, all) {
77         var Klass = this.hacks && this.hacks[name];
78         if (Klass) {
79             return new Klass(name, prefixes, all);
80         } else {
81             return new this(name, prefixes, all);
82         }
83     };
84
85     /**
86      * Clone node and clean autprefixer custom caches
87      */
88
89
90     Prefixer.clone = function clone(node, overrides) {
91         var cloned = _clone(node);
92         for (var name in overrides) {
93             cloned[name] = overrides[name];
94         }
95         return cloned;
96     };
97
98     function Prefixer(name, prefixes, all) {
99         _classCallCheck(this, Prefixer);
100
101         this.name = name;
102         this.prefixes = prefixes;
103         this.all = all;
104     }
105
106     /**
107      * Find prefix in node parents
108      */
109
110
111     Prefixer.prototype.parentPrefix = function parentPrefix(node) {
112         var prefix = void 0;
113
114         if (typeof node._autoprefixerPrefix !== 'undefined') {
115             prefix = node._autoprefixerPrefix;
116         } else if (node.type === 'decl' && node.prop[0] === '-') {
117             prefix = vendor.prefix(node.prop);
118         } else if (node.type === 'root') {
119             prefix = false;
120         } else if (node.type === 'rule' && node.selector.indexOf(':-') !== -1 && /:(-\w+-)/.test(node.selector)) {
121             prefix = node.selector.match(/:(-\w+-)/)[1];
122         } else if (node.type === 'atrule' && node.name[0] === '-') {
123             prefix = vendor.prefix(node.name);
124         } else {
125             prefix = this.parentPrefix(node.parent);
126         }
127
128         if (Browsers.prefixes().indexOf(prefix) === -1) {
129             prefix = false;
130         }
131
132         node._autoprefixerPrefix = prefix;
133
134         return node._autoprefixerPrefix;
135     };
136
137     /**
138      * Clone node with prefixes
139      */
140
141
142     Prefixer.prototype.process = function process(node, result) {
143         if (!this.check(node)) {
144             return undefined;
145         }
146
147         var parent = this.parentPrefix(node);
148
149         var prefixes = this.prefixes.filter(function (prefix) {
150             return !parent || parent === utils.removeNote(prefix);
151         });
152
153         var added = [];
154         for (var _iterator2 = prefixes, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
155             var _ref2;
156
157             if (_isArray2) {
158                 if (_i2 >= _iterator2.length) break;
159                 _ref2 = _iterator2[_i2++];
160             } else {
161                 _i2 = _iterator2.next();
162                 if (_i2.done) break;
163                 _ref2 = _i2.value;
164             }
165
166             var prefix = _ref2;
167
168             if (this.add(node, prefix, added.concat([prefix]), result)) {
169                 added.push(prefix);
170             }
171         }
172
173         return added;
174     };
175
176     /**
177      * Shortcut for Prefixer.clone
178      */
179
180
181     Prefixer.prototype.clone = function clone(node, overrides) {
182         return Prefixer.clone(node, overrides);
183     };
184
185     return Prefixer;
186 }();
187
188 module.exports = Prefixer;