2022-10-13 05:28:02 -07:00
|
|
|
import { HighlightStyle, syntaxHighlighting } from '@codemirror/language';
|
|
|
|
import { EditorView } from '@codemirror/view';
|
|
|
|
import { tags } from '@lezer/highlight';
|
|
|
|
|
|
|
|
/**
|
2022-10-27 03:17:45 -07:00
|
|
|
* Light theme based on Tomorrow theme by Chris Kempson
|
2022-10-13 05:28:02 -07:00
|
|
|
* https://github.com/vadimdemedes/thememirror/blob/main/source/themes/tomorrow.ts
|
2022-10-27 03:17:45 -07:00
|
|
|
*
|
|
|
|
* Dark theme based on Dracula theme by Zeno Rocha
|
|
|
|
* https://github.com/vadimdemedes/thememirror/blob/main/source/themes/dracula.ts
|
2022-10-13 05:28:02 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
const BASE_STYLING = {
|
|
|
|
fontSize: '0.8em',
|
|
|
|
fontFamily: "Menlo, Consolas, 'DejaVu Sans Mono', monospace !important",
|
|
|
|
maxHeight: '400px',
|
|
|
|
tooltip: {
|
|
|
|
maxWidth: '300px',
|
|
|
|
lineHeight: '1.3em',
|
|
|
|
},
|
|
|
|
diagnosticButton: {
|
|
|
|
backgroundColor: 'inherit',
|
|
|
|
lineHeight: '1em',
|
|
|
|
textDecoration: 'underline',
|
|
|
|
marginLeft: '0.2em',
|
|
|
|
cursor: 'pointer',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const cssStyleDeclaration = getComputedStyle(document.documentElement);
|
|
|
|
|
2023-04-25 07:57:21 -07:00
|
|
|
interface ThemeSettings {
|
|
|
|
isReadOnly?: boolean;
|
2023-06-22 07:47:28 -07:00
|
|
|
customMaxHeight?: string;
|
2023-04-25 07:57:21 -07:00
|
|
|
}
|
|
|
|
|
2023-06-22 07:47:28 -07:00
|
|
|
export const codeNodeEditorTheme = ({ isReadOnly, customMaxHeight }: ThemeSettings) => [
|
2022-10-13 05:28:02 -07:00
|
|
|
EditorView.theme({
|
|
|
|
'&': {
|
|
|
|
'font-size': BASE_STYLING.fontSize,
|
|
|
|
border: cssStyleDeclaration.getPropertyValue('--border-base'),
|
|
|
|
borderRadius: cssStyleDeclaration.getPropertyValue('--border-radius-base'),
|
2022-10-27 03:17:45 -07:00
|
|
|
backgroundColor: 'var(--color-code-background)',
|
|
|
|
color: 'var(--color-code-foreground)',
|
2023-04-25 07:57:21 -07:00
|
|
|
height: '100%',
|
2022-10-13 05:28:02 -07:00
|
|
|
},
|
|
|
|
'.cm-content': {
|
|
|
|
fontFamily: BASE_STYLING.fontFamily,
|
2022-10-27 03:17:45 -07:00
|
|
|
caretColor: 'var(--color-code-caret)',
|
2022-10-13 05:28:02 -07:00
|
|
|
},
|
|
|
|
'.cm-cursor, .cm-dropCursor': {
|
2022-10-27 03:17:45 -07:00
|
|
|
borderLeftColor: 'var(--color-code-caret)',
|
2022-10-13 05:28:02 -07:00
|
|
|
},
|
|
|
|
'&.cm-focused .cm-selectionBackgroundm .cm-selectionBackground, .cm-content ::selection': {
|
2022-10-27 03:17:45 -07:00
|
|
|
backgroundColor: 'var(--color-code-selection)',
|
2022-10-13 05:28:02 -07:00
|
|
|
},
|
2023-04-25 07:57:21 -07:00
|
|
|
'&.cm-editor': {
|
|
|
|
...(isReadOnly ? { backgroundColor: 'var(--color-code-background-readonly)' } : {}),
|
|
|
|
},
|
2023-03-31 07:44:26 -07:00
|
|
|
'&.cm-editor.cm-focused': {
|
|
|
|
outline: 'none',
|
|
|
|
borderColor: 'var(--color-secondary)',
|
|
|
|
},
|
2022-10-13 05:28:02 -07:00
|
|
|
'.cm-activeLine': {
|
2022-10-27 03:17:45 -07:00
|
|
|
backgroundColor: 'var(--color-code-lineHighlight)',
|
|
|
|
},
|
|
|
|
'.cm-activeLineGutter': {
|
|
|
|
backgroundColor: 'var(--color-code-lineHighlight)',
|
2022-10-13 05:28:02 -07:00
|
|
|
},
|
|
|
|
'.cm-gutters': {
|
2023-04-25 07:57:21 -07:00
|
|
|
backgroundColor: isReadOnly
|
|
|
|
? 'var(--color-code-background-readonly)'
|
|
|
|
: 'var(--color-code-gutterBackground)',
|
2022-10-27 03:17:45 -07:00
|
|
|
color: 'var(--color-code-gutterForeground)',
|
2023-03-31 07:44:26 -07:00
|
|
|
borderRadius: 'var(--border-radius-base)',
|
2022-10-13 05:28:02 -07:00
|
|
|
},
|
2022-10-27 03:17:45 -07:00
|
|
|
'.cm-tooltip': {
|
|
|
|
maxWidth: BASE_STYLING.tooltip.maxWidth,
|
|
|
|
lineHeight: BASE_STYLING.tooltip.lineHeight,
|
2022-10-13 05:28:02 -07:00
|
|
|
},
|
|
|
|
'.cm-scroller': {
|
|
|
|
overflow: 'auto',
|
2023-09-19 03:16:35 -07:00
|
|
|
|
2023-06-22 07:47:28 -07:00
|
|
|
maxHeight: customMaxHeight ?? '100%',
|
2023-09-19 03:16:35 -07:00
|
|
|
...(isReadOnly ? {} : { minHeight: '1.3em' }),
|
2022-10-13 05:28:02 -07:00
|
|
|
},
|
|
|
|
'.cm-diagnosticAction': {
|
|
|
|
backgroundColor: BASE_STYLING.diagnosticButton.backgroundColor,
|
|
|
|
color: cssStyleDeclaration.getPropertyValue('--color-primary'),
|
|
|
|
lineHeight: BASE_STYLING.diagnosticButton.lineHeight,
|
|
|
|
textDecoration: BASE_STYLING.diagnosticButton.textDecoration,
|
|
|
|
marginLeft: BASE_STYLING.diagnosticButton.marginLeft,
|
|
|
|
cursor: BASE_STYLING.diagnosticButton.cursor,
|
|
|
|
},
|
|
|
|
}),
|
2022-10-27 03:17:45 -07:00
|
|
|
syntaxHighlighting(
|
|
|
|
HighlightStyle.define([
|
|
|
|
{
|
|
|
|
tag: tags.comment,
|
|
|
|
color: 'var(--color-code-tags-comment)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tag: [tags.string, tags.special(tags.brace)],
|
|
|
|
color: 'var(--color-code-tags-string)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tag: [tags.number, tags.self, tags.bool, tags.null],
|
|
|
|
color: 'var(--color-code-tags-primitive)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tag: tags.keyword,
|
|
|
|
color: 'var(--color-code-tags-keyword)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tag: tags.operator,
|
|
|
|
color: 'var(--color-code-tags-operator)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tag: [
|
|
|
|
tags.variableName,
|
|
|
|
tags.propertyName,
|
|
|
|
tags.attributeName,
|
|
|
|
tags.regexp,
|
|
|
|
tags.className,
|
|
|
|
tags.typeName,
|
|
|
|
],
|
|
|
|
color: 'var(--color-code-tags-variable)',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tag: [
|
|
|
|
tags.definition(tags.typeName),
|
|
|
|
tags.definition(tags.propertyName),
|
|
|
|
tags.function(tags.variableName),
|
|
|
|
],
|
|
|
|
color: 'var(--color-code-tags-definition)',
|
|
|
|
},
|
|
|
|
]),
|
2022-12-14 01:04:10 -08:00
|
|
|
),
|
2022-10-13 05:28:02 -07:00
|
|
|
];
|