|
| 1 | +import { colors } from './themeTokenMapping'; |
| 2 | +import type { editor as monacoEditor } from 'monaco-editor/esm/vs/editor/editor.api'; |
| 3 | + |
| 4 | +const createTheme = (mode: 'light' | 'dark'): monacoEditor.IStandaloneThemeData => ({ |
| 5 | + base: mode === 'light' ? 'vs' : 'vs-dark', |
| 6 | + inherit: true, |
| 7 | + colors: { |
| 8 | + 'editor.background': colors.background[mode], |
| 9 | + 'editor.foreground': colors.foreground[mode], |
| 10 | + 'editorLineNumber.activeForeground': colors.foreground[mode], |
| 11 | + 'editorLineNumber.foreground': colors.secondaryForeground[mode] |
| 12 | + }, |
| 13 | + rules: [ |
| 14 | + { token: '', foreground: colors.foreground[mode], background: colors.background[mode] }, |
| 15 | + { token: 'invalid', foreground: colors.red[mode] }, |
| 16 | + { token: 'emphasis', fontStyle: 'italic' }, |
| 17 | + { token: 'strong', fontStyle: 'bold' }, |
| 18 | + |
| 19 | + { token: 'variable', foreground: colors.blue[mode] }, |
| 20 | + { token: 'variable.predefined', foreground: colors.teal[mode] }, |
| 21 | + { token: 'constant', foreground: colors.orange[mode] }, |
| 22 | + { token: 'comment', foreground: colors.gray[mode] }, |
| 23 | + { token: 'number', foreground: colors.orange[mode] }, |
| 24 | + { token: 'number.hex', foreground: colors.blue[mode] }, |
| 25 | + { token: 'regexp', foreground: colors.red[mode] }, |
| 26 | + { token: 'annotation', foreground: colors.purple[mode] }, |
| 27 | + { token: 'type', foreground: colors.yellow[mode] }, |
| 28 | + |
| 29 | + { token: 'delimiter', foreground: colors.foreground[mode] }, |
| 30 | + { token: 'delimiter.html', foreground: colors.gray[mode] }, |
| 31 | + { token: 'delimiter.xml', foreground: colors.blue[mode] }, |
| 32 | + |
| 33 | + { token: 'tag', foreground: colors.red[mode] }, |
| 34 | + { token: 'tag.id.jade', foreground: colors.teal[mode] }, |
| 35 | + { token: 'tag.class.jade', foreground: colors.teal[mode] }, |
| 36 | + { token: 'meta.scss', foreground: colors.red[mode] }, |
| 37 | + { token: 'metatag', foreground: colors.orange[mode] }, |
| 38 | + { token: 'metatag.content.html', foreground: colors.red[mode] }, |
| 39 | + { token: 'metatag.html', foreground: colors.gray[mode] }, |
| 40 | + { token: 'metatag.xml', foreground: colors.gray[mode] }, |
| 41 | + { token: 'metatag.php', fontStyle: 'bold' }, |
| 42 | + |
| 43 | + { token: 'key', foreground: colors.orange[mode] }, |
| 44 | + { token: 'string.key.json', foreground: colors.red[mode] }, |
| 45 | + { token: 'string.value.json', foreground: colors.blue[mode] }, |
| 46 | + |
| 47 | + { token: 'attribute.name', foreground: colors.red[mode] }, |
| 48 | + { token: 'attribute.value', foreground: colors.blue[mode] }, |
| 49 | + { token: 'attribute.value.number', foreground: colors.orange[mode] }, |
| 50 | + { token: 'attribute.value.unit', foreground: colors.orange[mode] }, |
| 51 | + { token: 'attribute.value.html', foreground: colors.blue[mode] }, |
| 52 | + { token: 'attribute.value.xml', foreground: colors.blue[mode] }, |
| 53 | + |
| 54 | + { token: 'string', foreground: colors.green[mode] }, |
| 55 | + { token: 'string.html', foreground: colors.green[mode] }, |
| 56 | + { token: 'string.sql', foreground: colors.green[mode] }, |
| 57 | + { token: 'string.yaml', foreground: colors.green[mode] }, |
| 58 | + |
| 59 | + { token: 'keyword', foreground: colors.purple[mode] }, |
| 60 | + { token: 'keyword.json', foreground: colors.purple[mode] }, |
| 61 | + { token: 'keyword.flow', foreground: colors.purple[mode] }, |
| 62 | + { token: 'keyword.flow.scss', foreground: colors.purple[mode] }, |
| 63 | + |
| 64 | + { token: 'operator.scss', foreground: colors.foreground[mode] }, |
| 65 | + { token: 'operator.sql', foreground: colors.foreground[mode] }, |
| 66 | + { token: 'operator.swift', foreground: colors.foreground[mode] }, |
| 67 | + { token: 'predefined.sql', foreground: colors.purple[mode] } |
| 68 | + ] |
| 69 | +}); |
| 70 | + |
| 71 | +/** |
| 72 | + * Define the themes `pf-v6-theme-light` and |
| 73 | + * `pf-v6-theme-dark` for an instance of Monaco editor. |
| 74 | + */ |
| 75 | +export const defineThemes = (editor: typeof monacoEditor) => { |
| 76 | + editor.defineTheme('pf-v6-theme-light', createTheme('light')); |
| 77 | + editor.defineTheme('pf-v6-theme-dark', createTheme('dark')); |
| 78 | +}; |
0 commit comments