Skip to content

Commit

Permalink
feat: expose .sheet property
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 17, 2018
1 parent f59bbe9 commit 4b4a32d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
8 changes: 1 addition & 7 deletions addon/keyframes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ exports.addon = function (renderer) {
}

var putAtrule = renderer.putAtrule;
var stylesheet;

if (renderer.client) {
stylesheet = document.createElement('style');
document.head.appendChild(stylesheet);
}

renderer.putAtrule = function (__, keyframes, prelude) {
// @keyframes
Expand All @@ -31,7 +25,7 @@ exports.addon = function (renderer) {
str = prelude + '{' + str + '}';

if (renderer.client) {
stylesheet.appendChild(document.createTextNode(str));
renderer.sheet.appendChild(document.createTextNode(str));
} else {
renderer.raw += str;
}
Expand Down
15 changes: 4 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,21 @@ exports.create = function (config) {
}
}, config);

var sheet, stylesheet;

if (renderer.client) {
if (process.env.NODE_ENV === 'production') {
sheet = document.head.appendChild(document.createElement('style')).sheet;
} else {
stylesheet = document.createElement('style');
document.head.appendChild(stylesheet);
}
document.head.appendChild(renderer.sheet = document.createElement('style'));

renderer.putRaw = function (rawCssRule) {
if (process.env.NODE_ENV === 'production') {
sheet.insertRule(rawCssRule, 0);
renderer.sheet.insertRule(rawCssRule, 0);
} else {
try {
stylesheet.sheet.insertRule(rawCssRule, 0);
renderer.sheet.sheet.insertRule(rawCssRule, 0);
} catch (error) {
// eslint-disable-next-line
console.info('Could not insert CSS rule.');
console.error(error);

stylesheet.appendChild(document.createTextNode(rawCssRule));
renderer.sheet.appendChild(document.createTextNode(rawCssRule));
}
}
};
Expand Down

0 comments on commit 4b4a32d

Please sign in to comment.