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