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