stylus.js 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/LICENSE
  3. // Stylus mode created by Dmitry Kiselyov http://git.io/AaRB
  4. ;(function (mod) {
  5. if (typeof exports == 'object' && typeof module == 'object')
  6. // CommonJS
  7. mod(require('../../lib/codemirror'))
  8. else if (typeof define == 'function' && define.amd)
  9. // AMD
  10. define(['../../lib/codemirror'], mod)
  11. // Plain browser env
  12. else mod(CodeMirror)
  13. })(function (CodeMirror) {
  14. 'use strict'
  15. CodeMirror.defineMode('stylus', function (config) {
  16. var indentUnit = config.indentUnit,
  17. indentUnitString = '',
  18. tagKeywords = keySet(tagKeywords_),
  19. tagVariablesRegexp = /^(a|b|i|s|col|em)$/i,
  20. propertyKeywords = keySet(propertyKeywords_),
  21. nonStandardPropertyKeywords = keySet(nonStandardPropertyKeywords_),
  22. valueKeywords = keySet(valueKeywords_),
  23. colorKeywords = keySet(colorKeywords_),
  24. documentTypes = keySet(documentTypes_),
  25. documentTypesRegexp = wordRegexp(documentTypes_),
  26. mediaFeatures = keySet(mediaFeatures_),
  27. mediaTypes = keySet(mediaTypes_),
  28. fontProperties = keySet(fontProperties_),
  29. operatorsRegexp = /^\s*([.]{2,3}|&&|\|\||\*\*|[?!=:]?=|[-+*\/%<>]=?|\?:|\~)/,
  30. wordOperatorKeywordsRegexp = wordRegexp(wordOperatorKeywords_),
  31. blockKeywords = keySet(blockKeywords_),
  32. vendorPrefixesRegexp = new RegExp(/^\-(moz|ms|o|webkit)-/i),
  33. commonAtoms = keySet(commonAtoms_),
  34. firstWordMatch = '',
  35. states = {},
  36. ch,
  37. style,
  38. type,
  39. override
  40. while (indentUnitString.length < indentUnit) indentUnitString += ' '
  41. /**
  42. * Tokenizers
  43. */
  44. function tokenBase(stream, state) {
  45. firstWordMatch = stream.string.match(/(^[\w-]+\s*=\s*$)|(^\s*[\w-]+\s*=\s*[\w-])|(^\s*(\.|#|@|\$|\&|\[|\d|\+|::?|\{|\>|~|\/)?\s*[\w-]*([a-z0-9-]|\*|\/\*)(\(|,)?)/)
  46. state.context.line.firstWord = firstWordMatch ? firstWordMatch[0].replace(/^\s*/, '') : ''
  47. state.context.line.indent = stream.indentation()
  48. ch = stream.peek()
  49. // Line comment
  50. if (stream.match('//')) {
  51. stream.skipToEnd()
  52. return ['comment', 'comment']
  53. }
  54. // Block comment
  55. if (stream.match('/*')) {
  56. state.tokenize = tokenCComment
  57. return tokenCComment(stream, state)
  58. }
  59. // String
  60. if (ch == '"' || ch == "'") {
  61. stream.next()
  62. state.tokenize = tokenString(ch)
  63. return state.tokenize(stream, state)
  64. }
  65. // Def
  66. if (ch == '@') {
  67. stream.next()
  68. stream.eatWhile(/[\w\\-]/)
  69. return ['def', stream.current()]
  70. }
  71. // ID selector or Hex color
  72. if (ch == '#') {
  73. stream.next()
  74. // Hex color
  75. if (stream.match(/^[0-9a-f]{3}([0-9a-f]([0-9a-f]{2}){0,2})?\b(?!-)/i)) {
  76. return ['atom', 'atom']
  77. }
  78. // ID selector
  79. if (stream.match(/^[a-z][\w-]*/i)) {
  80. return ['builtin', 'hash']
  81. }
  82. }
  83. // Vendor prefixes
  84. if (stream.match(vendorPrefixesRegexp)) {
  85. return ['meta', 'vendor-prefixes']
  86. }
  87. // Numbers
  88. if (stream.match(/^-?[0-9]?\.?[0-9]/)) {
  89. stream.eatWhile(/[a-z%]/i)
  90. return ['number', 'unit']
  91. }
  92. // !important|optional
  93. if (ch == '!') {
  94. stream.next()
  95. return [stream.match(/^(important|optional)/i) ? 'keyword' : 'operator', 'important']
  96. }
  97. // Class
  98. if (ch == '.' && stream.match(/^\.[a-z][\w-]*/i)) {
  99. return ['qualifier', 'qualifier']
  100. }
  101. // url url-prefix domain regexp
  102. if (stream.match(documentTypesRegexp)) {
  103. if (stream.peek() == '(') state.tokenize = tokenParenthesized
  104. return ['property', 'word']
  105. }
  106. // Mixins / Functions
  107. if (stream.match(/^[a-z][\w-]*\(/i)) {
  108. stream.backUp(1)
  109. return ['keyword', 'mixin']
  110. }
  111. // Block mixins
  112. if (stream.match(/^(\+|-)[a-z][\w-]*\(/i)) {
  113. stream.backUp(1)
  114. return ['keyword', 'block-mixin']
  115. }
  116. // Parent Reference BEM naming
  117. if (stream.string.match(/^\s*&/) && stream.match(/^[-_]+[a-z][\w-]*/)) {
  118. return ['qualifier', 'qualifier']
  119. }
  120. // / Root Reference & Parent Reference
  121. if (stream.match(/^(\/|&)(-|_|:|\.|#|[a-z])/)) {
  122. stream.backUp(1)
  123. return ['variable-3', 'reference']
  124. }
  125. if (stream.match(/^&{1}\s*$/)) {
  126. return ['variable-3', 'reference']
  127. }
  128. // Word operator
  129. if (stream.match(wordOperatorKeywordsRegexp)) {
  130. return ['operator', 'operator']
  131. }
  132. // Word
  133. if (stream.match(/^\$?[-_]*[a-z0-9]+[\w-]*/i)) {
  134. // Variable
  135. if (stream.match(/^(\.|\[)[\w-\'\"\]]+/i, false)) {
  136. if (!wordIsTag(stream.current())) {
  137. stream.match('.')
  138. return ['variable-2', 'variable-name']
  139. }
  140. }
  141. return ['variable-2', 'word']
  142. }
  143. // Operators
  144. if (stream.match(operatorsRegexp)) {
  145. return ['operator', stream.current()]
  146. }
  147. // Delimiters
  148. if (/[:;,{}\[\]\(\)]/.test(ch)) {
  149. stream.next()
  150. return [null, ch]
  151. }
  152. // Non-detected items
  153. stream.next()
  154. return [null, null]
  155. }
  156. /**
  157. * Token comment
  158. */
  159. function tokenCComment(stream, state) {
  160. var maybeEnd = false,
  161. ch
  162. while ((ch = stream.next()) != null) {
  163. if (maybeEnd && ch == '/') {
  164. state.tokenize = null
  165. break
  166. }
  167. maybeEnd = ch == '*'
  168. }
  169. return ['comment', 'comment']
  170. }
  171. /**
  172. * Token string
  173. */
  174. function tokenString(quote) {
  175. return function (stream, state) {
  176. var escaped = false,
  177. ch
  178. while ((ch = stream.next()) != null) {
  179. if (ch == quote && !escaped) {
  180. if (quote == ')') stream.backUp(1)
  181. break
  182. }
  183. escaped = !escaped && ch == '\\'
  184. }
  185. if (ch == quote || (!escaped && quote != ')')) state.tokenize = null
  186. return ['string', 'string']
  187. }
  188. }
  189. /**
  190. * Token parenthesized
  191. */
  192. function tokenParenthesized(stream, state) {
  193. stream.next() // Must be "("
  194. if (!stream.match(/\s*[\"\')]/, false)) state.tokenize = tokenString(')')
  195. else state.tokenize = null
  196. return [null, '(']
  197. }
  198. /**
  199. * Context management
  200. */
  201. function Context(type, indent, prev, line) {
  202. this.type = type
  203. this.indent = indent
  204. this.prev = prev
  205. this.line = line || { firstWord: '', indent: 0 }
  206. }
  207. function pushContext(state, stream, type, indent) {
  208. indent = indent >= 0 ? indent : indentUnit
  209. state.context = new Context(type, stream.indentation() + indent, state.context)
  210. return type
  211. }
  212. function popContext(state, currentIndent) {
  213. var contextIndent = state.context.indent - indentUnit
  214. currentIndent = currentIndent || false
  215. state.context = state.context.prev
  216. if (currentIndent) state.context.indent = contextIndent
  217. return state.context.type
  218. }
  219. function pass(type, stream, state) {
  220. return states[state.context.type](type, stream, state)
  221. }
  222. function popAndPass(type, stream, state, n) {
  223. for (var i = n || 1; i > 0; i--) state.context = state.context.prev
  224. return pass(type, stream, state)
  225. }
  226. /**
  227. * Parser
  228. */
  229. function wordIsTag(word) {
  230. return word.toLowerCase() in tagKeywords
  231. }
  232. function wordIsProperty(word) {
  233. word = word.toLowerCase()
  234. return word in propertyKeywords || word in fontProperties
  235. }
  236. function wordIsBlock(word) {
  237. return word.toLowerCase() in blockKeywords
  238. }
  239. function wordIsVendorPrefix(word) {
  240. return word.toLowerCase().match(vendorPrefixesRegexp)
  241. }
  242. function wordAsValue(word) {
  243. var wordLC = word.toLowerCase()
  244. var override = 'variable-2'
  245. if (wordIsTag(word)) override = 'tag'
  246. else if (wordIsBlock(word)) override = 'block-keyword'
  247. else if (wordIsProperty(word)) override = 'property'
  248. else if (wordLC in valueKeywords || wordLC in commonAtoms) override = 'atom'
  249. else if (wordLC == 'return' || wordLC in colorKeywords) override = 'keyword'
  250. // Font family
  251. else if (word.match(/^[A-Z]/)) override = 'string'
  252. return override
  253. }
  254. function typeIsBlock(type, stream) {
  255. return (endOfLine(stream) && (type == '{' || type == ']' || type == 'hash' || type == 'qualifier')) || type == 'block-mixin'
  256. }
  257. function typeIsInterpolation(type, stream) {
  258. return type == '{' && stream.match(/^\s*\$?[\w-]+/i, false)
  259. }
  260. function typeIsPseudo(type, stream) {
  261. return type == ':' && stream.match(/^[a-z-]+/, false)
  262. }
  263. function startOfLine(stream) {
  264. return stream.sol() || stream.string.match(new RegExp('^\\s*' + escapeRegExp(stream.current())))
  265. }
  266. function endOfLine(stream) {
  267. return stream.eol() || stream.match(/^\s*$/, false)
  268. }
  269. function firstWordOfLine(line) {
  270. var re = /^\s*[-_]*[a-z0-9]+[\w-]*/i
  271. var result = typeof line == 'string' ? line.match(re) : line.string.match(re)
  272. return result ? result[0].replace(/^\s*/, '') : ''
  273. }
  274. /**
  275. * Block
  276. */
  277. states.block = function (type, stream, state) {
  278. if ((type == 'comment' && startOfLine(stream)) || (type == ',' && endOfLine(stream)) || type == 'mixin') {
  279. return pushContext(state, stream, 'block', 0)
  280. }
  281. if (typeIsInterpolation(type, stream)) {
  282. return pushContext(state, stream, 'interpolation')
  283. }
  284. if (endOfLine(stream) && type == ']') {
  285. if (!/^\s*(\.|#|:|\[|\*|&)/.test(stream.string) && !wordIsTag(firstWordOfLine(stream))) {
  286. return pushContext(state, stream, 'block', 0)
  287. }
  288. }
  289. if (typeIsBlock(type, stream)) {
  290. return pushContext(state, stream, 'block')
  291. }
  292. if (type == '}' && endOfLine(stream)) {
  293. return pushContext(state, stream, 'block', 0)
  294. }
  295. if (type == 'variable-name') {
  296. if (stream.string.match(/^\s?\$[\w-\.\[\]\'\"]+$/) || wordIsBlock(firstWordOfLine(stream))) {
  297. return pushContext(state, stream, 'variableName')
  298. } else {
  299. return pushContext(state, stream, 'variableName', 0)
  300. }
  301. }
  302. if (type == '=') {
  303. if (!endOfLine(stream) && !wordIsBlock(firstWordOfLine(stream))) {
  304. return pushContext(state, stream, 'block', 0)
  305. }
  306. return pushContext(state, stream, 'block')
  307. }
  308. if (type == '*') {
  309. if (endOfLine(stream) || stream.match(/\s*(,|\.|#|\[|:|{)/, false)) {
  310. override = 'tag'
  311. return pushContext(state, stream, 'block')
  312. }
  313. }
  314. if (typeIsPseudo(type, stream)) {
  315. return pushContext(state, stream, 'pseudo')
  316. }
  317. if (/@(font-face|media|supports|(-moz-)?document)/.test(type)) {
  318. return pushContext(state, stream, endOfLine(stream) ? 'block' : 'atBlock')
  319. }
  320. if (/@(-(moz|ms|o|webkit)-)?keyframes$/.test(type)) {
  321. return pushContext(state, stream, 'keyframes')
  322. }
  323. if (/@extends?/.test(type)) {
  324. return pushContext(state, stream, 'extend', 0)
  325. }
  326. if (type && type.charAt(0) == '@') {
  327. // Property Lookup
  328. if (stream.indentation() > 0 && wordIsProperty(stream.current().slice(1))) {
  329. override = 'variable-2'
  330. return 'block'
  331. }
  332. if (/(@import|@require|@charset)/.test(type)) {
  333. return pushContext(state, stream, 'block', 0)
  334. }
  335. return pushContext(state, stream, 'block')
  336. }
  337. if (type == 'reference' && endOfLine(stream)) {
  338. return pushContext(state, stream, 'block')
  339. }
  340. if (type == '(') {
  341. return pushContext(state, stream, 'parens')
  342. }
  343. if (type == 'vendor-prefixes') {
  344. return pushContext(state, stream, 'vendorPrefixes')
  345. }
  346. if (type == 'word') {
  347. var word = stream.current()
  348. override = wordAsValue(word)
  349. if (override == 'property') {
  350. if (startOfLine(stream)) {
  351. return pushContext(state, stream, 'block', 0)
  352. } else {
  353. override = 'atom'
  354. return 'block'
  355. }
  356. }
  357. if (override == 'tag') {
  358. // tag is a css value
  359. if (/embed|menu|pre|progress|sub|table/.test(word)) {
  360. if (wordIsProperty(firstWordOfLine(stream))) {
  361. override = 'atom'
  362. return 'block'
  363. }
  364. }
  365. // tag is an attribute
  366. if (stream.string.match(new RegExp('\\[\\s*' + word + '|' + word + '\\s*\\]'))) {
  367. override = 'atom'
  368. return 'block'
  369. }
  370. // tag is a variable
  371. if (tagVariablesRegexp.test(word)) {
  372. if ((startOfLine(stream) && stream.string.match(/=/)) || (!startOfLine(stream) && !stream.string.match(/^(\s*\.|#|\&|\[|\/|>|\*)/) && !wordIsTag(firstWordOfLine(stream)))) {
  373. override = 'variable-2'
  374. if (wordIsBlock(firstWordOfLine(stream))) return 'block'
  375. return pushContext(state, stream, 'block', 0)
  376. }
  377. }
  378. if (endOfLine(stream)) return pushContext(state, stream, 'block')
  379. }
  380. if (override == 'block-keyword') {
  381. override = 'keyword'
  382. // Postfix conditionals
  383. if (stream.current(/(if|unless)/) && !startOfLine(stream)) {
  384. return 'block'
  385. }
  386. return pushContext(state, stream, 'block')
  387. }
  388. if (word == 'return') return pushContext(state, stream, 'block', 0)
  389. // Placeholder selector
  390. if (override == 'variable-2' && stream.string.match(/^\s?\$[\w-\.\[\]\'\"]+$/)) {
  391. return pushContext(state, stream, 'block')
  392. }
  393. }
  394. return state.context.type
  395. }
  396. /**
  397. * Parens
  398. */
  399. states.parens = function (type, stream, state) {
  400. if (type == '(') return pushContext(state, stream, 'parens')
  401. if (type == ')') {
  402. if (state.context.prev.type == 'parens') {
  403. return popContext(state)
  404. }
  405. if (
  406. (stream.string.match(/^[a-z][\w-]*\(/i) && endOfLine(stream)) ||
  407. wordIsBlock(firstWordOfLine(stream)) ||
  408. /(\.|#|:|\[|\*|&|>|~|\+|\/)/.test(firstWordOfLine(stream)) ||
  409. (!stream.string.match(/^-?[a-z][\w-\.\[\]\'\"]*\s*=/) && wordIsTag(firstWordOfLine(stream)))
  410. ) {
  411. return pushContext(state, stream, 'block')
  412. }
  413. if (
  414. stream.string.match(/^[\$-]?[a-z][\w-\.\[\]\'\"]*\s*=/) ||
  415. stream.string.match(/^\s*(\(|\)|[0-9])/) ||
  416. stream.string.match(/^\s+[a-z][\w-]*\(/i) ||
  417. stream.string.match(/^\s+[\$-]?[a-z]/i)
  418. ) {
  419. return pushContext(state, stream, 'block', 0)
  420. }
  421. if (endOfLine(stream)) return pushContext(state, stream, 'block')
  422. else return pushContext(state, stream, 'block', 0)
  423. }
  424. if (type && type.charAt(0) == '@' && wordIsProperty(stream.current().slice(1))) {
  425. override = 'variable-2'
  426. }
  427. if (type == 'word') {
  428. var word = stream.current()
  429. override = wordAsValue(word)
  430. if (override == 'tag' && tagVariablesRegexp.test(word)) {
  431. override = 'variable-2'
  432. }
  433. if (override == 'property' || word == 'to') override = 'atom'
  434. }
  435. if (type == 'variable-name') {
  436. return pushContext(state, stream, 'variableName')
  437. }
  438. if (typeIsPseudo(type, stream)) {
  439. return pushContext(state, stream, 'pseudo')
  440. }
  441. return state.context.type
  442. }
  443. /**
  444. * Vendor prefixes
  445. */
  446. states.vendorPrefixes = function (type, stream, state) {
  447. if (type == 'word') {
  448. override = 'property'
  449. return pushContext(state, stream, 'block', 0)
  450. }
  451. return popContext(state)
  452. }
  453. /**
  454. * Pseudo
  455. */
  456. states.pseudo = function (type, stream, state) {
  457. if (!wordIsProperty(firstWordOfLine(stream.string))) {
  458. stream.match(/^[a-z-]+/)
  459. override = 'variable-3'
  460. if (endOfLine(stream)) return pushContext(state, stream, 'block')
  461. return popContext(state)
  462. }
  463. return popAndPass(type, stream, state)
  464. }
  465. /**
  466. * atBlock
  467. */
  468. states.atBlock = function (type, stream, state) {
  469. if (type == '(') return pushContext(state, stream, 'atBlock_parens')
  470. if (typeIsBlock(type, stream)) {
  471. return pushContext(state, stream, 'block')
  472. }
  473. if (typeIsInterpolation(type, stream)) {
  474. return pushContext(state, stream, 'interpolation')
  475. }
  476. if (type == 'word') {
  477. var word = stream.current().toLowerCase()
  478. if (/^(only|not|and|or)$/.test(word)) override = 'keyword'
  479. else if (documentTypes.hasOwnProperty(word)) override = 'tag'
  480. else if (mediaTypes.hasOwnProperty(word)) override = 'attribute'
  481. else if (mediaFeatures.hasOwnProperty(word)) override = 'property'
  482. else if (nonStandardPropertyKeywords.hasOwnProperty(word)) override = 'string-2'
  483. else override = wordAsValue(stream.current())
  484. if (override == 'tag' && endOfLine(stream)) {
  485. return pushContext(state, stream, 'block')
  486. }
  487. }
  488. if (type == 'operator' && /^(not|and|or)$/.test(stream.current())) {
  489. override = 'keyword'
  490. }
  491. return state.context.type
  492. }
  493. states.atBlock_parens = function (type, stream, state) {
  494. if (type == '{' || type == '}') return state.context.type
  495. if (type == ')') {
  496. if (endOfLine(stream)) return pushContext(state, stream, 'block')
  497. else return pushContext(state, stream, 'atBlock')
  498. }
  499. if (type == 'word') {
  500. var word = stream.current().toLowerCase()
  501. override = wordAsValue(word)
  502. if (/^(max|min)/.test(word)) override = 'property'
  503. if (override == 'tag') {
  504. tagVariablesRegexp.test(word) ? (override = 'variable-2') : (override = 'atom')
  505. }
  506. return state.context.type
  507. }
  508. return states.atBlock(type, stream, state)
  509. }
  510. /**
  511. * Keyframes
  512. */
  513. states.keyframes = function (type, stream, state) {
  514. if (stream.indentation() == '0' && ((type == '}' && startOfLine(stream)) || type == ']' || type == 'hash' || type == 'qualifier' || wordIsTag(stream.current()))) {
  515. return popAndPass(type, stream, state)
  516. }
  517. if (type == '{') return pushContext(state, stream, 'keyframes')
  518. if (type == '}') {
  519. if (startOfLine(stream)) return popContext(state, true)
  520. else return pushContext(state, stream, 'keyframes')
  521. }
  522. if (type == 'unit' && /^[0-9]+\%$/.test(stream.current())) {
  523. return pushContext(state, stream, 'keyframes')
  524. }
  525. if (type == 'word') {
  526. override = wordAsValue(stream.current())
  527. if (override == 'block-keyword') {
  528. override = 'keyword'
  529. return pushContext(state, stream, 'keyframes')
  530. }
  531. }
  532. if (/@(font-face|media|supports|(-moz-)?document)/.test(type)) {
  533. return pushContext(state, stream, endOfLine(stream) ? 'block' : 'atBlock')
  534. }
  535. if (type == 'mixin') {
  536. return pushContext(state, stream, 'block', 0)
  537. }
  538. return state.context.type
  539. }
  540. /**
  541. * Interpolation
  542. */
  543. states.interpolation = function (type, stream, state) {
  544. if (type == '{') popContext(state) && pushContext(state, stream, 'block')
  545. if (type == '}') {
  546. if (stream.string.match(/^\s*(\.|#|:|\[|\*|&|>|~|\+|\/)/i) || (stream.string.match(/^\s*[a-z]/i) && wordIsTag(firstWordOfLine(stream)))) {
  547. return pushContext(state, stream, 'block')
  548. }
  549. if (!stream.string.match(/^(\{|\s*\&)/) || stream.match(/\s*[\w-]/, false)) {
  550. return pushContext(state, stream, 'block', 0)
  551. }
  552. return pushContext(state, stream, 'block')
  553. }
  554. if (type == 'variable-name') {
  555. return pushContext(state, stream, 'variableName', 0)
  556. }
  557. if (type == 'word') {
  558. override = wordAsValue(stream.current())
  559. if (override == 'tag') override = 'atom'
  560. }
  561. return state.context.type
  562. }
  563. /**
  564. * Extend/s
  565. */
  566. states.extend = function (type, stream, state) {
  567. if (type == '[' || type == '=') return 'extend'
  568. if (type == ']') return popContext(state)
  569. if (type == 'word') {
  570. override = wordAsValue(stream.current())
  571. return 'extend'
  572. }
  573. return popContext(state)
  574. }
  575. /**
  576. * Variable name
  577. */
  578. states.variableName = function (type, stream, state) {
  579. if (type == 'string' || type == '[' || type == ']' || stream.current().match(/^(\.|\$)/)) {
  580. if (stream.current().match(/^\.[\w-]+/i)) override = 'variable-2'
  581. return 'variableName'
  582. }
  583. return popAndPass(type, stream, state)
  584. }
  585. return {
  586. startState: function (base) {
  587. return {
  588. tokenize: null,
  589. state: 'block',
  590. context: new Context('block', base || 0, null),
  591. }
  592. },
  593. token: function (stream, state) {
  594. if (!state.tokenize && stream.eatSpace()) return null
  595. style = (state.tokenize || tokenBase)(stream, state)
  596. if (style && typeof style == 'object') {
  597. type = style[1]
  598. style = style[0]
  599. }
  600. override = style
  601. state.state = states[state.state](type, stream, state)
  602. return override
  603. },
  604. indent: function (state, textAfter, line) {
  605. var cx = state.context,
  606. ch = textAfter && textAfter.charAt(0),
  607. indent = cx.indent,
  608. lineFirstWord = firstWordOfLine(textAfter),
  609. lineIndent = line.match(/^\s*/)[0].replace(/\t/g, indentUnitString).length,
  610. prevLineFirstWord = state.context.prev ? state.context.prev.line.firstWord : '',
  611. prevLineIndent = state.context.prev ? state.context.prev.line.indent : lineIndent
  612. if (
  613. cx.prev &&
  614. ((ch == '}' && (cx.type == 'block' || cx.type == 'atBlock' || cx.type == 'keyframes')) ||
  615. (ch == ')' && (cx.type == 'parens' || cx.type == 'atBlock_parens')) ||
  616. (ch == '{' && cx.type == 'at'))
  617. ) {
  618. indent = cx.indent - indentUnit
  619. } else if (!/(\})/.test(ch)) {
  620. if (
  621. /@|\$|\d/.test(ch) ||
  622. /^\{/.test(textAfter) ||
  623. /^\s*\/(\/|\*)/.test(textAfter) ||
  624. /^\s*\/\*/.test(prevLineFirstWord) ||
  625. /^\s*[\w-\.\[\]\'\"]+\s*(\?|:|\+)?=/i.test(textAfter) ||
  626. /^(\+|-)?[a-z][\w-]*\(/i.test(textAfter) ||
  627. /^return/.test(textAfter) ||
  628. wordIsBlock(lineFirstWord)
  629. ) {
  630. indent = lineIndent
  631. } else if (/(\.|#|:|\[|\*|&|>|~|\+|\/)/.test(ch) || wordIsTag(lineFirstWord)) {
  632. if (/\,\s*$/.test(prevLineFirstWord)) {
  633. indent = prevLineIndent
  634. } else if (/^\s+/.test(line) && (/(\.|#|:|\[|\*|&|>|~|\+|\/)/.test(prevLineFirstWord) || wordIsTag(prevLineFirstWord))) {
  635. indent = lineIndent <= prevLineIndent ? prevLineIndent : prevLineIndent + indentUnit
  636. } else {
  637. indent = lineIndent
  638. }
  639. } else if (!/,\s*$/.test(line) && (wordIsVendorPrefix(lineFirstWord) || wordIsProperty(lineFirstWord))) {
  640. if (wordIsBlock(prevLineFirstWord)) {
  641. indent = lineIndent <= prevLineIndent ? prevLineIndent : prevLineIndent + indentUnit
  642. } else if (/^\{/.test(prevLineFirstWord)) {
  643. indent = lineIndent <= prevLineIndent ? lineIndent : prevLineIndent + indentUnit
  644. } else if (wordIsVendorPrefix(prevLineFirstWord) || wordIsProperty(prevLineFirstWord)) {
  645. indent = lineIndent >= prevLineIndent ? prevLineIndent : lineIndent
  646. } else if (
  647. /^(\.|#|:|\[|\*|&|@|\+|\-|>|~|\/)/.test(prevLineFirstWord) ||
  648. /=\s*$/.test(prevLineFirstWord) ||
  649. wordIsTag(prevLineFirstWord) ||
  650. /^\$[\w-\.\[\]\'\"]/.test(prevLineFirstWord)
  651. ) {
  652. indent = prevLineIndent + indentUnit
  653. } else {
  654. indent = lineIndent
  655. }
  656. }
  657. }
  658. return indent
  659. },
  660. electricChars: '}',
  661. blockCommentStart: '/*',
  662. blockCommentEnd: '*/',
  663. blockCommentContinue: ' * ',
  664. lineComment: '//',
  665. fold: 'indent',
  666. }
  667. })
  668. // developer.mozilla.org/en-US/docs/Web/HTML/Element
  669. var tagKeywords_ = [
  670. 'a',
  671. 'abbr',
  672. 'address',
  673. 'area',
  674. 'article',
  675. 'aside',
  676. 'audio',
  677. 'b',
  678. 'base',
  679. 'bdi',
  680. 'bdo',
  681. 'bgsound',
  682. 'blockquote',
  683. 'body',
  684. 'br',
  685. 'button',
  686. 'canvas',
  687. 'caption',
  688. 'cite',
  689. 'code',
  690. 'col',
  691. 'colgroup',
  692. 'data',
  693. 'datalist',
  694. 'dd',
  695. 'del',
  696. 'details',
  697. 'dfn',
  698. 'div',
  699. 'dl',
  700. 'dt',
  701. 'em',
  702. 'embed',
  703. 'fieldset',
  704. 'figcaption',
  705. 'figure',
  706. 'footer',
  707. 'form',
  708. 'h1',
  709. 'h2',
  710. 'h3',
  711. 'h4',
  712. 'h5',
  713. 'h6',
  714. 'head',
  715. 'header',
  716. 'hgroup',
  717. 'hr',
  718. 'html',
  719. 'i',
  720. 'iframe',
  721. 'img',
  722. 'input',
  723. 'ins',
  724. 'kbd',
  725. 'keygen',
  726. 'label',
  727. 'legend',
  728. 'li',
  729. 'link',
  730. 'main',
  731. 'map',
  732. 'mark',
  733. 'marquee',
  734. 'menu',
  735. 'menuitem',
  736. 'meta',
  737. 'meter',
  738. 'nav',
  739. 'nobr',
  740. 'noframes',
  741. 'noscript',
  742. 'object',
  743. 'ol',
  744. 'optgroup',
  745. 'option',
  746. 'output',
  747. 'p',
  748. 'param',
  749. 'pre',
  750. 'progress',
  751. 'q',
  752. 'rp',
  753. 'rt',
  754. 'ruby',
  755. 's',
  756. 'samp',
  757. 'script',
  758. 'section',
  759. 'select',
  760. 'small',
  761. 'source',
  762. 'span',
  763. 'strong',
  764. 'style',
  765. 'sub',
  766. 'summary',
  767. 'sup',
  768. 'table',
  769. 'tbody',
  770. 'td',
  771. 'textarea',
  772. 'tfoot',
  773. 'th',
  774. 'thead',
  775. 'time',
  776. 'tr',
  777. 'track',
  778. 'u',
  779. 'ul',
  780. 'var',
  781. 'video',
  782. ]
  783. // github.com/codemirror/CodeMirror/blob/master/mode/css/css.js
  784. // Note, "url-prefix" should precede "url" in order to match correctly in documentTypesRegexp
  785. var documentTypes_ = ['domain', 'regexp', 'url-prefix', 'url']
  786. var mediaTypes_ = ['all', 'aural', 'braille', 'handheld', 'print', 'projection', 'screen', 'tty', 'tv', 'embossed']
  787. var mediaFeatures_ = [
  788. 'width',
  789. 'min-width',
  790. 'max-width',
  791. 'height',
  792. 'min-height',
  793. 'max-height',
  794. 'device-width',
  795. 'min-device-width',
  796. 'max-device-width',
  797. 'device-height',
  798. 'min-device-height',
  799. 'max-device-height',
  800. 'aspect-ratio',
  801. 'min-aspect-ratio',
  802. 'max-aspect-ratio',
  803. 'device-aspect-ratio',
  804. 'min-device-aspect-ratio',
  805. 'max-device-aspect-ratio',
  806. 'color',
  807. 'min-color',
  808. 'max-color',
  809. 'color-index',
  810. 'min-color-index',
  811. 'max-color-index',
  812. 'monochrome',
  813. 'min-monochrome',
  814. 'max-monochrome',
  815. 'resolution',
  816. 'min-resolution',
  817. 'max-resolution',
  818. 'scan',
  819. 'grid',
  820. 'dynamic-range',
  821. 'video-dynamic-range',
  822. ]
  823. var propertyKeywords_ = [
  824. 'align-content',
  825. 'align-items',
  826. 'align-self',
  827. 'alignment-adjust',
  828. 'alignment-baseline',
  829. 'anchor-point',
  830. 'animation',
  831. 'animation-delay',
  832. 'animation-direction',
  833. 'animation-duration',
  834. 'animation-fill-mode',
  835. 'animation-iteration-count',
  836. 'animation-name',
  837. 'animation-play-state',
  838. 'animation-timing-function',
  839. 'appearance',
  840. 'azimuth',
  841. 'backface-visibility',
  842. 'background',
  843. 'background-attachment',
  844. 'background-clip',
  845. 'background-color',
  846. 'background-image',
  847. 'background-origin',
  848. 'background-position',
  849. 'background-repeat',
  850. 'background-size',
  851. 'baseline-shift',
  852. 'binding',
  853. 'bleed',
  854. 'bookmark-label',
  855. 'bookmark-level',
  856. 'bookmark-state',
  857. 'bookmark-target',
  858. 'border',
  859. 'border-bottom',
  860. 'border-bottom-color',
  861. 'border-bottom-left-radius',
  862. 'border-bottom-right-radius',
  863. 'border-bottom-style',
  864. 'border-bottom-width',
  865. 'border-collapse',
  866. 'border-color',
  867. 'border-image',
  868. 'border-image-outset',
  869. 'border-image-repeat',
  870. 'border-image-slice',
  871. 'border-image-source',
  872. 'border-image-width',
  873. 'border-left',
  874. 'border-left-color',
  875. 'border-left-style',
  876. 'border-left-width',
  877. 'border-radius',
  878. 'border-right',
  879. 'border-right-color',
  880. 'border-right-style',
  881. 'border-right-width',
  882. 'border-spacing',
  883. 'border-style',
  884. 'border-top',
  885. 'border-top-color',
  886. 'border-top-left-radius',
  887. 'border-top-right-radius',
  888. 'border-top-style',
  889. 'border-top-width',
  890. 'border-width',
  891. 'bottom',
  892. 'box-decoration-break',
  893. 'box-shadow',
  894. 'box-sizing',
  895. 'break-after',
  896. 'break-before',
  897. 'break-inside',
  898. 'caption-side',
  899. 'clear',
  900. 'clip',
  901. 'color',
  902. 'color-profile',
  903. 'column-count',
  904. 'column-fill',
  905. 'column-gap',
  906. 'column-rule',
  907. 'column-rule-color',
  908. 'column-rule-style',
  909. 'column-rule-width',
  910. 'column-span',
  911. 'column-width',
  912. 'columns',
  913. 'content',
  914. 'counter-increment',
  915. 'counter-reset',
  916. 'crop',
  917. 'cue',
  918. 'cue-after',
  919. 'cue-before',
  920. 'cursor',
  921. 'direction',
  922. 'display',
  923. 'dominant-baseline',
  924. 'drop-initial-after-adjust',
  925. 'drop-initial-after-align',
  926. 'drop-initial-before-adjust',
  927. 'drop-initial-before-align',
  928. 'drop-initial-size',
  929. 'drop-initial-value',
  930. 'elevation',
  931. 'empty-cells',
  932. 'fit',
  933. 'fit-position',
  934. 'flex',
  935. 'flex-basis',
  936. 'flex-direction',
  937. 'flex-flow',
  938. 'flex-grow',
  939. 'flex-shrink',
  940. 'flex-wrap',
  941. 'float',
  942. 'float-offset',
  943. 'flow-from',
  944. 'flow-into',
  945. 'font',
  946. 'font-feature-settings',
  947. 'font-family',
  948. 'font-kerning',
  949. 'font-language-override',
  950. 'font-size',
  951. 'font-size-adjust',
  952. 'font-stretch',
  953. 'font-style',
  954. 'font-synthesis',
  955. 'font-variant',
  956. 'font-variant-alternates',
  957. 'font-variant-caps',
  958. 'font-variant-east-asian',
  959. 'font-variant-ligatures',
  960. 'font-variant-numeric',
  961. 'font-variant-position',
  962. 'font-weight',
  963. 'grid',
  964. 'grid-area',
  965. 'grid-auto-columns',
  966. 'grid-auto-flow',
  967. 'grid-auto-position',
  968. 'grid-auto-rows',
  969. 'grid-column',
  970. 'grid-column-end',
  971. 'grid-column-start',
  972. 'grid-row',
  973. 'grid-row-end',
  974. 'grid-row-start',
  975. 'grid-template',
  976. 'grid-template-areas',
  977. 'grid-template-columns',
  978. 'grid-template-rows',
  979. 'hanging-punctuation',
  980. 'height',
  981. 'hyphens',
  982. 'icon',
  983. 'image-orientation',
  984. 'image-rendering',
  985. 'image-resolution',
  986. 'inline-box-align',
  987. 'justify-content',
  988. 'left',
  989. 'letter-spacing',
  990. 'line-break',
  991. 'line-height',
  992. 'line-stacking',
  993. 'line-stacking-ruby',
  994. 'line-stacking-shift',
  995. 'line-stacking-strategy',
  996. 'list-style',
  997. 'list-style-image',
  998. 'list-style-position',
  999. 'list-style-type',
  1000. 'margin',
  1001. 'margin-bottom',
  1002. 'margin-left',
  1003. 'margin-right',
  1004. 'margin-top',
  1005. 'marker-offset',
  1006. 'marks',
  1007. 'marquee-direction',
  1008. 'marquee-loop',
  1009. 'marquee-play-count',
  1010. 'marquee-speed',
  1011. 'marquee-style',
  1012. 'max-height',
  1013. 'max-width',
  1014. 'min-height',
  1015. 'min-width',
  1016. 'move-to',
  1017. 'nav-down',
  1018. 'nav-index',
  1019. 'nav-left',
  1020. 'nav-right',
  1021. 'nav-up',
  1022. 'object-fit',
  1023. 'object-position',
  1024. 'opacity',
  1025. 'order',
  1026. 'orphans',
  1027. 'outline',
  1028. 'outline-color',
  1029. 'outline-offset',
  1030. 'outline-style',
  1031. 'outline-width',
  1032. 'overflow',
  1033. 'overflow-style',
  1034. 'overflow-wrap',
  1035. 'overflow-x',
  1036. 'overflow-y',
  1037. 'padding',
  1038. 'padding-bottom',
  1039. 'padding-left',
  1040. 'padding-right',
  1041. 'padding-top',
  1042. 'page',
  1043. 'page-break-after',
  1044. 'page-break-before',
  1045. 'page-break-inside',
  1046. 'page-policy',
  1047. 'pause',
  1048. 'pause-after',
  1049. 'pause-before',
  1050. 'perspective',
  1051. 'perspective-origin',
  1052. 'pitch',
  1053. 'pitch-range',
  1054. 'play-during',
  1055. 'position',
  1056. 'presentation-level',
  1057. 'punctuation-trim',
  1058. 'quotes',
  1059. 'region-break-after',
  1060. 'region-break-before',
  1061. 'region-break-inside',
  1062. 'region-fragment',
  1063. 'rendering-intent',
  1064. 'resize',
  1065. 'rest',
  1066. 'rest-after',
  1067. 'rest-before',
  1068. 'richness',
  1069. 'right',
  1070. 'rotation',
  1071. 'rotation-point',
  1072. 'ruby-align',
  1073. 'ruby-overhang',
  1074. 'ruby-position',
  1075. 'ruby-span',
  1076. 'shape-image-threshold',
  1077. 'shape-inside',
  1078. 'shape-margin',
  1079. 'shape-outside',
  1080. 'size',
  1081. 'speak',
  1082. 'speak-as',
  1083. 'speak-header',
  1084. 'speak-numeral',
  1085. 'speak-punctuation',
  1086. 'speech-rate',
  1087. 'stress',
  1088. 'string-set',
  1089. 'tab-size',
  1090. 'table-layout',
  1091. 'target',
  1092. 'target-name',
  1093. 'target-new',
  1094. 'target-position',
  1095. 'text-align',
  1096. 'text-align-last',
  1097. 'text-decoration',
  1098. 'text-decoration-color',
  1099. 'text-decoration-line',
  1100. 'text-decoration-skip',
  1101. 'text-decoration-style',
  1102. 'text-emphasis',
  1103. 'text-emphasis-color',
  1104. 'text-emphasis-position',
  1105. 'text-emphasis-style',
  1106. 'text-height',
  1107. 'text-indent',
  1108. 'text-justify',
  1109. 'text-outline',
  1110. 'text-overflow',
  1111. 'text-shadow',
  1112. 'text-size-adjust',
  1113. 'text-space-collapse',
  1114. 'text-transform',
  1115. 'text-underline-position',
  1116. 'text-wrap',
  1117. 'top',
  1118. 'transform',
  1119. 'transform-origin',
  1120. 'transform-style',
  1121. 'transition',
  1122. 'transition-delay',
  1123. 'transition-duration',
  1124. 'transition-property',
  1125. 'transition-timing-function',
  1126. 'unicode-bidi',
  1127. 'vertical-align',
  1128. 'visibility',
  1129. 'voice-balance',
  1130. 'voice-duration',
  1131. 'voice-family',
  1132. 'voice-pitch',
  1133. 'voice-range',
  1134. 'voice-rate',
  1135. 'voice-stress',
  1136. 'voice-volume',
  1137. 'volume',
  1138. 'white-space',
  1139. 'widows',
  1140. 'width',
  1141. 'will-change',
  1142. 'word-break',
  1143. 'word-spacing',
  1144. 'word-wrap',
  1145. 'z-index',
  1146. 'clip-path',
  1147. 'clip-rule',
  1148. 'mask',
  1149. 'enable-background',
  1150. 'filter',
  1151. 'flood-color',
  1152. 'flood-opacity',
  1153. 'lighting-color',
  1154. 'stop-color',
  1155. 'stop-opacity',
  1156. 'pointer-events',
  1157. 'color-interpolation',
  1158. 'color-interpolation-filters',
  1159. 'color-rendering',
  1160. 'fill',
  1161. 'fill-opacity',
  1162. 'fill-rule',
  1163. 'image-rendering',
  1164. 'marker',
  1165. 'marker-end',
  1166. 'marker-mid',
  1167. 'marker-start',
  1168. 'shape-rendering',
  1169. 'stroke',
  1170. 'stroke-dasharray',
  1171. 'stroke-dashoffset',
  1172. 'stroke-linecap',
  1173. 'stroke-linejoin',
  1174. 'stroke-miterlimit',
  1175. 'stroke-opacity',
  1176. 'stroke-width',
  1177. 'text-rendering',
  1178. 'baseline-shift',
  1179. 'dominant-baseline',
  1180. 'glyph-orientation-horizontal',
  1181. 'glyph-orientation-vertical',
  1182. 'text-anchor',
  1183. 'writing-mode',
  1184. 'font-smoothing',
  1185. 'osx-font-smoothing',
  1186. ]
  1187. var nonStandardPropertyKeywords_ = [
  1188. 'scrollbar-arrow-color',
  1189. 'scrollbar-base-color',
  1190. 'scrollbar-dark-shadow-color',
  1191. 'scrollbar-face-color',
  1192. 'scrollbar-highlight-color',
  1193. 'scrollbar-shadow-color',
  1194. 'scrollbar-3d-light-color',
  1195. 'scrollbar-track-color',
  1196. 'shape-inside',
  1197. 'searchfield-cancel-button',
  1198. 'searchfield-decoration',
  1199. 'searchfield-results-button',
  1200. 'searchfield-results-decoration',
  1201. 'zoom',
  1202. ]
  1203. var fontProperties_ = ['font-family', 'src', 'unicode-range', 'font-variant', 'font-feature-settings', 'font-stretch', 'font-weight', 'font-style']
  1204. var colorKeywords_ = [
  1205. 'aliceblue',
  1206. 'antiquewhite',
  1207. 'aqua',
  1208. 'aquamarine',
  1209. 'azure',
  1210. 'beige',
  1211. 'bisque',
  1212. 'black',
  1213. 'blanchedalmond',
  1214. 'blue',
  1215. 'blueviolet',
  1216. 'brown',
  1217. 'burlywood',
  1218. 'cadetblue',
  1219. 'chartreuse',
  1220. 'chocolate',
  1221. 'coral',
  1222. 'cornflowerblue',
  1223. 'cornsilk',
  1224. 'crimson',
  1225. 'cyan',
  1226. 'darkblue',
  1227. 'darkcyan',
  1228. 'darkgoldenrod',
  1229. 'darkgray',
  1230. 'darkgreen',
  1231. 'darkkhaki',
  1232. 'darkmagenta',
  1233. 'darkolivegreen',
  1234. 'darkorange',
  1235. 'darkorchid',
  1236. 'darkred',
  1237. 'darksalmon',
  1238. 'darkseagreen',
  1239. 'darkslateblue',
  1240. 'darkslategray',
  1241. 'darkturquoise',
  1242. 'darkviolet',
  1243. 'deeppink',
  1244. 'deepskyblue',
  1245. 'dimgray',
  1246. 'dodgerblue',
  1247. 'firebrick',
  1248. 'floralwhite',
  1249. 'forestgreen',
  1250. 'fuchsia',
  1251. 'gainsboro',
  1252. 'ghostwhite',
  1253. 'gold',
  1254. 'goldenrod',
  1255. 'gray',
  1256. 'grey',
  1257. 'green',
  1258. 'greenyellow',
  1259. 'honeydew',
  1260. 'hotpink',
  1261. 'indianred',
  1262. 'indigo',
  1263. 'ivory',
  1264. 'khaki',
  1265. 'lavender',
  1266. 'lavenderblush',
  1267. 'lawngreen',
  1268. 'lemonchiffon',
  1269. 'lightblue',
  1270. 'lightcoral',
  1271. 'lightcyan',
  1272. 'lightgoldenrodyellow',
  1273. 'lightgray',
  1274. 'lightgreen',
  1275. 'lightpink',
  1276. 'lightsalmon',
  1277. 'lightseagreen',
  1278. 'lightskyblue',
  1279. 'lightslategray',
  1280. 'lightsteelblue',
  1281. 'lightyellow',
  1282. 'lime',
  1283. 'limegreen',
  1284. 'linen',
  1285. 'magenta',
  1286. 'maroon',
  1287. 'mediumaquamarine',
  1288. 'mediumblue',
  1289. 'mediumorchid',
  1290. 'mediumpurple',
  1291. 'mediumseagreen',
  1292. 'mediumslateblue',
  1293. 'mediumspringgreen',
  1294. 'mediumturquoise',
  1295. 'mediumvioletred',
  1296. 'midnightblue',
  1297. 'mintcream',
  1298. 'mistyrose',
  1299. 'moccasin',
  1300. 'navajowhite',
  1301. 'navy',
  1302. 'oldlace',
  1303. 'olive',
  1304. 'olivedrab',
  1305. 'orange',
  1306. 'orangered',
  1307. 'orchid',
  1308. 'palegoldenrod',
  1309. 'palegreen',
  1310. 'paleturquoise',
  1311. 'palevioletred',
  1312. 'papayawhip',
  1313. 'peachpuff',
  1314. 'peru',
  1315. 'pink',
  1316. 'plum',
  1317. 'powderblue',
  1318. 'purple',
  1319. 'rebeccapurple',
  1320. 'red',
  1321. 'rosybrown',
  1322. 'royalblue',
  1323. 'saddlebrown',
  1324. 'salmon',
  1325. 'sandybrown',
  1326. 'seagreen',
  1327. 'seashell',
  1328. 'sienna',
  1329. 'silver',
  1330. 'skyblue',
  1331. 'slateblue',
  1332. 'slategray',
  1333. 'snow',
  1334. 'springgreen',
  1335. 'steelblue',
  1336. 'tan',
  1337. 'teal',
  1338. 'thistle',
  1339. 'tomato',
  1340. 'turquoise',
  1341. 'violet',
  1342. 'wheat',
  1343. 'white',
  1344. 'whitesmoke',
  1345. 'yellow',
  1346. 'yellowgreen',
  1347. ]
  1348. var valueKeywords_ = [
  1349. 'above',
  1350. 'absolute',
  1351. 'activeborder',
  1352. 'additive',
  1353. 'activecaption',
  1354. 'afar',
  1355. 'after-white-space',
  1356. 'ahead',
  1357. 'alias',
  1358. 'all',
  1359. 'all-scroll',
  1360. 'alphabetic',
  1361. 'alternate',
  1362. 'always',
  1363. 'amharic',
  1364. 'amharic-abegede',
  1365. 'antialiased',
  1366. 'appworkspace',
  1367. 'arabic-indic',
  1368. 'armenian',
  1369. 'asterisks',
  1370. 'attr',
  1371. 'auto',
  1372. 'avoid',
  1373. 'avoid-column',
  1374. 'avoid-page',
  1375. 'avoid-region',
  1376. 'background',
  1377. 'backwards',
  1378. 'baseline',
  1379. 'below',
  1380. 'bidi-override',
  1381. 'binary',
  1382. 'bengali',
  1383. 'blink',
  1384. 'block',
  1385. 'block-axis',
  1386. 'bold',
  1387. 'bolder',
  1388. 'border',
  1389. 'border-box',
  1390. 'both',
  1391. 'bottom',
  1392. 'break',
  1393. 'break-all',
  1394. 'break-word',
  1395. 'bullets',
  1396. 'button',
  1397. 'button-bevel',
  1398. 'buttonface',
  1399. 'buttonhighlight',
  1400. 'buttonshadow',
  1401. 'buttontext',
  1402. 'calc',
  1403. 'cambodian',
  1404. 'capitalize',
  1405. 'caps-lock-indicator',
  1406. 'caption',
  1407. 'captiontext',
  1408. 'caret',
  1409. 'cell',
  1410. 'center',
  1411. 'checkbox',
  1412. 'circle',
  1413. 'cjk-decimal',
  1414. 'cjk-earthly-branch',
  1415. 'cjk-heavenly-stem',
  1416. 'cjk-ideographic',
  1417. 'clear',
  1418. 'clip',
  1419. 'close-quote',
  1420. 'col-resize',
  1421. 'collapse',
  1422. 'column',
  1423. 'compact',
  1424. 'condensed',
  1425. 'conic-gradient',
  1426. 'contain',
  1427. 'content',
  1428. 'contents',
  1429. 'content-box',
  1430. 'context-menu',
  1431. 'continuous',
  1432. 'copy',
  1433. 'counter',
  1434. 'counters',
  1435. 'cover',
  1436. 'crop',
  1437. 'cross',
  1438. 'crosshair',
  1439. 'currentcolor',
  1440. 'cursive',
  1441. 'cyclic',
  1442. 'dashed',
  1443. 'decimal',
  1444. 'decimal-leading-zero',
  1445. 'default',
  1446. 'default-button',
  1447. 'destination-atop',
  1448. 'destination-in',
  1449. 'destination-out',
  1450. 'destination-over',
  1451. 'devanagari',
  1452. 'disc',
  1453. 'discard',
  1454. 'disclosure-closed',
  1455. 'disclosure-open',
  1456. 'document',
  1457. 'dot-dash',
  1458. 'dot-dot-dash',
  1459. 'dotted',
  1460. 'double',
  1461. 'down',
  1462. 'e-resize',
  1463. 'ease',
  1464. 'ease-in',
  1465. 'ease-in-out',
  1466. 'ease-out',
  1467. 'element',
  1468. 'ellipse',
  1469. 'ellipsis',
  1470. 'embed',
  1471. 'end',
  1472. 'ethiopic',
  1473. 'ethiopic-abegede',
  1474. 'ethiopic-abegede-am-et',
  1475. 'ethiopic-abegede-gez',
  1476. 'ethiopic-abegede-ti-er',
  1477. 'ethiopic-abegede-ti-et',
  1478. 'ethiopic-halehame-aa-er',
  1479. 'ethiopic-halehame-aa-et',
  1480. 'ethiopic-halehame-am-et',
  1481. 'ethiopic-halehame-gez',
  1482. 'ethiopic-halehame-om-et',
  1483. 'ethiopic-halehame-sid-et',
  1484. 'ethiopic-halehame-so-et',
  1485. 'ethiopic-halehame-ti-er',
  1486. 'ethiopic-halehame-ti-et',
  1487. 'ethiopic-halehame-tig',
  1488. 'ethiopic-numeric',
  1489. 'ew-resize',
  1490. 'expanded',
  1491. 'extends',
  1492. 'extra-condensed',
  1493. 'extra-expanded',
  1494. 'fantasy',
  1495. 'fast',
  1496. 'fill',
  1497. 'fixed',
  1498. 'flat',
  1499. 'flex',
  1500. 'footnotes',
  1501. 'forwards',
  1502. 'from',
  1503. 'geometricPrecision',
  1504. 'georgian',
  1505. 'graytext',
  1506. 'groove',
  1507. 'gujarati',
  1508. 'gurmukhi',
  1509. 'hand',
  1510. 'hangul',
  1511. 'hangul-consonant',
  1512. 'hebrew',
  1513. 'help',
  1514. 'hidden',
  1515. 'hide',
  1516. 'high',
  1517. 'higher',
  1518. 'highlight',
  1519. 'highlighttext',
  1520. 'hiragana',
  1521. 'hiragana-iroha',
  1522. 'horizontal',
  1523. 'hsl',
  1524. 'hsla',
  1525. 'icon',
  1526. 'ignore',
  1527. 'inactiveborder',
  1528. 'inactivecaption',
  1529. 'inactivecaptiontext',
  1530. 'infinite',
  1531. 'infobackground',
  1532. 'infotext',
  1533. 'inherit',
  1534. 'initial',
  1535. 'inline',
  1536. 'inline-axis',
  1537. 'inline-block',
  1538. 'inline-flex',
  1539. 'inline-table',
  1540. 'inset',
  1541. 'inside',
  1542. 'intrinsic',
  1543. 'invert',
  1544. 'italic',
  1545. 'japanese-formal',
  1546. 'japanese-informal',
  1547. 'justify',
  1548. 'kannada',
  1549. 'katakana',
  1550. 'katakana-iroha',
  1551. 'keep-all',
  1552. 'khmer',
  1553. 'korean-hangul-formal',
  1554. 'korean-hanja-formal',
  1555. 'korean-hanja-informal',
  1556. 'landscape',
  1557. 'lao',
  1558. 'large',
  1559. 'larger',
  1560. 'left',
  1561. 'level',
  1562. 'lighter',
  1563. 'line-through',
  1564. 'linear',
  1565. 'linear-gradient',
  1566. 'lines',
  1567. 'list-item',
  1568. 'listbox',
  1569. 'listitem',
  1570. 'local',
  1571. 'logical',
  1572. 'loud',
  1573. 'lower',
  1574. 'lower-alpha',
  1575. 'lower-armenian',
  1576. 'lower-greek',
  1577. 'lower-hexadecimal',
  1578. 'lower-latin',
  1579. 'lower-norwegian',
  1580. 'lower-roman',
  1581. 'lowercase',
  1582. 'ltr',
  1583. 'malayalam',
  1584. 'match',
  1585. 'matrix',
  1586. 'matrix3d',
  1587. 'media-controls-background',
  1588. 'media-current-time-display',
  1589. 'media-fullscreen-button',
  1590. 'media-mute-button',
  1591. 'media-play-button',
  1592. 'media-return-to-realtime-button',
  1593. 'media-rewind-button',
  1594. 'media-seek-back-button',
  1595. 'media-seek-forward-button',
  1596. 'media-slider',
  1597. 'media-sliderthumb',
  1598. 'media-time-remaining-display',
  1599. 'media-volume-slider',
  1600. 'media-volume-slider-container',
  1601. 'media-volume-sliderthumb',
  1602. 'medium',
  1603. 'menu',
  1604. 'menulist',
  1605. 'menulist-button',
  1606. 'menulist-text',
  1607. 'menulist-textfield',
  1608. 'menutext',
  1609. 'message-box',
  1610. 'middle',
  1611. 'min-intrinsic',
  1612. 'mix',
  1613. 'mongolian',
  1614. 'monospace',
  1615. 'move',
  1616. 'multiple',
  1617. 'myanmar',
  1618. 'n-resize',
  1619. 'narrower',
  1620. 'ne-resize',
  1621. 'nesw-resize',
  1622. 'no-close-quote',
  1623. 'no-drop',
  1624. 'no-open-quote',
  1625. 'no-repeat',
  1626. 'none',
  1627. 'normal',
  1628. 'not-allowed',
  1629. 'nowrap',
  1630. 'ns-resize',
  1631. 'numbers',
  1632. 'numeric',
  1633. 'nw-resize',
  1634. 'nwse-resize',
  1635. 'oblique',
  1636. 'octal',
  1637. 'open-quote',
  1638. 'optimizeLegibility',
  1639. 'optimizeSpeed',
  1640. 'oriya',
  1641. 'oromo',
  1642. 'outset',
  1643. 'outside',
  1644. 'outside-shape',
  1645. 'overlay',
  1646. 'overline',
  1647. 'padding',
  1648. 'padding-box',
  1649. 'painted',
  1650. 'page',
  1651. 'paused',
  1652. 'persian',
  1653. 'perspective',
  1654. 'plus-darker',
  1655. 'plus-lighter',
  1656. 'pointer',
  1657. 'polygon',
  1658. 'portrait',
  1659. 'pre',
  1660. 'pre-line',
  1661. 'pre-wrap',
  1662. 'preserve-3d',
  1663. 'progress',
  1664. 'push-button',
  1665. 'radial-gradient',
  1666. 'radio',
  1667. 'read-only',
  1668. 'read-write',
  1669. 'read-write-plaintext-only',
  1670. 'rectangle',
  1671. 'region',
  1672. 'relative',
  1673. 'repeat',
  1674. 'repeating-linear-gradient',
  1675. 'repeating-radial-gradient',
  1676. 'repeating-conic-gradient',
  1677. 'repeat-x',
  1678. 'repeat-y',
  1679. 'reset',
  1680. 'reverse',
  1681. 'rgb',
  1682. 'rgba',
  1683. 'ridge',
  1684. 'right',
  1685. 'rotate',
  1686. 'rotate3d',
  1687. 'rotateX',
  1688. 'rotateY',
  1689. 'rotateZ',
  1690. 'round',
  1691. 'row-resize',
  1692. 'rtl',
  1693. 'run-in',
  1694. 'running',
  1695. 's-resize',
  1696. 'sans-serif',
  1697. 'scale',
  1698. 'scale3d',
  1699. 'scaleX',
  1700. 'scaleY',
  1701. 'scaleZ',
  1702. 'scroll',
  1703. 'scrollbar',
  1704. 'scroll-position',
  1705. 'se-resize',
  1706. 'searchfield',
  1707. 'searchfield-cancel-button',
  1708. 'searchfield-decoration',
  1709. 'searchfield-results-button',
  1710. 'searchfield-results-decoration',
  1711. 'semi-condensed',
  1712. 'semi-expanded',
  1713. 'separate',
  1714. 'serif',
  1715. 'show',
  1716. 'sidama',
  1717. 'simp-chinese-formal',
  1718. 'simp-chinese-informal',
  1719. 'single',
  1720. 'skew',
  1721. 'skewX',
  1722. 'skewY',
  1723. 'skip-white-space',
  1724. 'slide',
  1725. 'slider-horizontal',
  1726. 'slider-vertical',
  1727. 'sliderthumb-horizontal',
  1728. 'sliderthumb-vertical',
  1729. 'slow',
  1730. 'small',
  1731. 'small-caps',
  1732. 'small-caption',
  1733. 'smaller',
  1734. 'solid',
  1735. 'somali',
  1736. 'source-atop',
  1737. 'source-in',
  1738. 'source-out',
  1739. 'source-over',
  1740. 'space',
  1741. 'spell-out',
  1742. 'square',
  1743. 'square-button',
  1744. 'standard',
  1745. 'start',
  1746. 'static',
  1747. 'status-bar',
  1748. 'stretch',
  1749. 'stroke',
  1750. 'sub',
  1751. 'subpixel-antialiased',
  1752. 'super',
  1753. 'sw-resize',
  1754. 'symbolic',
  1755. 'symbols',
  1756. 'table',
  1757. 'table-caption',
  1758. 'table-cell',
  1759. 'table-column',
  1760. 'table-column-group',
  1761. 'table-footer-group',
  1762. 'table-header-group',
  1763. 'table-row',
  1764. 'table-row-group',
  1765. 'tamil',
  1766. 'telugu',
  1767. 'text',
  1768. 'text-bottom',
  1769. 'text-top',
  1770. 'textarea',
  1771. 'textfield',
  1772. 'thai',
  1773. 'thick',
  1774. 'thin',
  1775. 'threeddarkshadow',
  1776. 'threedface',
  1777. 'threedhighlight',
  1778. 'threedlightshadow',
  1779. 'threedshadow',
  1780. 'tibetan',
  1781. 'tigre',
  1782. 'tigrinya-er',
  1783. 'tigrinya-er-abegede',
  1784. 'tigrinya-et',
  1785. 'tigrinya-et-abegede',
  1786. 'to',
  1787. 'top',
  1788. 'trad-chinese-formal',
  1789. 'trad-chinese-informal',
  1790. 'translate',
  1791. 'translate3d',
  1792. 'translateX',
  1793. 'translateY',
  1794. 'translateZ',
  1795. 'transparent',
  1796. 'ultra-condensed',
  1797. 'ultra-expanded',
  1798. 'underline',
  1799. 'up',
  1800. 'upper-alpha',
  1801. 'upper-armenian',
  1802. 'upper-greek',
  1803. 'upper-hexadecimal',
  1804. 'upper-latin',
  1805. 'upper-norwegian',
  1806. 'upper-roman',
  1807. 'uppercase',
  1808. 'urdu',
  1809. 'url',
  1810. 'var',
  1811. 'vertical',
  1812. 'vertical-text',
  1813. 'visible',
  1814. 'visibleFill',
  1815. 'visiblePainted',
  1816. 'visibleStroke',
  1817. 'visual',
  1818. 'w-resize',
  1819. 'wait',
  1820. 'wave',
  1821. 'wider',
  1822. 'window',
  1823. 'windowframe',
  1824. 'windowtext',
  1825. 'words',
  1826. 'x-large',
  1827. 'x-small',
  1828. 'xor',
  1829. 'xx-large',
  1830. 'xx-small',
  1831. 'bicubic',
  1832. 'optimizespeed',
  1833. 'grayscale',
  1834. 'row',
  1835. 'row-reverse',
  1836. 'wrap',
  1837. 'wrap-reverse',
  1838. 'column-reverse',
  1839. 'flex-start',
  1840. 'flex-end',
  1841. 'space-between',
  1842. 'space-around',
  1843. 'unset',
  1844. ]
  1845. var wordOperatorKeywords_ = ['in', 'and', 'or', 'not', 'is not', 'is a', 'is', 'isnt', 'defined', 'if unless'],
  1846. blockKeywords_ = ['for', 'if', 'else', 'unless', 'from', 'to'],
  1847. commonAtoms_ = ['null', 'true', 'false', 'href', 'title', 'type', 'not-allowed', 'readonly', 'disabled'],
  1848. commonDef_ = ['@font-face', '@keyframes', '@media', '@viewport', '@page', '@host', '@supports', '@block', '@css']
  1849. var hintWords = tagKeywords_.concat(
  1850. documentTypes_,
  1851. mediaTypes_,
  1852. mediaFeatures_,
  1853. propertyKeywords_,
  1854. nonStandardPropertyKeywords_,
  1855. colorKeywords_,
  1856. valueKeywords_,
  1857. fontProperties_,
  1858. wordOperatorKeywords_,
  1859. blockKeywords_,
  1860. commonAtoms_,
  1861. commonDef_
  1862. )
  1863. function wordRegexp(words) {
  1864. words = words.sort(function (a, b) {
  1865. return b > a
  1866. })
  1867. return new RegExp('^((' + words.join(')|(') + '))\\b')
  1868. }
  1869. function keySet(array) {
  1870. var keys = {}
  1871. for (var i = 0; i < array.length; ++i) keys[array[i]] = true
  1872. return keys
  1873. }
  1874. function escapeRegExp(text) {
  1875. return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&')
  1876. }
  1877. CodeMirror.registerHelper('hintWords', 'stylus', hintWords)
  1878. CodeMirror.defineMIME('text/x-styl', 'stylus')
  1879. })