No Description

autoprefixer.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. (function() {
  2. var Browsers, Prefixes, browserslist, cache, isPlainObject, postcss,
  3. slice = [].slice;
  4. browserslist = require('browserslist');
  5. postcss = require('postcss');
  6. Browsers = require('./browsers');
  7. Prefixes = require('./prefixes');
  8. isPlainObject = function(obj) {
  9. return Object.prototype.toString.apply(obj) === '[object Object]';
  10. };
  11. cache = {};
  12. module.exports = postcss.plugin('autoprefixer', function() {
  13. var loadPrefixes, options, plugin, reqs;
  14. reqs = 1 <= arguments.length ? slice.call(arguments, 0) : [];
  15. if (reqs.length === 1 && isPlainObject(reqs[0])) {
  16. options = reqs[0];
  17. reqs = void 0;
  18. } else if (reqs.length === 0 || (reqs.length === 1 && (reqs[0] == null))) {
  19. reqs = void 0;
  20. } else if (reqs.length <= 2 && (reqs[0] instanceof Array || (reqs[0] == null))) {
  21. options = reqs[1];
  22. reqs = reqs[0];
  23. } else if (typeof reqs[reqs.length - 1] === 'object') {
  24. options = reqs.pop();
  25. }
  26. options || (options = {});
  27. if (options.browsers != null) {
  28. reqs = options.browsers;
  29. }
  30. loadPrefixes = function(opts) {
  31. var browsers, key;
  32. browsers = new Browsers(module.exports.data.browsers, reqs, opts);
  33. key = browsers.selected.join(', ') + options.cascade;
  34. return cache[key] || (cache[key] = new Prefixes(module.exports.data.prefixes, browsers, options));
  35. };
  36. plugin = function(css, result) {
  37. var prefixes;
  38. prefixes = loadPrefixes({
  39. from: css.source.input.file
  40. });
  41. if (options.remove !== false) {
  42. prefixes.processor.remove(css);
  43. }
  44. if (options.add !== false) {
  45. return prefixes.processor.add(css, result);
  46. }
  47. };
  48. plugin.options = options;
  49. plugin.process = function(str, options) {
  50. if (options == null) {
  51. options = {};
  52. }
  53. if (typeof console !== "undefined" && console !== null) {
  54. if (typeof console.warn === "function") {
  55. console.warn('Autoprefixer\'s process() method is deprecated ' + 'and will removed in next major release. ' + 'Use postcss([autoprefixer]).process() instead');
  56. }
  57. }
  58. return postcss(plugin).process(str, options);
  59. };
  60. plugin.info = function(opts) {
  61. return require('./info')(loadPrefixes(opts));
  62. };
  63. return plugin;
  64. });
  65. module.exports.data = {
  66. browsers: require('caniuse-db/data').agents,
  67. prefixes: require('../data/prefixes')
  68. };
  69. module.exports.defaults = browserslist.defaults;
  70. module.exports.process = function(css, options) {
  71. return module.exports().process(css, options);
  72. };
  73. module.exports.info = function() {
  74. return module.exports().info();
  75. };
  76. }).call(this);