|
| 1 | +import { tags as t } from '@lezer/highlight'; |
| 2 | +import { createTheme, CreateThemeOptions } from '@uiw/codemirror-themes'; |
| 3 | +import { config } from './color'; |
| 4 | + |
| 5 | +export const defaultSettingsMonokai: CreateThemeOptions['settings'] = { |
| 6 | + background: config.background, |
| 7 | + foreground: config.foreground, |
| 8 | + caret: config.cursor, |
| 9 | + selection: config.selection, |
| 10 | + selectionMatch: config.selection, |
| 11 | + gutterBackground: config.background, |
| 12 | + gutterForeground: config.foreground, |
| 13 | + lineHighlight: config.activeLine, |
| 14 | +}; |
| 15 | + |
| 16 | +export const monokaiInit = (options?: Partial<CreateThemeOptions>) => { |
| 17 | + const { theme = 'dark', settings = {}, styles = [] } = options || {}; |
| 18 | + return createTheme({ |
| 19 | + theme: theme, |
| 20 | + settings: { |
| 21 | + ...defaultSettingsMonokai, |
| 22 | + ...settings, |
| 23 | + }, |
| 24 | + styles: [ |
| 25 | + { tag: t.keyword, color: config.keyword }, |
| 26 | + { tag: [t.name, t.deleted, t.character, t.macroName], color: config.variable }, |
| 27 | + { tag: [t.propertyName], color: config.function }, |
| 28 | + { tag: [t.processingInstruction, t.string, t.inserted, t.special(t.string)], color: config.string }, |
| 29 | + { tag: [t.function(t.variableName), t.labelName], color: config.function }, |
| 30 | + { tag: [t.color, t.constant(t.name), t.standard(t.name)], color: config.constant }, |
| 31 | + { tag: [t.definition(t.name), t.separator], color: config.variable }, |
| 32 | + { tag: [t.className], color: config.class }, |
| 33 | + { tag: [t.number, t.changed, t.annotation, t.modifier, t.self, t.namespace], color: config.number }, |
| 34 | + { tag: [t.typeName], color: config.type, fontStyle: config.type }, |
| 35 | + { tag: [t.operator, t.operatorKeyword], color: config.keyword }, |
| 36 | + { tag: [t.url, t.escape, t.regexp, t.link], color: config.regexp }, |
| 37 | + { tag: [t.meta, t.comment], color: config.comment }, |
| 38 | + { tag: t.tagName, color: config.tag }, |
| 39 | + { tag: t.strong, fontWeight: 'bold' }, |
| 40 | + { tag: t.emphasis, fontStyle: 'italic' }, |
| 41 | + { tag: t.link, textDecoration: 'underline' }, |
| 42 | + { tag: t.heading, fontWeight: 'bold', color: config.heading }, |
| 43 | + { tag: [t.atom, t.bool, t.special(t.variableName)], color: config.variable }, |
| 44 | + { tag: t.invalid, color: config.invalid }, |
| 45 | + { tag: t.strikethrough, textDecoration: 'line-through' }, |
| 46 | + ...styles, |
| 47 | + ], |
| 48 | + }); |
| 49 | +}; |
| 50 | + |
| 51 | +export const monokai = monokaiInit(); |
0 commit comments