(
themes?: { [themeName: string]: Theme },
defaultThemeName?: string,
extraData?: {
[themeName: string]: {
appendClasses?: Array<string>;
cssVariables?: {
[cssVarName: string]: string;
};
};
},
ieSupport = false, // TODO:css-var-ponyflll 仍有一些问题待定位
allowDynamicTheme = false
)
| 16 | * |
| 17 | */ |
| 18 | export function ThemeServiceInit( |
| 19 | themes?: { [themeName: string]: Theme }, |
| 20 | defaultThemeName?: string, |
| 21 | extraData?: { |
| 22 | [themeName: string]: { |
| 23 | appendClasses?: Array<string>; |
| 24 | cssVariables?: { |
| 25 | [cssVarName: string]: string; |
| 26 | }; |
| 27 | }; |
| 28 | }, |
| 29 | ieSupport = false, // TODO:css-var-ponyflll 仍有一些问题待定位 |
| 30 | allowDynamicTheme = false |
| 31 | ) { |
| 32 | if (typeof window === 'undefined' || typeof document === 'undefined') { |
| 33 | return null; |
| 34 | } |
| 35 | window[THEME_KEY.themeCollection] = themes || { |
| 36 | 'devui-light-theme': devuiLightTheme, |
| 37 | 'devui-dark-theme': devuiDarkTheme, |
| 38 | }; |
| 39 | window[THEME_KEY.currentTheme] = defaultThemeName || 'devui-light-theme'; |
| 40 | const eventBus = (window as any).globalEventBus || new EventBus(); // window.globalEventBus 为 框架的事件总线 |
| 41 | const themeService = new ThemeService(eventBus); |
| 42 | window[THEME_KEY.themeService] = themeService; |
| 43 | |
| 44 | themeService.setExtraData( |
| 45 | extraData || { |
| 46 | 'devui-dark-theme': { |
| 47 | appendClasses: ['dark-mode'], |
| 48 | }, |
| 49 | } |
| 50 | ); |
| 51 | |
| 52 | const currentTheme = window?.localStorage.getItem(THEME_KEY.userLastPreferTheme) || defaultThemeName; |
| 53 | themeService.initializeTheme(currentTheme, allowDynamicTheme); |
| 54 | if (ieSupport) { |
| 55 | ieSupportCssVar(); |
| 56 | } |
| 57 | return themeService; |
| 58 | } |
| 59 | |
| 60 | export function ThemeServiceFollowSystemOn(themeConfig?: { lightThemeName: string; darkThemeName: string }): Subscription { |
| 61 | if (typeof window === 'undefined' || typeof document === 'undefined') { |
no test coverage detected