UNPKG

@tdb/util

Version:
32 lines (31 loc) 948 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var constants_1 = require("../../constants"); function importStylesheet(url) { if (!constants_1.IS_BROWSER) { return; } if (exists('style', url)) { return; } var head = document.head; var style = document.createElement('style'); style.type = 'text/css'; var css = "@import url('" + url + "')"; style.dataset.url = url; style.appendChild(document.createTextNode(css)); head.appendChild(style); } exports.importStylesheet = importStylesheet; function exists(tag, url) { return constants_1.IS_BROWSER ? Boolean(findByUrl(tag, url)) : false; } function findByUrl(tag, url) { if (constants_1.IS_BROWSER) { var items = Array.from(document.getElementsByTagName(tag)); return items.find(function (style) { return style.dataset.url === url; }); } else { return undefined; } }