1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.init = void 0;
|
4 | var common_1 = require("../common");
|
5 | function init() {
|
6 | var importStylesheet = function (url) {
|
7 | if (!common_1.is.browser) {
|
8 | return res;
|
9 | }
|
10 | if (exists('style', url)) {
|
11 | return res;
|
12 | }
|
13 | var head = document.head;
|
14 | var style = document.createElement('style');
|
15 | style.type = 'text/css';
|
16 | var css = "@import url('" + url + "')";
|
17 | style.dataset.url = url;
|
18 | style.appendChild(document.createTextNode(css));
|
19 | head.appendChild(style);
|
20 | return res;
|
21 | };
|
22 | var res = {
|
23 | importStylesheet: importStylesheet,
|
24 | };
|
25 | return res;
|
26 | }
|
27 | exports.init = init;
|
28 | function exists(tag, url) {
|
29 | return common_1.is.browser ? Boolean(findByUrl(tag, url)) : false;
|
30 | }
|
31 | function findByUrl(tag, url) {
|
32 | if (common_1.is.browser) {
|
33 | var items = Array.from(document.getElementsByTagName(tag));
|
34 | return items.find(function (style) { return style.dataset.url === url; });
|
35 | }
|
36 | else {
|
37 | return undefined;
|
38 | }
|
39 | }
|