css.js 34 KB

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