blob: ec929d92f840492d39f53cb3ee8d35704a9bee0a [file] [log] [blame]
Paul Lewis9950e182019-12-16 16:06:071// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Tim van der Lippeee97fa32020-04-23 15:20:565// @ts-nocheck
6// TODO(crbug.com/1011811): Enable TypeScript compiler checks
7
Tim van der Lippe5df64b22020-09-11 12:04:248import * as Root from '../../root/root.js';
Paul Lewisca569a52020-09-09 16:11:519import * as ThemeSupport from '../../theme_support/theme_support.js';
10
Paul Lewis9950e182019-12-16 16:06:0711/**
12 * @param {!Node} node
13 * @param {string} cssFile
14 * @suppressGlobalPropertiesCheck
15 */
16export function appendStyle(node, cssFile) {
Tim van der Lippe5df64b22020-09-11 12:04:2417 const content = Root.Runtime.cachedResources.get(cssFile) || '';
Paul Lewis9950e182019-12-16 16:06:0718 if (!content) {
19 console.error(cssFile + ' not preloaded. Check module.json');
20 }
21 let styleElement = createElement('style');
22 styleElement.textContent = content;
23 node.appendChild(styleElement);
24
Paul Lewisca569a52020-09-09 16:11:5125 const themeStyleSheet = ThemeSupport.ThemeSupport.instance().themeStyleSheet(cssFile, content);
Paul Lewis9950e182019-12-16 16:06:0726 if (themeStyleSheet) {
27 styleElement = createElement('style');
Tim van der Lippe5df64b22020-09-11 12:04:2428 styleElement.textContent = themeStyleSheet + '\n' + Root.Runtime.Runtime.resolveSourceURL(cssFile + '.theme');
Paul Lewis9950e182019-12-16 16:06:0729 node.appendChild(styleElement);
30 }
31}