@uiw/codemirror-themes 4.8.1
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 +186 -0
- package/cjs/index.d.ts +33 -0
- package/cjs/index.js +54 -0
- package/cjs/index.js.map +34 -0
- package/esm/index.d.ts +33 -0
- package/esm/index.js +43 -0
- package/esm/index.js.map +34 -0
- package/package.json +45 -0
- package/src/index.tsx +75 -0
package/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Codemirror Themes
|
|
2
|
+
|
|
3
|
+
Themes for CodeMirror.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @uiw/codemirror-themes --save
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { EditorView } from '@codemirror/view';
|
|
15
|
+
import { EditorState } from '@codemirror/state';
|
|
16
|
+
import { createTheme } from '@uiw/codemirror-themes';
|
|
17
|
+
import { javascript } from '@codemirror/lang-javascript';
|
|
18
|
+
import { tags as t } from '@lezer/highlight';
|
|
19
|
+
|
|
20
|
+
const myTheme = createTheme({
|
|
21
|
+
variant: 'light',
|
|
22
|
+
settings: {
|
|
23
|
+
background: '#ffffff',
|
|
24
|
+
foreground: '#75baff',
|
|
25
|
+
caret: '#5d00ff',
|
|
26
|
+
selection: '#036dd626',
|
|
27
|
+
lineHighlight: '#8a91991a',
|
|
28
|
+
gutterBackground: '#fff',
|
|
29
|
+
gutterForeground: '#8a919966',
|
|
30
|
+
},
|
|
31
|
+
styles: [
|
|
32
|
+
{ tag: t.comment, color: '#787b8099', },
|
|
33
|
+
{ tag: t.variableName, color: '#0080ff', },
|
|
34
|
+
{ tag: [t.string, t.special(t.brace)], color: '#5c6166', },
|
|
35
|
+
{ tag: t.number, color: '#5c6166', },
|
|
36
|
+
{ tag: t.bool, color: '#5c6166', },
|
|
37
|
+
{ tag: t.null, color: '#5c6166', },
|
|
38
|
+
{ tag: t.keyword, color: '#5c6166', },
|
|
39
|
+
{ tag: t.operator, color: '#5c6166', },
|
|
40
|
+
{ tag: t.className, color: '#5c6166', },
|
|
41
|
+
{ tag: t.definition(t.typeName), color: '#5c6166', },
|
|
42
|
+
{ tag: t.typeName, color: '#5c6166', },
|
|
43
|
+
{ tag: t.angleBracket, color: '#5c6166', },
|
|
44
|
+
{ tag: t.tagName, color: '#5c6166', },
|
|
45
|
+
{ tag: t.attributeName, color: '#5c6166', },
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const state = EditorState.create({
|
|
50
|
+
doc: 'my source code',
|
|
51
|
+
extensions: [myTheme, javascript({ jsx: true })],
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const view = new EditorView({
|
|
55
|
+
parent: document.querySelector('#editor'),
|
|
56
|
+
state,
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```jsx
|
|
61
|
+
import CodeMirror from '@uiw/react-codemirror';
|
|
62
|
+
import { createTheme } from '@uiw/codemirror-themes';
|
|
63
|
+
import { javascript } from '@codemirror/lang-javascript';
|
|
64
|
+
import { tags as t } from '@lezer/highlight';
|
|
65
|
+
|
|
66
|
+
const myTheme = createTheme({
|
|
67
|
+
variant: 'light',
|
|
68
|
+
settings: {
|
|
69
|
+
background: '#ffffff',
|
|
70
|
+
foreground: '#75baff',
|
|
71
|
+
caret: '#5d00ff',
|
|
72
|
+
selection: '#036dd626',
|
|
73
|
+
lineHighlight: '#8a91991a',
|
|
74
|
+
gutterBackground: '#fff',
|
|
75
|
+
gutterForeground: '#8a919966',
|
|
76
|
+
},
|
|
77
|
+
styles: [
|
|
78
|
+
{ tag: t.comment, color: '#787b8099', },
|
|
79
|
+
{ tag: t.variableName, color: '#0080ff', },
|
|
80
|
+
{ tag: [t.string, t.special(t.brace)], color: '#5c6166', },
|
|
81
|
+
{ tag: t.number, color: '#5c6166', },
|
|
82
|
+
{ tag: t.bool, color: '#5c6166', },
|
|
83
|
+
{ tag: t.null, color: '#5c6166', },
|
|
84
|
+
{ tag: t.keyword, color: '#5c6166', },
|
|
85
|
+
{ tag: t.operator, color: '#5c6166', },
|
|
86
|
+
{ tag: t.className, color: '#5c6166', },
|
|
87
|
+
{ tag: t.definition(t.typeName), color: '#5c6166', },
|
|
88
|
+
{ tag: t.typeName, color: '#5c6166', },
|
|
89
|
+
{ tag: t.angleBracket, color: '#5c6166', },
|
|
90
|
+
{ tag: t.tagName, color: '#5c6166', },
|
|
91
|
+
{ tag: t.attributeName, color: '#5c6166', },
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
function App() {
|
|
96
|
+
return (
|
|
97
|
+
<CodeMirror
|
|
98
|
+
value="console.log('hello world!');"
|
|
99
|
+
height="200px"
|
|
100
|
+
theme={myTheme}
|
|
101
|
+
extensions={[javascript({ jsx: true })]}
|
|
102
|
+
onChange={(value, viewUpdate) => {
|
|
103
|
+
console.log('value:', value);
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
export default App;
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Props
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { Extension } from '@codemirror/state';
|
|
115
|
+
import { TagStyle } from '@codemirror/language';
|
|
116
|
+
export interface CreateThemeOptions {
|
|
117
|
+
/**
|
|
118
|
+
* Theme inheritance. Determines which styles CodeMirror will apply by default.
|
|
119
|
+
*/
|
|
120
|
+
dark: Theme;
|
|
121
|
+
/**
|
|
122
|
+
* Settings to customize the look of the editor, like background, gutter, selection and others.
|
|
123
|
+
*/
|
|
124
|
+
settings: Settings;
|
|
125
|
+
/**
|
|
126
|
+
* Syntax highlighting styles.
|
|
127
|
+
*/
|
|
128
|
+
styles: TagStyle[];
|
|
129
|
+
}
|
|
130
|
+
declare type Theme = 'light' | 'dark';
|
|
131
|
+
interface Settings {
|
|
132
|
+
/**
|
|
133
|
+
* Editor background.
|
|
134
|
+
*/
|
|
135
|
+
background: string;
|
|
136
|
+
/**
|
|
137
|
+
* Default text color.
|
|
138
|
+
*/
|
|
139
|
+
foreground: string;
|
|
140
|
+
/**
|
|
141
|
+
* Caret color.
|
|
142
|
+
*/
|
|
143
|
+
caret: string;
|
|
144
|
+
/**
|
|
145
|
+
* Selection background.
|
|
146
|
+
*/
|
|
147
|
+
selection: string;
|
|
148
|
+
/**
|
|
149
|
+
* Background of highlighted lines.
|
|
150
|
+
*/
|
|
151
|
+
lineHighlight: string;
|
|
152
|
+
/**
|
|
153
|
+
* Gutter background.
|
|
154
|
+
*/
|
|
155
|
+
gutterBackground: string;
|
|
156
|
+
/**
|
|
157
|
+
* Text color inside gutter.
|
|
158
|
+
*/
|
|
159
|
+
gutterForeground: string;
|
|
160
|
+
}
|
|
161
|
+
declare const createTheme: ({ dark, settings, styles }: CreateThemeOptions) => Extension;
|
|
162
|
+
export default createTheme;
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Related
|
|
166
|
+
|
|
167
|
+
- [@uiw/react-textarea-code-editor](https://github.com/uiwjs/react-textarea-code-editor): A simple code editor with syntax highlighting.
|
|
168
|
+
- [@uiw/react-md-editor](https://github.com/uiwjs/react-md-editor): A simple markdown editor with preview, implemented with React.js and TypeScript.
|
|
169
|
+
- [@uiw/react-monacoeditor](https://github.com/jaywcjlove/react-monacoeditor): Monaco Editor component for React.
|
|
170
|
+
- [@uiw/react-markdown-editor](https://github.com/uiwjs/react-markdown-editor): A markdown editor with preview, implemented with React.js and TypeScript.
|
|
171
|
+
- [@uiw/react-markdown-preview](https://github.com/uiwjs/react-markdown-preview): React component preview markdown text in web browser.
|
|
172
|
+
- [Online JSON Viewer](https://github.com/uiwjs/json-viewer) Online JSON Viewer, JSON Beautifier to beautify and tree view of JSON data - It works as JSON Pretty Print to pretty print JSON data.
|
|
173
|
+
|
|
174
|
+
## Contributors
|
|
175
|
+
|
|
176
|
+
As always, thanks to our amazing contributors!
|
|
177
|
+
|
|
178
|
+
<a href="https://github.com/uiwjs/react-codemirror/graphs/contributors">
|
|
179
|
+
<img src="https://uiwjs.github.io/react-codemirror/CONTRIBUTORS.svg" />
|
|
180
|
+
</a>
|
|
181
|
+
|
|
182
|
+
Made with [github-action-contributors](https://github.com/jaywcjlove/github-action-contributors).
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
Licensed under the MIT License.
|
package/cjs/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Extension } from '@codemirror/state';
|
|
2
|
+
import { TagStyle } from '@codemirror/language';
|
|
3
|
+
export interface CreateThemeOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Theme inheritance. Determines which styles CodeMirror will apply by default.
|
|
6
|
+
*/
|
|
7
|
+
dark: Theme;
|
|
8
|
+
/**
|
|
9
|
+
* Settings to customize the look of the editor, like background, gutter, selection and others.
|
|
10
|
+
*/
|
|
11
|
+
settings: Settings;
|
|
12
|
+
/** Syntax highlighting styles. */
|
|
13
|
+
styles: TagStyle[];
|
|
14
|
+
}
|
|
15
|
+
declare type Theme = 'light' | 'dark';
|
|
16
|
+
export interface Settings {
|
|
17
|
+
/** Editor background. */
|
|
18
|
+
background: string;
|
|
19
|
+
/** Default text color. */
|
|
20
|
+
foreground: string;
|
|
21
|
+
/** Caret color. */
|
|
22
|
+
caret: string;
|
|
23
|
+
/** Selection background. */
|
|
24
|
+
selection: string;
|
|
25
|
+
/** Background of highlighted lines. */
|
|
26
|
+
lineHighlight: string;
|
|
27
|
+
/** Gutter background. */
|
|
28
|
+
gutterBackground: string;
|
|
29
|
+
/** Text color inside gutter. */
|
|
30
|
+
gutterForeground: string;
|
|
31
|
+
}
|
|
32
|
+
declare const createTheme: ({ dark, settings, styles }: CreateThemeOptions) => Extension;
|
|
33
|
+
export default createTheme;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _view = require("@codemirror/view");
|
|
9
|
+
|
|
10
|
+
var _language = require("@codemirror/language");
|
|
11
|
+
|
|
12
|
+
var createTheme = function createTheme(_ref) {
|
|
13
|
+
var dark = _ref.dark,
|
|
14
|
+
settings = _ref.settings,
|
|
15
|
+
styles = _ref.styles;
|
|
16
|
+
|
|
17
|
+
var theme = _view.EditorView.theme({
|
|
18
|
+
'&': {
|
|
19
|
+
backgroundColor: settings.background,
|
|
20
|
+
color: settings.foreground
|
|
21
|
+
},
|
|
22
|
+
'.cm-content': {
|
|
23
|
+
caretColor: settings.caret
|
|
24
|
+
},
|
|
25
|
+
'.cm-cursor, .cm-dropCursor': {
|
|
26
|
+
borderLeftColor: settings.caret
|
|
27
|
+
},
|
|
28
|
+
'&.cm-focused .cm-selectionBackgroundm .cm-selectionBackground, .cm-content ::selection': {
|
|
29
|
+
backgroundColor: settings.selection
|
|
30
|
+
},
|
|
31
|
+
'.cm-activeLine': {
|
|
32
|
+
backgroundColor: settings.lineHighlight
|
|
33
|
+
},
|
|
34
|
+
'.cm-gutters': {
|
|
35
|
+
backgroundColor: settings.gutterBackground,
|
|
36
|
+
color: settings.gutterForeground
|
|
37
|
+
},
|
|
38
|
+
'.cm-activeLineGutter': {
|
|
39
|
+
backgroundColor: settings.lineHighlight
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
dark: dark === 'dark'
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
var highlightStyle = _language.HighlightStyle.define(styles);
|
|
46
|
+
|
|
47
|
+
var extension = [theme, (0, _language.syntaxHighlighting)(highlightStyle)];
|
|
48
|
+
return extension;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
var _default = createTheme;
|
|
52
|
+
exports["default"] = _default;
|
|
53
|
+
module.exports = exports.default;
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"names": [
|
|
4
|
+
"createTheme",
|
|
5
|
+
"dark",
|
|
6
|
+
"settings",
|
|
7
|
+
"styles",
|
|
8
|
+
"theme",
|
|
9
|
+
"EditorView",
|
|
10
|
+
"backgroundColor",
|
|
11
|
+
"background",
|
|
12
|
+
"color",
|
|
13
|
+
"foreground",
|
|
14
|
+
"caretColor",
|
|
15
|
+
"caret",
|
|
16
|
+
"borderLeftColor",
|
|
17
|
+
"selection",
|
|
18
|
+
"lineHighlight",
|
|
19
|
+
"gutterBackground",
|
|
20
|
+
"gutterForeground",
|
|
21
|
+
"highlightStyle",
|
|
22
|
+
"HighlightStyle",
|
|
23
|
+
"define",
|
|
24
|
+
"extension",
|
|
25
|
+
"syntaxHighlighting"
|
|
26
|
+
],
|
|
27
|
+
"sources": [
|
|
28
|
+
"../src/index.tsx"
|
|
29
|
+
],
|
|
30
|
+
"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 dark: 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 /** Background of highlighted lines. */\n lineHighlight: string;\n /** Gutter background. */\n gutterBackground: string;\n /** Text color inside gutter. */\n gutterForeground: string;\n}\n\nconst createTheme = ({ dark, settings, styles }: CreateThemeOptions): Extension => {\n const theme = EditorView.theme(\n {\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-focused .cm-selectionBackgroundm .cm-selectionBackground, .cm-content ::selection': {\n backgroundColor: settings.selection,\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 {\n dark: dark === 'dark',\n },\n );\n\n const highlightStyle = HighlightStyle.define(styles);\n const extension = [theme, syntaxHighlighting(highlightStyle)];\n\n return extension;\n};\n\nexport default createTheme;\n"
|
|
32
|
+
],
|
|
33
|
+
"mappings": ";;;;;;;AAAA;;AAEA;;AAkCA,IAAMA,WAAW,GAAG,SAAdA,WAAc,OAA+D;EAAA,IAA5DC,IAA4D,QAA5DA,IAA4D;EAAA,IAAtDC,QAAsD,QAAtDA,QAAsD;EAAA,IAA5CC,MAA4C,QAA5CA,MAA4C;;EACjF,IAAMC,KAAK,GAAGC,gBAAA,CAAWD,KAAX,CACZ;IACE,KAAK;MACHE,eAAe,EAAEJ,QAAQ,CAACK,UADvB;MAEHC,KAAK,EAAEN,QAAQ,CAACO;IAFb,CADP;IAKE,eAAe;MACbC,UAAU,EAAER,QAAQ,CAACS;IADR,CALjB;IAQE,8BAA8B;MAC5BC,eAAe,EAAEV,QAAQ,CAACS;IADE,CARhC;IAWE,0FAA0F;MACxFL,eAAe,EAAEJ,QAAQ,CAACW;IAD8D,CAX5F;IAcE,kBAAkB;MAChBP,eAAe,EAAEJ,QAAQ,CAACY;IADV,CAdpB;IAiBE,eAAe;MACbR,eAAe,EAAEJ,QAAQ,CAACa,gBADb;MAEbP,KAAK,EAAEN,QAAQ,CAACc;IAFH,CAjBjB;IAqBE,wBAAwB;MACtBV,eAAe,EAAEJ,QAAQ,CAACY;IADJ;EArB1B,CADY,EA0BZ;IACEb,IAAI,EAAEA,IAAI,KAAK;EADjB,CA1BY,CAAd;;EA+BA,IAAMgB,cAAc,GAAGC,wBAAA,CAAeC,MAAf,CAAsBhB,MAAtB,CAAvB;;EACA,IAAMiB,SAAS,GAAG,CAAChB,KAAD,EAAQ,IAAAiB,4BAAA,EAAmBJ,cAAnB,CAAR,CAAlB;EAEA,OAAOG,SAAP;AACD,CApCD;;eAsCepB,W"
|
|
34
|
+
}
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Extension } from '@codemirror/state';
|
|
2
|
+
import { TagStyle } from '@codemirror/language';
|
|
3
|
+
export interface CreateThemeOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Theme inheritance. Determines which styles CodeMirror will apply by default.
|
|
6
|
+
*/
|
|
7
|
+
dark: Theme;
|
|
8
|
+
/**
|
|
9
|
+
* Settings to customize the look of the editor, like background, gutter, selection and others.
|
|
10
|
+
*/
|
|
11
|
+
settings: Settings;
|
|
12
|
+
/** Syntax highlighting styles. */
|
|
13
|
+
styles: TagStyle[];
|
|
14
|
+
}
|
|
15
|
+
declare type Theme = 'light' | 'dark';
|
|
16
|
+
export interface Settings {
|
|
17
|
+
/** Editor background. */
|
|
18
|
+
background: string;
|
|
19
|
+
/** Default text color. */
|
|
20
|
+
foreground: string;
|
|
21
|
+
/** Caret color. */
|
|
22
|
+
caret: string;
|
|
23
|
+
/** Selection background. */
|
|
24
|
+
selection: string;
|
|
25
|
+
/** Background of highlighted lines. */
|
|
26
|
+
lineHighlight: string;
|
|
27
|
+
/** Gutter background. */
|
|
28
|
+
gutterBackground: string;
|
|
29
|
+
/** Text color inside gutter. */
|
|
30
|
+
gutterForeground: string;
|
|
31
|
+
}
|
|
32
|
+
declare const createTheme: ({ dark, settings, styles }: CreateThemeOptions) => Extension;
|
|
33
|
+
export default createTheme;
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { EditorView } from '@codemirror/view';
|
|
2
|
+
import { HighlightStyle, syntaxHighlighting } from '@codemirror/language';
|
|
3
|
+
|
|
4
|
+
var createTheme = _ref => {
|
|
5
|
+
var {
|
|
6
|
+
dark,
|
|
7
|
+
settings,
|
|
8
|
+
styles
|
|
9
|
+
} = _ref;
|
|
10
|
+
var theme = EditorView.theme({
|
|
11
|
+
'&': {
|
|
12
|
+
backgroundColor: settings.background,
|
|
13
|
+
color: settings.foreground
|
|
14
|
+
},
|
|
15
|
+
'.cm-content': {
|
|
16
|
+
caretColor: settings.caret
|
|
17
|
+
},
|
|
18
|
+
'.cm-cursor, .cm-dropCursor': {
|
|
19
|
+
borderLeftColor: settings.caret
|
|
20
|
+
},
|
|
21
|
+
'&.cm-focused .cm-selectionBackgroundm .cm-selectionBackground, .cm-content ::selection': {
|
|
22
|
+
backgroundColor: settings.selection
|
|
23
|
+
},
|
|
24
|
+
'.cm-activeLine': {
|
|
25
|
+
backgroundColor: settings.lineHighlight
|
|
26
|
+
},
|
|
27
|
+
'.cm-gutters': {
|
|
28
|
+
backgroundColor: settings.gutterBackground,
|
|
29
|
+
color: settings.gutterForeground
|
|
30
|
+
},
|
|
31
|
+
'.cm-activeLineGutter': {
|
|
32
|
+
backgroundColor: settings.lineHighlight
|
|
33
|
+
}
|
|
34
|
+
}, {
|
|
35
|
+
dark: dark === 'dark'
|
|
36
|
+
});
|
|
37
|
+
var highlightStyle = HighlightStyle.define(styles);
|
|
38
|
+
var extension = [theme, syntaxHighlighting(highlightStyle)];
|
|
39
|
+
return extension;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default createTheme;
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"names": [
|
|
4
|
+
"EditorView",
|
|
5
|
+
"HighlightStyle",
|
|
6
|
+
"syntaxHighlighting",
|
|
7
|
+
"createTheme",
|
|
8
|
+
"dark",
|
|
9
|
+
"settings",
|
|
10
|
+
"styles",
|
|
11
|
+
"theme",
|
|
12
|
+
"backgroundColor",
|
|
13
|
+
"background",
|
|
14
|
+
"color",
|
|
15
|
+
"foreground",
|
|
16
|
+
"caretColor",
|
|
17
|
+
"caret",
|
|
18
|
+
"borderLeftColor",
|
|
19
|
+
"selection",
|
|
20
|
+
"lineHighlight",
|
|
21
|
+
"gutterBackground",
|
|
22
|
+
"gutterForeground",
|
|
23
|
+
"highlightStyle",
|
|
24
|
+
"define",
|
|
25
|
+
"extension"
|
|
26
|
+
],
|
|
27
|
+
"sources": [
|
|
28
|
+
"../src/index.tsx"
|
|
29
|
+
],
|
|
30
|
+
"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 dark: 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 /** Background of highlighted lines. */\n lineHighlight: string;\n /** Gutter background. */\n gutterBackground: string;\n /** Text color inside gutter. */\n gutterForeground: string;\n}\n\nconst createTheme = ({ dark, settings, styles }: CreateThemeOptions): Extension => {\n const theme = EditorView.theme(\n {\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-focused .cm-selectionBackgroundm .cm-selectionBackground, .cm-content ::selection': {\n backgroundColor: settings.selection,\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 {\n dark: dark === 'dark',\n },\n );\n\n const highlightStyle = HighlightStyle.define(styles);\n const extension = [theme, syntaxHighlighting(highlightStyle)];\n\n return extension;\n};\n\nexport default createTheme;\n"
|
|
32
|
+
],
|
|
33
|
+
"mappings": "AAAA,SAASA,UAAT,QAA2B,kBAA3B;AAEA,SAASC,cAAT,EAAmCC,kBAAnC,QAA6D,sBAA7D;;AAkCA,IAAMC,WAAW,GAAG,QAA+D;EAAA,IAA9D;IAAEC,IAAF;IAAQC,QAAR;IAAkBC;EAAlB,CAA8D;EACjF,IAAMC,KAAK,GAAGP,UAAU,CAACO,KAAX,CACZ;IACE,KAAK;MACHC,eAAe,EAAEH,QAAQ,CAACI,UADvB;MAEHC,KAAK,EAAEL,QAAQ,CAACM;IAFb,CADP;IAKE,eAAe;MACbC,UAAU,EAAEP,QAAQ,CAACQ;IADR,CALjB;IAQE,8BAA8B;MAC5BC,eAAe,EAAET,QAAQ,CAACQ;IADE,CARhC;IAWE,0FAA0F;MACxFL,eAAe,EAAEH,QAAQ,CAACU;IAD8D,CAX5F;IAcE,kBAAkB;MAChBP,eAAe,EAAEH,QAAQ,CAACW;IADV,CAdpB;IAiBE,eAAe;MACbR,eAAe,EAAEH,QAAQ,CAACY,gBADb;MAEbP,KAAK,EAAEL,QAAQ,CAACa;IAFH,CAjBjB;IAqBE,wBAAwB;MACtBV,eAAe,EAAEH,QAAQ,CAACW;IADJ;EArB1B,CADY,EA0BZ;IACEZ,IAAI,EAAEA,IAAI,KAAK;EADjB,CA1BY,CAAd;EA+BA,IAAMe,cAAc,GAAGlB,cAAc,CAACmB,MAAf,CAAsBd,MAAtB,CAAvB;EACA,IAAMe,SAAS,GAAG,CAACd,KAAD,EAAQL,kBAAkB,CAACiB,cAAD,CAA1B,CAAlB;EAEA,OAAOE,SAAP;AACD,CApCD;;AAsCA,eAAelB,WAAf"
|
|
34
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uiw/codemirror-themes",
|
|
3
|
+
"version": "4.8.1",
|
|
4
|
+
"description": "Themes for CodeMirror.",
|
|
5
|
+
"homepage": "https://uiwjs.github.io/react-codemirror",
|
|
6
|
+
"author": "kenny wong <wowohoo@qq.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "./cjs/index.js",
|
|
9
|
+
"module": "./esm/index.js",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"watch": "tsbb watch",
|
|
12
|
+
"build": "tsbb build"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/uiwjs/react-codemirror.git"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"src",
|
|
20
|
+
"esm",
|
|
21
|
+
"cjs"
|
|
22
|
+
],
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@babel/runtime": ">=7.11.0"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@codemirror/language": "^6.0.0",
|
|
28
|
+
"@codemirror/view": "^6.0.0",
|
|
29
|
+
"@codemirror/state": "^6.0.0"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"codemirror",
|
|
33
|
+
"codemirror6",
|
|
34
|
+
"theme",
|
|
35
|
+
"syntax",
|
|
36
|
+
"ide",
|
|
37
|
+
"code"
|
|
38
|
+
],
|
|
39
|
+
"jest": {
|
|
40
|
+
"coverageReporters": [
|
|
41
|
+
"lcov",
|
|
42
|
+
"json-summary"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { EditorView } from '@codemirror/view';
|
|
2
|
+
import { Extension } from '@codemirror/state';
|
|
3
|
+
import { HighlightStyle, TagStyle, syntaxHighlighting } from '@codemirror/language';
|
|
4
|
+
|
|
5
|
+
export interface CreateThemeOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Theme inheritance. Determines which styles CodeMirror will apply by default.
|
|
8
|
+
*/
|
|
9
|
+
dark: Theme;
|
|
10
|
+
/**
|
|
11
|
+
* Settings to customize the look of the editor, like background, gutter, selection and others.
|
|
12
|
+
*/
|
|
13
|
+
settings: Settings;
|
|
14
|
+
/** Syntax highlighting styles. */
|
|
15
|
+
styles: TagStyle[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type Theme = 'light' | 'dark';
|
|
19
|
+
|
|
20
|
+
export interface Settings {
|
|
21
|
+
/** Editor background. */
|
|
22
|
+
background: string;
|
|
23
|
+
/** Default text color. */
|
|
24
|
+
foreground: string;
|
|
25
|
+
/** Caret color. */
|
|
26
|
+
caret: string;
|
|
27
|
+
/** Selection background. */
|
|
28
|
+
selection: string;
|
|
29
|
+
/** Background of highlighted lines. */
|
|
30
|
+
lineHighlight: string;
|
|
31
|
+
/** Gutter background. */
|
|
32
|
+
gutterBackground: string;
|
|
33
|
+
/** Text color inside gutter. */
|
|
34
|
+
gutterForeground: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const createTheme = ({ dark, settings, styles }: CreateThemeOptions): Extension => {
|
|
38
|
+
const theme = EditorView.theme(
|
|
39
|
+
{
|
|
40
|
+
'&': {
|
|
41
|
+
backgroundColor: settings.background,
|
|
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-selectionBackgroundm .cm-selectionBackground, .cm-content ::selection': {
|
|
51
|
+
backgroundColor: settings.selection,
|
|
52
|
+
},
|
|
53
|
+
'.cm-activeLine': {
|
|
54
|
+
backgroundColor: settings.lineHighlight,
|
|
55
|
+
},
|
|
56
|
+
'.cm-gutters': {
|
|
57
|
+
backgroundColor: settings.gutterBackground,
|
|
58
|
+
color: settings.gutterForeground,
|
|
59
|
+
},
|
|
60
|
+
'.cm-activeLineGutter': {
|
|
61
|
+
backgroundColor: settings.lineHighlight,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
dark: dark === 'dark',
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const highlightStyle = HighlightStyle.define(styles);
|
|
70
|
+
const extension = [theme, syntaxHighlighting(highlightStyle)];
|
|
71
|
+
|
|
72
|
+
return extension;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export default createTheme;
|