@platform/css
Version:
Helpers for working with inline CSS.
40 lines (39 loc) • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
var common_1 = require("../common");
function init() {
var importStylesheet = function (url) {
if (!common_1.is.browser) {
return res;
}
if (exists('style', url)) {
return res;
}
var head = document.head;
var style = document.createElement('style');
style.type = 'text/css';
var css = "@import url('".concat(url, "')");
style.dataset.url = url;
style.appendChild(document.createTextNode(css));
head.appendChild(style);
return res;
};
var res = {
importStylesheet: importStylesheet,
};
return res;
}
exports.init = init;
function exists(tag, url) {
return common_1.is.browser ? Boolean(findByUrl(tag, url)) : false;
}
function findByUrl(tag, url) {
if (common_1.is.browser) {
var items = Array.from(document.getElementsByTagName(tag));
return items.find(function (style) { return style.dataset.url === url; });
}
else {
return undefined;
}
}