material.ts 5.7 KB

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