3bd536e62a79d5f2488554467d969e2cdcb8b75220e7b56635a5ef1753b22eac9d4a19e49538fda450d0d161c6577a2ddab6a68126d126cbdd832c563a3c1a 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _postcss = require('postcss');
  4. var _postcss2 = _interopRequireDefault(_postcss);
  5. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  6. exports.default = _postcss2.default.plugin('postcss-filter-plugins', function () {
  7. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  8. _ref$template = _ref.template,
  9. template = _ref$template === undefined ? function (_ref2) {
  10. var postcssPlugin = _ref2.postcssPlugin;
  11. return 'Found duplicate plugin: ' + postcssPlugin;
  12. } : _ref$template,
  13. _ref$silent = _ref.silent,
  14. silent = _ref$silent === undefined ? false : _ref$silent,
  15. _ref$exclude = _ref.exclude,
  16. exclude = _ref$exclude === undefined ? [] : _ref$exclude,
  17. _ref$direction = _ref.direction,
  18. direction = _ref$direction === undefined ? 'both' : _ref$direction;
  19. var id = Math.random().toString();
  20. var prev = void 0,
  21. next = void 0,
  22. both = void 0;
  23. switch (direction) {
  24. case 'both':
  25. both = true;
  26. break;
  27. case 'backward':
  28. prev = true;
  29. break;
  30. case 'forward':
  31. next = true;
  32. break;
  33. }
  34. var processor = function processor(css, result) {
  35. var previousPlugins = [];
  36. var nextPlugins = [];
  37. var bothPlugins = [];
  38. var filter = false;
  39. var position = 0;
  40. var detect = function detect(list, plugin) {
  41. var name = plugin.postcssPlugin;
  42. if (typeof name === 'undefined') {
  43. position++;
  44. return;
  45. }
  46. if (~list.indexOf(name)) {
  47. if (!silent) {
  48. result.warn(template(plugin));
  49. }
  50. result.processor.plugins.splice(position, 1);
  51. } else {
  52. list.push(name);
  53. position++;
  54. }
  55. };
  56. while (position < result.processor.plugins.length) {
  57. var plugin = result.processor.plugins[position];
  58. if (~exclude.indexOf(plugin.postcssPlugin)) {
  59. position++;
  60. continue;
  61. }
  62. if (plugin._id === id) {
  63. position++;
  64. filter = true;
  65. continue;
  66. } else if (plugin.postcssPlugin === 'postcss-filter-plugins') {
  67. position++;
  68. continue;
  69. }
  70. if (both) {
  71. detect(bothPlugins, plugin);
  72. continue;
  73. }
  74. if (filter && next) {
  75. detect(nextPlugins, plugin);
  76. continue;
  77. }
  78. if (!filter && prev) {
  79. detect(previousPlugins, plugin);
  80. continue;
  81. }
  82. position++;
  83. }
  84. };
  85. processor._id = id;
  86. return processor;
  87. });
  88. module.exports = exports['default'];