css.js 30 KB

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