Blame view

node_modules/autoprefixer/lib/value.js 3.14 KB
ce4c83ff   wxy   初始提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  (function() {
    var OldValue, Prefixer, Value, utils, vendor,
      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; },
      hasProp = {}.hasOwnProperty;
  
    Prefixer = require('./prefixer');
  
    OldValue = require('./old-value');
  
    utils = require('./utils');
  
    vendor = require('postcss/lib/vendor');
  
    Value = (function(superClass) {
      extend(Value, superClass);
  
      function Value() {
        return Value.__super__.constructor.apply(this, arguments);
      }
  
      Value.save = function(prefixes, decl) {
        var already, cloned, prefix, prefixed, prop, propPrefix, ref, results, rule, trimmed, value;
        prop = decl.prop;
        ref = decl._autoprefixerValues;
        results = [];
        for (prefix in ref) {
          value = ref[prefix];
          if (value === decl.value) {
            continue;
          }
          propPrefix = vendor.prefix(prop);
          if (propPrefix === prefix) {
            results.push(decl.value = value);
          } else if (propPrefix === '-pie-') {
            continue;
          } else {
            prefixed = prefixes.prefixed(prop, prefix);
            rule = decl.parent;
            if (rule.every(function(i) {
              return i.prop !== prefixed;
            })) {
              trimmed = value.replace(/\s+/, ' ');
              already = rule.some(function(i) {
                return i.prop === decl.prop && i.value.replace(/\s+/, ' ') === trimmed;
              });
              if (!already) {
                cloned = this.clone(decl, {
                  value: value
                });
                results.push(decl.parent.insertBefore(decl, cloned));
              } else {
                results.push(void 0);
              }
            } else {
              results.push(void 0);
            }
          }
        }
        return results;
      };
  
      Value.prototype.check = function(decl) {
        var value;
        value = decl.value;
        if (value.indexOf(this.name) !== -1) {
          return !!value.match(this.regexp());
        } else {
          return false;
        }
      };
  
      Value.prototype.regexp = function() {
        return this.regexpCache || (this.regexpCache = utils.regexp(this.name));
      };
  
      Value.prototype.replace = function(string, prefix) {
        return string.replace(this.regexp(), '$1' + prefix + '$2');
      };
  
      Value.prototype.value = function(decl) {
        if (decl.raws.value && decl.raws.value.value === decl.value) {
          return decl.raws.value.raw;
        } else {
          return decl.value;
        }
      };
  
      Value.prototype.add = function(decl, prefix) {
        var value;
        decl._autoprefixerValues || (decl._autoprefixerValues = {});
        value = decl._autoprefixerValues[prefix] || this.value(decl);
        value = this.replace(value, prefix);
        if (value) {
          return decl._autoprefixerValues[prefix] = value;
        }
      };
  
      Value.prototype.old = function(prefix) {
        return new OldValue(this.name, prefix + this.name);
      };
  
      return Value;
  
    })(Prefixer);
  
    module.exports = Value;
  
  }).call(this);