UNPKG

@fsegurai/codemirror-theme-android-studio

Version:

Android Studio theme for the CodeMirror editor

482 lines (475 loc) 17.1 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', 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 Android Studio theme color palette * ------------------------------------------ * Colors refined for better contrast and visual hierarchy */ // Base colors const base00 = '#282b2e', // Background (authentic IntelliJ IDEA dark theme) base01 = '#a9b7c6', // Foreground (standard text) base02 = '#3f3f3f', // Selection background (slightly darker for contrast) base03 = '#3b3b3b', // Gutter background (slightly lighter than the main background) base04 = '#606366', // Line numbers (slightly darker for less distraction) // Language syntax colors base05 = '#cc7832', // Keywords (signature orange) base06 = '#6897bb', // Numbers, constants (signature blue) base07 = '#9876aa', // Variables (improved purple) base08 = '#787878', // Comments (authentic gray) base09 = '#bbb529', // Meta, annotations (yellow-green) base0A = '#6a8759', // Strings (signature green) base0B = '#ffc66d', // Class names, types (warmer gold) base0C = '#a9b7c6', // Attribute names (default text color) base0D = '#629755', // Function names, docs (forest green) base0E = '#d0d0ff', // Brackets, special constructs (soft purple) base0F = '#e8bf6a', // Tags (amber) base10 = '#3c7abb', // Links (blue) base11 = '#50a658', // URLs (green) // UI-specific colors invalid = '#ff5353', // Error highlighting (more visible) cursor = '#ffffff', // Cursor color selectionBackground = '#2e5280', // Stronger selection background selectionForeground = '#ffffff', // Selection text color highlightBackground = '#323232', // Active line highlight gutterBackground = '#313335', // Gutter background tooltipBackground = base03, // Tooltip background activeBracketBg = '#3b514d', activeBracketBorder = '#43705c', darkBackground = '#313335', // Diff/merge specific colors addedBackground = '#294436', // Dark green for insertions, matching IntelliJ removedBackground = '#484a4a', // Dark gray/red for deletions addedText = '#6a8759', // Matching the string color for added text removedText = '#cc7832'; // Using the keyword orange for removed text /** * Enhanced editor theme styles for Android Studio */ const androidStudioTheme = 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, }, // Search functionality '.cm-searchMatch': { backgroundColor: '#32593d', outline: '1px solid #ffffff', borderRadius: generalSearchField.borderRadius, '& span': { color: selectionForeground, }, }, '.cm-searchMatch.cm-searchMatch-selected': { backgroundColor: '#375580', color: selectionForeground, padding: generalSearchField.padding, '& span': { color: selectionForeground, }, }, '.cm-search.cm-panel.cm-textfield': { color: base01, borderRadius: generalSearchField.borderRadius, padding: generalSearchField.padding, }, // Panels '.cm-panels': { backgroundColor: darkBackground, color: base01, }, '.cm-panels.cm-panels-top': { borderBottom: '2px solid #5b5b5b', }, '.cm-panels.cm-panels-bottom': { borderTop: '2px solid #5b5b5b', }, '.cm-panel button': { backgroundColor: darkBackground, color: base01, border: generalPanel.border, borderRadius: generalPanel.borderRadius, padding: generalPanel.padding, }, '.cm-panel button:hover': { backgroundColor: '#404040', }, // Line highlighting '.cm-activeLine': { backgroundColor: '#32323221', borderRadius: generalLine.borderRadius, }, // Gutters '.cm-gutters': { backgroundColor: gutterBackground, color: base04, border: generalGutter.border, borderRight: '1px solid #3f3f3f', paddingRight: generalGutter.paddingRight, }, '.cm-activeLineGutter': { backgroundColor: highlightBackground, color: '#c0c0c0', fontWeight: generalGutter.fontWeight, }, '.cm-lineNumbers': { fontSize: generalGutter.fontSize, lineHeight: generalGutter.lineHeight, }, '.cm-foldGutter': { fontSize: generalGutter.fontSize, lineHeight: generalGutter.lineHeight, }, '.cm-foldGutter .cm-gutterElement': { color: base04, 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}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.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}40`, }, 'del .cm-deletedText, del .cm-changedText': { background: 'transparent !important', }, // Tooltips and autocomplete '.cm-tooltip': { backgroundColor: tooltipBackground, border: '1px solid #5b5b5b', borderRadius: generalTooltip.borderRadius, padding: generalTooltip.padding, boxShadow: '0 2px 8px rgba(0, 0, 0, 0.3)', }, '.cm-tooltip-autocomplete': { '& > ul > li': { padding: generalTooltip.padding, lineHeight: generalTooltip.lineHeight, }, '& > ul > li[aria-selected]': { backgroundColor: selectionBackground, color: selectionForeground, borderRadius: generalTooltip.borderRadiusSelected, }, '& > ul > li > span.cm-completionIcon': { color: base04, paddingRight: generalTooltip.paddingRight, }, '& > ul > li > span.cm-completionDetail': { color: base04, 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 ${base0F}`, }, '&-info': { borderLeft: `3px solid ${base0D}`, }, }, '.cm-lintPoint-error': { borderBottom: `2px wavy ${invalid}`, }, '.cm-lintPoint-warning': { borderBottom: `2px wavy ${base0F}`, }, // Matching brackets '.cm-matchingBracket': { backgroundColor: activeBracketBg, outline: `1px solid ${activeBracketBorder}`, borderRadius: generalMatching.borderRadius, }, '.cm-nonmatchingBracket': { backgroundColor: '#53383e', outline: `1px solid ${invalid}`, borderRadius: generalMatching.borderRadius, }, // Selection matches '.cm-selectionMatch': { backgroundColor: '#32593d40', outline: `1px solid ${base0D}`, borderRadius: generalMatching.borderRadius, }, // Fold placeholder '.cm-foldPlaceholder': { backgroundColor: tooltipBackground, color: '#a1a1a1', border: `1px dotted ${base04}`, borderRadius: generalPlaceholder.borderRadius, padding: generalPlaceholder.padding, margin: generalPlaceholder.margin, }, // Focus outline '&.cm-focused': { outline: 'none', boxShadow: `0 0 0 2px ${base02}, 0 0 0 4px ${base00}`, }, // Scrollbars '& .cm-scroller::-webkit-scrollbar': { width: generalScroller.width, height: generalScroller.height, }, '& .cm-scroller::-webkit-scrollbar-track': { background: darkBackground, }, '& .cm-scroller::-webkit-scrollbar-thumb': { backgroundColor: '#5a5a5a', borderRadius: generalScroller.borderRadius, border: `3px solid ${darkBackground}`, }, '& .cm-scroller::-webkit-scrollbar-thumb:hover': { backgroundColor: '#6e6e6e', }, // Ghost text '.cm-ghostText': { opacity: '0.5', color: '#a9a9a9', }, }, { dark: true }); /** * Enhanced syntax highlighting for the Android Studio theme */ const androidStudioHighlightStyle = 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: base07 }, { tag: [highlight.tags.variableName], color: base07 }, { tag: [highlight.tags.propertyName], color: base0A, fontStyle: 'normal' }, // Classes and types { tag: [highlight.tags.typeName], color: base0B }, { tag: [highlight.tags.className], color: base0B, fontStyle: 'italic' }, { tag: [highlight.tags.namespace], color: base07, fontStyle: 'italic' }, // Operators and punctuation { tag: [highlight.tags.operator, highlight.tags.operatorKeyword], color: base05 }, { tag: [highlight.tags.bracket], color: base0E }, { tag: [highlight.tags.brace], color: base01 }, { tag: [highlight.tags.punctuation], color: base01 }, // Functions and parameters { tag: [highlight.tags.function(highlight.tags.variableName), highlight.tags.labelName], color: base01 }, { tag: [highlight.tags.definition(highlight.tags.variableName)], color: base07 }, // Constants and literals { tag: highlight.tags.number, color: base06 }, { tag: highlight.tags.changed, color: base06 }, { tag: highlight.tags.annotation, color: base09, fontStyle: 'italic' }, { tag: highlight.tags.modifier, color: base09, fontStyle: 'italic' }, { tag: highlight.tags.self, color: base05 }, { tag: [highlight.tags.color, highlight.tags.constant(highlight.tags.name), highlight.tags.standard(highlight.tags.name)], color: base06 }, { tag: [highlight.tags.atom, highlight.tags.bool, highlight.tags.special(highlight.tags.variableName)], color: base05 }, // Strings and regex { tag: [highlight.tags.processingInstruction, highlight.tags.inserted], color: base0A }, { 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: base0B, fontWeight: 'bold' }, // Comments and documentation { tag: highlight.tags.meta, color: base08 }, { tag: highlight.tags.comment, fontStyle: 'italic', color: base08 }, { tag: highlight.tags.docComment, fontStyle: 'italic', color: base0D }, // HTML/XML elements { tag: [highlight.tags.tagName], color: base0F }, { tag: [highlight.tags.attributeName], color: base0C }, // Markdown and text formatting { tag: [highlight.tags.heading], fontWeight: 'bold', color: base0B }, { tag: [highlight.tags.strong], fontWeight: 'bold' }, { tag: [highlight.tags.emphasis], fontStyle: 'italic' }, // Links and URLs { tag: [highlight.tags.link], color: base10, fontWeight: '500' }, { tag: [highlight.tags.url], color: base11, 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: base06 }, { tag: highlight.tags.deleted, color: invalid }, { tag: highlight.tags.labelName, color: base0D }, ]); /** * Combined Android Studio theme extension */ const androidStudio = [ androidStudioTheme, language.syntaxHighlighting(androidStudioHighlightStyle), ]; /** * Android Studio merge revert styles configuration */ const androidStudioMergeStyles = { backgroundColor: darkBackground, borderColor: '#5b5b5b', buttonColor: base01, buttonHoverColor: '#414141', }; exports.androidStudio = androidStudio; exports.androidStudioMergeStyles = androidStudioMergeStyles; exports.applyMergeRevertStyles = applyMergeRevertStyles;