-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.js
39 lines (33 loc) · 984 Bytes
/
index.js
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
var cascade = require('./cascade');
var registerClass = require('./registerClass');
var styleRuleConverter = require('./styleRuleConverter');
var global = Function("return this")();
global.__RCSS_0_registry = global.__RCSS_0_registry || {};
function descriptorsToString(styleDescriptor) {
return styleRuleConverter.rulesToString(
styleDescriptor.className,
styleDescriptor.style
);
}
var RCSS = {
cascade: cascade,
registerClass: registerClass,
injectAll: function() {
var tag = document.createElement('style');
tag.innerHTML = RCSS.getStylesString();
document.getElementsByTagName('head')[0].appendChild(tag);
},
getStylesString: function() {
var registry = global.__RCSS_0_registry;
var str = '';
for (var key in registry) {
if (!registry.hasOwnProperty(key)) {
continue;
}
str += descriptorsToString(registry[key]);
}
global.__RCSS_0_registry = {};
return str;
}
};
module.exports = RCSS;