No Description

prefixer.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. (function() {
  2. var Browsers, Prefixer, clone, utils, vendor,
  3. hasProp = {}.hasOwnProperty;
  4. Browsers = require('./browsers');
  5. utils = require('./utils');
  6. vendor = require('postcss/lib/vendor');
  7. clone = function(obj, parent) {
  8. var cloned, i, value;
  9. cloned = new obj.constructor();
  10. for (i in obj) {
  11. if (!hasProp.call(obj, i)) continue;
  12. value = obj[i];
  13. if (i === 'parent' && typeof value === 'object') {
  14. if (parent) {
  15. cloned[i] = parent;
  16. }
  17. } else if (i === 'source') {
  18. cloned[i] = value;
  19. } else if (value instanceof Array) {
  20. cloned[i] = value.map(function(i) {
  21. return clone(i, cloned);
  22. });
  23. } else if (i !== '_autoprefixerPrefix' && i !== '_autoprefixerValues') {
  24. if (typeof value === 'object') {
  25. value = clone(value, cloned);
  26. }
  27. cloned[i] = value;
  28. }
  29. }
  30. return cloned;
  31. };
  32. Prefixer = (function() {
  33. Prefixer.hack = function(klass) {
  34. var j, len, name, ref, results;
  35. this.hacks || (this.hacks = {});
  36. ref = klass.names;
  37. results = [];
  38. for (j = 0, len = ref.length; j < len; j++) {
  39. name = ref[j];
  40. results.push(this.hacks[name] = klass);
  41. }
  42. return results;
  43. };
  44. Prefixer.load = function(name, prefixes, all) {
  45. var klass, ref;
  46. klass = (ref = this.hacks) != null ? ref[name] : void 0;
  47. if (klass) {
  48. return new klass(name, prefixes, all);
  49. } else {
  50. return new this(name, prefixes, all);
  51. }
  52. };
  53. Prefixer.clone = function(node, overrides) {
  54. var cloned, name;
  55. cloned = clone(node);
  56. for (name in overrides) {
  57. cloned[name] = overrides[name];
  58. }
  59. return cloned;
  60. };
  61. function Prefixer(name1, prefixes1, all1) {
  62. this.name = name1;
  63. this.prefixes = prefixes1;
  64. this.all = all1;
  65. }
  66. Prefixer.prototype.parentPrefix = function(node) {
  67. var prefix;
  68. prefix = node._autoprefixerPrefix != null ? node._autoprefixerPrefix : node.type === 'decl' && node.prop[0] === '-' ? vendor.prefix(node.prop) : node.type === 'root' ? false : node.type === 'rule' && node.selector.indexOf(':-') !== -1 ? node.selector.match(/:(-\w+-)/)[1] : node.type === 'atrule' && node.name[0] === '-' ? vendor.prefix(node.name) : this.parentPrefix(node.parent);
  69. if (Browsers.prefixes().indexOf(prefix) === -1) {
  70. prefix = false;
  71. }
  72. return node._autoprefixerPrefix = prefix;
  73. };
  74. Prefixer.prototype.process = function(node) {
  75. var added, j, k, len, len1, parent, prefix, prefixes, ref;
  76. if (!this.check(node)) {
  77. return;
  78. }
  79. parent = this.parentPrefix(node);
  80. prefixes = [];
  81. ref = this.prefixes;
  82. for (j = 0, len = ref.length; j < len; j++) {
  83. prefix = ref[j];
  84. if (parent && parent !== utils.removeNote(prefix)) {
  85. continue;
  86. }
  87. prefixes.push(prefix);
  88. }
  89. added = [];
  90. for (k = 0, len1 = prefixes.length; k < len1; k++) {
  91. prefix = prefixes[k];
  92. if (this.add(node, prefix, added.concat([prefix]))) {
  93. added.push(prefix);
  94. }
  95. }
  96. return added;
  97. };
  98. Prefixer.prototype.clone = function(node, overrides) {
  99. return Prefixer.clone(node, overrides);
  100. };
  101. return Prefixer;
  102. })();
  103. module.exports = Prefixer;
  104. }).call(this);