UNPKG

@bookbox/view-html

Version:

Bookbox view for html

40 lines (39 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCssApiForList = exports.getBrowserCssApi = exports.applyCss = void 0; function applyCss(text) { const cssNode = document.createElement('style'); cssNode.appendChild(document.createTextNode(text)); document.head.appendChild(cssNode); return cssNode; } exports.applyCss = applyCss; 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); }, }); } exports.getBrowserCssApi = getBrowserCssApi; function getCssApiForList(list) { const set = () => { list.forEach(api => api()); }; return Object.assign(set, { remove: () => { list.forEach(api => api.remove()); }, }); } exports.getCssApiForList = getCssApiForList;