No Description

value.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. (function() {
  2. var OldValue, Prefixer, Value, utils, vendor,
  3. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  4. hasProp = {}.hasOwnProperty;
  5. Prefixer = require('./prefixer');
  6. OldValue = require('./old-value');
  7. utils = require('./utils');
  8. vendor = require('postcss/lib/vendor');
  9. Value = (function(superClass) {
  10. extend(Value, superClass);
  11. function Value() {
  12. return Value.__super__.constructor.apply(this, arguments);
  13. }
  14. Value.save = function(prefixes, decl) {
  15. var already, cloned, prefix, prefixed, propPrefix, ref, results, rule, trimmed, value;
  16. ref = decl._autoprefixerValues;
  17. results = [];
  18. for (prefix in ref) {
  19. value = ref[prefix];
  20. if (value === decl.value) {
  21. continue;
  22. }
  23. propPrefix = vendor.prefix(decl.prop);
  24. if (propPrefix === prefix) {
  25. results.push(decl.value = value);
  26. } else if (propPrefix === '-pie-') {
  27. continue;
  28. } else {
  29. prefixed = prefixes.prefixed(decl.prop, prefix);
  30. rule = decl.parent;
  31. if (rule.every(function(i) {
  32. return i.prop !== prefixed;
  33. })) {
  34. trimmed = value.replace(/\s+/, ' ');
  35. already = rule.some(function(i) {
  36. return i.prop === decl.prop && i.value.replace(/\s+/, ' ') === trimmed;
  37. });
  38. if (!already) {
  39. if (value.indexOf('-webkit-filter') !== -1 && (decl.prop === 'transition' || decl.prop === 'trasition-property')) {
  40. results.push(decl.value = value);
  41. } else {
  42. cloned = this.clone(decl, {
  43. value: value
  44. });
  45. results.push(decl.parent.insertBefore(decl, cloned));
  46. }
  47. } else {
  48. results.push(void 0);
  49. }
  50. } else {
  51. results.push(void 0);
  52. }
  53. }
  54. }
  55. return results;
  56. };
  57. Value.prototype.check = function(decl) {
  58. var value;
  59. value = decl.value;
  60. if (value.indexOf(this.name) !== -1) {
  61. return !!value.match(this.regexp());
  62. } else {
  63. return false;
  64. }
  65. };
  66. Value.prototype.regexp = function() {
  67. return this.regexpCache || (this.regexpCache = utils.regexp(this.name));
  68. };
  69. Value.prototype.replace = function(string, prefix) {
  70. return string.replace(this.regexp(), '$1' + prefix + '$2');
  71. };
  72. Value.prototype.add = function(decl, prefix) {
  73. var ref, value;
  74. decl._autoprefixerValues || (decl._autoprefixerValues = {});
  75. value = decl._autoprefixerValues[prefix] || ((ref = decl._value) != null ? ref.raw : void 0) || decl.value;
  76. value = this.replace(value, prefix);
  77. if (value) {
  78. return decl._autoprefixerValues[prefix] = value;
  79. }
  80. };
  81. Value.prototype.old = function(prefix) {
  82. return new OldValue(this.name, prefix + this.name);
  83. };
  84. return Value;
  85. })(Prefixer);
  86. module.exports = Value;
  87. }).call(this);