{"version":3,"sources":["browser/monaco-theming-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAE,oBAAoB,EAAC,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAuB,YAAY,EAAC,MAAM,kCAAkC,CAAC;AACpF,OAAO,EAAY,gBAAgB,EAAyB,MAAM,qBAAqB,CAAC;AAGxF,eAAO,MAAM,kBAAkB,eAAyB,CAAC;AAEzD,qBACa,oBAAoB;IAE7B,SAAS,CAAC,MAAM,CAAC,eAAe,uBAA8B;IAE9D,MAAM,CAAC,GAAG,IAAI,YAAY;IAW1B,MAAM,CAAC,IAAI,IAAI,IAAI;IAMnB,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,gBAAgB,GAAG,UAAU;qBAOzC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAY/C,SAAS,CAAC,MAAM,CAAC,iBAAiB,IAAI,IAAI;CAO7C","file":"../../src/browser/monaco-theming-service.d.ts","sourcesContent":["import {injectable} from 'inversify';\r\nimport {Disposable, DisposableCollection} from '@tartjs/core/lib/common';\r\nimport {BuiltinThemeProvider, ThemeService} from '@tartjs/core/lib/browser/theming';\r\nimport {getThemes, MonacoThemeState, putTheme, stateToTheme} from './monaco-indexed-db';\r\nimport {MonacoThemeRegistry} from './textmate/monaco-theme-registry';\r\n\r\nexport const ThemeServiceSymbol = Symbol('ThemeService');\r\n\r\n@injectable()\r\nexport class MonacoThemingService {\r\n\r\n    protected static toUpdateUiTheme = new DisposableCollection();\r\n\r\n    static get(): ThemeService {\r\n        const global = window as any; // eslint-disable-line @typescript-eslint/no-explicit-any\r\n        if (!global[ThemeServiceSymbol]) {\r\n            const themeService = new ThemeService();\r\n            themeService.register(...BuiltinThemeProvider.themes);\r\n            themeService.startupTheme();\r\n            global[ThemeServiceSymbol] = themeService;\r\n        }\r\n        return global[ThemeServiceSymbol];\r\n    }\r\n\r\n    static init(): void {\r\n        this.updateBodyUiTheme();\r\n        ThemeService.get().onDidColorThemeChange(() => this.updateBodyUiTheme());\r\n        this.restore();\r\n    }\r\n\r\n    protected static doRegister(state: MonacoThemeState): Disposable {\r\n        return new DisposableCollection(\r\n            ThemeService.get().register(stateToTheme(state)),\r\n            putTheme(state)\r\n        );\r\n    }\r\n\r\n    protected static async restore(): Promise<void> {\r\n        try {\r\n            const themes = await getThemes();\r\n            for (const state of themes) {\r\n                MonacoThemeRegistry.SINGLETON.setTheme(state.data.name!, state.data);\r\n                MonacoThemingService.doRegister(state);\r\n            }\r\n        } catch (e) {\r\n            console.error('Failed to restore monaco themes', e);\r\n        }\r\n    }\r\n\r\n    protected static updateBodyUiTheme(): void {\r\n        this.toUpdateUiTheme.dispose();\r\n        const type = ThemeService.get().getCurrentTheme().type;\r\n        const uiTheme: monaco.editor.BuiltinTheme = type === 'hc' ? 'hc-black' : type === 'light' ? 'vs' : 'vs-dark';\r\n        document.body.classList.add(uiTheme);\r\n        this.toUpdateUiTheme.push(Disposable.create(() => document.body.classList.remove(uiTheme)));\r\n    }\r\n}\r\n"]}