No Description

supports.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. (function() {
  2. var Prefixes, Supports, Value, findCondition, findDecl, list, postcss, split, utils;
  3. Prefixes = require('./prefixes');
  4. Value = require('./value');
  5. utils = require('./utils');
  6. postcss = require('postcss');
  7. list = require('postcss/lib/list');
  8. split = /\(\s*([^\(\):]+)\s*:([^\)]+)/;
  9. findDecl = /\(\s*([^\(\):]+)\s*:\s*(.+)\s*\)/g;
  10. findCondition = /(not\s*)?\(\s*([^\(\):]+)\s*:\s*(.+?(?!\s*or\s*).+?)\s*\)*\s*\)\s*or\s*/gi;
  11. Supports = (function() {
  12. function Supports(all1) {
  13. this.all = all1;
  14. }
  15. Supports.prototype.virtual = function(prop, value) {
  16. var rule;
  17. rule = postcss.parse('a{}').first;
  18. rule.append({
  19. prop: prop,
  20. value: value,
  21. before: ''
  22. });
  23. return rule;
  24. };
  25. Supports.prototype.prefixed = function(prop, value) {
  26. var decl, j, k, len, len1, prefixer, ref, ref1, rule;
  27. rule = this.virtual(prop, value);
  28. prefixer = this.all.add[prop];
  29. if (prefixer != null) {
  30. if (typeof prefixer.process === "function") {
  31. prefixer.process(rule.first);
  32. }
  33. }
  34. ref = rule.nodes;
  35. for (j = 0, len = ref.length; j < len; j++) {
  36. decl = ref[j];
  37. ref1 = this.all.values('add', prop);
  38. for (k = 0, len1 = ref1.length; k < len1; k++) {
  39. value = ref1[k];
  40. value.process(decl);
  41. }
  42. Value.save(this.all, decl);
  43. }
  44. return rule.nodes;
  45. };
  46. Supports.prototype.clean = function(params) {
  47. return params.replace(findCondition, (function(_this) {
  48. return function(all) {
  49. var _, check, checker, j, len, prop, ref, ref1, ref2, unprefixed, value;
  50. if (all.slice(0, 3).toLowerCase() === 'not') {
  51. return all;
  52. }
  53. ref = all.match(split), _ = ref[0], prop = ref[1], value = ref[2];
  54. unprefixed = _this.all.unprefixed(prop);
  55. if ((ref1 = _this.all.cleaner().remove[prop]) != null ? ref1.remove : void 0) {
  56. check = new RegExp('(\\(|\\s)' + utils.escapeRegexp(unprefixed) + ':');
  57. if (check.test(params)) {
  58. return '';
  59. }
  60. }
  61. ref2 = _this.all.cleaner().values('remove', unprefixed);
  62. for (j = 0, len = ref2.length; j < len; j++) {
  63. checker = ref2[j];
  64. if (checker.check(value)) {
  65. return '';
  66. }
  67. }
  68. return all;
  69. };
  70. })(this)).replace(/\(\s*\((.*)\)\s*\)/g, '($1)');
  71. };
  72. Supports.prototype.process = function(rule) {
  73. rule.params = this.clean(rule.params);
  74. return rule.params = rule.params.replace(findDecl, (function(_this) {
  75. return function(all, prop, value) {
  76. var i, stringed;
  77. stringed = (function() {
  78. var j, len, ref, results;
  79. ref = this.prefixed(prop, value);
  80. results = [];
  81. for (j = 0, len = ref.length; j < len; j++) {
  82. i = ref[j];
  83. results.push("(" + i.prop + ": " + i.value + ")");
  84. }
  85. return results;
  86. }).call(_this);
  87. if (stringed.length === 1) {
  88. return stringed[0];
  89. } else {
  90. return '(' + stringed.join(' or ') + ')';
  91. }
  92. };
  93. })(this));
  94. };
  95. return Supports;
  96. })();
  97. module.exports = Supports;
  98. }).call(this);