css.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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("css", function(config, parserConfig) {
  13. if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css");
  14. var indentUnit = config.indentUnit,
  15. tokenHooks = parserConfig.tokenHooks,
  16. mediaTypes = parserConfig.mediaTypes || {},
  17. mediaFeatures = parserConfig.mediaFeatures || {},
  18. propertyKeywords = parserConfig.propertyKeywords || {},
  19. nonStandardPropertyKeywords = parserConfig.nonStandardPropertyKeywords || {},
  20. colorKeywords = parserConfig.colorKeywords || {},
  21. valueKeywords = parserConfig.valueKeywords || {},
  22. fontProperties = parserConfig.fontProperties || {},
  23. allowNested = parserConfig.allowNested;
  24. var type, override;
  25. function ret(style, tp) { type = tp; return style; }
  26. // Tokenizers
  27. function tokenBase(stream, state) {
  28. var ch = stream.next();
  29. if (tokenHooks[ch]) {
  30. var result = tokenHooks[ch](stream, state);
  31. if (result !== false) return result;
  32. }
  33. if (ch == "@") {
  34. stream.eatWhile(/[\w\\\-]/);
  35. return ret("def", stream.current());
  36. } else if (ch == "=" || (ch == "~" || ch == "|") && stream.eat("=")) {
  37. return ret(null, "compare");
  38. } else if (ch == "\"" || ch == "'") {
  39. state.tokenize = tokenString(ch);
  40. return state.tokenize(stream, state);
  41. } else if (ch == "#") {
  42. stream.eatWhile(/[\w\\\-]/);
  43. return ret("atom", "hash");
  44. } else if (ch == "!") {
  45. stream.match(/^\s*\w*/);
  46. return ret("keyword", "important");
  47. } else if (/\d/.test(ch) || ch == "." && stream.eat(/\d/)) {
  48. stream.eatWhile(/[\w.%]/);
  49. return ret("number", "unit");
  50. } else if (ch === "-") {
  51. if (/[\d.]/.test(stream.peek())) {
  52. stream.eatWhile(/[\w.%]/);
  53. return ret("number", "unit");
  54. } else if (stream.match(/^\w+-/)) {
  55. return ret("meta", "meta");
  56. }
  57. } else if (/[,+>*\/]/.test(ch)) {
  58. return ret(null, "select-op");
  59. } else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) {
  60. return ret("qualifier", "qualifier");
  61. } else if (/[:;{}\[\]\(\)]/.test(ch)) {
  62. return ret(null, ch);
  63. } else if (ch == "u" && stream.match("rl(")) {
  64. stream.backUp(1);
  65. state.tokenize = tokenParenthesized;
  66. return ret("property", "word");
  67. } else if (/[\w\\\-]/.test(ch)) {
  68. stream.eatWhile(/[\w\\\-]/);
  69. return ret("property", "word");
  70. } else {
  71. return ret(null, null);
  72. }
  73. }
  74. function tokenString(quote) {
  75. return function(stream, state) {
  76. var escaped = false, ch;
  77. while ((ch = stream.next()) != null) {
  78. if (ch == quote && !escaped) {
  79. if (quote == ")") stream.backUp(1);
  80. break;
  81. }
  82. escaped = !escaped && ch == "\\";
  83. }
  84. if (ch == quote || !escaped && quote != ")") state.tokenize = null;
  85. return ret("string", "string");
  86. };
  87. }
  88. function tokenParenthesized(stream, state) {
  89. stream.next(); // Must be '('
  90. if (!stream.match(/\s*[\"\')]/, false))
  91. state.tokenize = tokenString(")");
  92. else
  93. state.tokenize = null;
  94. return ret(null, "(");
  95. }
  96. // Context management
  97. function Context(type, indent, prev) {
  98. this.type = type;
  99. this.indent = indent;
  100. this.prev = prev;
  101. }
  102. function pushContext(state, stream, type) {
  103. state.context = new Context(type, stream.indentation() + indentUnit, state.context);
  104. return type;
  105. }
  106. function popContext(state) {
  107. state.context = state.context.prev;
  108. return state.context.type;
  109. }
  110. function pass(type, stream, state) {
  111. return states[state.context.type](type, stream, state);
  112. }
  113. function popAndPass(type, stream, state, n) {
  114. for (var i = n || 1; i > 0; i--)
  115. state.context = state.context.prev;
  116. return pass(type, stream, state);
  117. }
  118. // Parser
  119. function wordAsValue(stream) {
  120. var word = stream.current().toLowerCase();
  121. if (valueKeywords.hasOwnProperty(word))
  122. override = "atom";
  123. else if (colorKeywords.hasOwnProperty(word))
  124. override = "keyword";
  125. else
  126. override = "variable";
  127. }
  128. var states = {};
  129. states.top = function(type, stream, state) {
  130. if (type == "{") {
  131. return pushContext(state, stream, "block");
  132. } else if (type == "}" && state.context.prev) {
  133. return popContext(state);
  134. } else if (type == "@media") {
  135. return pushContext(state, stream, "media");
  136. } else if (type == "@font-face") {
  137. return "font_face_before";
  138. } else if (/^@(-(moz|ms|o|webkit)-)?keyframes$/.test(type)) {
  139. return "keyframes";
  140. } else if (type && type.charAt(0) == "@") {
  141. return pushContext(state, stream, "at");
  142. } else if (type == "hash") {
  143. override = "builtin";
  144. } else if (type == "word") {
  145. override = "tag";
  146. } else if (type == "variable-definition") {
  147. return "maybeprop";
  148. } else if (type == "interpolation") {
  149. return pushContext(state, stream, "interpolation");
  150. } else if (type == ":") {
  151. return "pseudo";
  152. } else if (allowNested && type == "(") {
  153. return pushContext(state, stream, "parens");
  154. }
  155. return state.context.type;
  156. };
  157. states.block = function(type, stream, state) {
  158. if (type == "word") {
  159. var word = stream.current().toLowerCase();
  160. if (propertyKeywords.hasOwnProperty(word)) {
  161. override = "property";
  162. return "maybeprop";
  163. } else if (nonStandardPropertyKeywords.hasOwnProperty(word)) {
  164. override = "string-2";
  165. return "maybeprop";
  166. } else if (allowNested) {
  167. override = stream.match(/^\s*:(?:\s|$)/, false) ? "property" : "tag";
  168. return "block";
  169. } else {
  170. override += " error";
  171. return "maybeprop";
  172. }
  173. } else if (type == "meta") {
  174. return "block";
  175. } else if (!allowNested && (type == "hash" || type == "qualifier")) {
  176. override = "error";
  177. return "block";
  178. } else {
  179. return states.top(type, stream, state);
  180. }
  181. };
  182. states.maybeprop = function(type, stream, state) {
  183. if (type == ":") return pushContext(state, stream, "prop");
  184. return pass(type, stream, state);
  185. };
  186. states.prop = function(type, stream, state) {
  187. if (type == ";") return popContext(state);
  188. if (type == "{" && allowNested) return pushContext(state, stream, "propBlock");
  189. if (type == "}" || type == "{") return popAndPass(type, stream, state);
  190. if (type == "(") return pushContext(state, stream, "parens");
  191. if (type == "hash" && !/^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/.test(stream.current())) {
  192. override += " error";
  193. } else if (type == "word") {
  194. wordAsValue(stream);
  195. } else if (type == "interpolation") {
  196. return pushContext(state, stream, "interpolation");
  197. }
  198. return "prop";
  199. };
  200. states.propBlock = function(type, _stream, state) {
  201. if (type == "}") return popContext(state);
  202. if (type == "word") { override = "property"; return "maybeprop"; }
  203. return state.context.type;
  204. };
  205. states.parens = function(type, stream, state) {
  206. if (type == "{" || type == "}") return popAndPass(type, stream, state);
  207. if (type == ")") return popContext(state);
  208. if (type == "(") return pushContext(state, stream, "parens");
  209. if (type == "word") wordAsValue(stream);
  210. return "parens";
  211. };
  212. states.pseudo = function(type, stream, state) {
  213. if (type == "word") {
  214. override = "variable-3";
  215. return state.context.type;
  216. }
  217. return pass(type, stream, state);
  218. };
  219. states.media = function(type, stream, state) {
  220. if (type == "(") return pushContext(state, stream, "media_parens");
  221. if (type == "}") return popAndPass(type, stream, state);
  222. if (type == "{") return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top");
  223. if (type == "word") {
  224. var word = stream.current().toLowerCase();
  225. if (word == "only" || word == "not" || word == "and")
  226. override = "keyword";
  227. else if (mediaTypes.hasOwnProperty(word))
  228. override = "attribute";
  229. else if (mediaFeatures.hasOwnProperty(word))
  230. override = "property";
  231. else
  232. override = "error";
  233. }
  234. return state.context.type;
  235. };
  236. states.media_parens = function(type, stream, state) {
  237. if (type == ")") return popContext(state);
  238. if (type == "{" || type == "}") return popAndPass(type, stream, state, 2);
  239. return states.media(type, stream, state);
  240. };
  241. states.font_face_before = function(type, stream, state) {
  242. if (type == "{")
  243. return pushContext(state, stream, "font_face");
  244. return pass(type, stream, state);
  245. };
  246. states.font_face = function(type, stream, state) {
  247. if (type == "}") return popContext(state);
  248. if (type == "word") {
  249. if (!fontProperties.hasOwnProperty(stream.current().toLowerCase()))
  250. override = "error";
  251. else
  252. override = "property";
  253. return "maybeprop";
  254. }
  255. return "font_face";
  256. };
  257. states.keyframes = function(type, stream, state) {
  258. if (type == "word") { override = "variable"; return "keyframes"; }
  259. if (type == "{") return pushContext(state, stream, "top");
  260. return pass(type, stream, state);
  261. };
  262. states.at = function(type, stream, state) {
  263. if (type == ";") return popContext(state);
  264. if (type == "{" || type == "}") return popAndPass(type, stream, state);
  265. if (type == "word") override = "tag";
  266. else if (type == "hash") override = "builtin";
  267. return "at";
  268. };
  269. states.interpolation = function(type, stream, state) {
  270. if (type == "}") return popContext(state);
  271. if (type == "{" || type == ";") return popAndPass(type, stream, state);
  272. if (type != "variable") override = "error";
  273. return "interpolation";
  274. };
  275. return {
  276. startState: function(base) {
  277. return {tokenize: null,
  278. state: "top",
  279. context: new Context("top", base || 0, null)};
  280. },
  281. token: function(stream, state) {
  282. if (!state.tokenize && stream.eatSpace()) return null;
  283. var style = (state.tokenize || tokenBase)(stream, state);
  284. if (style && typeof style == "object") {
  285. type = style[1];
  286. style = style[0];
  287. }
  288. override = style;
  289. state.state = states[state.state](type, stream, state);
  290. return override;
  291. },
  292. indent: function(state, textAfter) {
  293. var cx = state.context, ch = textAfter && textAfter.charAt(0);
  294. var indent = cx.indent;
  295. if (cx.type == "prop" && (ch == "}" || ch == ")")) cx = cx.prev;
  296. if (cx.prev &&
  297. (ch == "}" && (cx.type == "block" || cx.type == "top" || cx.type == "interpolation" || cx.type == "font_face") ||
  298. ch == ")" && (cx.type == "parens" || cx.type == "media_parens") ||
  299. ch == "{" && (cx.type == "at" || cx.type == "media"))) {
  300. indent = cx.indent - indentUnit;
  301. cx = cx.prev;
  302. }
  303. return indent;
  304. },
  305. electricChars: "}",
  306. blockCommentStart: "/*",
  307. blockCommentEnd: "*/",
  308. fold: "brace"
  309. };
  310. });
  311. function keySet(array) {
  312. var keys = {};
  313. for (var i = 0; i < array.length; ++i) {
  314. keys[array[i]] = true;
  315. }
  316. return keys;
  317. }
  318. var mediaTypes_ = [
  319. "all", "aural", "braille", "handheld", "print", "projection", "screen",
  320. "tty", "tv", "embossed"
  321. ], mediaTypes = keySet(mediaTypes_);
  322. var mediaFeatures_ = [
  323. "width", "min-width", "max-width", "height", "min-height", "max-height",
  324. "device-width", "min-device-width", "max-device-width", "device-height",
  325. "min-device-height", "max-device-height", "aspect-ratio",
  326. "min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio",
  327. "min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color",
  328. "max-color", "color-index", "min-color-index", "max-color-index",
  329. "monochrome", "min-monochrome", "max-monochrome", "resolution",
  330. "min-resolution", "max-resolution", "scan", "grid"
  331. ], mediaFeatures = keySet(mediaFeatures_);
  332. var propertyKeywords_ = [
  333. "align-content", "align-items", "align-self", "alignment-adjust",
  334. "alignment-baseline", "anchor-point", "animation", "animation-delay",
  335. "animation-direction", "animation-duration", "animation-fill-mode",
  336. "animation-iteration-count", "animation-name", "animation-play-state",
  337. "animation-timing-function", "appearance", "azimuth", "backface-visibility",
  338. "background", "background-attachment", "background-clip", "background-color",
  339. "background-image", "background-origin", "background-position",
  340. "background-repeat", "background-size", "baseline-shift", "binding",
  341. "bleed", "bookmark-label", "bookmark-level", "bookmark-state",
  342. "bookmark-target", "border", "border-bottom", "border-bottom-color",
  343. "border-bottom-left-radius", "border-bottom-right-radius",
  344. "border-bottom-style", "border-bottom-width", "border-collapse",
  345. "border-color", "border-image", "border-image-outset",
  346. "border-image-repeat", "border-image-slice", "border-image-source",
  347. "border-image-width", "border-left", "border-left-color",
  348. "border-left-style", "border-left-width", "border-radius", "border-right",
  349. "border-right-color", "border-right-style", "border-right-width",
  350. "border-spacing", "border-style", "border-top", "border-top-color",
  351. "border-top-left-radius", "border-top-right-radius", "border-top-style",
  352. "border-top-width", "border-width", "bottom", "box-decoration-break",
  353. "box-shadow", "box-sizing", "break-after", "break-before", "break-inside",
  354. "caption-side", "clear", "clip", "color", "color-profile", "column-count",
  355. "column-fill", "column-gap", "column-rule", "column-rule-color",
  356. "column-rule-style", "column-rule-width", "column-span", "column-width",
  357. "columns", "content", "counter-increment", "counter-reset", "crop", "cue",
  358. "cue-after", "cue-before", "cursor", "direction", "display",
  359. "dominant-baseline", "drop-initial-after-adjust",
  360. "drop-initial-after-align", "drop-initial-before-adjust",
  361. "drop-initial-before-align", "drop-initial-size", "drop-initial-value",
  362. "elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis",
  363. "flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap",
  364. "float", "float-offset", "flow-from", "flow-into", "font", "font-feature-settings",
  365. "font-family", "font-kerning", "font-language-override", "font-size", "font-size-adjust",
  366. "font-stretch", "font-style", "font-synthesis", "font-variant",
  367. "font-variant-alternates", "font-variant-caps", "font-variant-east-asian",
  368. "font-variant-ligatures", "font-variant-numeric", "font-variant-position",
  369. "font-weight", "grid", "grid-area", "grid-auto-columns", "grid-auto-flow",
  370. "grid-auto-position", "grid-auto-rows", "grid-column", "grid-column-end",
  371. "grid-column-start", "grid-row", "grid-row-end", "grid-row-start",
  372. "grid-template", "grid-template-areas", "grid-template-columns",
  373. "grid-template-rows", "hanging-punctuation", "height", "hyphens",
  374. "icon", "image-orientation", "image-rendering", "image-resolution",
  375. "inline-box-align", "justify-content", "left", "letter-spacing",
  376. "line-break", "line-height", "line-stacking", "line-stacking-ruby",
  377. "line-stacking-shift", "line-stacking-strategy", "list-style",
  378. "list-style-image", "list-style-position", "list-style-type", "margin",
  379. "margin-bottom", "margin-left", "margin-right", "margin-top",
  380. "marker-offset", "marks", "marquee-direction", "marquee-loop",
  381. "marquee-play-count", "marquee-speed", "marquee-style", "max-height",
  382. "max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index",
  383. "nav-left", "nav-right", "nav-up", "object-fit", "object-position",
  384. "opacity", "order", "orphans", "outline",
  385. "outline-color", "outline-offset", "outline-style", "outline-width",
  386. "overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y",
  387. "padding", "padding-bottom", "padding-left", "padding-right", "padding-top",
  388. "page", "page-break-after", "page-break-before", "page-break-inside",
  389. "page-policy", "pause", "pause-after", "pause-before", "perspective",
  390. "perspective-origin", "pitch", "pitch-range", "play-during", "position",
  391. "presentation-level", "punctuation-trim", "quotes", "region-break-after",
  392. "region-break-before", "region-break-inside", "region-fragment",
  393. "rendering-intent", "resize", "rest", "rest-after", "rest-before", "richness",
  394. "right", "rotation", "rotation-point", "ruby-align", "ruby-overhang",
  395. "ruby-position", "ruby-span", "shape-image-threshold", "shape-inside", "shape-margin",
  396. "shape-outside", "size", "speak", "speak-as", "speak-header",
  397. "speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set",
  398. "tab-size", "table-layout", "target", "target-name", "target-new",
  399. "target-position", "text-align", "text-align-last", "text-decoration",
  400. "text-decoration-color", "text-decoration-line", "text-decoration-skip",
  401. "text-decoration-style", "text-emphasis", "text-emphasis-color",
  402. "text-emphasis-position", "text-emphasis-style", "text-height",
  403. "text-indent", "text-justify", "text-outline", "text-overflow", "text-shadow",
  404. "text-size-adjust", "text-space-collapse", "text-transform", "text-underline-position",
  405. "text-wrap", "top", "transform", "transform-origin", "transform-style",
  406. "transition", "transition-delay", "transition-duration",
  407. "transition-property", "transition-timing-function", "unicode-bidi",
  408. "vertical-align", "visibility", "voice-balance", "voice-duration",
  409. "voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",
  410. "voice-volume", "volume", "white-space", "widows", "width", "word-break",
  411. "word-spacing", "word-wrap", "z-index",
  412. // SVG-specific
  413. "clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color",
  414. "flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events",
  415. "color-interpolation", "color-interpolation-filters",
  416. "color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering",
  417. "marker", "marker-end", "marker-mid", "marker-start", "shape-rendering", "stroke",
  418. "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin",
  419. "stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering",
  420. "baseline-shift", "dominant-baseline", "glyph-orientation-horizontal",
  421. "glyph-orientation-vertical", "text-anchor", "writing-mode"
  422. ], propertyKeywords = keySet(propertyKeywords_);
  423. var nonStandardPropertyKeywords_ = [
  424. "scrollbar-arrow-color", "scrollbar-base-color", "scrollbar-dark-shadow-color",
  425. "scrollbar-face-color", "scrollbar-highlight-color", "scrollbar-shadow-color",
  426. "scrollbar-3d-light-color", "scrollbar-track-color", "shape-inside",
  427. "searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button",
  428. "searchfield-results-decoration", "zoom"
  429. ], nonStandardPropertyKeywords = keySet(nonStandardPropertyKeywords_);
  430. var colorKeywords_ = [
  431. "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
  432. "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
  433. "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue",
  434. "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod",
  435. "darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen",
  436. "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen",
  437. "darkslateblue", "darkslategray", "darkturquoise", "darkviolet",
  438. "deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick",
  439. "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite",
  440. "gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew",
  441. "hotpink", "indianred", "indigo", "ivory", "khaki", "lavender",
  442. "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral",
  443. "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink",
  444. "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray",
  445. "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta",
  446. "maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple",
  447. "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise",
  448. "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin",
  449. "navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered",
  450. "orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred",
  451. "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue",
  452. "purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown",
  453. "salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue",
  454. "slateblue", "slategray", "snow", "springgreen", "steelblue", "tan",
  455. "teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white",
  456. "whitesmoke", "yellow", "yellowgreen"
  457. ], colorKeywords = keySet(colorKeywords_);
  458. var valueKeywords_ = [
  459. "above", "absolute", "activeborder", "activecaption", "afar",
  460. "after-white-space", "ahead", "alias", "all", "all-scroll", "alternate",
  461. "always", "amharic", "amharic-abegede", "antialiased", "appworkspace",
  462. "arabic-indic", "armenian", "asterisks", "auto", "avoid", "avoid-column", "avoid-page",
  463. "avoid-region", "background", "backwards", "baseline", "below", "bidi-override", "binary",
  464. "bengali", "blink", "block", "block-axis", "bold", "bolder", "border", "border-box",
  465. "both", "bottom", "break", "break-all", "break-word", "button", "button-bevel",
  466. "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "cambodian",
  467. "capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",
  468. "cell", "center", "checkbox", "circle", "cjk-earthly-branch",
  469. "cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",
  470. "col-resize", "collapse", "column", "compact", "condensed", "contain", "content",
  471. "content-box", "context-menu", "continuous", "copy", "cover", "crop",
  472. "cross", "crosshair", "currentcolor", "cursive", "dashed", "decimal",
  473. "decimal-leading-zero", "default", "default-button", "destination-atop",
  474. "destination-in", "destination-out", "destination-over", "devanagari",
  475. "disc", "discard", "document", "dot-dash", "dot-dot-dash", "dotted",
  476. "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out",
  477. "element", "ellipse", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede",
  478. "ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er",
  479. "ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er",
  480. "ethiopic-halehame-aa-et", "ethiopic-halehame-am-et",
  481. "ethiopic-halehame-gez", "ethiopic-halehame-om-et",
  482. "ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",
  483. "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et",
  484. "ethiopic-halehame-tig", "ew-resize", "expanded", "extra-condensed",
  485. "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "flex", "footnotes",
  486. "forwards", "from", "geometricPrecision", "georgian", "graytext", "groove",
  487. "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew",
  488. "help", "hidden", "hide", "higher", "highlight", "highlighttext",
  489. "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore",
  490. "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
  491. "infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
  492. "inline-block", "inline-flex", "inline-table", "inset", "inside", "intrinsic", "invert",
  493. "italic", "justify", "kannada", "katakana", "katakana-iroha", "keep-all", "khmer",
  494. "landscape", "lao", "large", "larger", "left", "level", "lighter",
  495. "line-through", "linear", "lines", "list-item", "listbox", "listitem",
  496. "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian",
  497. "lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian",
  498. "lower-roman", "lowercase", "ltr", "malayalam", "match",
  499. "media-controls-background", "media-current-time-display",
  500. "media-fullscreen-button", "media-mute-button", "media-play-button",
  501. "media-return-to-realtime-button", "media-rewind-button",
  502. "media-seek-back-button", "media-seek-forward-button", "media-slider",
  503. "media-sliderthumb", "media-time-remaining-display", "media-volume-slider",
  504. "media-volume-slider-container", "media-volume-sliderthumb", "medium",
  505. "menu", "menulist", "menulist-button", "menulist-text",
  506. "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic",
  507. "mix", "mongolian", "monospace", "move", "multiple", "myanmar", "n-resize",
  508. "narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop",
  509. "no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap",
  510. "ns-resize", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote",
  511. "optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset",
  512. "outside", "outside-shape", "overlay", "overline", "padding", "padding-box",
  513. "painted", "page", "paused", "persian", "plus-darker", "plus-lighter", "pointer",
  514. "polygon", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d", "progress", "push-button",
  515. "radio", "read-only", "read-write", "read-write-plaintext-only", "rectangle", "region",
  516. "relative", "repeat", "repeat-x", "repeat-y", "reset", "reverse", "rgb", "rgba",
  517. "ridge", "right", "round", "row-resize", "rtl", "run-in", "running",
  518. "s-resize", "sans-serif", "scroll", "scrollbar", "se-resize", "searchfield",
  519. "searchfield-cancel-button", "searchfield-decoration",
  520. "searchfield-results-button", "searchfield-results-decoration",
  521. "semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama",
  522. "single", "skip-white-space", "slide", "slider-horizontal",
  523. "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
  524. "small", "small-caps", "small-caption", "smaller", "solid", "somali",
  525. "source-atop", "source-in", "source-out", "source-over", "space", "square",
  526. "square-button", "start", "static", "status-bar", "stretch", "stroke",
  527. "sub", "subpixel-antialiased", "super", "sw-resize", "table",
  528. "table-caption", "table-cell", "table-column", "table-column-group",
  529. "table-footer-group", "table-header-group", "table-row", "table-row-group",
  530. "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai",
  531. "thick", "thin", "threeddarkshadow", "threedface", "threedhighlight",
  532. "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er",
  533. "tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top",
  534. "transparent", "ultra-condensed", "ultra-expanded", "underline", "up",
  535. "upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal",
  536. "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url",
  537. "vertical", "vertical-text", "visible", "visibleFill", "visiblePainted",
  538. "visibleStroke", "visual", "w-resize", "wait", "wave", "wider",
  539. "window", "windowframe", "windowtext", "x-large", "x-small", "xor",
  540. "xx-large", "xx-small"
  541. ], valueKeywords = keySet(valueKeywords_);
  542. var fontProperties_ = [
  543. "font-family", "src", "unicode-range", "font-variant", "font-feature-settings",
  544. "font-stretch", "font-weight", "font-style"
  545. ], fontProperties = keySet(fontProperties_);
  546. var allWords = mediaTypes_.concat(mediaFeatures_).concat(propertyKeywords_)
  547. .concat(nonStandardPropertyKeywords_).concat(colorKeywords_).concat(valueKeywords_);
  548. CodeMirror.registerHelper("hintWords", "css", allWords);
  549. function tokenCComment(stream, state) {
  550. var maybeEnd = false, ch;
  551. while ((ch = stream.next()) != null) {
  552. if (maybeEnd && ch == "/") {
  553. state.tokenize = null;
  554. break;
  555. }
  556. maybeEnd = (ch == "*");
  557. }
  558. return ["comment", "comment"];
  559. }
  560. function tokenSGMLComment(stream, state) {
  561. if (stream.skipTo("-->")) {
  562. stream.match("-->");
  563. state.tokenize = null;
  564. } else {
  565. stream.skipToEnd();
  566. }
  567. return ["comment", "comment"];
  568. }
  569. CodeMirror.defineMIME("text/css", {
  570. mediaTypes: mediaTypes,
  571. mediaFeatures: mediaFeatures,
  572. propertyKeywords: propertyKeywords,
  573. nonStandardPropertyKeywords: nonStandardPropertyKeywords,
  574. colorKeywords: colorKeywords,
  575. valueKeywords: valueKeywords,
  576. fontProperties: fontProperties,
  577. tokenHooks: {
  578. "<": function(stream, state) {
  579. if (!stream.match("!--")) return false;
  580. state.tokenize = tokenSGMLComment;
  581. return tokenSGMLComment(stream, state);
  582. },
  583. "/": function(stream, state) {
  584. if (!stream.eat("*")) return false;
  585. state.tokenize = tokenCComment;
  586. return tokenCComment(stream, state);
  587. }
  588. },
  589. name: "css"
  590. });
  591. CodeMirror.defineMIME("text/x-scss", {
  592. mediaTypes: mediaTypes,
  593. mediaFeatures: mediaFeatures,
  594. propertyKeywords: propertyKeywords,
  595. nonStandardPropertyKeywords: nonStandardPropertyKeywords,
  596. colorKeywords: colorKeywords,
  597. valueKeywords: valueKeywords,
  598. fontProperties: fontProperties,
  599. allowNested: true,
  600. tokenHooks: {
  601. "/": function(stream, state) {
  602. if (stream.eat("/")) {
  603. stream.skipToEnd();
  604. return ["comment", "comment"];
  605. } else if (stream.eat("*")) {
  606. state.tokenize = tokenCComment;
  607. return tokenCComment(stream, state);
  608. } else {
  609. return ["operator", "operator"];
  610. }
  611. },
  612. ":": function(stream) {
  613. if (stream.match(/\s*\{/))
  614. return [null, "{"];
  615. return false;
  616. },
  617. "$": function(stream) {
  618. stream.match(/^[\w-]+/);
  619. if (stream.match(/^\s*:/, false))
  620. return ["variable-2", "variable-definition"];
  621. return ["variable-2", "variable"];
  622. },
  623. "#": function(stream) {
  624. if (!stream.eat("{")) return false;
  625. return [null, "interpolation"];
  626. }
  627. },
  628. name: "css",
  629. helperType: "scss"
  630. });
  631. CodeMirror.defineMIME("text/x-less", {
  632. mediaTypes: mediaTypes,
  633. mediaFeatures: mediaFeatures,
  634. propertyKeywords: propertyKeywords,
  635. nonStandardPropertyKeywords: nonStandardPropertyKeywords,
  636. colorKeywords: colorKeywords,
  637. valueKeywords: valueKeywords,
  638. fontProperties: fontProperties,
  639. allowNested: true,
  640. tokenHooks: {
  641. "/": function(stream, state) {
  642. if (stream.eat("/")) {
  643. stream.skipToEnd();
  644. return ["comment", "comment"];
  645. } else if (stream.eat("*")) {
  646. state.tokenize = tokenCComment;
  647. return tokenCComment(stream, state);
  648. } else {
  649. return ["operator", "operator"];
  650. }
  651. },
  652. "@": function(stream) {
  653. if (stream.match(/^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\b/, false)) return false;
  654. stream.eatWhile(/[\w\\\-]/);
  655. if (stream.match(/^\s*:/, false))
  656. return ["variable-2", "variable-definition"];
  657. return ["variable-2", "variable"];
  658. },
  659. "&": function() {
  660. return ["atom", "atom"];
  661. }
  662. },
  663. name: "css",
  664. helperType: "less"
  665. });
  666. });