|
| 1 | +import { HighlightStyle, syntaxHighlighting } from "@codemirror/language"; |
| 2 | +import { EditorView } from "@codemirror/view"; |
| 3 | +import { tags as t } from "@lezer/highlight"; |
| 4 | + |
| 5 | +// One Dark's layout on Studio's tokens: every colour is a theme.css variable, so the editor |
| 6 | +// follows the light or dark theme the page paints with no editor reconfiguration. |
| 7 | +const editorTheme = EditorView.theme({ |
| 8 | + "&": { height: "100%", color: "var(--color-text-0)", backgroundColor: "var(--color-surface)" }, |
| 9 | + ".cm-scroller": { overflow: "auto" }, |
| 10 | + ".cm-content": { caretColor: "var(--color-text-0)" }, |
| 11 | + ".cm-cursor, .cm-dropCursor": { borderLeftColor: "var(--color-text-0)" }, |
| 12 | + "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": |
| 13 | + { backgroundColor: "var(--color-on)" }, |
| 14 | + ".cm-activeLine": { backgroundColor: "var(--color-hover)" }, |
| 15 | + ".cm-selectionMatch": { |
| 16 | + backgroundColor: "transparent", |
| 17 | + outline: "1px solid var(--color-text-muted)", |
| 18 | + }, |
| 19 | + ".cm-searchMatch": { |
| 20 | + backgroundColor: "transparent", |
| 21 | + outline: "1px solid var(--color-text-muted)", |
| 22 | + }, |
| 23 | + ".cm-searchMatch.cm-searchMatch-selected": { |
| 24 | + backgroundColor: "transparent", |
| 25 | + outline: "2px solid var(--color-accent-ink)", |
| 26 | + }, |
| 27 | + "&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket": { |
| 28 | + backgroundColor: "var(--color-on)", |
| 29 | + }, |
| 30 | + ".cm-gutters": { |
| 31 | + backgroundColor: "var(--color-surface)", |
| 32 | + color: "var(--color-text-muted)", |
| 33 | + border: "none", |
| 34 | + }, |
| 35 | + ".cm-activeLineGutter": { backgroundColor: "var(--color-hover)", color: "var(--color-text-2)" }, |
| 36 | + ".cm-foldPlaceholder": { |
| 37 | + backgroundColor: "transparent", |
| 38 | + border: "none", |
| 39 | + color: "var(--color-text-2)", |
| 40 | + }, |
| 41 | + ".cm-panels": { backgroundColor: "var(--color-raised)", color: "var(--color-text-0)" }, |
| 42 | + ".cm-panels.cm-panels-top": { borderBottom: "1px solid var(--color-border)" }, |
| 43 | + ".cm-panels.cm-panels-bottom": { borderTop: "1px solid var(--color-border)" }, |
| 44 | + ".cm-textfield": { |
| 45 | + backgroundColor: "var(--color-input)", |
| 46 | + color: "var(--color-text-0)", |
| 47 | + border: "1px solid var(--color-border-input)", |
| 48 | + }, |
| 49 | + ".cm-button": { |
| 50 | + backgroundImage: "none", |
| 51 | + backgroundColor: "var(--color-hover)", |
| 52 | + color: "var(--color-text-0)", |
| 53 | + border: "1px solid var(--color-border)", |
| 54 | + }, |
| 55 | + "&.cm-editor .cm-button:active": { |
| 56 | + backgroundImage: "none", |
| 57 | + backgroundColor: "var(--color-press)", |
| 58 | + }, |
| 59 | + ".cm-specialChar": { color: "var(--color-danger-ink)" }, |
| 60 | +}); |
| 61 | + |
| 62 | +const highlightStyle = HighlightStyle.define([ |
| 63 | + { tag: t.keyword, color: "var(--color-code-keyword)" }, |
| 64 | + { |
| 65 | + tag: [t.name, t.deleted, t.character, t.propertyName, t.macroName], |
| 66 | + color: "var(--color-code-name)", |
| 67 | + }, |
| 68 | + { tag: [t.function(t.variableName), t.labelName], color: "var(--color-code-function)" }, |
| 69 | + { tag: [t.color, t.constant(t.name), t.standard(t.name)], color: "var(--color-code-constant)" }, |
| 70 | + { tag: [t.definition(t.name), t.separator], color: "var(--color-text-0)" }, |
| 71 | + { |
| 72 | + tag: [ |
| 73 | + t.typeName, |
| 74 | + t.className, |
| 75 | + t.number, |
| 76 | + t.changed, |
| 77 | + t.annotation, |
| 78 | + t.modifier, |
| 79 | + t.self, |
| 80 | + t.namespace, |
| 81 | + ], |
| 82 | + color: "var(--color-code-type)", |
| 83 | + }, |
| 84 | + { |
| 85 | + tag: [t.operator, t.operatorKeyword, t.url, t.escape, t.regexp, t.special(t.string)], |
| 86 | + color: "var(--color-code-operator)", |
| 87 | + }, |
| 88 | + { tag: [t.meta, t.comment], color: "var(--color-code-comment)" }, |
| 89 | + { tag: t.strong, fontWeight: "bold" }, |
| 90 | + { tag: t.emphasis, fontStyle: "italic" }, |
| 91 | + { tag: t.strikethrough, textDecoration: "line-through" }, |
| 92 | + { tag: t.link, color: "var(--color-code-comment)", textDecoration: "underline" }, |
| 93 | + { tag: t.heading, fontWeight: "bold", color: "var(--color-code-name)" }, |
| 94 | + { tag: [t.atom, t.bool, t.special(t.variableName)], color: "var(--color-code-constant)" }, |
| 95 | + { tag: [t.processingInstruction, t.string, t.inserted], color: "var(--color-code-string)" }, |
| 96 | + { tag: t.invalid, color: "var(--color-danger-ink)" }, |
| 97 | +]); |
| 98 | + |
| 99 | +export const studioCodeTheme = [editorTheme, syntaxHighlighting(highlightStyle)]; |
0 commit comments