@uiw/codemirror-themes 4.9.1 → 4.9.4
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/README.md +3 -3
- package/cjs/index.d.ts +4 -2
- package/cjs/index.js +19 -9
- package/cjs/index.js.map +9 -6
- package/esm/index.d.ts +4 -2
- package/esm/index.js +19 -8
- package/esm/index.js.map +8 -5
- package/package.json +2 -2
- package/src/index.tsx +41 -32
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ import { javascript } from '@codemirror/lang-javascript';
|
|
|
20
20
|
import { tags as t } from '@lezer/highlight';
|
|
21
21
|
|
|
22
22
|
const myTheme = createTheme({
|
|
23
|
-
|
|
23
|
+
theme: 'light',
|
|
24
24
|
settings: {
|
|
25
25
|
background: '#ffffff',
|
|
26
26
|
foreground: '#75baff',
|
|
@@ -66,7 +66,7 @@ import { javascript } from '@codemirror/lang-javascript';
|
|
|
66
66
|
import { tags as t } from '@lezer/highlight';
|
|
67
67
|
|
|
68
68
|
const myTheme = createTheme({
|
|
69
|
-
|
|
69
|
+
theme: 'light',
|
|
70
70
|
settings: {
|
|
71
71
|
background: '#ffffff',
|
|
72
72
|
foreground: '#75baff',
|
|
@@ -119,7 +119,7 @@ export interface CreateThemeOptions {
|
|
|
119
119
|
/**
|
|
120
120
|
* Theme inheritance. Determines which styles CodeMirror will apply by default.
|
|
121
121
|
*/
|
|
122
|
-
|
|
122
|
+
theme: Theme;
|
|
123
123
|
/**
|
|
124
124
|
* Settings to customize the look of the editor, like background, gutter, selection and others.
|
|
125
125
|
*/
|
package/cjs/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface CreateThemeOptions {
|
|
|
4
4
|
/**
|
|
5
5
|
* Theme inheritance. Determines which styles CodeMirror will apply by default.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
theme: Theme;
|
|
8
8
|
/**
|
|
9
9
|
* Settings to customize the look of the editor, like background, gutter, selection and others.
|
|
10
10
|
*/
|
|
@@ -22,6 +22,8 @@ export interface Settings {
|
|
|
22
22
|
caret: string;
|
|
23
23
|
/** Selection background. */
|
|
24
24
|
selection: string;
|
|
25
|
+
/** Selection match background. */
|
|
26
|
+
selectionMatch?: string;
|
|
25
27
|
/** Background of highlighted lines. */
|
|
26
28
|
lineHighlight: string;
|
|
27
29
|
/** Gutter background. */
|
|
@@ -29,5 +31,5 @@ export interface Settings {
|
|
|
29
31
|
/** Text color inside gutter. */
|
|
30
32
|
gutterForeground: string;
|
|
31
33
|
}
|
|
32
|
-
export declare const createTheme: ({
|
|
34
|
+
export declare const createTheme: ({ theme, settings, styles }: CreateThemeOptions) => Extension;
|
|
33
35
|
export default createTheme;
|
package/cjs/index.js
CHANGED
|
@@ -10,11 +10,10 @@ var _view = require("@codemirror/view");
|
|
|
10
10
|
var _language = require("@codemirror/language");
|
|
11
11
|
|
|
12
12
|
var createTheme = function createTheme(_ref) {
|
|
13
|
-
var
|
|
13
|
+
var theme = _ref.theme,
|
|
14
14
|
settings = _ref.settings,
|
|
15
15
|
styles = _ref.styles;
|
|
16
|
-
|
|
17
|
-
var theme = _view.EditorView.theme({
|
|
16
|
+
var themeOptions = {
|
|
18
17
|
'&': {
|
|
19
18
|
backgroundColor: settings.background,
|
|
20
19
|
color: settings.foreground
|
|
@@ -25,9 +24,6 @@ var createTheme = function createTheme(_ref) {
|
|
|
25
24
|
'.cm-cursor, .cm-dropCursor': {
|
|
26
25
|
borderLeftColor: settings.caret
|
|
27
26
|
},
|
|
28
|
-
'&.cm-focused .cm-selectionBackground .cm-selectionBackground, & .cm-selectionLayer .cm-selectionBackground, ::selection': {
|
|
29
|
-
backgroundColor: settings.selection
|
|
30
|
-
},
|
|
31
27
|
'.cm-activeLine': {
|
|
32
28
|
backgroundColor: settings.lineHighlight
|
|
33
29
|
},
|
|
@@ -38,13 +34,27 @@ var createTheme = function createTheme(_ref) {
|
|
|
38
34
|
'.cm-activeLineGutter': {
|
|
39
35
|
backgroundColor: settings.lineHighlight
|
|
40
36
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
if (settings.selection) {
|
|
40
|
+
themeOptions['&.cm-focused .cm-selectionBackground .cm-selectionBackground, & .cm-selectionLayer .cm-selectionBackground, ::selection'] = {
|
|
41
|
+
backgroundColor: settings.selection
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (settings.selectionMatch) {
|
|
46
|
+
themeOptions['& .cm-selectionMatch'] = {
|
|
47
|
+
backgroundColor: settings.selectionMatch
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var themeExtension = _view.EditorView.theme(themeOptions, {
|
|
52
|
+
dark: theme === 'dark'
|
|
43
53
|
});
|
|
44
54
|
|
|
45
55
|
var highlightStyle = _language.HighlightStyle.define(styles);
|
|
46
56
|
|
|
47
|
-
var extension = [
|
|
57
|
+
var extension = [themeExtension, (0, _language.syntaxHighlighting)(highlightStyle)];
|
|
48
58
|
return extension;
|
|
49
59
|
};
|
|
50
60
|
|
package/cjs/index.js.map
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"names": [
|
|
4
4
|
"createTheme",
|
|
5
|
-
"
|
|
5
|
+
"theme",
|
|
6
6
|
"settings",
|
|
7
7
|
"styles",
|
|
8
|
-
"
|
|
9
|
-
"EditorView",
|
|
8
|
+
"themeOptions",
|
|
10
9
|
"backgroundColor",
|
|
11
10
|
"background",
|
|
12
11
|
"color",
|
|
@@ -14,10 +13,14 @@
|
|
|
14
13
|
"caretColor",
|
|
15
14
|
"caret",
|
|
16
15
|
"borderLeftColor",
|
|
17
|
-
"selection",
|
|
18
16
|
"lineHighlight",
|
|
19
17
|
"gutterBackground",
|
|
20
18
|
"gutterForeground",
|
|
19
|
+
"selection",
|
|
20
|
+
"selectionMatch",
|
|
21
|
+
"themeExtension",
|
|
22
|
+
"EditorView",
|
|
23
|
+
"dark",
|
|
21
24
|
"highlightStyle",
|
|
22
25
|
"HighlightStyle",
|
|
23
26
|
"define",
|
|
@@ -28,7 +31,7 @@
|
|
|
28
31
|
"../src/index.tsx"
|
|
29
32
|
],
|
|
30
33
|
"sourcesContent": [
|
|
31
|
-
"import { EditorView } from '@codemirror/view';\nimport { Extension } from '@codemirror/state';\nimport { HighlightStyle, TagStyle, syntaxHighlighting } from '@codemirror/language';\n\nexport interface CreateThemeOptions {\n /**\n * Theme inheritance. Determines which styles CodeMirror will apply by default.\n */\n
|
|
34
|
+
"import { EditorView } from '@codemirror/view';\nimport { Extension } from '@codemirror/state';\nimport { HighlightStyle, TagStyle, syntaxHighlighting } from '@codemirror/language';\nimport { StyleSpec } from 'style-mod';\n\nexport interface CreateThemeOptions {\n /**\n * Theme inheritance. Determines which styles CodeMirror will apply by default.\n */\n theme: Theme;\n /**\n * Settings to customize the look of the editor, like background, gutter, selection and others.\n */\n settings: Settings;\n /** Syntax highlighting styles. */\n styles: TagStyle[];\n}\n\ntype Theme = 'light' | 'dark';\n\nexport interface Settings {\n /** Editor background. */\n background: string;\n /** Default text color. */\n foreground: string;\n /** Caret color. */\n caret: string;\n /** Selection background. */\n selection: string;\n /** Selection match background. */\n selectionMatch?: string;\n /** Background of highlighted lines. */\n lineHighlight: string;\n /** Gutter background. */\n gutterBackground: string;\n /** Text color inside gutter. */\n gutterForeground: string;\n}\n\nexport const createTheme = ({ theme, settings, styles }: CreateThemeOptions): Extension => {\n const themeOptions: Record<string, StyleSpec> = {\n '&': {\n backgroundColor: settings.background,\n color: settings.foreground,\n },\n '.cm-content': {\n caretColor: settings.caret,\n },\n '.cm-cursor, .cm-dropCursor': {\n borderLeftColor: settings.caret,\n },\n '.cm-activeLine': {\n backgroundColor: settings.lineHighlight,\n },\n '.cm-gutters': {\n backgroundColor: settings.gutterBackground,\n color: settings.gutterForeground,\n },\n '.cm-activeLineGutter': {\n backgroundColor: settings.lineHighlight,\n },\n };\n if (settings.selection) {\n themeOptions[\n '&.cm-focused .cm-selectionBackground .cm-selectionBackground, & .cm-selectionLayer .cm-selectionBackground, ::selection'\n ] = {\n backgroundColor: settings.selection,\n };\n }\n if (settings.selectionMatch) {\n themeOptions['& .cm-selectionMatch'] = {\n backgroundColor: settings.selectionMatch,\n };\n }\n const themeExtension = EditorView.theme(themeOptions, {\n dark: theme === 'dark',\n });\n\n const highlightStyle = HighlightStyle.define(styles);\n const extension = [themeExtension, syntaxHighlighting(highlightStyle)];\n\n return extension;\n};\n\nexport default createTheme;\n"
|
|
32
35
|
],
|
|
33
|
-
"mappings": ";;;;;;;AAAA;;AAEA;;
|
|
36
|
+
"mappings": ";;;;;;;AAAA;;AAEA;;AAqCO,IAAMA,WAAW,GAAG,SAAdA,WAAc,OAAgE;EAAA,IAA7DC,KAA6D,QAA7DA,KAA6D;EAAA,IAAtDC,QAAsD,QAAtDA,QAAsD;EAAA,IAA5CC,MAA4C,QAA5CA,MAA4C;EACzF,IAAMC,YAAuC,GAAG;IAC9C,KAAK;MACHC,eAAe,EAAEH,QAAQ,CAACI,UADvB;MAEHC,KAAK,EAAEL,QAAQ,CAACM;IAFb,CADyC;IAK9C,eAAe;MACbC,UAAU,EAAEP,QAAQ,CAACQ;IADR,CAL+B;IAQ9C,8BAA8B;MAC5BC,eAAe,EAAET,QAAQ,CAACQ;IADE,CARgB;IAW9C,kBAAkB;MAChBL,eAAe,EAAEH,QAAQ,CAACU;IADV,CAX4B;IAc9C,eAAe;MACbP,eAAe,EAAEH,QAAQ,CAACW,gBADb;MAEbN,KAAK,EAAEL,QAAQ,CAACY;IAFH,CAd+B;IAkB9C,wBAAwB;MACtBT,eAAe,EAAEH,QAAQ,CAACU;IADJ;EAlBsB,CAAhD;;EAsBA,IAAIV,QAAQ,CAACa,SAAb,EAAwB;IACtBX,YAAY,CACV,yHADU,CAAZ,GAEI;MACFC,eAAe,EAAEH,QAAQ,CAACa;IADxB,CAFJ;EAKD;;EACD,IAAIb,QAAQ,CAACc,cAAb,EAA6B;IAC3BZ,YAAY,CAAC,sBAAD,CAAZ,GAAuC;MACrCC,eAAe,EAAEH,QAAQ,CAACc;IADW,CAAvC;EAGD;;EACD,IAAMC,cAAc,GAAGC,gBAAA,CAAWjB,KAAX,CAAiBG,YAAjB,EAA+B;IACpDe,IAAI,EAAElB,KAAK,KAAK;EADoC,CAA/B,CAAvB;;EAIA,IAAMmB,cAAc,GAAGC,wBAAA,CAAeC,MAAf,CAAsBnB,MAAtB,CAAvB;;EACA,IAAMoB,SAAS,GAAG,CAACN,cAAD,EAAiB,IAAAO,4BAAA,EAAmBJ,cAAnB,CAAjB,CAAlB;EAEA,OAAOG,SAAP;AACD,CA3CM;;;eA6CQvB,W"
|
|
34
37
|
}
|
package/esm/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface CreateThemeOptions {
|
|
|
4
4
|
/**
|
|
5
5
|
* Theme inheritance. Determines which styles CodeMirror will apply by default.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
theme: Theme;
|
|
8
8
|
/**
|
|
9
9
|
* Settings to customize the look of the editor, like background, gutter, selection and others.
|
|
10
10
|
*/
|
|
@@ -22,6 +22,8 @@ export interface Settings {
|
|
|
22
22
|
caret: string;
|
|
23
23
|
/** Selection background. */
|
|
24
24
|
selection: string;
|
|
25
|
+
/** Selection match background. */
|
|
26
|
+
selectionMatch?: string;
|
|
25
27
|
/** Background of highlighted lines. */
|
|
26
28
|
lineHighlight: string;
|
|
27
29
|
/** Gutter background. */
|
|
@@ -29,5 +31,5 @@ export interface Settings {
|
|
|
29
31
|
/** Text color inside gutter. */
|
|
30
32
|
gutterForeground: string;
|
|
31
33
|
}
|
|
32
|
-
export declare const createTheme: ({
|
|
34
|
+
export declare const createTheme: ({ theme, settings, styles }: CreateThemeOptions) => Extension;
|
|
33
35
|
export default createTheme;
|
package/esm/index.js
CHANGED
|
@@ -2,11 +2,11 @@ import { EditorView } from '@codemirror/view';
|
|
|
2
2
|
import { HighlightStyle, syntaxHighlighting } from '@codemirror/language';
|
|
3
3
|
export var createTheme = _ref => {
|
|
4
4
|
var {
|
|
5
|
-
|
|
5
|
+
theme,
|
|
6
6
|
settings,
|
|
7
7
|
styles
|
|
8
8
|
} = _ref;
|
|
9
|
-
var
|
|
9
|
+
var themeOptions = {
|
|
10
10
|
'&': {
|
|
11
11
|
backgroundColor: settings.background,
|
|
12
12
|
color: settings.foreground
|
|
@@ -17,9 +17,6 @@ export var createTheme = _ref => {
|
|
|
17
17
|
'.cm-cursor, .cm-dropCursor': {
|
|
18
18
|
borderLeftColor: settings.caret
|
|
19
19
|
},
|
|
20
|
-
'&.cm-focused .cm-selectionBackground .cm-selectionBackground, & .cm-selectionLayer .cm-selectionBackground, ::selection': {
|
|
21
|
-
backgroundColor: settings.selection
|
|
22
|
-
},
|
|
23
20
|
'.cm-activeLine': {
|
|
24
21
|
backgroundColor: settings.lineHighlight
|
|
25
22
|
},
|
|
@@ -30,11 +27,25 @@ export var createTheme = _ref => {
|
|
|
30
27
|
'.cm-activeLineGutter': {
|
|
31
28
|
backgroundColor: settings.lineHighlight
|
|
32
29
|
}
|
|
33
|
-
}
|
|
34
|
-
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
if (settings.selection) {
|
|
33
|
+
themeOptions['&.cm-focused .cm-selectionBackground .cm-selectionBackground, & .cm-selectionLayer .cm-selectionBackground, ::selection'] = {
|
|
34
|
+
backgroundColor: settings.selection
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (settings.selectionMatch) {
|
|
39
|
+
themeOptions['& .cm-selectionMatch'] = {
|
|
40
|
+
backgroundColor: settings.selectionMatch
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var themeExtension = EditorView.theme(themeOptions, {
|
|
45
|
+
dark: theme === 'dark'
|
|
35
46
|
});
|
|
36
47
|
var highlightStyle = HighlightStyle.define(styles);
|
|
37
|
-
var extension = [
|
|
48
|
+
var extension = [themeExtension, syntaxHighlighting(highlightStyle)];
|
|
38
49
|
return extension;
|
|
39
50
|
};
|
|
40
51
|
export default createTheme;
|
package/esm/index.js.map
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
"HighlightStyle",
|
|
6
6
|
"syntaxHighlighting",
|
|
7
7
|
"createTheme",
|
|
8
|
-
"
|
|
8
|
+
"theme",
|
|
9
9
|
"settings",
|
|
10
10
|
"styles",
|
|
11
|
-
"
|
|
11
|
+
"themeOptions",
|
|
12
12
|
"backgroundColor",
|
|
13
13
|
"background",
|
|
14
14
|
"color",
|
|
@@ -16,10 +16,13 @@
|
|
|
16
16
|
"caretColor",
|
|
17
17
|
"caret",
|
|
18
18
|
"borderLeftColor",
|
|
19
|
-
"selection",
|
|
20
19
|
"lineHighlight",
|
|
21
20
|
"gutterBackground",
|
|
22
21
|
"gutterForeground",
|
|
22
|
+
"selection",
|
|
23
|
+
"selectionMatch",
|
|
24
|
+
"themeExtension",
|
|
25
|
+
"dark",
|
|
23
26
|
"highlightStyle",
|
|
24
27
|
"define",
|
|
25
28
|
"extension"
|
|
@@ -28,7 +31,7 @@
|
|
|
28
31
|
"../src/index.tsx"
|
|
29
32
|
],
|
|
30
33
|
"sourcesContent": [
|
|
31
|
-
"import { EditorView } from '@codemirror/view';\nimport { Extension } from '@codemirror/state';\nimport { HighlightStyle, TagStyle, syntaxHighlighting } from '@codemirror/language';\n\nexport interface CreateThemeOptions {\n /**\n * Theme inheritance. Determines which styles CodeMirror will apply by default.\n */\n
|
|
34
|
+
"import { EditorView } from '@codemirror/view';\nimport { Extension } from '@codemirror/state';\nimport { HighlightStyle, TagStyle, syntaxHighlighting } from '@codemirror/language';\nimport { StyleSpec } from 'style-mod';\n\nexport interface CreateThemeOptions {\n /**\n * Theme inheritance. Determines which styles CodeMirror will apply by default.\n */\n theme: Theme;\n /**\n * Settings to customize the look of the editor, like background, gutter, selection and others.\n */\n settings: Settings;\n /** Syntax highlighting styles. */\n styles: TagStyle[];\n}\n\ntype Theme = 'light' | 'dark';\n\nexport interface Settings {\n /** Editor background. */\n background: string;\n /** Default text color. */\n foreground: string;\n /** Caret color. */\n caret: string;\n /** Selection background. */\n selection: string;\n /** Selection match background. */\n selectionMatch?: string;\n /** Background of highlighted lines. */\n lineHighlight: string;\n /** Gutter background. */\n gutterBackground: string;\n /** Text color inside gutter. */\n gutterForeground: string;\n}\n\nexport const createTheme = ({ theme, settings, styles }: CreateThemeOptions): Extension => {\n const themeOptions: Record<string, StyleSpec> = {\n '&': {\n backgroundColor: settings.background,\n color: settings.foreground,\n },\n '.cm-content': {\n caretColor: settings.caret,\n },\n '.cm-cursor, .cm-dropCursor': {\n borderLeftColor: settings.caret,\n },\n '.cm-activeLine': {\n backgroundColor: settings.lineHighlight,\n },\n '.cm-gutters': {\n backgroundColor: settings.gutterBackground,\n color: settings.gutterForeground,\n },\n '.cm-activeLineGutter': {\n backgroundColor: settings.lineHighlight,\n },\n };\n if (settings.selection) {\n themeOptions[\n '&.cm-focused .cm-selectionBackground .cm-selectionBackground, & .cm-selectionLayer .cm-selectionBackground, ::selection'\n ] = {\n backgroundColor: settings.selection,\n };\n }\n if (settings.selectionMatch) {\n themeOptions['& .cm-selectionMatch'] = {\n backgroundColor: settings.selectionMatch,\n };\n }\n const themeExtension = EditorView.theme(themeOptions, {\n dark: theme === 'dark',\n });\n\n const highlightStyle = HighlightStyle.define(styles);\n const extension = [themeExtension, syntaxHighlighting(highlightStyle)];\n\n return extension;\n};\n\nexport default createTheme;\n"
|
|
32
35
|
],
|
|
33
|
-
"mappings": "AAAA,SAASA,UAAT,QAA2B,kBAA3B;AAEA,SAASC,cAAT,EAAmCC,kBAAnC,QAA6D,sBAA7D;
|
|
36
|
+
"mappings": "AAAA,SAASA,UAAT,QAA2B,kBAA3B;AAEA,SAASC,cAAT,EAAmCC,kBAAnC,QAA6D,sBAA7D;AAqCA,OAAO,IAAMC,WAAW,GAAG,QAAgE;EAAA,IAA/D;IAAEC,KAAF;IAASC,QAAT;IAAmBC;EAAnB,CAA+D;EACzF,IAAMC,YAAuC,GAAG;IAC9C,KAAK;MACHC,eAAe,EAAEH,QAAQ,CAACI,UADvB;MAEHC,KAAK,EAAEL,QAAQ,CAACM;IAFb,CADyC;IAK9C,eAAe;MACbC,UAAU,EAAEP,QAAQ,CAACQ;IADR,CAL+B;IAQ9C,8BAA8B;MAC5BC,eAAe,EAAET,QAAQ,CAACQ;IADE,CARgB;IAW9C,kBAAkB;MAChBL,eAAe,EAAEH,QAAQ,CAACU;IADV,CAX4B;IAc9C,eAAe;MACbP,eAAe,EAAEH,QAAQ,CAACW,gBADb;MAEbN,KAAK,EAAEL,QAAQ,CAACY;IAFH,CAd+B;IAkB9C,wBAAwB;MACtBT,eAAe,EAAEH,QAAQ,CAACU;IADJ;EAlBsB,CAAhD;;EAsBA,IAAIV,QAAQ,CAACa,SAAb,EAAwB;IACtBX,YAAY,CACV,yHADU,CAAZ,GAEI;MACFC,eAAe,EAAEH,QAAQ,CAACa;IADxB,CAFJ;EAKD;;EACD,IAAIb,QAAQ,CAACc,cAAb,EAA6B;IAC3BZ,YAAY,CAAC,sBAAD,CAAZ,GAAuC;MACrCC,eAAe,EAAEH,QAAQ,CAACc;IADW,CAAvC;EAGD;;EACD,IAAMC,cAAc,GAAGpB,UAAU,CAACI,KAAX,CAAiBG,YAAjB,EAA+B;IACpDc,IAAI,EAAEjB,KAAK,KAAK;EADoC,CAA/B,CAAvB;EAIA,IAAMkB,cAAc,GAAGrB,cAAc,CAACsB,MAAf,CAAsBjB,MAAtB,CAAvB;EACA,IAAMkB,SAAS,GAAG,CAACJ,cAAD,EAAiBlB,kBAAkB,CAACoB,cAAD,CAAnC,CAAlB;EAEA,OAAOE,SAAP;AACD,CA3CM;AA6CP,eAAerB,WAAf"
|
|
34
37
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiw/codemirror-themes",
|
|
3
|
-
"version": "4.9.
|
|
3
|
+
"version": "4.9.4",
|
|
4
4
|
"description": "Themes for CodeMirror.",
|
|
5
|
-
"homepage": "https://uiwjs.github.io/react-codemirror",
|
|
5
|
+
"homepage": "https://uiwjs.github.io/react-codemirror/#/theme/doc",
|
|
6
6
|
"author": "kenny wong <wowohoo@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"main": "./cjs/index.js",
|
package/src/index.tsx
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { EditorView } from '@codemirror/view';
|
|
2
2
|
import { Extension } from '@codemirror/state';
|
|
3
3
|
import { HighlightStyle, TagStyle, syntaxHighlighting } from '@codemirror/language';
|
|
4
|
+
import { StyleSpec } from 'style-mod';
|
|
4
5
|
|
|
5
6
|
export interface CreateThemeOptions {
|
|
6
7
|
/**
|
|
7
8
|
* Theme inheritance. Determines which styles CodeMirror will apply by default.
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
+
theme: Theme;
|
|
10
11
|
/**
|
|
11
12
|
* Settings to customize the look of the editor, like background, gutter, selection and others.
|
|
12
13
|
*/
|
|
@@ -26,6 +27,8 @@ export interface Settings {
|
|
|
26
27
|
caret: string;
|
|
27
28
|
/** Selection background. */
|
|
28
29
|
selection: string;
|
|
30
|
+
/** Selection match background. */
|
|
31
|
+
selectionMatch?: string;
|
|
29
32
|
/** Background of highlighted lines. */
|
|
30
33
|
lineHighlight: string;
|
|
31
34
|
/** Gutter background. */
|
|
@@ -34,41 +37,47 @@ export interface Settings {
|
|
|
34
37
|
gutterForeground: string;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
|
-
export const createTheme = ({
|
|
38
|
-
const
|
|
39
|
-
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
color: settings.foreground,
|
|
43
|
-
},
|
|
44
|
-
'.cm-content': {
|
|
45
|
-
caretColor: settings.caret,
|
|
46
|
-
},
|
|
47
|
-
'.cm-cursor, .cm-dropCursor': {
|
|
48
|
-
borderLeftColor: settings.caret,
|
|
49
|
-
},
|
|
50
|
-
'&.cm-focused .cm-selectionBackground .cm-selectionBackground, & .cm-selectionLayer .cm-selectionBackground, ::selection':
|
|
51
|
-
{
|
|
52
|
-
backgroundColor: settings.selection,
|
|
53
|
-
},
|
|
54
|
-
'.cm-activeLine': {
|
|
55
|
-
backgroundColor: settings.lineHighlight,
|
|
56
|
-
},
|
|
57
|
-
'.cm-gutters': {
|
|
58
|
-
backgroundColor: settings.gutterBackground,
|
|
59
|
-
color: settings.gutterForeground,
|
|
60
|
-
},
|
|
61
|
-
'.cm-activeLineGutter': {
|
|
62
|
-
backgroundColor: settings.lineHighlight,
|
|
63
|
-
},
|
|
40
|
+
export const createTheme = ({ theme, settings, styles }: CreateThemeOptions): Extension => {
|
|
41
|
+
const themeOptions: Record<string, StyleSpec> = {
|
|
42
|
+
'&': {
|
|
43
|
+
backgroundColor: settings.background,
|
|
44
|
+
color: settings.foreground,
|
|
64
45
|
},
|
|
65
|
-
{
|
|
66
|
-
|
|
46
|
+
'.cm-content': {
|
|
47
|
+
caretColor: settings.caret,
|
|
67
48
|
},
|
|
68
|
-
|
|
49
|
+
'.cm-cursor, .cm-dropCursor': {
|
|
50
|
+
borderLeftColor: settings.caret,
|
|
51
|
+
},
|
|
52
|
+
'.cm-activeLine': {
|
|
53
|
+
backgroundColor: settings.lineHighlight,
|
|
54
|
+
},
|
|
55
|
+
'.cm-gutters': {
|
|
56
|
+
backgroundColor: settings.gutterBackground,
|
|
57
|
+
color: settings.gutterForeground,
|
|
58
|
+
},
|
|
59
|
+
'.cm-activeLineGutter': {
|
|
60
|
+
backgroundColor: settings.lineHighlight,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
if (settings.selection) {
|
|
64
|
+
themeOptions[
|
|
65
|
+
'&.cm-focused .cm-selectionBackground .cm-selectionBackground, & .cm-selectionLayer .cm-selectionBackground, ::selection'
|
|
66
|
+
] = {
|
|
67
|
+
backgroundColor: settings.selection,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (settings.selectionMatch) {
|
|
71
|
+
themeOptions['& .cm-selectionMatch'] = {
|
|
72
|
+
backgroundColor: settings.selectionMatch,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const themeExtension = EditorView.theme(themeOptions, {
|
|
76
|
+
dark: theme === 'dark',
|
|
77
|
+
});
|
|
69
78
|
|
|
70
79
|
const highlightStyle = HighlightStyle.define(styles);
|
|
71
|
-
const extension = [
|
|
80
|
+
const extension = [themeExtension, syntaxHighlighting(highlightStyle)];
|
|
72
81
|
|
|
73
82
|
return extension;
|
|
74
83
|
};
|