@fsegurai/codemirror-theme-github-light
Version:
GitHub Light theme for the CodeMirror editor
515 lines (508 loc) • 17.8 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',
borderRadious: '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 GitHub Light theme color palette
* ----------------------------------------
* Colors organized by function with visual color blocks for reference
*/
// Core UI colors
const base00 = '#ffffff', // Background (GitHub light mode background)
base01 = '#24292e', // Foreground (main text color)
base02 = '#BBDFFF', // Selection - light blue
base03 = '#6e7781', // Comments, subdued text
base04 = '#f6f8fa', // Light gray (gutter, panels)
// Syntax highlighting colors
base05 = '#116329', // Tag names - GitHub green
base06 = '#6a737d', // Comments, brackets - GitHub gray
base07 = '#6f42c1', // Classes, properties - GitHub purple
base08 = '#005cc5', // Variables, attributes - GitHub blue
base09 = '#d73a49', // Keywords, types - GitHub red
base0A = '#032f62', // Strings, regexps - GitHub navy
base0B = '#22863a', // Names, quotes - GitHub green
base0C = '#e36209', // Atoms, booleans - GitHub orange
// Background variants
base0D = '#f1f8ff', // Active line gutter background
base0E = '#e1e4e8', // Panel and tooltip border color
base0F = '#f8f9fa'; // Tooltip background
// Special states
const invalid = '#cb2431', // Invalid color - error red
highlightBackground = '#BBDFFF20', // Line highlight (light blue and opacity)
tooltipBackground = base0F, // Tooltip background
cursor = base01, // Caret color
selection = base02, // Selection color
activeBracketBg = '#e8f0fe', // Active bracket background
activeBracketBorder = '#0366d6', // Active bracket border
diagnosticWarning = '#b08800', // Warning color
selectionMatch = '#79b8ff40', // Selection match background
linkColor = '#0969da', // Bright blue for links
visitedLinkColor = '#8250df'; // Purple for visited links
// Diff/merge specific colors
const addedBackground = '#e6ffec80', // GitHub light green with transparency
removedBackground = '#ffebe980', // GitHub light red with transparency
addedText = '#0f6d31', // GitHub dark green for added text
removedText = '#cf222e'; // GitHub red for removed text
/**
* Enhanced editor theme styles for GitHub Light
*/
const githubLightTheme = 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: selection,
color: base01,
},
// Make sure selection appears above active line
'.cm-selectionLayer': {
zIndex: 100,
},
// Search functionality
'.cm-searchMatch': {
backgroundColor: '#daebff',
outline: `1px solid ${base08}`,
color: base01,
borderRadius: generalSearchField.borderRadius,
'& span': {
color: base01,
},
},
'.cm-searchMatch.cm-searchMatch-selected': {
backgroundColor: '#79b8ff',
color: base00,
padding: generalSearchField.padding,
'& span': {
color: base00,
},
},
'.cm-search.cm-panel.cm-textfield': {
color: base01,
borderRadius: generalSearchField.borderRadius,
padding: generalSearchField.padding,
},
// Panels
'.cm-panels': {
backgroundColor: base04,
color: base03,
borderRadius: '0 0 4px 4px',
},
'.cm-panels.cm-panels-top': {
borderBottom: `1px solid ${base0E}`,
},
'.cm-panels.cm-panels-bottom': {
borderTop: `1px solid ${base0E}`,
},
'.cm-panel button': {
backgroundColor: base00,
color: base01,
border: generalPanel.border,
borderRadius: generalPanel.borderRadius,
padding: generalPanel.padding,
},
'.cm-panel button:hover': {
backgroundColor: '#f5f5f5',
},
// Line highlighting
'.cm-activeLine': {
backgroundColor: highlightBackground,
borderRadius: generalLine.borderRadius,
zIndex: 1,
},
// Gutters
'.cm-gutters': {
backgroundColor: base04,
color: base03,
border: generalGutter.border,
borderRight: `1px solid ${base0E}`,
paddingRight: generalGutter.paddingRight,
},
'.cm-activeLineGutter': {
backgroundColor: base0D,
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: base03,
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.borderRadious,
},
'ins.cm-insertedLine, ins.cm-insertedLine:not(:has(.cm-changedText))': {
textDecoration: generalDiff.insertedTextDecoration,
backgroundColor: `${addedBackground} !important`,
color: addedText,
padding: generalDiff.insertedLinePadding,
borderRadius: generalDiff.borderRadious,
border: `1px solid ${addedText}30`,
},
'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.borderRadious,
},
'del.cm-deletedLine, del, del:not(:has(.cm-deletedText))': {
textDecoration: generalDiff.deletedTextDecoration,
backgroundColor: `${removedBackground} !important`,
color: removedText,
padding: generalDiff.insertedLinePadding,
borderRadius: generalDiff.borderRadious,
border: `1px solid ${removedText}30`,
},
'del .cm-deletedText, del .cm-changedText': {
background: 'transparent !important',
},
// Tooltips and autocomplete
'.cm-tooltip': {
backgroundColor: tooltipBackground,
border: `1px solid ${base0E}`,
borderRadius: generalTooltip.borderRadius,
padding: generalTooltip.padding,
boxShadow: '0 1px 5px rgba(0, 0, 0, 0.1)',
},
'.cm-tooltip-autocomplete': {
'& > ul': {
backgroundColor: tooltipBackground,
border: 'none',
},
'& > ul > li': {
padding: generalTooltip.padding,
lineHeight: generalTooltip.lineHeight,
},
'& > ul > li[aria-selected]': {
backgroundColor: '#0366d630',
color: base01,
borderRadius: generalTooltip.borderRadiusSelected,
},
'& > ul > li:hover': {
backgroundColor: '#0366d615',
},
'& > ul > li > span.cm-completionIcon': {
color: base03,
paddingRight: generalTooltip.paddingRight,
},
'& > ul > li > span.cm-completionDetail': {
color: base03,
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 ${diagnosticWarning}`,
},
'&-info': {
borderLeft: `3px solid ${linkColor}`,
},
},
'.cm-lintPoint-error': {
borderBottom: `2px wavy ${invalid}`,
},
'.cm-lintPoint-warning': {
borderBottom: `2px wavy ${diagnosticWarning}`,
},
// Matching brackets
'.cm-matchingBracket': {
backgroundColor: activeBracketBg,
outline: `1px solid ${activeBracketBorder}80`,
borderRadius: generalMatching.borderRadius,
},
'.cm-nonmatchingBracket': {
backgroundColor: '#ffeef080',
outline: `1px solid ${invalid}`,
borderRadius: generalMatching.borderRadius,
},
// Selection matches
'.cm-selectionMatch': {
backgroundColor: selectionMatch,
outline: `1px solid ${base02}50`,
borderRadius: generalMatching.borderRadius,
},
// Fold placeholder
'.cm-foldPlaceholder': {
backgroundColor: selectionMatch,
color: base03,
border: `1px dotted ${base0E}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 ${linkColor}40`,
},
// Scrollbars
'& .cm-scroller::-webkit-scrollbar': {
width: generalScroller.width,
height: generalScroller.height,
},
'& .cm-scroller::-webkit-scrollbar-track': {
background: base0E,
},
'& .cm-scroller::-webkit-scrollbar-thumb': {
backgroundColor: base01,
borderRadius: generalScroller.borderRadius,
border: `3px solid ${base0E}`,
},
'& .cm-scroller::-webkit-scrollbar-thumb:hover': {
backgroundColor: base06,
},
// Ghost text
'.cm-ghostText': {
opacity: '0.5',
color: '#959da5',
},
}, { dark: false });
/**
* Enhanced syntax highlighting for GitHub Light theme
*/
const githubLightHighlightStyle = language.HighlightStyle.define([
// Keywords and control flow
{ tag: highlight.tags.keyword, color: base09, fontWeight: 'bold' },
{ tag: highlight.tags.controlKeyword, color: base09, fontWeight: 'bold' },
{ tag: highlight.tags.moduleKeyword, color: base09, fontWeight: 'bold' },
// Names and variables
{ tag: [highlight.tags.name, highlight.tags.deleted, highlight.tags.character, highlight.tags.macroName], color: base08 },
{ tag: [highlight.tags.variableName], color: base08 },
{ tag: [highlight.tags.propertyName], color: base07, fontStyle: 'normal' },
// Classes and types
{ tag: [highlight.tags.typeName], color: base09 },
{ tag: [highlight.tags.className], color: base07, fontStyle: 'italic' },
{ tag: [highlight.tags.namespace], color: base08, fontStyle: 'italic' },
// Operators and punctuation
{ tag: [highlight.tags.operator, highlight.tags.operatorKeyword], color: base01 },
{ tag: [highlight.tags.bracket], color: base06 },
{ tag: [highlight.tags.brace], color: base06 },
{ tag: [highlight.tags.punctuation], color: base06 },
// Functions and parameters
{ tag: [highlight.tags.function(highlight.tags.variableName), highlight.tags.labelName], color: base0B },
{ tag: [highlight.tags.definition(highlight.tags.variableName)], color: base08 },
// Constants and literals
{ tag: highlight.tags.number, color: base0C },
{ tag: highlight.tags.changed, color: base0C },
{ tag: highlight.tags.annotation, color: invalid, fontStyle: 'italic' },
{ tag: highlight.tags.modifier, color: base0C, fontStyle: 'italic' },
{ tag: highlight.tags.self, color: base0C },
{ tag: [highlight.tags.color, highlight.tags.constant(highlight.tags.name), highlight.tags.standard(highlight.tags.name)], color: base0C },
{ tag: [highlight.tags.atom, highlight.tags.bool, highlight.tags.special(highlight.tags.variableName)], color: base0C },
// Strings and regex
{ tag: [highlight.tags.processingInstruction, highlight.tags.inserted], color: base0B },
{ tag: [highlight.tags.special(highlight.tags.string), highlight.tags.regexp], color: base0A },
{ tag: highlight.tags.string, color: base0A },
// Punctuation and structure
{ tag: highlight.tags.definition(highlight.tags.typeName), color: base09, fontWeight: 'bold' },
// Comments and documentation
{ tag: highlight.tags.meta, color: base06 },
{ tag: highlight.tags.comment, fontStyle: 'italic', color: base06 },
{ tag: highlight.tags.docComment, fontStyle: 'italic', color: base06 },
// HTML/XML elements
{ tag: [highlight.tags.tagName], color: base05 },
{ tag: [highlight.tags.attributeName], color: base07 },
// Markdown and text formatting
{ tag: [highlight.tags.heading], fontWeight: 'bold', color: base08 },
{ tag: [highlight.tags.strong], fontWeight: 'bold', color: base08 },
{ tag: [highlight.tags.emphasis], fontStyle: 'italic', color: base0A },
// Links and URLs
{
tag: [highlight.tags.link],
color: visitedLinkColor,
fontWeight: '500',
textDecoration: 'underline',
textUnderlinePosition: 'under',
},
{
tag: [highlight.tags.url],
color: linkColor,
textDecoration: 'underline',
textUnderlineOffset: '2px',
},
// Special states
{
tag: [highlight.tags.invalid],
color: base01,
textDecoration: 'underline wavy',
borderBottom: `1px wavy ${invalid}`,
},
{ tag: [highlight.tags.strikethrough], color: invalid, textDecoration: 'line-through' },
// Enhanced syntax highlighting
{ tag: highlight.tags.constant(highlight.tags.name), color: base0C },
{ tag: highlight.tags.deleted, color: invalid },
{ tag: highlight.tags.squareBracket, color: base06 },
{ tag: highlight.tags.angleBracket, color: base06 },
// Additional specific styles
{ tag: highlight.tags.monospace, color: base01 },
{ tag: [highlight.tags.contentSeparator], color: base08 },
{ tag: highlight.tags.quote, color: base06 },
]);
/**
* Combined GitHub Light theme extension
*/
const githubLight = [
githubLightTheme,
language.syntaxHighlighting(githubLightHighlightStyle),
];
/**
* GitHub Light merge revert styles configuration
*/
const githubLightMergeStyles = {
backgroundColor: tooltipBackground,
borderColor: base0E,
buttonColor: base01,
buttonHoverColor: '#f5f5f5',
};
exports.applyMergeRevertStyles = applyMergeRevertStyles;
exports.githubLight = githubLight;
exports.githubLightMergeStyles = githubLightMergeStyles;