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,EAAE,MAIH,CAAC;IACxB,MAAM,mBAAmB,EAAE,MAIR,CAAC;IACpB,MAAM,gBAAgB,EAAE,MAGF,CAAC;CACjC","file":"../../../src/browser/textmate/monaco-theme-registry.d.ts","sourcesContent":["import {injectable} from 'inversify';\nimport {IRawTheme, IRawThemeSetting, Registry} from 'vscode-textmate';\nimport darkTheme from '../../assets/data/monaco-themes/vscode/dark_wm.json';\nimport darkDefaults from '../../assets/data/monaco-themes/vscode/dark_defaults.json';\nimport darkVs from '../../assets/data/monaco-themes/vscode/dark_vs.json';\nimport darkPlus from '../../assets/data/monaco-themes/vscode/dark_plus.json';\n\nimport lightTheme from '../../assets/data/monaco-themes/vscode/light_wm.json';\nimport lightDefaults from '../../assets/data/monaco-themes/vscode/light_defaults.json';\nimport lightVs from '../../assets/data/monaco-themes/vscode/light_vs.json';\nimport lightPlus from '../../assets/data/monaco-themes/vscode/light_plus.json';\n\nimport hcTheme from '../../assets/data/monaco-themes/vscode/hc_wm.json';\nimport hcBlackDefault from '../../assets/data/monaco-themes/vscode/hc_black_defaults.json';\nimport hcBlack from '../../assets/data/monaco-themes/vscode/hc_black.json';\n\nexport interface ThemeMix extends IRawTheme, monaco.editor.IStandaloneThemeData {\n}\n\nexport interface MixStandaloneTheme extends monaco.services.IStandaloneTheme {\n    themeData: ThemeMix\n}\n\n@injectable()\nexport class MonacoThemeRegistry {\n\n    getThemeData(): ThemeMix;\n    getThemeData(name: string): ThemeMix | undefined;\n    getThemeData(name?: string): ThemeMix | undefined {\n        const theme = this.doGetTheme(name);\n        return theme && theme.themeData;\n    }\n\n    getTheme(): MixStandaloneTheme;\n    getTheme(name: string): MixStandaloneTheme | undefined;\n    getTheme(name?: string): MixStandaloneTheme | undefined {\n        return this.doGetTheme(name);\n    }\n\n    setTheme(name: string, data: ThemeMix): void {\n        // monaco auto refreshes a theme with new data\n        monaco.editor.defineTheme(name, data);\n    }\n\n    /**\n     * Register VS Code compatible themes\n     */\n    register(json: any, includes?: { [includePath: string]: any }, givenName?: string, monacoBase?: monaco.editor.BuiltinTheme): ThemeMix {\n        const name = givenName || json.name!;\n        const result: ThemeMix = {\n            name,\n            base: monacoBase || 'vs',\n            inherit: true,\n            colors: {},\n            rules: [],\n            settings: []\n        };\n        if (typeof json.include !== 'undefined') {\n            if (!includes || !includes[json.include]) {\n                console.error(`Couldn't resolve includes theme ${json.include}.`);\n            } else {\n                const parentTheme = this.register(includes[json.include], includes);\n                Object.assign(result.colors, parentTheme.colors);\n                result.rules.push(...parentTheme.rules);\n                result.settings.push(...parentTheme.settings);\n            }\n        }\n        const tokenColors: Array<IRawThemeSetting> = json.tokenColors;\n        if (Array.isArray(tokenColors)) {\n            for (const tokenColor of tokenColors) {\n                if (tokenColor.scope && tokenColor.settings) {\n                    result.settings.push({\n                        scope: tokenColor.scope,\n                        settings: {\n                            foreground: this.normalizeColor(tokenColor.settings.foreground),\n                            background: this.normalizeColor(tokenColor.settings.background),\n                            fontStyle: tokenColor.settings.fontStyle\n                        }\n                    });\n                }\n            }\n        }\n        if (json.colors) {\n            Object.assign(result.colors, json.colors);\n            result.encodedTokensColors = Object.keys(result.colors).map(key => result.colors[key]);\n        }\n        if (monacoBase && givenName) {\n            for (const setting of result.settings) {\n                this.transform(setting, rule => result.rules.push(rule));\n            }\n\n            // the default rule (scope empty) is always the first rule. Ignore all other default rules.\n            const defaultTheme = monaco.services.StaticServices.standaloneThemeService.get()._knownThemes.get(result.base)!;\n            const foreground = result.colors['editor.foreground'] || defaultTheme.getColor('editor.foreground');\n            const background = result.colors['editor.background'] || defaultTheme.getColor('editor.background');\n            result.settings.unshift({\n                settings: {\n                    foreground: this.normalizeColor(foreground),\n                    background: this.normalizeColor(background)\n                }\n            });\n\n            const reg = new Registry();\n            reg.setTheme(result);\n            result.encodedTokensColors = reg.getColorMap();\n            // index 0 has to be set to null as it is 'undefined' by default, but monaco code expects it to be null\n            // eslint-disable-next-line no-null/no-null\n            result.encodedTokensColors[0] = null!;\n            this.setTheme(givenName, result);\n        }\n        return result;\n    }\n\n    protected doGetTheme(name: string | undefined): MixStandaloneTheme | undefined {\n        const standaloneThemeService = monaco.services.StaticServices.standaloneThemeService.get();\n        const theme = !name ? standaloneThemeService.getColorTheme() : standaloneThemeService._knownThemes.get(name);\n        return theme as MixStandaloneTheme | undefined;\n    }\n\n    protected transform(tokenColor: any, acceptor: (rule: monaco.editor.ITokenThemeRule) => void): void {\n        if (typeof tokenColor.scope === 'undefined') {\n            tokenColor.scope = [''];\n        } else if (typeof tokenColor.scope === 'string') {\n            tokenColor.scope = tokenColor.scope.split(',').map((scope: string) => scope.trim());\n        }\n\n        for (const scope of tokenColor.scope) {\n            acceptor({\n                ...tokenColor.settings, token: scope\n            });\n        }\n    }\n\n    protected normalizeColor(color: string | monaco.color.Color | undefined): string | undefined {\n        if (!color) {\n            return undefined;\n        }\n        const normalized = String(color).replace(/^\\#/, '').slice(0, 6);\n        if (normalized.length < 6 || !(normalized).match(/^[0-9A-Fa-f]{6}$/)) {\n            // ignoring not normalized colors to avoid breaking token color indexes between monaco and vscode-textmate\n            console.error(`Color '${normalized}' is NOT normalized, it must have 6 positions.`);\n            return undefined;\n        }\n        return '#' + normalized;\n    }\n}\n\nexport namespace MonacoThemeRegistry {\n    export const SINGLETON = new MonacoThemeRegistry();\n\n    export const DARK_DEFAULT_THEME: string = SINGLETON.register(darkTheme, {\n        './dark_defaults.json': darkDefaults,\n        './dark_vs.json': darkVs,\n        './dark_plus.json': darkPlus\n    }, 'dark-wm', 'vs-dark').name!;\n    export const LIGHT_DEFAULT_THEME: string = SINGLETON.register(lightTheme, {\n        './light_defaults.json': lightDefaults,\n        './light_vs.json': lightVs,\n        './light_plus.json': lightPlus,\n    }, 'light-wm', 'vs').name!;\n    export const HC_DEFAULT_THEME: string = SINGLETON.register(hcTheme, {\n        './hc_black_defaults.json': hcBlackDefault,\n        './hc_black.json': hcBlack\n    }, 'hc-wm', 'hc-black').name!;\n}\n"]}