Styles.js
1.73 KB
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
// Generated by CoffeeScript 1.9.3
var MixedDeclarationSet, StyleSheet, Styles, terminalWidth;
StyleSheet = require('./styles/StyleSheet');
MixedDeclarationSet = require('./styles/rule/MixedDeclarationSet');
terminalWidth = require('../tools').getCols();
module.exports = Styles = (function() {
var self;
self = Styles;
Styles.defaultRules = {
'*': {
display: 'inline'
},
'body': {
background: 'none',
color: 'white',
display: 'block',
width: terminalWidth + ' !important'
}
};
function Styles() {
this._defaultStyles = new StyleSheet;
this._userStyles = new StyleSheet;
this._setDefaultStyles();
}
Styles.prototype._setDefaultStyles = function() {
this._defaultStyles.setRule(self.defaultRules);
};
Styles.prototype.setRule = function(selector, rules) {
this._userStyles.setRule.apply(this._userStyles, arguments);
return this;
};
Styles.prototype.getStyleFor = function(el) {
var styles;
styles = el.styles;
if (styles == null) {
el.styles = styles = this._getComputedStyleFor(el);
}
return styles;
};
Styles.prototype._getRawStyleFor = function(el) {
var def, user;
def = this._defaultStyles.getRulesFor(el);
user = this._userStyles.getRulesFor(el);
return MixedDeclarationSet.mix(def, user).toObject();
};
Styles.prototype._getComputedStyleFor = function(el) {
var decs, parent, prop, ref, val;
decs = {};
parent = el.parent;
ref = this._getRawStyleFor(el);
for (prop in ref) {
val = ref[prop];
if (val !== 'inherit') {
decs[prop] = val;
} else {
throw Error("Inherited styles are not supported yet.");
}
}
return decs;
};
return Styles;
})();