autoprefixer.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. (function() {
  2. var Autoprefixer, Browsers, Prefixes, autoprefixer, browserslist, infoCache, isPlainObject, postcss,
  3. __slice = [].slice,
  4. __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  5. browserslist = require('browserslist');
  6. postcss = require('postcss');
  7. Browsers = require('./browsers');
  8. Prefixes = require('./prefixes');
  9. infoCache = null;
  10. isPlainObject = function(obj) {
  11. return Object.prototype.toString.apply(obj) === '[object Object]';
  12. };
  13. autoprefixer = function() {
  14. var options, reqs;
  15. reqs = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
  16. if (reqs.length === 1 && isPlainObject(reqs[0])) {
  17. options = reqs[0];
  18. reqs = void 0;
  19. } else if (reqs.length === 0 || (reqs.length === 1 && (reqs[0] == null))) {
  20. reqs = void 0;
  21. } else if (reqs.length <= 2 && (reqs[0] instanceof Array || (reqs[0] == null))) {
  22. options = reqs[1];
  23. reqs = reqs[0];
  24. } else if (typeof reqs[reqs.length - 1] === 'object') {
  25. options = reqs.pop();
  26. }
  27. if ((options != null ? options.browsers : void 0) != null) {
  28. reqs = options.browsers;
  29. }
  30. return new Autoprefixer(autoprefixer.data, reqs, options);
  31. };
  32. autoprefixer.data = {
  33. browsers: require('caniuse-db/data').agents,
  34. prefixes: require('../data/prefixes')
  35. };
  36. Autoprefixer = (function() {
  37. function Autoprefixer(_at_data, _at_reqs, _at_options) {
  38. this.data = _at_data;
  39. this.reqs = _at_reqs;
  40. this.options = _at_options != null ? _at_options : {};
  41. this.postcss = __bind(this.postcss, this);
  42. }
  43. Autoprefixer.prototype.process = function(str, options) {
  44. if (options == null) {
  45. options = {};
  46. }
  47. return postcss(this.postcss).process(str, options);
  48. };
  49. Autoprefixer.prototype.postcss = function(css) {
  50. var prefixes;
  51. prefixes = this.prefixes({
  52. from: css.source.input.file
  53. });
  54. if (this.options.remove !== false) {
  55. prefixes.processor.remove(css);
  56. }
  57. return prefixes.processor.add(css);
  58. };
  59. Autoprefixer.prototype.prefixes = function(opts) {
  60. var browsers;
  61. browsers = new Browsers(autoprefixer.data.browsers, this.reqs, opts);
  62. return new Prefixes(autoprefixer.data.prefixes, browsers, this.options);
  63. };
  64. Autoprefixer.prototype.info = function(opts) {
  65. infoCache || (infoCache = require('./info'));
  66. return infoCache(this.prefixes(opts));
  67. };
  68. return Autoprefixer;
  69. })();
  70. autoprefixer.defaults = browserslist.defaults;
  71. autoprefixer.loadDefault = function() {
  72. return this.defaultCache || (this.defaultCache = autoprefixer());
  73. };
  74. autoprefixer.process = function(str, options) {
  75. if (options == null) {
  76. options = {};
  77. }
  78. return this.loadDefault().process(str, options);
  79. };
  80. autoprefixer.postcss = function(css) {
  81. return autoprefixer.loadDefault().postcss(css);
  82. };
  83. autoprefixer.info = function() {
  84. return this.loadDefault().info();
  85. };
  86. module.exports = autoprefixer;
  87. }).call(this);