.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / autoprefixer / lib / autoprefixer.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 var browserslist = require('browserslist');
6 var postcss = require('postcss');
7
8 var Browsers = require('./browsers');
9 var Prefixes = require('./prefixes');
10
11 function isPlainObject(obj) {
12     return Object.prototype.toString.apply(obj) === '[object Object]';
13 }
14
15 var cache = {};
16
17 function timeCapsule(result, prefixes) {
18     if (prefixes.browsers.selected.length === 0) {
19         return;
20     }
21     if (prefixes.add.selectors.length > 0) {
22         return;
23     }
24     if (Object.keys(prefixes.add).length > 2) {
25         return;
26     }
27
28     /* istanbul ignore next */
29     result.warn('Greetings, time traveller. ' + 'We are in the golden age of prefix-less CSS, ' + 'where Autoprefixer is no longer needed for your stylesheet.');
30 }
31
32 module.exports = postcss.plugin('autoprefixer', function () {
33     for (var _len = arguments.length, reqs = Array(_len), _key = 0; _key < _len; _key++) {
34         reqs[_key] = arguments[_key];
35     }
36
37     var options = void 0;
38     if (reqs.length === 1 && isPlainObject(reqs[0])) {
39         options = reqs[0];
40         reqs = undefined;
41     } else if (reqs.length === 0 || reqs.length === 1 && !reqs[0]) {
42         reqs = undefined;
43     } else if (reqs.length <= 2 && (reqs[0] instanceof Array || !reqs[0])) {
44         options = reqs[1];
45         reqs = reqs[0];
46     } else if (_typeof(reqs[reqs.length - 1]) === 'object') {
47         options = reqs.pop();
48     }
49
50     if (!options) {
51         options = {};
52     }
53
54     if (options.browser) {
55         throw new Error('Change `browser` option to `browsers` in Autoprefixer');
56     } else if (options.browserslist) {
57         throw new Error('Change `browserslist` option to `browsers` in Autoprefixer');
58     }
59
60     if (options.browsers) {
61         reqs = options.browsers;
62     }
63
64     if (typeof options.grid === 'undefined') {
65         options.grid = false;
66     }
67
68     var loadPrefixes = function loadPrefixes(opts) {
69         var data = module.exports.data;
70         var browsers = new Browsers(data.browsers, reqs, opts, options.stats);
71         var key = browsers.selected.join(', ') + JSON.stringify(options);
72
73         if (!cache[key]) {
74             cache[key] = new Prefixes(data.prefixes, browsers, options);
75         }
76
77         return cache[key];
78     };
79
80     var plugin = function plugin(css, result) {
81         var prefixes = loadPrefixes({
82             from: css.source && css.source.input.file,
83             env: options.env
84         });
85         timeCapsule(result, prefixes);
86         if (options.remove !== false) {
87             prefixes.processor.remove(css, result);
88         }
89         if (options.add !== false) {
90             prefixes.processor.add(css, result);
91         }
92     };
93
94     plugin.options = options;
95
96     plugin.browsers = reqs;
97
98     plugin.info = function (opts) {
99         opts = opts || {};
100         opts.from = opts.from || process.cwd();
101
102         return require('./info')(loadPrefixes(opts));
103     };
104
105     return plugin;
106 });
107
108 /**
109  * Autoprefixer data
110  */
111 module.exports.data = {
112     browsers: require('caniuse-lite').agents,
113     prefixes: require('../data/prefixes')
114 };
115
116 /**
117  * Autoprefixer default browsers
118  */
119 module.exports.defaults = browserslist.defaults;
120
121 /**
122  * Inspect with default Autoprefixer
123  */
124 module.exports.info = function () {
125     return module.exports().info();
126 };