-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
cssom.js
36 lines (29 loc) · 1.33 KB
/
cssom.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
'use strict';
exports.addon = function (renderer) {
// CSSOM support only browser environment.
if (!renderer.client) return;
if (process.env.NODE_ENV !== 'production') {
require('./__dev__/warnOnMissingDependencies')('cssom', renderer, ['sh']);
}
// Style sheet for media queries.
document.head.appendChild(renderer.msh = document.createElement('style'));
renderer.createRule = function (selector, prelude) {
var rawCss = selector + '{}';
if (prelude) rawCss = prelude + '{' + rawCss + '}';
var sheet = prelude ? renderer.msh.sheet : renderer.sh.sheet;
var index = sheet.insertRule(rawCss, sheet.cssRules.length);
var rule = (sheet.cssRules || sheet.rules)[index];
// Keep track of `index` where rule was inserted in the sheet. This is
// needed for rule deletion.
rule.index = index;
if (prelude) {
// If rule has media query (it has prelude), move style (CSSStyleDeclaration)
// object to the "top" to normalize it with a rule without the media
// query, so that both rules have `.style` property available.
var selectorRule = (rule.cssRules || rule.rules)[0];
rule.style = selectorRule.style;
rule.styleMap = selectorRule.styleMap;
}
return rule;
};
};