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 | ca569a5 | 2020-09-09 16:11:51 | [diff] [blame^] | 8 | import * as ThemeSupport from '../../theme_support/theme_support.js'; |
| 9 | |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 10 | /** |
| 11 | * @param {!Node} node |
| 12 | * @param {string} cssFile |
| 13 | * @suppressGlobalPropertiesCheck |
| 14 | */ |
| 15 | export function appendStyle(node, cssFile) { |
Tim van der Lippe | 6d51bf0 | 2020-03-18 12:15:14 | [diff] [blame] | 16 | const content = self.Runtime.cachedResources[cssFile] || ''; |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 17 | 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 Lewis | ca569a5 | 2020-09-09 16:11:51 | [diff] [blame^] | 24 | const themeStyleSheet = ThemeSupport.ThemeSupport.instance().themeStyleSheet(cssFile, content); |
Paul Lewis | 9950e18 | 2019-12-16 16:06:07 | [diff] [blame] | 25 | if (themeStyleSheet) { |
| 26 | styleElement = createElement('style'); |
| 27 | styleElement.textContent = themeStyleSheet + '\n' + Root.Runtime.resolveSourceURL(cssFile + '.theme'); |
| 28 | node.appendChild(styleElement); |
| 29 | } |
| 30 | } |