1
0

stylus.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: http://codemirror.net/LICENSE
  3. (function(mod) {
  4. if (typeof exports == "object" && typeof module == "object") // CommonJS
  5. mod(require("../../lib/codemirror"));
  6. else if (typeof define == "function" && define.amd) // AMD
  7. define(["../../lib/codemirror"], mod);
  8. else // Plain browser env
  9. mod(CodeMirror);
  10. })(function(CodeMirror) {
  11. "use strict";
  12. CodeMirror.defineMode("stylus", function(config) {
  13. var operatorsRegexp = /^(\?:?|\+[+=]?|-[\-=]?|\*[\*=]?|\/=?|[=!:\?]?=|<=?|>=?|%=?|&&|\|=?|\~|!|\^|\\)/,
  14. delimitersRegexp = /^(?:[()\[\]{},:`=;]|\.\.?\.?)/,
  15. wordOperatorsRegexp = wordRegexp(wordOperators),
  16. commonKeywordsRegexp = wordRegexp(commonKeywords),
  17. commonAtomsRegexp = wordRegexp(commonAtoms),
  18. commonDefRegexp = wordRegexp(commonDef),
  19. vendorPrefixesRegexp = new RegExp(/^\-(moz|ms|o|webkit)-/),
  20. cssValuesWithBracketsRegexp = new RegExp("^(" + cssValuesWithBrackets_.join("|") + ")\\([\\w\-\\#\\,\\.\\%\\s\\(\\)]*\\)");
  21. var tokenBase = function(stream, state) {
  22. if (stream.eatSpace()) return null;
  23. var ch = stream.peek();
  24. // Single line Comment
  25. if (stream.match('//')) {
  26. stream.skipToEnd();
  27. return "comment";
  28. }
  29. // Multiline Comment
  30. if (stream.match('/*')) {
  31. state.tokenizer = multilineComment;
  32. return state.tokenizer(stream, state);
  33. }
  34. // Strings
  35. if (ch === '"' || ch === "'") {
  36. stream.next();
  37. state.tokenizer = buildStringTokenizer(ch);
  38. return "string";
  39. }
  40. // Def
  41. if (ch === "@") {
  42. stream.next();
  43. if (stream.match(/extend/)) {
  44. dedent(state); // remove indentation after selectors
  45. } else if (stream.match(/media[\w-\s]*[\w-]/)) {
  46. indent(state);
  47. } else if(stream.eatWhile(/[\w-]/)) {
  48. if(stream.current().match(commonDefRegexp)) {
  49. indent(state);
  50. }
  51. }
  52. return "def";
  53. }
  54. // Number
  55. if (stream.match(/^-?[0-9\.]/, false)) {
  56. // Floats
  57. if (stream.match(/^-?\d*\.\d+(e[\+\-]?\d+)?/i) || stream.match(/^-?\d+\.\d*/)) {
  58. // Prevent from getting extra . on 1..
  59. if (stream.peek() == ".") {
  60. stream.backUp(1);
  61. }
  62. // Units
  63. stream.eatWhile(/[a-z%]/i);
  64. return "number";
  65. }
  66. // Integers
  67. if (stream.match(/^-?[1-9]\d*(e[\+\-]?\d+)?/) || stream.match(/^-?0(?![\dx])/i)) {
  68. // Units
  69. stream.eatWhile(/[a-z%]/i);
  70. return "number";
  71. }
  72. }
  73. // Hex color and id selector
  74. if (ch === "#") {
  75. stream.next();
  76. // Hex color
  77. if (stream.match(/^[0-9a-f]{6}|[0-9a-f]{3}/i)) {
  78. return "atom";
  79. }
  80. // ID selector
  81. if (stream.match(/^[\w-]+/i)) {
  82. indent(state);
  83. return "builtin";
  84. }
  85. }
  86. // Vendor prefixes
  87. if (stream.match(vendorPrefixesRegexp)) {
  88. return "meta";
  89. }
  90. // Gradients and animation as CSS value
  91. if (stream.match(cssValuesWithBracketsRegexp)) {
  92. return "atom";
  93. }
  94. // Mixins / Functions with indentation
  95. if (stream.sol() && stream.match(/^\.?[a-z][\w-]*\(/i)) {
  96. stream.backUp(1);
  97. indent(state);
  98. return "keyword";
  99. }
  100. // Mixins / Functions
  101. if (stream.match(/^\.?[a-z][\w-]*\(/i)) {
  102. stream.backUp(1);
  103. return "keyword";
  104. }
  105. // +Block mixins
  106. if (stream.match(/^(\+|\-)[a-z][\w-]+\(/i)) {
  107. stream.backUp(1);
  108. indent(state);
  109. return "keyword";
  110. }
  111. // url tokens
  112. if (stream.match(/^url/) && stream.peek() === "(") {
  113. state.tokenizer = urlTokens;
  114. if(!stream.peek()) {
  115. state.cursorHalf = 0;
  116. }
  117. return "atom";
  118. }
  119. // Class
  120. if (stream.match(/^\.[a-z][\w-]*/i)) {
  121. indent(state);
  122. return "qualifier";
  123. }
  124. // & Parent Reference with BEM naming
  125. if (stream.match(/^(_|__|-|--)[a-z0-9-]+/)) {
  126. return "qualifier";
  127. }
  128. // Pseudo elements/classes
  129. if (ch == ':' && stream.match(/^::?[\w-]+/)) {
  130. indent(state);
  131. return "variable-3";
  132. }
  133. // Conditionals
  134. if (stream.match(wordRegexp(["for", "if", "else", "unless"]))) {
  135. indent(state);
  136. return "keyword";
  137. }
  138. // Keywords
  139. if (stream.match(commonKeywordsRegexp)) {
  140. return "keyword";
  141. }
  142. // Atoms
  143. if (stream.match(commonAtomsRegexp)) {
  144. return "atom";
  145. }
  146. // Variables
  147. if (stream.match(/^\$?[a-z][\w-]+\s?=(\s|[\w-'"\$])/i)) {
  148. stream.backUp(2);
  149. var cssPropertie = stream.current().toLowerCase().match(/[\w-]+/)[0];
  150. return cssProperties[cssPropertie] === undefined ? "variable-2" : "property";
  151. } else if (stream.match(/\$[\w-\.]+/i)) {
  152. return "variable-2";
  153. } else if (stream.match(/\$?[\w-]+\.[\w-]+/i)) {
  154. var cssTypeSelector = stream.current().toLowerCase().match(/[\w]+/)[0];
  155. if(cssTypeSelectors[cssTypeSelector] === undefined) {
  156. return "variable-2";
  157. } else stream.backUp(stream.current().length);
  158. }
  159. // !important
  160. if (ch === "!") {
  161. stream.next();
  162. return stream.match(/^[\w]+/) ? "keyword": "operator";
  163. }
  164. // / Root Reference
  165. if (stream.match(/^\/(:|\.|#|[a-z])/)) {
  166. stream.backUp(1);
  167. return "variable-3";
  168. }
  169. // Operators and delimiters
  170. if (stream.match(operatorsRegexp) || stream.match(wordOperatorsRegexp)) {
  171. return "operator";
  172. }
  173. if (stream.match(delimitersRegexp)) {
  174. return null;
  175. }
  176. // & Parent Reference
  177. if (ch === "&") {
  178. stream.next();
  179. return "variable-3";
  180. }
  181. // Font family
  182. if (stream.match(/^[A-Z][a-z0-9-]+/)) {
  183. return "string";
  184. }
  185. // CSS rule
  186. // NOTE: Some css selectors and property values have the same name
  187. // (embed, menu, pre, progress, sub, table),
  188. // so they will have the same color (.cm-atom).
  189. if (stream.match(/[\w-]*/i)) {
  190. var word = stream.current().toLowerCase();
  191. if(cssProperties[word] !== undefined) {
  192. // CSS property
  193. if(!stream.eol())
  194. return "property";
  195. else
  196. return "variable-2";
  197. } else if(cssValues[word] !== undefined) {
  198. // CSS value
  199. return "atom";
  200. } else if(cssTypeSelectors[word] !== undefined) {
  201. // CSS type selectors
  202. indent(state);
  203. return "tag";
  204. } else if(word) {
  205. // By default variable-2
  206. return "variable-2";
  207. }
  208. }
  209. // Handle non-detected items
  210. stream.next();
  211. return null;
  212. };
  213. var tokenLexer = function(stream, state) {
  214. if (stream.sol()) {
  215. state.indentCount = 0;
  216. }
  217. var style = state.tokenizer(stream, state);
  218. var current = stream.current();
  219. if (stream.eol() && (current === "}" || current === ",")) {
  220. dedent(state);
  221. }
  222. if (style !== null) {
  223. var startOfToken = stream.pos - current.length;
  224. var withCurrentIndent = startOfToken + (config.indentUnit * state.indentCount);
  225. var newScopes = [];
  226. for (var i = 0; i < state.scopes.length; i++) {
  227. var scope = state.scopes[i];
  228. if (scope.offset <= withCurrentIndent) {
  229. newScopes.push(scope);
  230. }
  231. }
  232. state.scopes = newScopes;
  233. }
  234. return style;
  235. };
  236. return {
  237. startState: function() {
  238. return {
  239. tokenizer: tokenBase,
  240. scopes: [{offset: 0, type: 'styl'}]
  241. };
  242. },
  243. token: function(stream, state) {
  244. var style = tokenLexer(stream, state);
  245. state.lastToken = { style: style, content: stream.current() };
  246. return style;
  247. },
  248. indent: function(state) {
  249. return state.scopes[0].offset;
  250. },
  251. lineComment: "//",
  252. fold: "indent"
  253. };
  254. function urlTokens(stream, state) {
  255. var ch = stream.peek();
  256. if (ch === ")") {
  257. stream.next();
  258. state.tokenizer = tokenBase;
  259. return "operator";
  260. } else if (ch === "(") {
  261. stream.next();
  262. stream.eatSpace();
  263. return "operator";
  264. } else if (ch === "'" || ch === '"') {
  265. state.tokenizer = buildStringTokenizer(stream.next());
  266. return "string";
  267. } else {
  268. state.tokenizer = buildStringTokenizer(")", false);
  269. return "string";
  270. }
  271. }
  272. function multilineComment(stream, state) {
  273. if (stream.skipTo("*/")) {
  274. stream.next();
  275. stream.next();
  276. state.tokenizer = tokenBase;
  277. } else {
  278. stream.next();
  279. }
  280. return "comment";
  281. }
  282. function buildStringTokenizer(quote, greedy) {
  283. if(greedy == null) {
  284. greedy = true;
  285. }
  286. function stringTokenizer(stream, state) {
  287. var nextChar = stream.next();
  288. var peekChar = stream.peek();
  289. var previousChar = stream.string.charAt(stream.pos-2);
  290. var endingString = ((nextChar !== "\\" && peekChar === quote) ||
  291. (nextChar === quote && previousChar !== "\\"));
  292. if (endingString) {
  293. if (nextChar !== quote && greedy) {
  294. stream.next();
  295. }
  296. state.tokenizer = tokenBase;
  297. return "string";
  298. } else if (nextChar === "#" && peekChar === "{") {
  299. state.tokenizer = buildInterpolationTokenizer(stringTokenizer);
  300. stream.next();
  301. return "operator";
  302. } else {
  303. return "string";
  304. }
  305. }
  306. return stringTokenizer;
  307. }
  308. function buildInterpolationTokenizer(currentTokenizer) {
  309. return function(stream, state) {
  310. if (stream.peek() === "}") {
  311. stream.next();
  312. state.tokenizer = currentTokenizer;
  313. return "operator";
  314. } else {
  315. return tokenBase(stream, state);
  316. }
  317. };
  318. }
  319. function indent(state) {
  320. if (state.indentCount == 0) {
  321. state.indentCount++;
  322. var lastScopeOffset = state.scopes[0].offset;
  323. var currentOffset = lastScopeOffset + config.indentUnit;
  324. state.scopes.unshift({ offset:currentOffset });
  325. }
  326. }
  327. function dedent(state) {
  328. if (state.scopes.length == 1) { return true; }
  329. state.scopes.shift();
  330. }
  331. });
  332. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  333. var cssTypeSelectors_ = ["a","abbr","address","area","article","aside","audio", "b", "base","bdi","bdo","bgsound","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","marquee","menu","menuitem","meta","meter","nav","nobr","noframes","noscript","object","ol","optgroup","option","output","p","param","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"];
  334. // https://github.com/csscomb/csscomb.js/blob/master/config/zen.json
  335. var cssProperties_ = ["position","top","right","bottom","left","z-index","display","visibility","flex-direction","flex-order","flex-pack","float","clear","flex-align","overflow","overflow-x","overflow-y","overflow-scrolling","clip","box-sizing","margin","margin-top","margin-right","margin-bottom","margin-left","padding","padding-top","padding-right","padding-bottom","padding-left","min-width","min-height","max-width","max-height","width","height","outline","outline-width","outline-style","outline-color","outline-offset","border","border-spacing","border-collapse","border-width","border-style","border-color","border-top","border-top-width","border-top-style","border-top-color","border-right","border-right-width","border-right-style","border-right-color","border-bottom","border-bottom-width","border-bottom-style","border-bottom-color","border-left","border-left-width","border-left-style","border-left-color","border-radius","border-top-left-radius","border-top-right-radius","border-bottom-right-radius","border-bottom-left-radius","border-image","border-image-source","border-image-slice","border-image-width","border-image-outset","border-image-repeat","border-top-image","border-right-image","border-bottom-image","border-left-image","border-corner-image","border-top-left-image","border-top-right-image","border-bottom-right-image","border-bottom-left-image","background","filter:progid:DXImageTransform\\.Microsoft\\.AlphaImageLoader","background-color","background-image","background-attachment","background-position","background-position-x","background-position-y","background-clip","background-origin","background-size","background-repeat","box-decoration-break","box-shadow","color","table-layout","caption-side","empty-cells","list-style","list-style-position","list-style-type","list-style-image","quotes","content","counter-increment","counter-reset","writing-mode","vertical-align","text-align","text-align-last","text-decoration","text-emphasis","text-emphasis-position","text-emphasis-style","text-emphasis-color","text-indent","-ms-text-justify","text-justify","text-outline","text-transform","text-wrap","text-overflow","text-overflow-ellipsis","text-overflow-mode","text-size-adjust","text-shadow","white-space","word-spacing","word-wrap","word-break","tab-size","hyphens","letter-spacing","font","font-weight","font-style","font-variant","font-size-adjust","font-stretch","font-size","font-family","src","line-height","opacity","filter:\\\\\\\\'progid:DXImageTransform.Microsoft.Alpha","filter:progid:DXImageTransform.Microsoft.Alpha\\(Opacity","interpolation-mode","filter","resize","cursor","nav-index","nav-up","nav-right","nav-down","nav-left","transition","transition-delay","transition-timing-function","transition-duration","transition-property","transform","transform-origin","animation","animation-name","animation-duration","animation-play-state","animation-timing-function","animation-delay","animation-iteration-count","animation-direction","pointer-events","unicode-bidi","direction","columns","column-span","column-width","column-count","column-fill","column-gap","column-rule","column-rule-width","column-rule-style","column-rule-color","break-before","break-inside","break-after","page-break-before","page-break-inside","page-break-after","orphans","widows","zoom","max-zoom","min-zoom","user-zoom","orientation","text-rendering","speak","animation-fill-mode","backface-visibility","user-drag","user-select","appearance"];
  336. // https://github.com/codemirror/CodeMirror/blob/master/mode/css/css.js#L501
  337. var cssValues_ = ["above","absolute","activeborder","activecaption","afar","after-white-space","ahead","alias","all","all-scroll","alternate","always","amharic","amharic-abegede","antialiased","appworkspace","arabic-indic","armenian","asterisks","auto","avoid","avoid-column","avoid-page","avoid-region","background","backwards","baseline","below","bidi-override","binary","bengali","block","block-axis","bold","bolder","border","border-box","both","bottom","break","break-all","break-word","button-bevel","buttonface","buttonhighlight","buttonshadow","buttontext","cambodian","capitalize","caps-lock-indicator","captiontext","caret","cell","center","checkbox","circle","cjk-earthly-branch","cjk-heavenly-stem","cjk-ideographic","clear","clip","close-quote","col-resize","collapse","column","compact","condensed","contain","content","content-box","context-menu","continuous","copy","cover","crop","cross","crosshair","currentcolor","cursive","dashed","decimal","decimal-leading-zero","default","default-button","destination-atop","destination-in","destination-out","destination-over","devanagari","disc","discard","document","dot-dash","dot-dot-dash","dotted","double","down","e-resize","ease","ease-in","ease-in-out","ease-out","element","ellipse","ellipsis","embed","end","ethiopic","ethiopic-abegede","ethiopic-abegede-am-et","ethiopic-abegede-gez","ethiopic-abegede-ti-er","ethiopic-abegede-ti-et","ethiopic-halehame-aa-er","ethiopic-halehame-aa-et","ethiopic-halehame-am-et","ethiopic-halehame-gez","ethiopic-halehame-om-et","ethiopic-halehame-sid-et","ethiopic-halehame-so-et","ethiopic-halehame-ti-er","ethiopic-halehame-ti-et","ethiopic-halehame-tig","ew-resize","expanded","extra-condensed","extra-expanded","fantasy","fast","fill","fixed","flat","footnotes","forwards","from","geometricPrecision","georgian","graytext","groove","gujarati","gurmukhi","hand","hangul","hangul-consonant","hebrew","help","hidden","hide","higher","highlight","highlighttext","hiragana","hiragana-iroha","horizontal","hsl","hsla","icon","ignore","inactiveborder","inactivecaption","inactivecaptiontext","infinite","infobackground","infotext","inherit","initial","inline","inline-axis","inline-block","inline-table","inset","inside","intrinsic","invert","italic","justify","kannada","katakana","katakana-iroha","keep-all","khmer","landscape","lao","large","larger","left","level","lighter","line-through","linear","lines","list-item","listbox","listitem","local","logical","loud","lower","lower-alpha","lower-armenian","lower-greek","lower-hexadecimal","lower-latin","lower-norwegian","lower-roman","lowercase","ltr","malayalam","match","media-controls-background","media-current-time-display","media-fullscreen-button","media-mute-button","media-play-button","media-return-to-realtime-button","media-rewind-button","media-seek-back-button","media-seek-forward-button","media-slider","media-sliderthumb","media-time-remaining-display","media-volume-slider","media-volume-slider-container","media-volume-sliderthumb","medium","menu","menulist","menulist-button","menulist-text","menulist-textfield","menutext","message-box","middle","min-intrinsic","mix","mongolian","monospace","move","multiple","myanmar","n-resize","narrower","ne-resize","nesw-resize","no-close-quote","no-drop","no-open-quote","no-repeat","none","normal","not-allowed","nowrap","ns-resize","nw-resize","nwse-resize","oblique","octal","open-quote","optimizeLegibility","optimizeSpeed","oriya","oromo","outset","outside","outside-shape","overlay","overline","padding","padding-box","painted","page","paused","persian","plus-darker","plus-lighter","pointer","polygon","portrait","pre","pre-line","pre-wrap","preserve-3d","progress","push-button","radio","read-only","read-write","read-write-plaintext-only","rectangle","region","relative","repeat","repeat-x","repeat-y","reset","reverse","rgb","rgba","ridge","right","round","row-resize","rtl","run-in","running","s-resize","sans-serif","scroll","scrollbar","se-resize","searchfield","searchfield-cancel-button","searchfield-decoration","searchfield-results-button","searchfield-results-decoration","semi-condensed","semi-expanded","separate","serif","show","sidama","single","skip-white-space","slide","slider-horizontal","slider-vertical","sliderthumb-horizontal","sliderthumb-vertical","slow","small-caps","small-caption","smaller","solid","somali","source-atop","source-in","source-out","source-over","space","square","square-button","start","static","status-bar","stretch","stroke","sub","subpixel-antialiased","super","sw-resize","table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row","table-row-group","telugu","text","text-bottom","text-top","textfield","thai","thick","thin","threeddarkshadow","threedface","threedhighlight","threedlightshadow","threedshadow","tibetan","tigre","tigrinya-er","tigrinya-er-abegede","tigrinya-et","tigrinya-et-abegede","to","top","transparent","ultra-condensed","ultra-expanded","underline","up","upper-alpha","upper-armenian","upper-greek","upper-hexadecimal","upper-latin","upper-norwegian","upper-roman","uppercase","urdu","url","vertical","vertical-text","visible","visibleFill","visiblePainted","visibleStroke","visual","w-resize","wait","wave","wider","window","windowframe","windowtext","x-large","x-small","xor","xx-large","xx-small","bicubic","optimizespeed","grayscale"];
  338. var cssColorValues_ = ["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","grey","green","greenyellow","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"];
  339. var cssValuesWithBrackets_ = ["gradient","linear-gradient","radial-gradient","repeating-linear-gradient","repeating-radial-gradient","cubic-bezier","translateX","translateY","translate3d","rotate3d","scale","scale3d","perspective","skewX"];
  340. var wordOperators = ["in", "and", "or", "not", "is a", "is", "isnt", "defined", "if unless"],
  341. commonKeywords = ["for", "if", "else", "unless", "return"],
  342. commonAtoms = ["null", "true", "false", "href", "title", "type", "not-allowed", "readonly", "disabled"],
  343. commonDef = ["@font-face", "@keyframes", "@media", "@viewport", "@page", "@host", "@supports", "@block", "@css"],
  344. cssTypeSelectors = keySet(cssTypeSelectors_),
  345. cssProperties = keySet(cssProperties_),
  346. cssValues = keySet(cssValues_.concat(cssColorValues_)),
  347. hintWords = wordOperators.concat(commonKeywords,
  348. commonAtoms,
  349. commonDef,
  350. cssTypeSelectors_,
  351. cssProperties_,
  352. cssValues_,
  353. cssValuesWithBrackets_,
  354. cssColorValues_);
  355. function wordRegexp(words) {
  356. return new RegExp("^((" + words.join(")|(") + "))\\b");
  357. };
  358. function keySet(array) {
  359. var keys = {};
  360. for (var i = 0; i < array.length; ++i) {
  361. keys[array[i]] = true;
  362. }
  363. return keys;
  364. };
  365. CodeMirror.registerHelper("hintWords", "stylus", hintWords);
  366. CodeMirror.defineMIME("text/x-styl", "stylus");
  367. });