UNPKG

@grafana/ui

Version:
1 lines 4.24 kB
{"version":3,"file":"theme.mjs","sources":["../../../../src/components/Monaco/theme.ts"],"sourcesContent":["import tinycolor from 'tinycolor2';\n\nimport { GrafanaTheme2 } from '@grafana/data';\n\nimport { Monaco, monacoTypes } from './types';\n\nfunction getColors(theme?: GrafanaTheme2): monacoTypes.editor.IColors {\n if (theme === undefined) {\n return {};\n } else {\n const colors: Record<string, string> = {\n 'editor.background': theme.components.input.background,\n 'minimap.background': theme.colors.background.secondary,\n };\n\n Object.keys(colors).forEach((resultKey) => {\n colors[resultKey] = normalizeColorForMonaco(colors[resultKey]);\n });\n return colors;\n }\n}\n\nfunction normalizeColorForMonaco(color?: string): string {\n // monaco needs 6char hex colors\n // see https://github.com/grafana/grafana/issues/43158\n return tinycolor(color).toHexString();\n}\n\n// we support calling this without a theme, it will make sure the themes\n// are registered in monaco, even if the colors are not perfect.\nexport default function defineThemes(monaco: Monaco, theme?: GrafanaTheme2) {\n // color tokens are defined here https://github.com/microsoft/vscode/blob/main/src/vs/platform/theme/common/colorRegistry.ts#L174\n const colors = getColors(theme);\n monaco.editor.defineTheme('grafana-dark', {\n base: 'vs-dark',\n inherit: true,\n colors: colors,\n // fallback syntax highlighting for languages that microsoft doesn't handle (ex cloudwatch's metric math)\n rules: [\n { token: 'predefined', foreground: normalizeColorForMonaco(theme?.visualization.getColorByName('purple')) },\n { token: 'operator', foreground: normalizeColorForMonaco(theme?.visualization.getColorByName('orange')) },\n { token: 'tag', foreground: normalizeColorForMonaco(theme?.visualization.getColorByName('green')) },\n ],\n });\n\n monaco.editor.defineTheme('grafana-light', {\n base: 'vs',\n inherit: true,\n colors: colors,\n // fallback syntax highlighting for languages that microsoft doesn't handle (ex cloudwatch's metric math)\n rules: [\n { token: 'predefined', foreground: normalizeColorForMonaco(theme?.visualization.getColorByName('purple')) },\n { token: 'operator', foreground: normalizeColorForMonaco(theme?.visualization.getColorByName('orange')) },\n { token: 'tag', foreground: normalizeColorForMonaco(theme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