-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
pipe.js
57 lines (46 loc) · 1.73 KB
/
pipe.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
var addonCssom = require('./cssom').addon;
exports.addon = function (renderer) {
if (!renderer.putRule) {
addonCssom(renderer);
}
if (process.env.NODE_ENV !== 'production') {
require('./__dev__/warnOnMissingDependencies')('pipe', renderer, ['putRule']);
}
var counter = 0;
renderer.pipe = function () {
var rules = {};
var className = renderer.pfx + 'pipe-' + (counter++).toString(36);
var attr = 'data-' + className;
var scope1 = '.' + className;
var scope2 = '[' + attr + ']';
var obj = {
attr: attr,
className: className,
css: function (css) {
for (var selectorTemplate in css) {
var declarations = css[selectorTemplate];
var rule = rules[selectorTemplate];
if (!rule) {
var selector = selectorTemplate.replace('&', scope1) + ',' + selectorTemplate.replace('&', scope2);
rules[selectorTemplate] = rule = renderer.putRule(selector);
}
for (var prop in declarations)
rule.style.setProperty(prop, declarations[prop]);
}
// GC
for (var selectorTemplate2 in rules) {
if (!(selectorTemplate2 in css)) {
rules[selectorTemplate2].remove();
delete rules[selectorTemplate2];
}
}
},
remove: function () {
for (var selectorTemplate in rules)
rules[selectorTemplate].remove();
}
};
return obj;
};
};