UNPKG

@bookbox/view-html

Version:

Bookbox view for html

34 lines (33 loc) 806 B
export function applyCss(text) { const cssNode = document.createElement('style'); cssNode.appendChild(document.createTextNode(text)); document.head.appendChild(cssNode); return cssNode; } export 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); }, }); } export function getCssApiForList(list) { const set = () => { list.forEach(api => api()); }; return Object.assign(set, { remove: () => { list.forEach(api => api.remove()); }, }); }