1+ import { EditorView } from '@codemirror/view' ;
2+ import { Extension } from '@codemirror/state' ;
3+ import { HighlightStyle , syntaxHighlighting } from '@codemirror/language' ;
4+ import { tags as t } from '@lezer/highlight' ;
5+
6+ const draculaColors = {
7+ background : '#1a1a2e' ,
8+ foreground : '#f1f5f9' ,
9+ selection : '#3d4852' ,
10+ lineHighlight : '#252b3a' ,
11+ cursor : '#50fa7b' ,
12+ comment : '#8be9fd' ,
13+ string : '#50fa7b' ,
14+ number : '#bd93f9' ,
15+ keyword : '#8be9fd' ,
16+ function : '#8be9fd' ,
17+ className : '#50fa7b' ,
18+ tag : '#8be9fd' ,
19+ attribute : '#50fa7b' ,
20+ property : '#8be9fd' ,
21+ variable : '#8be9fd' ,
22+ constant : '#bd93f9' ,
23+ type : '#bd93f9' ,
24+ operator : '#ff79c6' ,
25+ punctuation : '#f8f8f2' ,
26+ bracket : '#f8f8f2' ,
27+ invalid : '#ff5555' ,
28+ deprecated : '#ffb86c' ,
29+ lineNumber : '#64748b' ,
30+ activeLineNumber : '#8be9fd' ,
31+ gutter : '#16213e' ,
32+ scrollbar : '#50fa7b30' ,
33+ scrollbarHover : '#50fa7b50' ,
34+ scrollbarActive : '#50fa7b70' ,
35+ } ;
36+
37+ const draculaTheme = EditorView . theme ( {
38+ '&' : {
39+ color : draculaColors . foreground ,
40+ backgroundColor : draculaColors . background ,
41+ } ,
42+ '.cm-content' : {
43+ padding : '16px' ,
44+ caretColor : draculaColors . cursor ,
45+ } ,
46+ '.cm-focused .cm-cursor' : {
47+ borderLeftColor : draculaColors . cursor ,
48+ } ,
49+ '.cm-focused .cm-selectionBackground, ::selection' : {
50+ backgroundColor : draculaColors . selection ,
51+ } ,
52+ '.cm-selectionBackground' : {
53+ backgroundColor : `${ draculaColors . selection } 99` ,
54+ } ,
55+ '.cm-activeLine' : {
56+ backgroundColor : draculaColors . lineHighlight ,
57+ } ,
58+ '.cm-gutters' : {
59+ backgroundColor : draculaColors . gutter ,
60+ color : draculaColors . lineNumber ,
61+ borderRight : 'none' ,
62+ } ,
63+ '.cm-activeLineGutter' : {
64+ backgroundColor : draculaColors . lineHighlight ,
65+ color : draculaColors . activeLineNumber ,
66+ } ,
67+ '.cm-lineNumbers' : {
68+ color : draculaColors . lineNumber ,
69+ } ,
70+ '.cm-foldPlaceholder' : {
71+ backgroundColor : 'transparent' ,
72+ border : 'none' ,
73+ color : draculaColors . comment ,
74+ } ,
75+ '.cm-tooltip' : {
76+ border : 'none' ,
77+ backgroundColor : draculaColors . background ,
78+ color : draculaColors . foreground ,
79+ } ,
80+ '.cm-tooltip-autocomplete' : {
81+ '& > ul > li[aria-selected]' : {
82+ backgroundColor : draculaColors . selection ,
83+ color : draculaColors . foreground ,
84+ }
85+ } ,
86+ '.cm-searchMatch' : {
87+ backgroundColor : '#50fa7b40' ,
88+ outline : '1px solid #50fa7b' ,
89+ } ,
90+ '.cm-searchMatch.cm-searchMatch-selected' : {
91+ backgroundColor : '#50fa7b80' ,
92+ } ,
93+ '.cm-panels' : {
94+ backgroundColor : draculaColors . gutter ,
95+ color : draculaColors . foreground ,
96+ } ,
97+ '.cm-panels.cm-panels-top' : {
98+ borderBottom : '2px solid #374151' ,
99+ } ,
100+ '.cm-panels.cm-panels-bottom' : {
101+ borderTop : '2px solid #374151' ,
102+ } ,
103+ '.cm-scroller' : {
104+ fontFamily : 'Monaco, Menlo, "Ubuntu Mono", monospace' ,
105+ fontSize : '14px' ,
106+ lineHeight : '1.5' ,
107+ } ,
108+ } , { dark : true } ) ;
109+
110+ const draculaHighlightStyle = HighlightStyle . define ( [
111+ { tag : t . comment , color : draculaColors . comment , fontStyle : 'italic' } ,
112+ { tag : t . lineComment , color : draculaColors . comment , fontStyle : 'italic' } ,
113+ { tag : t . blockComment , color : draculaColors . comment , fontStyle : 'italic' } ,
114+ { tag : t . docComment , color : draculaColors . comment , fontStyle : 'italic' } ,
115+
116+ { tag : t . keyword , color : draculaColors . keyword , fontWeight : 'bold' } ,
117+ { tag : t . controlKeyword , color : draculaColors . keyword , fontWeight : 'bold' } ,
118+ { tag : t . modifier , color : draculaColors . keyword , fontWeight : 'bold' } ,
119+ { tag : t . operatorKeyword , color : draculaColors . keyword , fontWeight : 'bold' } ,
120+
121+ { tag : t . variableName , color : draculaColors . variable } ,
122+ { tag : t . typeName , color : draculaColors . type , fontStyle : 'italic' } ,
123+ { tag : t . atom , color : draculaColors . constant } ,
124+ { tag : t . bool , color : draculaColors . constant } ,
125+ { tag : t . special ( t . variableName ) , color : draculaColors . constant } ,
126+
127+ { tag : t . number , color : draculaColors . number } ,
128+ { tag : t . string , color : draculaColors . string } ,
129+ { tag : t . special ( t . string ) , color : draculaColors . string } ,
130+ { tag : t . regexp , color : draculaColors . string } ,
131+
132+ { tag : t . definition ( t . typeName ) , color : draculaColors . className , fontWeight : 'bold' } ,
133+ { tag : t . className , color : draculaColors . className , fontWeight : 'bold' } ,
134+ { tag : t . definition ( t . propertyName ) , color : draculaColors . function , fontWeight : 'bold' } ,
135+ { tag : t . function ( t . variableName ) , color : draculaColors . function , fontWeight : 'bold' } ,
136+ { tag : t . function ( t . propertyName ) , color : draculaColors . function , fontWeight : 'bold' } ,
137+
138+ { tag : t . tagName , color : draculaColors . tag } ,
139+ { tag : t . attributeName , color : draculaColors . attribute } ,
140+ { tag : t . attributeValue , color : draculaColors . string } ,
141+
142+ { tag : t . propertyName , color : draculaColors . property } ,
143+ { tag : t . namespace , color : draculaColors . variable } ,
144+ { tag : t . macroName , color : draculaColors . function } ,
145+
146+ { tag : t . operator , color : draculaColors . operator } ,
147+ { tag : t . separator , color : draculaColors . punctuation } ,
148+ { tag : t . punctuation , color : draculaColors . punctuation } ,
149+ { tag : t . bracket , color : draculaColors . bracket } ,
150+ { tag : t . angleBracket , color : draculaColors . bracket } ,
151+ { tag : t . squareBracket , color : draculaColors . bracket } ,
152+ { tag : t . paren , color : draculaColors . bracket } ,
153+ { tag : t . brace , color : draculaColors . bracket } ,
154+
155+ { tag : t . invalid , color : draculaColors . invalid , fontWeight : 'bold' } ,
156+ { tag : t . deleted , color : draculaColors . invalid , backgroundColor : '#ff555540' } ,
157+ { tag : t . inserted , color : draculaColors . string , backgroundColor : '#50fa7b40' } ,
158+ { tag : t . changed , color : draculaColors . deprecated , backgroundColor : '#ffb86c40' } ,
159+
160+ { tag : t . strong , fontWeight : 'bold' } ,
161+ { tag : t . emphasis , fontStyle : 'italic' } ,
162+ { tag : t . strikethrough , textDecoration : 'line-through' } ,
163+ { tag : t . link , color : draculaColors . string , textDecoration : 'underline' } ,
164+ { tag : t . heading , color : draculaColors . function , fontWeight : 'bold' } ,
165+ ] ) ;
166+
167+ export const draculaExtension : Extension = [
168+ draculaTheme ,
169+ syntaxHighlighting ( draculaHighlightStyle ) ,
170+ ] ;
0 commit comments