@fsegurai/codemirror-theme-high-contrast-dark 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts ADDED
@@ -0,0 +1,484 @@
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
+ import {
7
+ applyMergeRevertStyles,
8
+ generalContent,
9
+ generalDiff,
10
+ generalGutter,
11
+ generalLine,
12
+ generalMatching,
13
+ generalPanel,
14
+ generalPlaceholder,
15
+ generalScroller,
16
+ generalSearchField,
17
+ generalTooltip,
18
+ IMergeRevertStyles,
19
+ } from './utils';
20
+
21
+ /**
22
+ * High Contrast Dark theme color definitions
23
+ * ------------------------------------------
24
+ * Maximum contrast theme for accessibility
25
+ */
26
+
27
+ // Base colors - Pure black and white for maximum contrast
28
+ const base00 = '#000000', // Background - pure black
29
+ base01 = '#0a0a0a', // Darker background
30
+ base02 = '#1f1f1f', // Selection background
31
+ base03 = '#808080', // Comments - medium grey
32
+ base04 = '#b0b0b0', // Dark grey
33
+ base05 = '#ffffff', // Foreground - pure white
34
+
35
+ // High contrast accent colors
36
+ brightYellow = '#ffff00',
37
+ brightCyan = '#00ffff',
38
+ brightGreen = '#00ff00',
39
+ brightRed = '#ff0000',
40
+ brightMagenta = '#ff00ff',
41
+ brightBlue = '#0099ff',
42
+ brightOrange = '#ff9900',
43
+ brightPurple = '#cc66ff';
44
+
45
+ // UI specific colors
46
+ const invalid = brightRed,
47
+ darkBackground = base00,
48
+ background = base00,
49
+ tooltipBackground = '#1a1a1a',
50
+ selection = '#264f78',
51
+ selectionMatch = '#264f7880',
52
+ cursor = brightYellow,
53
+ activeBracketBg = '#1f1f1f',
54
+ activeBracketBorder = brightCyan,
55
+ diagnosticWarning = brightYellow,
56
+ linkColor = brightCyan,
57
+ visitedLinkColor = brightMagenta;
58
+
59
+ // Diff/merge specific colors
60
+ const addedBackground = '#00550060',
61
+ removedBackground = '#55000060',
62
+ addedText = brightGreen,
63
+ removedText = brightRed;
64
+
65
+ /**
66
+ * Enhanced editor theme styles for High Contrast Dark
67
+ */
68
+ const highContrastDarkTheme = EditorView.theme(
69
+ {
70
+ // Base editor styles
71
+ '&': {
72
+ color: base05,
73
+ backgroundColor: background,
74
+ fontSize: generalContent.fontSize,
75
+ fontFamily: generalContent.fontFamily,
76
+ border: `1px solid ${base04}`,
77
+ },
78
+
79
+ // Content and cursor
80
+ '.cm-content': {
81
+ caretColor: cursor,
82
+ lineHeight: generalContent.lineHeight,
83
+ },
84
+ '.cm-cursor, .cm-dropCursor': {
85
+ borderLeftColor: cursor,
86
+ borderLeftWidth: '3px',
87
+ },
88
+ '.cm-fat-cursor': {
89
+ backgroundColor: cursor,
90
+ color: background,
91
+ border: `2px solid ${base05}`,
92
+ },
93
+
94
+ // Selection
95
+ '&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection':
96
+ {
97
+ backgroundColor: '#3a5a8a',
98
+ outline: `2px solid ${brightCyan}`,
99
+ },
100
+
101
+ // Make sure selection appears above active line
102
+ '.cm-selectionLayer': {
103
+ zIndex: 100,
104
+ },
105
+
106
+ // Search functionality
107
+ '.cm-searchMatch': {
108
+ backgroundColor: '#006400',
109
+ outline: `2px solid ${brightGreen}`,
110
+ color: base05,
111
+ borderRadius: generalSearchField.borderRadius,
112
+
113
+ '& span': {
114
+ color: base05,
115
+ },
116
+ },
117
+ '.cm-searchMatch.cm-searchMatch-selected': {
118
+ backgroundColor: brightGreen,
119
+ color: base00,
120
+ padding: generalSearchField.padding,
121
+ outline: `2px solid ${base05}`,
122
+
123
+ '& span': {
124
+ color: base00,
125
+ },
126
+ },
127
+ '.cm-search.cm-panel.cm-textfield': {
128
+ color: base05,
129
+ backgroundColor: base01,
130
+ border: `1px solid ${base04}`,
131
+ borderRadius: generalSearchField.borderRadius,
132
+ padding: generalSearchField.padding,
133
+ },
134
+
135
+ // Panels
136
+ '.cm-panels': {
137
+ backgroundColor: darkBackground,
138
+ color: base05,
139
+ borderRadius: '4px',
140
+ border: `1px solid ${base04}`,
141
+ },
142
+ '.cm-panels.cm-panels-top': {
143
+ borderBottom: `2px solid ${base04}`,
144
+ },
145
+ '.cm-panels.cm-panels-bottom': {
146
+ borderTop: `2px solid ${base04}`,
147
+ },
148
+ '.cm-panel button': {
149
+ backgroundColor: tooltipBackground,
150
+ color: brightCyan,
151
+ border: `1px solid ${base04}`,
152
+ borderRadius: generalPanel.borderRadius,
153
+ padding: generalPanel.padding,
154
+ },
155
+ '.cm-panel button:hover': {
156
+ backgroundColor: base02,
157
+ border: `1px solid ${brightCyan}`,
158
+ },
159
+
160
+ // Line highlighting
161
+ '.cm-activeLine': {
162
+ backgroundColor: '#2a2a2aa6',
163
+ borderRadius: generalLine.borderRadius,
164
+ borderLeft: `3px solid ${brightCyan}`,
165
+ borderRight: `1px solid ${base04}`,
166
+ zIndex: 1,
167
+ },
168
+
169
+ // Gutters
170
+ '.cm-gutters': {
171
+ backgroundColor: darkBackground,
172
+ color: base04,
173
+ border: generalGutter.border,
174
+ borderRight: `2px solid ${base04}`,
175
+ paddingRight: generalGutter.paddingRight,
176
+ },
177
+ '.cm-activeLineGutter': {
178
+ backgroundColor: base02,
179
+ color: brightYellow,
180
+ fontWeight: 'bold',
181
+ border: `1px solid ${base03}`,
182
+ },
183
+ '.cm-lineNumbers': {
184
+ fontSize: generalGutter.fontSize,
185
+ lineHeight: generalGutter.lineHeight,
186
+ },
187
+ '.cm-foldGutter': {
188
+ fontSize: generalGutter.fontSize,
189
+ lineHeight: generalGutter.lineHeight,
190
+ },
191
+ '.cm-foldGutter .cm-gutterElement': {
192
+ color: base04,
193
+ cursor: 'pointer',
194
+ },
195
+ '.cm-foldGutter .cm-gutterElement:hover': {
196
+ color: brightCyan,
197
+ },
198
+
199
+ // Diff/Merge View Styles
200
+ '.cm-insertedLine': {
201
+ textDecoration: generalDiff.insertedTextDecoration,
202
+ backgroundColor: addedBackground,
203
+ color: addedText,
204
+ padding: generalDiff.insertedLinePadding,
205
+ borderRadius: generalDiff.borderRadious,
206
+ border: `1px solid ${addedText}`,
207
+ },
208
+ 'ins.cm-insertedLine, ins.cm-insertedLine:not(:has(.cm-changedText))': {
209
+ textDecoration: generalDiff.insertedTextDecoration,
210
+ backgroundColor: `${addedBackground} !important`,
211
+ color: addedText,
212
+ padding: generalDiff.insertedLinePadding,
213
+ borderRadius: generalDiff.borderRadious,
214
+ border: `1px solid ${addedText}`,
215
+ },
216
+ 'ins.cm-insertedLine .cm-changedText': {
217
+ background: 'transparent !important',
218
+ },
219
+
220
+ '.cm-deletedLine': {
221
+ textDecoration: generalDiff.deletedTextDecoration,
222
+ backgroundColor: removedBackground,
223
+ color: removedText,
224
+ padding: generalDiff.insertedLinePadding,
225
+ borderRadius: generalDiff.borderRadious,
226
+ border: `1px solid ${removedText}`,
227
+ },
228
+ 'del.cm-deletedLine, del, del:not(:has(.cm-deletedText))': {
229
+ textDecoration: generalDiff.deletedTextDecoration,
230
+ backgroundColor: `${removedBackground} !important`,
231
+ color: removedText,
232
+ padding: generalDiff.insertedLinePadding,
233
+ borderRadius: generalDiff.borderRadious,
234
+ border: `1px solid ${removedText}`,
235
+ },
236
+ 'del .cm-deletedText, del .cm-changedText': {
237
+ background: 'transparent !important',
238
+ },
239
+
240
+ // Tooltips and autocomplete
241
+ '.cm-tooltip': {
242
+ backgroundColor: tooltipBackground,
243
+ border: `2px solid ${brightCyan}`,
244
+ borderRadius: generalTooltip.borderRadius,
245
+ padding: generalTooltip.padding,
246
+ color: base05,
247
+ },
248
+ '.cm-tooltip-autocomplete': {
249
+ '& > ul': {
250
+ backgroundColor: tooltipBackground,
251
+ border: `1px solid ${base04}`,
252
+ },
253
+ '& > ul > li': {
254
+ padding: generalTooltip.padding,
255
+ lineHeight: generalTooltip.lineHeight,
256
+ },
257
+ '& > ul > li[aria-selected]': {
258
+ backgroundColor: selection,
259
+ color: brightYellow,
260
+ borderRadius: generalTooltip.borderRadiusSelected,
261
+ border: `1px solid ${brightCyan}`,
262
+ },
263
+ '& > ul > li > span.cm-completionIcon': {
264
+ color: brightCyan,
265
+ paddingRight: generalTooltip.paddingRight,
266
+ },
267
+ '& > ul > li > span.cm-completionDetail': {
268
+ color: brightYellow,
269
+ fontStyle: 'italic',
270
+ },
271
+ },
272
+ '.cm-tooltip .cm-tooltip-arrow:before': {
273
+ borderTopColor: 'transparent',
274
+ borderBottomColor: 'transparent',
275
+ },
276
+ '.cm-tooltip .cm-tooltip-arrow:after': {
277
+ borderTopColor: brightCyan,
278
+ borderBottomColor: brightCyan,
279
+ },
280
+
281
+ // Diagnostics styling
282
+ '.cm-diagnostic': {
283
+ '&-error': {
284
+ borderLeft: `4px solid ${brightRed}`,
285
+ backgroundColor: '#33000020',
286
+ },
287
+ '&-warning': {
288
+ borderLeft: `4px solid ${diagnosticWarning}`,
289
+ backgroundColor: '#33330020',
290
+ },
291
+ '&-info': {
292
+ borderLeft: `4px solid ${linkColor}`,
293
+ backgroundColor: '#00333320',
294
+ },
295
+ },
296
+ '.cm-lintPoint-error': {
297
+ borderBottom: `3px wavy ${brightRed}`,
298
+ },
299
+ '.cm-lintPoint-warning': {
300
+ borderBottom: `3px wavy ${diagnosticWarning}`,
301
+ },
302
+
303
+ // Matching brackets
304
+ '.cm-matchingBracket': {
305
+ backgroundColor: activeBracketBg,
306
+ outline: `2px solid ${activeBracketBorder}`,
307
+ borderRadius: generalMatching.borderRadius,
308
+ },
309
+ '.cm-nonmatchingBracket': {
310
+ backgroundColor: '#33000050',
311
+ outline: `2px solid ${invalid}`,
312
+ borderRadius: generalMatching.borderRadius,
313
+ },
314
+
315
+ // Selection matches
316
+ '.cm-selectionMatch': {
317
+ backgroundColor: selectionMatch,
318
+ outline: `2px solid ${brightCyan}50`,
319
+ borderRadius: generalMatching.borderRadius,
320
+ },
321
+
322
+ // Fold placeholder
323
+ '.cm-foldPlaceholder': {
324
+ backgroundColor: tooltipBackground,
325
+ color: brightCyan,
326
+ border: `2px solid ${brightCyan}`,
327
+ borderRadius: generalPlaceholder.borderRadius,
328
+ padding: generalPlaceholder.padding,
329
+ margin: generalPlaceholder.margin,
330
+ },
331
+
332
+ // Focus outline
333
+ '&.cm-focused': {
334
+ outline: `3px solid ${brightCyan}`,
335
+ outlineOffset: '2px',
336
+ },
337
+
338
+ // Scrollbars
339
+ '& .cm-scroller::-webkit-scrollbar': {
340
+ width: generalScroller.width,
341
+ height: generalScroller.height,
342
+ },
343
+ '& .cm-scroller::-webkit-scrollbar-track': {
344
+ background: darkBackground,
345
+ border: `1px solid ${base04}`,
346
+ },
347
+ '& .cm-scroller::-webkit-scrollbar-thumb': {
348
+ backgroundColor: base04,
349
+ border: `2px solid ${base05}`,
350
+ borderRadius: generalScroller.borderRadius,
351
+ },
352
+ '& .cm-scroller::-webkit-scrollbar-thumb:hover': {
353
+ backgroundColor: brightCyan,
354
+ },
355
+
356
+ // Ghost text
357
+ '.cm-ghostText': {
358
+ opacity: '0.7',
359
+ color: base03,
360
+ },
361
+ },
362
+ { dark: true },
363
+ );
364
+
365
+ /**
366
+ * Enhanced syntax highlighting for High Contrast Dark theme
367
+ */
368
+ const highContrastDarkHighlightStyle = HighlightStyle.define([
369
+ // Keywords and control flow
370
+ { tag: t.keyword, color: brightMagenta, fontWeight: 'bold' },
371
+ { tag: t.controlKeyword, color: brightMagenta, fontWeight: 'bold' },
372
+ { tag: t.moduleKeyword, color: brightMagenta, fontWeight: 'bold' },
373
+
374
+ // Names and variables
375
+ { tag: [t.name, t.deleted, t.character, t.macroName], color: base05 },
376
+ { tag: [t.variableName], color: base05 },
377
+ { tag: [t.propertyName], color: brightCyan, fontStyle: 'normal' },
378
+
379
+ // Classes and types
380
+ { tag: [t.typeName], color: brightYellow },
381
+ { tag: [t.className], color: brightYellow, fontStyle: 'italic' },
382
+ { tag: [t.namespace], color: brightOrange, fontStyle: 'italic' },
383
+
384
+ // Operators and punctuation
385
+ { tag: [t.operator, t.operatorKeyword], color: brightCyan },
386
+ { tag: [t.bracket], color: brightYellow },
387
+ { tag: [t.brace], color: brightCyan },
388
+ { tag: [t.punctuation], color: base05 },
389
+
390
+ // Functions and parameters
391
+ { tag: [t.function(t.variableName), t.labelName], color: brightBlue },
392
+ { tag: [t.definition(t.function(t.variableName))], color: brightBlue },
393
+ { tag: [t.definition(t.variableName)], color: brightOrange },
394
+
395
+ // Constants and literals
396
+ { tag: t.number, color: brightOrange },
397
+ { tag: t.changed, color: brightYellow },
398
+ { tag: t.annotation, color: brightRed, fontStyle: 'italic' },
399
+ { tag: t.modifier, color: brightPurple, fontStyle: 'italic' },
400
+ { tag: t.self, color: brightRed },
401
+ {
402
+ tag: [t.color, t.constant(t.name), t.standard(t.name)],
403
+ color: brightOrange,
404
+ },
405
+ { tag: [t.atom, t.bool, t.special(t.variableName)], color: brightOrange },
406
+
407
+ // Strings and regex
408
+ { tag: [t.processingInstruction, t.inserted], color: brightGreen },
409
+ { tag: [t.special(t.string), t.regexp], color: brightMagenta },
410
+ { tag: t.string, color: brightGreen },
411
+
412
+ // Punctuation and structure
413
+ { tag: t.definition(t.typeName), color: brightYellow, fontWeight: 'bold' },
414
+ { tag: [t.definition(t.name), t.separator], color: brightCyan },
415
+
416
+ // Comments and documentation
417
+ { tag: t.meta, color: base03 },
418
+ { tag: t.comment, fontStyle: 'italic', color: base03 },
419
+ { tag: t.docComment, fontStyle: 'italic', color: base03 },
420
+
421
+ // HTML/XML elements
422
+ { tag: [t.tagName], color: brightMagenta },
423
+ { tag: [t.attributeName], color: brightYellow },
424
+
425
+ // Markdown and text formatting
426
+ { tag: [t.heading], fontWeight: 'bold', color: brightMagenta },
427
+ { tag: [t.strong], fontWeight: 'bold', color: brightOrange },
428
+ { tag: [t.emphasis], fontStyle: 'italic', color: brightMagenta },
429
+
430
+ // Links and URLs
431
+ {
432
+ tag: [t.link],
433
+ color: visitedLinkColor,
434
+ fontWeight: '500',
435
+ textDecoration: 'underline',
436
+ textUnderlinePosition: 'under',
437
+ },
438
+ {
439
+ tag: [t.url],
440
+ color: linkColor,
441
+ textDecoration: 'underline',
442
+ textUnderlineOffset: '2px',
443
+ },
444
+
445
+ // Special states
446
+ {
447
+ tag: [t.invalid],
448
+ color: brightRed,
449
+ textDecoration: 'underline wavy',
450
+ borderBottom: `2px wavy ${brightRed}`,
451
+ },
452
+ { tag: [t.strikethrough], color: brightRed, textDecoration: 'line-through' },
453
+
454
+ // Enhanced syntax highlighting
455
+ { tag: t.constant(t.name), color: brightOrange },
456
+ { tag: t.deleted, color: brightRed },
457
+ { tag: t.squareBracket, color: brightYellow },
458
+ { tag: t.angleBracket, color: brightCyan },
459
+
460
+ // Additional specific styles
461
+ { tag: t.monospace, color: brightBlue, fontStyle: 'italic' },
462
+ { tag: [t.contentSeparator], color: brightPurple },
463
+ { tag: t.quote, color: brightPurple },
464
+ ]);
465
+
466
+ /**
467
+ * Combined High Contrast Dark theme extension
468
+ */
469
+ const highContrastDark: Extension = [
470
+ highContrastDarkTheme,
471
+ syntaxHighlighting(highContrastDarkHighlightStyle),
472
+ ];
473
+
474
+ /**
475
+ * High Contrast Dark merge revert styles configuration
476
+ */
477
+ const highContrastDarkMergeStyles: IMergeRevertStyles = {
478
+ backgroundColor: darkBackground,
479
+ borderColor: brightCyan,
480
+ buttonColor: brightCyan,
481
+ buttonHoverColor: brightYellow,
482
+ };
483
+
484
+ export { highContrastDark, highContrastDarkMergeStyles, applyMergeRevertStyles };
package/src/utils.ts ADDED
@@ -0,0 +1,126 @@
1
+ // Helper module for styling options
2
+ export const generalContent = {
3
+ fontSize: '14px',
4
+ fontFamily: 'JetBrains Mono, Consolas, monospace',
5
+ lineHeight: '1.6',
6
+ };
7
+
8
+ export const generalCursor = {
9
+ borderLeftWidth: '2px',
10
+ };
11
+
12
+ export const generalDiff = {
13
+ insertedTextDecoration: 'none',
14
+ deletedTextDecoration: 'line-through',
15
+ insertedLinePadding: '1px 3px',
16
+ borderRadious: '3px',
17
+ ins_del_linePadding: '1px 3px',
18
+ };
19
+
20
+ export const generalGutter = {
21
+ border: 'none',
22
+ paddingRight: '8px',
23
+ fontSize: '0.9em',
24
+ fontWeight: '500',
25
+ lineHeight: '1.78', // Adjusted to compensate for 0.9em fontSize (1.6 / 0.9 ≈ 1.78)
26
+ };
27
+
28
+ export const generalPanel = {
29
+ border: 'none',
30
+ borderRadius: '4px',
31
+ padding: '2px 10px',
32
+ };
33
+
34
+ export const generalLine = {
35
+ borderRadius: '2px',
36
+ };
37
+
38
+ export const generalMatching = {
39
+ borderRadius: '2px',
40
+ };
41
+
42
+ export const generalPlaceholder = {
43
+ borderRadius: '4px',
44
+ padding: '0 5px',
45
+ margin: '0 2px',
46
+ };
47
+
48
+ export const generalScroller = {
49
+ width: '12px',
50
+ height: '12px',
51
+ borderRadius: '6px',
52
+ };
53
+
54
+ export const generalSearchField = {
55
+ borderRadius: '4px',
56
+ padding: '2px 6px',
57
+ };
58
+
59
+ export const generalTooltip = {
60
+ borderRadius: '4px',
61
+ borderRadiusSelected: '3px',
62
+ lineHeight: '1.3',
63
+ padding: '4px 8px',
64
+ paddingRight: '8px',
65
+ };
66
+
67
+ //---------------------------------------
68
+
69
+ // Interface for merge revert styling options
70
+ export interface IMergeRevertStyles {
71
+ backgroundColor: string
72
+ borderColor: string
73
+ buttonColor: string
74
+ buttonHoverColor: string
75
+ }
76
+
77
+ /**
78
+ * Function to apply merge revert styles for a theme
79
+ * @param styles Styles for the merge revert buttons
80
+ * @param styles.backgroundColor Background color of the revert area
81
+ * @param styles.borderColor Border color of the revert area
82
+ * @param styles.buttonColor Color of the revert buttons
83
+ * @param styles.buttonHoverColor Hover color of the revert buttons
84
+ */
85
+ export function applyMergeRevertStyles(styles: IMergeRevertStyles) {
86
+ // Create a stylesheet
87
+ const styleEl = document.createElement('style');
88
+ styleEl.id = 'cm-merge-revert-styles';
89
+
90
+ // Define CSS with the theme-specific values
91
+ styleEl.textContent = `
92
+ .cm-merge-revert {
93
+ display: flex;
94
+ flex-direction: column;
95
+ align-items: center;
96
+ justify-content: flex-start;
97
+ padding: 4px;
98
+ background-color: ${styles.backgroundColor};
99
+ border-left: 1px solid ${styles.borderColor};
100
+ border-right: 1px solid ${styles.borderColor};
101
+ width: 32px;
102
+ }
103
+
104
+ .cm-merge-revert button {
105
+ width: 100%;
106
+ height: auto;
107
+ background-color: transparent;
108
+ border: none;
109
+ color: ${styles.buttonColor};
110
+ cursor: pointer;
111
+ margin: 0 auto;
112
+ font-size: 20px;
113
+ }
114
+
115
+ .cm-merge-revert button:hover {
116
+ background-color: ${styles.buttonHoverColor};
117
+ }
118
+ `;
119
+
120
+ // Remove any existing merge styles
121
+ const existingStyle = document.getElementById('cm-merge-revert-styles');
122
+ if (existingStyle) existingStyle.remove();
123
+
124
+ // Add the new styles
125
+ document.head.appendChild(styleEl);
126
+ }