Blame view

node_modules/autoprefixer/lib/prefixer.js 3.45 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
109
110
111
112
113
114
115
116
117
118
119
120
121
  (function() {
    var Browsers, Prefixer, clone, utils, vendor,
      hasProp = {}.hasOwnProperty;
  
    Browsers = require('./browsers');
  
    utils = require('./utils');
  
    vendor = require('postcss/lib/vendor');
  
    clone = function(obj, parent) {
      var cloned, i, value;
      cloned = new obj.constructor();
      for (i in obj) {
        if (!hasProp.call(obj, i)) continue;
        value = obj[i];
        if (i === 'parent' && typeof value === 'object') {
          if (parent) {
            cloned[i] = parent;
          }
        } else if (i === 'source') {
          cloned[i] = value;
        } else if (i === null) {
          cloned[i] = value;
        } else if (value instanceof Array) {
          cloned[i] = value.map(function(i) {
            return clone(i, cloned);
          });
        } else if (i !== '_autoprefixerPrefix' && i !== '_autoprefixerValues') {
          if (typeof value === 'object' && value !== null) {
            value = clone(value, cloned);
          }
          cloned[i] = value;
        }
      }
      return cloned;
    };
  
    Prefixer = (function() {
      Prefixer.hack = function(klass) {
        var j, len, name, ref, results;
        this.hacks || (this.hacks = {});
        ref = klass.names;
        results = [];
        for (j = 0, len = ref.length; j < len; j++) {
          name = ref[j];
          results.push(this.hacks[name] = klass);
        }
        return results;
      };
  
      Prefixer.load = function(name, prefixes, all) {
        var klass, ref;
        klass = (ref = this.hacks) != null ? ref[name] : void 0;
        if (klass) {
          return new klass(name, prefixes, all);
        } else {
          return new this(name, prefixes, all);
        }
      };
  
      Prefixer.clone = function(node, overrides) {
        var cloned, name;
        cloned = clone(node);
        for (name in overrides) {
          cloned[name] = overrides[name];
        }
        return cloned;
      };
  
      function Prefixer(name1, prefixes1, all1) {
        this.name = name1;
        this.prefixes = prefixes1;
        this.all = all1;
      }
  
      Prefixer.prototype.parentPrefix = function(node) {
        var prefix;
        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 && /:(-\w+-)/.test(node.selector) ? node.selector.match(/:(-\w+-)/)[1] : node.type === 'atrule' && node.name[0] === '-' ? vendor.prefix(node.name) : this.parentPrefix(node.parent);
        if (Browsers.prefixes().indexOf(prefix) === -1) {
          prefix = false;
        }
        return node._autoprefixerPrefix = prefix;
      };
  
      Prefixer.prototype.process = function(node) {
        var added, j, k, len, len1, parent, prefix, prefixes, ref;
        if (!this.check(node)) {
          return;
        }
        parent = this.parentPrefix(node);
        prefixes = [];
        ref = this.prefixes;
        for (j = 0, len = ref.length; j < len; j++) {
          prefix = ref[j];
          if (parent && parent !== utils.removeNote(prefix)) {
            continue;
          }
          prefixes.push(prefix);
        }
        added = [];
        for (k = 0, len1 = prefixes.length; k < len1; k++) {
          prefix = prefixes[k];
          if (this.add(node, prefix, added.concat([prefix]))) {
            added.push(prefix);
          }
        }
        return added;
      };
  
      Prefixer.prototype.clone = function(node, overrides) {
        return Prefixer.clone(node, overrides);
      };
  
      return Prefixer;
  
    })();
  
    module.exports = Prefixer;
  
  }).call(this);