You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

825 lines
36 KiB

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