UNPKG

@fsegurai/codemirror-theme-palenight

Version:
512 lines (505 loc) 17.9 kB
'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 Palenight theme color definitions * --------------------------------------- * Colors organized by function with visual color blocks */ // Base colors const base00 = '#292D3E', // Background - deep indigo base01 = '#A6ACCD', // Foreground - lavender blue base02 = '#444267', // Selection background - muted indigo base03 = '#676E95', // Comments, invisible - steel blue base04 = '#BFC7D5', // Cursor - lighter lavender // Accent colors base05 = '#C3E88D', // Strings - light green base06 = '#82AAFF', // Keywords, Functions - sky blue base07 = '#C792EA', // Classes, Types - purple base08 = '#F78C6C', // Numbers, Constants - orange base09 = '#FFCB6B', // Classes, Attributes - yellow base0A = '#89DDFF', // Punctuation, Operators - light blue base0B = '#FF5370', // Tags, Errors - red base0C = '#BB80B3', // Special elements - mauve base0D = '#80CBC4'; // Properties - seafoam // UI specific colors const invalid = '#FF5370', // Error color - red darkBackground = '#202331', // Darker background for panels and gutter highlightBackground = '#2e324817', // Active line background background = base00, // Main editor background tooltipBackground = '#343A50', // Tooltip background selection = base02, // Selection background selectionMatch = '#444267AA', // Selection match with opacity cursor = base04, // Cursor color activeBracketBg = '#2E3248', // Active bracket background activeBracketBorder = base06, // Active bracket border - sky blue diagnosticWarning = base09, // Warning color - yellow linkColor = base06, // Link color - sky blue visitedLinkColor = base07; // Visited link color - purple // Diff/merge specific colors const addedBackground = '#2c3c2e80', // Dark green with transparency for insertions removedBackground = '#3e2e3180', // Dark red with transparency for deletions addedText = '#C3E88D', // Palenight green for added text removedText = '#FF5370'; // Palenight red for removed text /** * Enhanced editor theme styles for Palenight */ const palenightTheme = view.EditorView.theme({ // Base editor styles '&': { color: base01, backgroundColor: background, 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: background, }, // Selection '&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection': { backgroundColor: selection, }, // Make sure selection appears above active line '.cm-selectionLayer': { zIndex: 100, }, // Search functionality '.cm-searchMatch': { backgroundColor: '#444267CC', outline: `1px solid ${base06}`, color: base01, borderRadius: generalSearchField.borderRadius, '& span': { color: base01, }, }, '.cm-searchMatch.cm-searchMatch-selected': { backgroundColor: base06, color: background, padding: generalSearchField.padding, '& span': { color: background, }, }, '.cm-search.cm-panel.cm-textfield': { color: base01, borderRadius: generalSearchField.borderRadius, padding: generalSearchField.padding, }, // Panels '.cm-panels': { backgroundColor: darkBackground, color: base01, borderRadius: '4px', }, '.cm-panels.cm-panels-top': { borderBottom: `1px solid ${base02}`, }, '.cm-panels.cm-panels-bottom': { borderTop: `1px solid ${base02}`, }, '.cm-panel button': { backgroundColor: tooltipBackground, color: base01, border: generalPanel.border, borderRadius: generalPanel.borderRadius, padding: generalPanel.padding, }, '.cm-panel button:hover': { backgroundColor: '#3A4058', }, // Line highlighting '.cm-activeLine': { backgroundColor: highlightBackground, borderRadius: generalLine.borderRadius, zIndex: 1, }, // Gutters '.cm-gutters': { backgroundColor: darkBackground, color: base03, border: generalGutter.border, borderRight: '1px solid #3A405880', paddingRight: generalGutter.paddingRight, }, '.cm-activeLineGutter': { backgroundColor: '#2A2D40', 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.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 #3A4058', borderRadius: generalTooltip.borderRadius, padding: generalTooltip.padding, boxShadow: '0 2px 8px rgba(0, 0, 0, 0.4)', }, '.cm-tooltip-autocomplete': { '& > ul': { backgroundColor: tooltipBackground, border: 'none', }, '& > ul > li': { padding: generalTooltip.padding, lineHeight: generalTooltip.lineHeight, }, '& > ul > li[aria-selected]': { backgroundColor: selection, color: base04, borderRadius: generalTooltip.borderRadiusSelected, }, '& > 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}`, borderRadius: generalMatching.borderRadius, }, '.cm-nonmatchingBracket': { backgroundColor: `${invalid}40`, outline: `1px solid ${invalid}`, borderRadius: generalMatching.borderRadius, }, // Selection matches '.cm-selectionMatch': { backgroundColor: selectionMatch, outline: `1px solid ${base03}50`, borderRadius: generalMatching.borderRadius, }, // Fold placeholder '.cm-foldPlaceholder': { backgroundColor: tooltipBackground, color: base03, border: `1px dotted ${base03}70`, borderRadius: generalPlaceholder.borderRadius, padding: generalPlaceholder.padding, margin: generalPlaceholder.margin, }, // Focus outline '&.cm-focused': { outline: 'none', boxShadow: `0 0 0 2px ${background}, 0 0 0 3px ${base06}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: base02, borderRadius: generalScroller.borderRadius, border: `3px solid ${darkBackground}`, }, '& .cm-scroller::-webkit-scrollbar-thumb:hover': { backgroundColor: '#515580', }, // Ghost text '.cm-ghostText': { opacity: '0.5', color: base03, }, }, { dark: true }); /** * Enhanced syntax highlighting for Palenight theme */ const palenightHighlightStyle = language.HighlightStyle.define([ // Keywords and control flow { tag: highlight.tags.keyword, color: base06, fontWeight: 'bold' }, { tag: highlight.tags.controlKeyword, color: base06, fontWeight: 'bold' }, { tag: highlight.tags.moduleKeyword, color: base06, fontWeight: 'bold' }, // Names and variables { tag: [highlight.tags.name, highlight.tags.deleted, highlight.tags.character, highlight.tags.macroName], color: base01 }, { tag: [highlight.tags.variableName], color: base01 }, { tag: [highlight.tags.propertyName], color: base0D, fontStyle: 'normal' }, // Classes and types { tag: [highlight.tags.typeName], color: base07 }, { tag: [highlight.tags.className], color: base09, fontStyle: 'italic' }, { tag: [highlight.tags.namespace], color: base09, fontStyle: 'italic' }, // Operators and punctuation { tag: [highlight.tags.operator, highlight.tags.operatorKeyword], color: base0A }, { tag: [highlight.tags.bracket], color: base0A }, { tag: [highlight.tags.brace], color: base0A }, { tag: [highlight.tags.punctuation], color: base0A }, // Functions and parameters { tag: [highlight.tags.function(highlight.tags.variableName), highlight.tags.labelName], color: base06 }, { tag: [highlight.tags.definition(highlight.tags.function(highlight.tags.variableName))], color: base06 }, { tag: [highlight.tags.definition(highlight.tags.variableName)], color: base08 }, // Constants and literals { tag: highlight.tags.number, color: base08 }, { tag: highlight.tags.changed, color: base08 }, { tag: highlight.tags.annotation, color: invalid, fontStyle: 'italic' }, { tag: highlight.tags.modifier, color: base0C, fontStyle: 'italic' }, { tag: highlight.tags.self, color: base07 }, { tag: [highlight.tags.color, highlight.tags.constant(highlight.tags.name), highlight.tags.standard(highlight.tags.name)], color: base08 }, { 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: base05 }, { tag: [highlight.tags.special(highlight.tags.string), highlight.tags.regexp], color: base05 }, { tag: highlight.tags.string, color: base05 }, // Punctuation and structure { tag: highlight.tags.definition(highlight.tags.typeName), color: base07, fontWeight: 'bold' }, { tag: [highlight.tags.definition(highlight.tags.name), highlight.tags.separator], color: base0A }, // Comments and documentation { tag: highlight.tags.meta, color: base03 }, { tag: highlight.tags.comment, fontStyle: 'italic', color: base03 }, { tag: highlight.tags.docComment, fontStyle: 'italic', color: base03 }, // HTML/XML elements { tag: [highlight.tags.tagName], color: base0B }, { tag: [highlight.tags.attributeName], color: base09 }, // Markdown and text formatting { tag: [highlight.tags.heading], fontWeight: 'bold', color: base09 }, { tag: [highlight.tags.strong], fontWeight: 'bold', color: base09 }, { tag: [highlight.tags.emphasis], fontStyle: 'italic', color: base05 }, // 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: base08 }, { tag: highlight.tags.deleted, color: invalid }, { tag: highlight.tags.squareBracket, color: base0A }, { tag: highlight.tags.angleBracket, color: base0A }, // Additional specific styles { tag: highlight.tags.monospace, color: base01 }, { tag: [highlight.tags.contentSeparator], color: base09 }, { tag: highlight.tags.quote, color: base03 }, ]); /** * Combined Palenight theme extension */ const palenight = [ palenightTheme, language.syntaxHighlighting(palenightHighlightStyle), ]; /** * Palenight merge revert styles configuration */ const palenightMergeStyles = { backgroundColor: darkBackground, borderColor: '#3A4058', buttonColor: base01, buttonHoverColor: '#3A4058', }; exports.applyMergeRevertStyles = applyMergeRevertStyles; exports.palenight = palenight; exports.palenightMergeStyles = palenightMergeStyles;