blob: c9c5ff985314e5805fb702c5eb5598a7d697caa5 [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
Paul Lewisca569a52020-09-09 16:11:518import * as ThemeSupport from '../../theme_support/theme_support.js';
9
Paul Lewis9950e182019-12-16 16:06:0710/**
11 * @param {!Node} node
12 * @param {string} cssFile
13 * @suppressGlobalPropertiesCheck
14 */
15export function appendStyle(node, cssFile) {
Tim van der Lippe6d51bf02020-03-18 12:15:1416 const content = self.Runtime.cachedResources[cssFile] || '';
Paul Lewis9950e182019-12-16 16:06:0717 if (!content) {
18 console.error(cssFile + ' not preloaded. Check module.json');
19 }
20 let styleElement = createElement('style');
21 styleElement.textContent = content;
22 node.appendChild(styleElement);
23
Paul Lewisca569a52020-09-09 16:11:5124 const themeStyleSheet = ThemeSupport.ThemeSupport.instance().themeStyleSheet(cssFile, content);
Paul Lewis9950e182019-12-16 16:06:0725 if (themeStyleSheet) {
26 styleElement = createElement('style');
27 styleElement.textContent = themeStyleSheet + '\n' + Root.Runtime.resolveSourceURL(cssFile + '.theme');
28 node.appendChild(styleElement);
29 }
30}