Blame view

node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/_Declaration.js 1.81 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
  // Generated by CoffeeScript 1.9.3
  var _Declaration;
  
  module.exports = _Declaration = (function() {
    var self;
  
    self = _Declaration;
  
    _Declaration.importantClauseRx = /(\s\!important)$/;
  
    _Declaration.setOnto = function(declarations, prop, val) {
      var dec;
      if (!(dec = declarations[prop])) {
        return declarations[prop] = new this(prop, val);
      } else {
        return dec.set(val);
      }
    };
  
    _Declaration.sanitizeValue = function(val) {
      return String(val).trim().replace(/[\s]+/g, ' ');
    };
  
    _Declaration.inheritAllowed = false;
  
    function _Declaration(prop1, val) {
      this.prop = prop1;
      this.important = false;
      this.set(val);
    }
  
    _Declaration.prototype.get = function() {
      return this._get();
    };
  
    _Declaration.prototype._get = function() {
      return this.val;
    };
  
    _Declaration.prototype._pickImportantClause = function(val) {
      if (self.importantClauseRx.test(String(val))) {
        this.important = true;
        return val.replace(self.importantClauseRx, '');
      } else {
        this.important = false;
        return val;
      }
    };
  
    _Declaration.prototype.set = function(val) {
      val = self.sanitizeValue(val);
      val = this._pickImportantClause(val);
      val = val.trim();
      if (this._handleNullOrInherit(val)) {
        return this;
      }
      this._set(val);
      return this;
    };
  
    _Declaration.prototype._set = function(val) {
      return this.val = val;
    };
  
    _Declaration.prototype._handleNullOrInherit = function(val) {
      if (val === '') {
        this.val = '';
        return true;
      }
      if (val === 'inherit') {
        if (this.constructor.inheritAllowed) {
          this.val = 'inherit';
        } else {
          throw Error("Inherit is not allowed for `" + this.prop + "`");
        }
        return true;
      } else {
        return false;
      }
    };
  
    return _Declaration;
  
  })();