css.js 33 KB

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