diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/_Declaration.js | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/_Declaration.js')
| -rw-r--r-- | node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/_Declaration.js | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/_Declaration.js b/node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/_Declaration.js new file mode 100644 index 00000000..dce27e21 --- /dev/null +++ b/node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/_Declaration.js @@ -0,0 +1,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; + +})(); |
