diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/autoprefixer/lib/autoprefixer.js | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/autoprefixer/lib/autoprefixer.js')
| -rw-r--r-- | node_modules/autoprefixer/lib/autoprefixer.js | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/node_modules/autoprefixer/lib/autoprefixer.js b/node_modules/autoprefixer/lib/autoprefixer.js new file mode 100644 index 00000000..581d372b --- /dev/null +++ b/node_modules/autoprefixer/lib/autoprefixer.js @@ -0,0 +1,131 @@ +'use strict'; + +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; }; + +var browserslist = require('browserslist'); +var postcss = require('postcss'); + +var Browsers = require('./browsers'); +var Prefixes = require('./prefixes'); + +function isPlainObject(obj) { + return Object.prototype.toString.apply(obj) === '[object Object]'; +} + +var cache = {}; + +function timeCapsule(result, prefixes) { + if (prefixes.browsers.selected.length === 0) { + return; + } + if (prefixes.add.selectors.length > 0) { + return; + } + if (Object.keys(prefixes.add).length > 2) { + return; + } + + /* istanbul ignore next */ + result.warn('Greetings, time traveller. ' + 'We are in the golden age of prefix-less CSS, ' + 'where Autoprefixer is no longer needed for your stylesheet.'); +} + +module.exports = postcss.plugin('autoprefixer', function () { + for (var _len = arguments.length, reqs = Array(_len), _key = 0; _key < _len; _key++) { + reqs[_key] = arguments[_key]; + } + + var options = void 0; + if (reqs.length === 1 && isPlainObject(reqs[0])) { + options = reqs[0]; + reqs = undefined; + } else if (reqs.length === 0 || reqs.length === 1 && !reqs[0]) { + reqs = undefined; + } else if (reqs.length <= 2 && (reqs[0] instanceof Array || !reqs[0])) { + options = reqs[1]; + reqs = reqs[0]; + } else if (_typeof(reqs[reqs.length - 1]) === 'object') { + options = reqs.pop(); + } + + if (!options) { + options = {}; + } + + if (options.browser) { + throw new Error('Change `browser` option to `browsers` in Autoprefixer'); + } else if (options.browserslist) { + throw new Error('Change `browserslist` option to `browsers` in Autoprefixer'); + } + + if (options.browsers) { + reqs = options.browsers; + } + + if (typeof options.grid === 'undefined') { + options.grid = false; + } + + var brwlstOpts = { + ignoreUnknownVersions: options.ignoreUnknownVersions, + stats: options.stats + }; + + var loadPrefixes = function loadPrefixes(opts) { + var data = module.exports.data; + var browsers = new Browsers(data.browsers, reqs, opts, brwlstOpts); + var key = browsers.selected.join(', ') + JSON.stringify(options); + + if (!cache[key]) { + cache[key] = new Prefixes(data.prefixes, browsers, options); + } + + return cache[key]; + }; + + var plugin = function plugin(css, result) { + var prefixes = loadPrefixes({ + from: css.source && css.source.input.file, + env: options.env + }); + timeCapsule(result, prefixes); + if (options.remove !== false) { + prefixes.processor.remove(css, result); + } + if (options.add !== false) { + prefixes.processor.add(css, result); + } + }; + + plugin.options = options; + + plugin.browsers = reqs; + + plugin.info = function (opts) { + opts = opts || {}; + opts.from = opts.from || process.cwd(); + + return require('./info')(loadPrefixes(opts)); + }; + + return plugin; +}); + +/** + * Autoprefixer data + */ +module.exports.data = { + browsers: require('caniuse-lite').agents, + prefixes: require('../data/prefixes') +}; + +/** + * Autoprefixer default browsers + */ +module.exports.defaults = browserslist.defaults; + +/** + * Inspect with default Autoprefixer + */ +module.exports.info = function () { + return module.exports().info(); +};
\ No newline at end of file |
