Debian Codegraph @

codemirror-legacy-modes/mode/css.js

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