@bookbox/view-html
Version:
Bookbox view for html
39 lines (38 loc) • 981 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyCss = applyCss;
exports.getBrowserCssApi = getBrowserCssApi;
exports.getCssApiForList = getCssApiForList;
function applyCss(text) {
const cssNode = document.createElement('style');
cssNode.appendChild(document.createTextNode(text));
document.head.appendChild(cssNode);
return cssNode;
}
function getBrowserCssApi(text) {
let added = false;
let node;
const set = () => {
if (added)
return;
node = applyCss(text);
added = true;
};
return Object.assign(set, {
remove: () => {
if (!node)
return;
document.head.removeChild(node);
},
});
}
function getCssApiForList(list) {
const set = () => {
list.forEach(api => api());
};
return Object.assign(set, {
remove: () => {
list.forEach(api => api.remove());
},
});
}