(specificThemeId?: string, allowDynamicTheme?: boolean)
| 50 | } |
| 51 | |
| 52 | initializeTheme(specificThemeId?: string, allowDynamicTheme?: boolean) { |
| 53 | const themeId = specificThemeId |
| 54 | || this.storage.tryGetLocalStorage(THEME_KEY.userLastPreferTheme) |
| 55 | || this.context.getDataFromNameSpace(THEME_KEY.currentTheme); |
| 56 | let theme; |
| 57 | |
| 58 | if (themeId) { |
| 59 | const themes = this.context.getDataFromNameSpace(THEME_KEY.themeCollection); |
| 60 | if (themes && Object.keys(themes).length > 0) { |
| 61 | theme = themes[themeId]; |
| 62 | if (!theme) { |
| 63 | const key = Object.keys(themes).find(t => themes[t].id === themeId); |
| 64 | theme = themes[key]; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | this.currentTheme = theme || { |
| 69 | id: 'empty-theme', |
| 70 | name: '', |
| 71 | data: {}, |
| 72 | isDark: false |
| 73 | }; |
| 74 | this.createColorTransition(); |
| 75 | if (!theme && allowDynamicTheme) { |
| 76 | document.body.setAttribute(THEME_KEY.uiThemeAttributeName, 'empty-theme'); |
| 77 | return; |
| 78 | } |
| 79 | this.applyTheme(this.currentTheme); |
| 80 | } |
| 81 | |
| 82 | formatCSSVariables(themeData: Theme['data']) { |
| 83 | return Object.keys(themeData).map( |
no test coverage detected