@fsegurai/codemirror-theme-andromeda
Version:
Andromeda theme for the CodeMirror editor
486 lines (479 loc) • 17.3 kB
JavaScript
'use strict';
var view = require('@codemirror/view');
var language = require('@codemirror/language');
var highlight = require('@lezer/highlight');
// Helper module for styling options
const generalContent = {
fontSize: '14px',
fontFamily: 'JetBrains Mono, Consolas, monospace',
lineHeight: '1.6',
};
const generalCursor = {
borderLeftWidth: '2px',
};
const generalDiff = {
insertedTextDecoration: 'none',
deletedTextDecoration: 'line-through',
insertedLinePadding: '1px 3px',
borderRadius: '3px'};
const generalGutter = {
border: 'none',
paddingRight: '8px',
fontSize: '0.9em',
fontWeight: '500',
lineHeight: '1.78', // Adjusted to compensate for 0.9em fontSize (1.6 / 0.9 ≈ 1.78)
};
const generalPanel = {
border: 'none',
borderRadius: '4px',
padding: '2px 10px',
};
const generalLine = {
borderRadius: '2px',
};
const generalMatching = {
borderRadius: '2px',
};
const generalPlaceholder = {
borderRadius: '4px',
padding: '0 5px',
margin: '0 2px',
};
const generalScroller = {
width: '12px',
height: '12px',
borderRadius: '6px',
};
const generalSearchField = {
borderRadius: '4px',
padding: '2px 6px',
};
const generalTooltip = {
borderRadius: '4px',
borderRadiusSelected: '3px',
lineHeight: '1.3',
padding: '4px 8px',
paddingRight: '8px',
};
/**
* Function to apply merge revert styles for a theme
* @param styles Styles for the merge revert buttons
* @param styles.backgroundColor Background color of the revert area
* @param styles.borderColor Border color of the revert area
* @param styles.buttonColor Color of the revert buttons
* @param styles.buttonHoverColor Hover color of the revert buttons
*/
function applyMergeRevertStyles(styles) {
// Create a stylesheet
const styleEl = document.createElement('style');
styleEl.id = 'cm-merge-revert-styles';
// Define CSS with the theme-specific values
styleEl.textContent = `
.cm-merge-revert {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
padding: 4px;
background-color: ${styles.backgroundColor};
border-left: 1px solid ${styles.borderColor};
border-right: 1px solid ${styles.borderColor};
width: 32px;
}
.cm-merge-revert button {
width: 100%;
height: auto;
background-color: transparent;
border: none;
color: ${styles.buttonColor};
cursor: pointer;
margin: 0 auto;
font-size: 20px;
}
.cm-merge-revert button:hover {
background-color: ${styles.buttonHoverColor};
}
`;
// Remove any existing merge styles
const existingStyle = document.getElementById('cm-merge-revert-styles');
if (existingStyle)
existingStyle.remove();
// Add the new styles
document.head.appendChild(styleEl);
}
/**
* Enhanced Andromeda theme color palette
* ------------------------------------------
* Colors refined for better contrast and visual hierarchy
*/
// Base colors
const base00 = '#1b1e26', // Background (slightly darker for better contrast)
base01 = '#e4dff0', // Foreground (slightly brighter for better readability)
base02 = '#db45a270', // Selection and Selection Match (reduced opacity)
base03 = '#2b303b', // Dropdown Background
base04 = '#ffffff', // Cursor (pure white for better visibility)
base05 = '#d667ff', // Keyword, Storage (brighter purple)
base06 = '#24e3c3', // Variable, Parameter (slightly desaturated teal)
base07 = '#ffdd80', // Function, Type, Class (warmer yellow)
base08 = '#a6e07a', // String, RegExp (slightly muted green for better readability)
base09 = '#ff7057', // Constant, Number (brighter orange-red)
base0A = '#a8aab9', // Comment (higher contrast gray)
base0B = '#ff40b3', // Heading (slightly desaturated magenta)
base0C = '#fd3681', // Tag (adjusted pink)
base0D = '#c7c7ff', // New color for brackets/punctuation
base0E = '#6ae4b9', // New color for special elements
base0F = '#3c94ff', // New color for attributes and links
invalid = '#ff3162', // Invalid (more visible red)
// UI-specific colors
darkBackground = '#242830', selectionBackground = base02, selectionForeground = '#ffffff', highlightBackground = '#30343d40', tooltipBackground = '#1f232d', // Darker tooltip for better contrast
cursor = base04, activeBracketBg = '#db45a230', activeBracketBorder = base05,
// Diff/merge specific colors
addedBackground = '#0f3a2440', // Dark green with transparency for insertions
removedBackground = '#78112230', // Dark red with transparency for deletions
addedText = base08, // Using string color for added text for consistency
removedText = '#ff5d7a'; // Bright red for removed text
/**
* Enhanced editor theme styles for Andromeda
*/
const andromedaTheme = view.EditorView.theme({
// Base editor styles
'&': {
color: base01,
backgroundColor: base00,
fontSize: generalContent.fontSize,
fontFamily: generalContent.fontFamily,
},
// Content and cursor
'.cm-content': {
caretColor: cursor,
lineHeight: generalContent.lineHeight,
},
'.cm-cursor, .cm-dropCursor': {
borderLeftColor: cursor,
borderLeftWidth: generalCursor.borderLeftWidth,
},
'.cm-fat-cursor': {
backgroundColor: `${cursor}99`,
color: base00,
},
// Selection
'&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection': {
backgroundColor: selectionBackground,
color: selectionForeground,
},
// Make sure selection appears above active line
'.cm-selectionLayer': {
zIndex: 100,
},
// Search functionality
'.cm-searchMatch': {
backgroundColor: '#db45a230',
outline: `1px solid ${base05}30`,
color: base01,
borderRadius: generalSearchField.borderRadius,
'& span': {
color: base01,
},
},
'.cm-searchMatch.cm-searchMatch-selected': {
backgroundColor: '#db45a280',
color: base01,
padding: generalSearchField.padding,
'& span': {
color: base01,
},
},
'.cm-search.cm-panel.cm-textfield': {
color: base06,
borderRadius: generalSearchField.borderRadius,
padding: generalSearchField.padding,
},
// Panels
'.cm-panels': {
backgroundColor: darkBackground,
color: base06,
},
'.cm-panels.cm-panels-top': {
borderBottom: '1px solid #3a3e4c',
},
'.cm-panels.cm-panels-bottom': {
borderTop: '1px solid #3a3e4c',
},
'.cm-panel button': {
backgroundColor: darkBackground,
color: base06,
border: generalPanel.border,
borderRadius: generalPanel.borderRadius,
padding: generalPanel.padding,
},
'.cm-panel button:hover': {
backgroundColor: '#343946',
},
// Line highlighting
'.cm-activeLine': {
backgroundColor: highlightBackground,
borderRadius: generalLine.borderRadius,
zIndex: 1,
},
// Gutters
'.cm-gutters': {
backgroundColor: darkBackground,
color: '#748099',
border: generalGutter.border,
borderRight: '1px solid #33384550',
paddingRight: generalGutter.paddingRight,
},
'.cm-activeLineGutter': {
backgroundColor: highlightBackground,
color: base01,
fontWeight: generalGutter.fontWeight,
},
'.cm-lineNumbers': {
fontSize: generalGutter.fontSize,
lineHeight: generalGutter.lineHeight,
},
'.cm-foldGutter': {
fontSize: generalGutter.fontSize,
lineHeight: generalGutter.lineHeight,
},
'.cm-foldGutter .cm-gutterElement': {
color: '#748099',
cursor: 'pointer',
},
'.cm-foldGutter .cm-gutterElement:hover': {
color: base01,
},
// Diff/Merge View Styles
// Inserted/Added Content
'.cm-insertedLine': {
textDecoration: generalDiff.insertedTextDecoration,
backgroundColor: addedBackground,
color: addedText,
padding: generalDiff.insertedLinePadding,
borderRadius: generalDiff.borderRadius,
},
'ins.cm-insertedLine, ins.cm-insertedLine:not(:has(.cm-changedText))': {
textDecoration: generalDiff.insertedTextDecoration,
backgroundColor: `${addedBackground} !important`,
color: addedText,
padding: generalDiff.insertedLinePadding,
borderRadius: generalDiff.borderRadius,
border: `1px solid ${addedText}40`,
},
'ins.cm-insertedLine .cm-changedText': {
background: 'transparent !important',
},
// Deleted/Removed Content
'.cm-deletedLine': {
textDecoration: generalDiff.deletedTextDecoration,
backgroundColor: removedBackground,
color: removedText,
padding: generalDiff.insertedLinePadding,
borderRadius: generalDiff.borderRadius,
},
'del.cm-deletedLine, del, del:not(:has(.cm-deletedText))': {
textDecoration: generalDiff.deletedTextDecoration,
backgroundColor: `${removedBackground} !important`,
color: removedText,
padding: generalDiff.insertedLinePadding,
borderRadius: generalDiff.borderRadius,
border: `1px solid ${removedText}40`,
},
'del .cm-deletedText, del .cm-changedText': {
background: 'transparent !important',
},
// Tooltips and autocomplete
'.cm-tooltip': {
backgroundColor: tooltipBackground,
border: '1px solid #3a3e4c',
borderRadius: generalTooltip.borderRadius,
padding: generalTooltip.padding,
boxShadow: '0 2px 8px rgba(0, 0, 0, 0.3)',
},
'.cm-tooltip-autocomplete': {
'& > ul': {
backgroundColor: base03,
border: 'none',
},
'& > ul > li': {
padding: generalTooltip.padding,
lineHeight: generalTooltip.lineHeight,
},
'& > ul > li[aria-selected]': {
backgroundColor: '#db45a240',
color: base01,
borderRadius: generalTooltip.borderRadiusSelected,
},
'& > ul > li > span.cm-completionIcon': {
color: '#748099',
paddingRight: generalTooltip.paddingRight,
},
'& > ul > li > span.cm-completionDetail': {
color: '#748099',
fontStyle: 'italic',
},
},
'.cm-tooltip .cm-tooltip-arrow:before': {
borderTopColor: 'transparent',
borderBottomColor: 'transparent',
},
'.cm-tooltip .cm-tooltip-arrow:after': {
borderTopColor: tooltipBackground,
borderBottomColor: tooltipBackground,
},
// Diagnostics styling
'.cm-diagnostic': {
'&-error': {
borderLeft: `3px solid ${invalid}`,
},
'&-warning': {
borderLeft: `3px solid ${base07}`,
},
'&-info': {
borderLeft: `3px solid ${base0F}`,
},
},
'.cm-lintPoint-error': {
borderBottom: `2px wavy ${invalid}`,
},
'.cm-lintPoint-warning': {
borderBottom: `2px wavy ${base07}`,
},
// Matching brackets
'.cm-matchingBracket': {
backgroundColor: activeBracketBg,
outline: `1px solid ${activeBracketBorder}50`,
borderRadius: generalMatching.borderRadius,
},
'.cm-nonmatchingBracket': {
backgroundColor: '#ff405030',
outline: `1px solid ${invalid}`,
borderRadius: generalMatching.borderRadius,
},
// Selection matches
'.cm-selectionMatch': {
backgroundColor: '#db45a240',
outline: `1px solid ${base05}50`,
borderRadius: generalMatching.borderRadius,
},
// Fold placeholder
'.cm-foldPlaceholder': {
backgroundColor: 'transparent',
color: base02,
border: `1px dotted ${base05}70`,
borderRadius: generalPlaceholder.borderRadius,
padding: generalPlaceholder.padding,
margin: generalPlaceholder.margin,
},
// Focus outline
'&.cm-focused': {
outline: 'none',
boxShadow: `0 0 0 2px ${base00}, 0 0 0 3px ${base05}40`,
},
// Scrollbars
'& .cm-scroller::-webkit-scrollbar': {
width: generalScroller.width,
height: generalScroller.height,
},
'& .cm-scroller::-webkit-scrollbar-track': {
background: darkBackground,
},
'& .cm-scroller::-webkit-scrollbar-thumb': {
backgroundColor: '#3b4151',
borderRadius: generalScroller.borderRadius,
border: `3px solid ${darkBackground}`,
},
'& .cm-scroller::-webkit-scrollbar-thumb:hover': {
backgroundColor: '#4e5568',
},
// Ghost text
'.cm-ghostText': {
opacity: '0.5',
color: '#a8aab9',
},
}, { dark: true });
/**
* Enhanced syntax highlighting for the Andromeda theme
*/
const andromedaHighlightStyle = language.HighlightStyle.define([
// Keywords and control flow
{ tag: highlight.tags.keyword, color: base05, fontWeight: 'bold' },
{ tag: highlight.tags.controlKeyword, color: base05, fontWeight: 'bold' },
{ tag: highlight.tags.moduleKeyword, color: base05, fontWeight: 'bold' },
// Names and variables
{ tag: [highlight.tags.name, highlight.tags.deleted, highlight.tags.character, highlight.tags.macroName], color: base06 },
{ tag: [highlight.tags.variableName], color: base06 },
{ tag: [highlight.tags.propertyName], color: base06, fontStyle: 'normal' },
// Classes and types
{ tag: [highlight.tags.typeName], color: base07 },
{ tag: [highlight.tags.className], color: base07, fontStyle: 'italic' },
{ tag: [highlight.tags.namespace], color: base0E, fontStyle: 'italic' },
// Operators and punctuation
{ tag: [highlight.tags.operator, highlight.tags.operatorKeyword], color: base0D },
{ tag: [highlight.tags.bracket], color: base0D },
{ tag: [highlight.tags.brace], color: base0D },
{ tag: [highlight.tags.punctuation], color: base0D },
// Functions and parameters
{ tag: [highlight.tags.function(highlight.tags.variableName), highlight.tags.labelName], color: base07 },
{ tag: [highlight.tags.definition(highlight.tags.variableName)], color: base06 },
// Constants and literals
{ tag: highlight.tags.number, color: base09 },
{ tag: highlight.tags.changed, color: base09 },
{ tag: highlight.tags.annotation, color: base0F, fontStyle: 'italic' },
{ tag: highlight.tags.modifier, color: base0F, fontStyle: 'italic' },
{ tag: highlight.tags.self, color: base09 },
{ tag: [highlight.tags.color, highlight.tags.constant(highlight.tags.name), highlight.tags.standard(highlight.tags.name)], color: base09 },
{ tag: [highlight.tags.atom, highlight.tags.bool, highlight.tags.special(highlight.tags.variableName)], color: base09 },
// Strings and regex
{ tag: [highlight.tags.processingInstruction, highlight.tags.inserted], color: base08 },
{ tag: [highlight.tags.special(highlight.tags.string), highlight.tags.regexp], color: base08 },
{ tag: highlight.tags.string, color: base08 },
// Punctuation and structure
{ tag: highlight.tags.definition(highlight.tags.typeName), color: base07, fontWeight: 'bold' },
// Comments and documentation
{ tag: highlight.tags.meta, color: base0A },
{ tag: highlight.tags.comment, fontStyle: 'italic', color: base0A },
{ tag: highlight.tags.docComment, fontStyle: 'italic', color: base0A },
// HTML/XML elements
{ tag: [highlight.tags.tagName], color: base0C },
{ tag: [highlight.tags.attributeName], color: base0F },
// Markdown and text formatting
{ tag: [highlight.tags.heading], fontWeight: 'bold', color: base0B },
{ tag: [highlight.tags.strong], fontWeight: 'bold', color: base09 },
{ tag: [highlight.tags.emphasis], fontStyle: 'italic', color: base0E },
// Links and URLs
{ tag: [highlight.tags.link], color: base0F, fontWeight: '500', textDecoration: 'underline', textUnderlinePosition: 'under' },
{
tag: [highlight.tags.url],
color: base0E,
textDecoration: 'underline',
textUnderlineOffset: '2px',
},
// Special states
{ tag: [highlight.tags.invalid], color: invalid, textDecoration: 'underline wavy' },
{ tag: [highlight.tags.strikethrough], color: invalid, textDecoration: 'line-through' },
// Enhanced syntax highlighting
{ tag: highlight.tags.constant(highlight.tags.name), color: base09 },
{ tag: highlight.tags.deleted, color: invalid },
{ tag: highlight.tags.squareBracket, color: base0D },
{ tag: highlight.tags.angleBracket, color: base0D },
]);
/**
* Combined Andromeda theme extension
*/
const andromeda = [
andromedaTheme,
language.syntaxHighlighting(andromedaHighlightStyle),
];
/**
* Andromeda merge revert styles configuration
*/
const andromedaMergeStyles = {
backgroundColor: darkBackground,
borderColor: '#3a3e4c',
buttonColor: base06,
buttonHoverColor: '#343946',
};
exports.andromeda = andromeda;
exports.andromedaMergeStyles = andromedaMergeStyles;
exports.applyMergeRevertStyles = applyMergeRevertStyles;