material.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // Ref: https://github.com/craftzdog/cm6-themes/blob/289d9e0ca6b500f4cdf68464f4f21dd8e2dd8963/packages/material-dark/src/index.ts
  2. import { HighlightStyle, syntaxHighlighting } from '@codemirror/language';
  3. import type { Extension } from '@codemirror/state';
  4. import { EditorView } from '@codemirror/view';
  5. import { tags as t } from '@lezer/highlight';
  6. // Auther: stephen-liu-fipo
  7. const base00 = '#2e3235';
  8. const base01 = '#505d64';
  9. const base02 = '#606f7a';
  10. const base03 = '#707d8b';
  11. // base04 = '#a0a4ae',
  12. const base05 = '#bdbdbd';
  13. const base06 = '#e0e0e0';
  14. const base07 = '#fdf6e3';
  15. const base_red = '#ff5f52';
  16. const base_deeporange = '#ff6e40';
  17. const base_pink = '#fa5788';
  18. const base_yellow = '#facf4e';
  19. const base_orange = '#ffad42';
  20. const base_cyan = '#56c8d8';
  21. const base_indigo = '#7186f0';
  22. const base_purple = '#cf6edf';
  23. const base_green = '#6abf69';
  24. const base_lightgreen = '#99d066';
  25. const base_teal = '#4ebaaa';
  26. const invalid = base_red;
  27. // Adjust color
  28. const darkBackground = '#36383a';
  29. // Adjust color
  30. const highlightBackground = '#44494d';
  31. const background = base00;
  32. const tooltipBackground = base01;
  33. const selection = base01;
  34. // Change color
  35. const cursor = base05;
  36. // Create New color
  37. const activeLineBackground = '#00000020';
  38. // / The editor theme styles for Material Dark.
  39. export const materialDarkTheme = EditorView.theme(
  40. {
  41. '&': {
  42. color: base05,
  43. backgroundColor: background,
  44. },
  45. '.cm-content': {
  46. caretColor: cursor,
  47. },
  48. '.cm-cursor, .cm-dropCursor': { borderLeftColor: cursor },
  49. '&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection':
  50. { backgroundColor: selection },
  51. '.cm-panels': { backgroundColor: darkBackground, color: base03 },
  52. '.cm-panels.cm-panels-top': { borderBottom: '2px solid black' },
  53. '.cm-panels.cm-panels-bottom': { borderTop: '2px solid black' },
  54. '.cm-searchMatch': {
  55. outline: `1px solid ${base_yellow}`,
  56. backgroundColor: 'transparent',
  57. },
  58. '.cm-searchMatch.cm-searchMatch-selected': {
  59. backgroundColor: highlightBackground,
  60. },
  61. // Customize
  62. '.cm-activeLine': { backgroundColor: activeLineBackground },
  63. '.cm-selectionMatch': {
  64. backgroundColor: darkBackground,
  65. outline: `1px solid ${base_teal}`,
  66. },
  67. '&.cm-focused .cm-matchingBracket': {
  68. color: base06,
  69. outline: `1px solid ${base_teal}`,
  70. },
  71. '&.cm-focused .cm-nonmatchingBracket': {
  72. color: base_red,
  73. },
  74. '.cm-gutters': {
  75. backgroundColor: base00,
  76. borderRight: '1px solid #4f5b66',
  77. color: base02,
  78. },
  79. // Customize
  80. '.cm-activeLineGutter': {
  81. backgroundColor: activeLineBackground,
  82. color: base07,
  83. },
  84. '.cm-foldPlaceholder': {
  85. backgroundColor: 'transparent',
  86. border: 'none',
  87. color: '#ddd',
  88. },
  89. '.cm-tooltip': {
  90. border: 'none',
  91. backgroundColor: tooltipBackground,
  92. },
  93. '.cm-tooltip .cm-tooltip-arrow:before': {
  94. borderTopColor: 'transparent',
  95. borderBottomColor: 'transparent',
  96. },
  97. '.cm-tooltip .cm-tooltip-arrow:after': {
  98. borderTopColor: tooltipBackground,
  99. borderBottomColor: tooltipBackground,
  100. },
  101. '.cm-tooltip-autocomplete': {
  102. '& > ul > li[aria-selected]': {
  103. backgroundColor: highlightBackground,
  104. color: base03,
  105. },
  106. },
  107. },
  108. { dark: true },
  109. );
  110. // / The highlighting style for code in the Material Dark theme.
  111. export const materialDarkHighlightStyle = HighlightStyle.define([
  112. { tag: t.keyword, color: base_purple },
  113. {
  114. tag: [t.name, t.deleted, t.character, t.macroName],
  115. color: base_cyan,
  116. },
  117. { tag: [t.propertyName], color: base_yellow },
  118. { tag: [t.variableName], color: base05 },
  119. { tag: [t.function(t.variableName)], color: base_cyan },
  120. { tag: [t.labelName], color: base_purple },
  121. {
  122. tag: [t.color, t.constant(t.name), t.standard(t.name)],
  123. color: base_yellow,
  124. },
  125. { tag: [t.definition(t.name), t.separator], color: base_pink },
  126. { tag: [t.brace], color: base_purple },
  127. {
  128. tag: [t.annotation],
  129. color: invalid,
  130. },
  131. {
  132. tag: [t.number, t.changed, t.annotation, t.modifier, t.self, t.namespace],
  133. color: base_orange,
  134. },
  135. {
  136. tag: [t.typeName, t.className],
  137. color: base_orange,
  138. },
  139. {
  140. tag: [t.operator, t.operatorKeyword],
  141. color: base_indigo,
  142. },
  143. {
  144. tag: [t.tagName],
  145. color: base_deeporange,
  146. },
  147. {
  148. tag: [t.squareBracket],
  149. color: base_red,
  150. },
  151. {
  152. tag: [t.angleBracket],
  153. color: base02,
  154. },
  155. {
  156. tag: [t.attributeName],
  157. color: base05,
  158. },
  159. {
  160. tag: [t.regexp],
  161. color: invalid,
  162. },
  163. {
  164. tag: [t.quote],
  165. color: base_green,
  166. },
  167. { tag: [t.string], color: base_lightgreen },
  168. {
  169. tag: t.link,
  170. color: base_cyan,
  171. textDecoration: 'underline',
  172. textUnderlinePosition: 'under',
  173. },
  174. {
  175. tag: [t.url, t.escape, t.special(t.string)],
  176. color: base_yellow,
  177. },
  178. { tag: [t.meta], color: base03 },
  179. { tag: [t.comment], color: base03, fontStyle: 'italic' },
  180. { tag: t.monospace, color: base05 },
  181. { tag: t.strong, fontWeight: 'bold', color: base_red },
  182. { tag: t.emphasis, fontStyle: 'italic', color: base_lightgreen },
  183. { tag: t.strikethrough, textDecoration: 'line-through' },
  184. { tag: t.heading, fontWeight: 'bold', color: base_yellow },
  185. { tag: t.heading1, fontWeight: 'bold', color: base_yellow },
  186. {
  187. tag: [t.heading2, t.heading3, t.heading4],
  188. fontWeight: 'bold',
  189. color: base_yellow,
  190. },
  191. {
  192. tag: [t.heading5, t.heading6],
  193. color: base_yellow,
  194. },
  195. { tag: [t.atom, t.bool, t.special(t.variableName)], color: base_cyan },
  196. {
  197. tag: [t.processingInstruction, t.inserted],
  198. color: base_red,
  199. },
  200. {
  201. tag: [t.contentSeparator],
  202. color: base_cyan,
  203. },
  204. { tag: t.invalid, color: base02, borderBottom: `1px dotted ${base_red}` },
  205. ]);
  206. // / Extension to enable the Material Dark theme (both the editor theme and
  207. // / the highlight style).
  208. export const materialDark: Extension = [
  209. materialDarkTheme,
  210. syntaxHighlighting(materialDarkHighlightStyle),
  211. ];