Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 1 | // 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 Lippe | ee97fa3 | 2020-04-23 15:20:56 | [diff] [blame^] | 5 | // @ts-nocheck |
| 6 | // TODO(crbug.com/1011811): Enable TypeScript compiler checks |
| 7 | |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 8 | /** |
| 9 | * @param {!Node} node |
| 10 | * @param {string} cssFile |
| 11 | * @suppressGlobalPropertiesCheck |
| 12 | */ |
| 13 | export function appendStyle(node, cssFile) { |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 14 | const content = self.Runtime.cachedResources[cssFile] || ''; |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 15 | if (!content) { |
| 16 | console.error(cssFile + ' not preloaded. Check module.json'); |
| 17 | } |
| 18 | let styleElement = createElement('style'); |
| 19 | styleElement.textContent = content; |
| 20 | node.appendChild(styleElement); |
| 21 | |
Paul Lewis | 93d8e2c | 2020-01-24 16:34:55 | [diff] [blame] | 22 | const themeStyleSheet = self.UI.themeSupport.themeStyleSheet(cssFile, content); |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 23 | if (themeStyleSheet) { |
| 24 | styleElement = createElement('style'); |
| 25 | styleElement.textContent = themeStyleSheet + '\n' + Root.Runtime.resolveSourceURL(cssFile + '.theme'); |
| 26 | node.appendChild(styleElement); |
| 27 | } |
| 28 | } |