vscode-css-languageservice 5.4.2 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/lib/esm/cssLanguageService.d.ts +37 -37
  3. package/lib/esm/cssLanguageService.js +72 -75
  4. package/lib/esm/cssLanguageTypes.d.ts +238 -238
  5. package/lib/esm/cssLanguageTypes.js +42 -42
  6. package/lib/esm/data/webCustomData.js +21965 -21965
  7. package/lib/esm/languageFacts/builtinData.js +142 -142
  8. package/lib/esm/languageFacts/colors.js +469 -472
  9. package/lib/esm/languageFacts/dataManager.js +88 -92
  10. package/lib/esm/languageFacts/dataProvider.js +73 -79
  11. package/lib/esm/languageFacts/entry.js +137 -138
  12. package/lib/esm/languageFacts/facts.js +8 -8
  13. package/lib/esm/parser/cssErrors.js +48 -50
  14. package/lib/esm/parser/cssNodes.js +1502 -2019
  15. package/lib/esm/parser/cssParser.js +1534 -1563
  16. package/lib/esm/parser/cssScanner.js +592 -599
  17. package/lib/esm/parser/cssSymbolScope.js +311 -341
  18. package/lib/esm/parser/lessParser.js +714 -740
  19. package/lib/esm/parser/lessScanner.js +57 -78
  20. package/lib/esm/parser/scssErrors.js +18 -20
  21. package/lib/esm/parser/scssParser.js +796 -818
  22. package/lib/esm/parser/scssScanner.js +95 -116
  23. package/lib/esm/services/cssCodeActions.js +77 -81
  24. package/lib/esm/services/cssCompletion.js +1054 -1149
  25. package/lib/esm/services/cssFolding.js +190 -193
  26. package/lib/esm/services/cssFormatter.js +136 -136
  27. package/lib/esm/services/cssHover.js +148 -151
  28. package/lib/esm/services/cssNavigation.js +378 -470
  29. package/lib/esm/services/cssSelectionRange.js +47 -47
  30. package/lib/esm/services/cssValidation.js +41 -44
  31. package/lib/esm/services/lessCompletion.js +378 -397
  32. package/lib/esm/services/lint.js +518 -532
  33. package/lib/esm/services/lintRules.js +76 -83
  34. package/lib/esm/services/lintUtil.js +196 -205
  35. package/lib/esm/services/pathCompletion.js +157 -231
  36. package/lib/esm/services/scssCompletion.js +354 -378
  37. package/lib/esm/services/scssNavigation.js +82 -154
  38. package/lib/esm/services/selectorPrinting.js +492 -536
  39. package/lib/esm/utils/arrays.js +40 -46
  40. package/lib/esm/utils/objects.js +11 -11
  41. package/lib/esm/utils/resources.js +11 -24
  42. package/lib/esm/utils/strings.js +102 -104
  43. package/lib/umd/cssLanguageService.d.ts +37 -37
  44. package/lib/umd/cssLanguageService.js +99 -102
  45. package/lib/umd/cssLanguageTypes.d.ts +238 -238
  46. package/lib/umd/cssLanguageTypes.js +89 -88
  47. package/lib/umd/data/webCustomData.js +21978 -21978
  48. package/lib/umd/languageFacts/builtinData.js +154 -154
  49. package/lib/umd/languageFacts/colors.js +492 -495
  50. package/lib/umd/languageFacts/dataManager.js +101 -104
  51. package/lib/umd/languageFacts/dataProvider.js +86 -91
  52. package/lib/umd/languageFacts/entry.js +152 -153
  53. package/lib/umd/languageFacts/facts.js +29 -29
  54. package/lib/umd/parser/cssErrors.js +61 -62
  55. package/lib/umd/parser/cssNodes.js +1587 -2034
  56. package/lib/umd/parser/cssParser.js +1547 -1575
  57. package/lib/umd/parser/cssScanner.js +606 -611
  58. package/lib/umd/parser/cssSymbolScope.js +328 -353
  59. package/lib/umd/parser/lessParser.js +727 -752
  60. package/lib/umd/parser/lessScanner.js +70 -90
  61. package/lib/umd/parser/scssErrors.js +31 -32
  62. package/lib/umd/parser/scssParser.js +809 -830
  63. package/lib/umd/parser/scssScanner.js +108 -128
  64. package/lib/umd/services/cssCodeActions.js +90 -93
  65. package/lib/umd/services/cssCompletion.js +1067 -1161
  66. package/lib/umd/services/cssFolding.js +203 -206
  67. package/lib/umd/services/cssFormatter.js +150 -150
  68. package/lib/umd/services/cssHover.js +161 -163
  69. package/lib/umd/services/cssNavigation.js +391 -482
  70. package/lib/umd/services/cssSelectionRange.js +60 -60
  71. package/lib/umd/services/cssValidation.js +54 -56
  72. package/lib/umd/services/lessCompletion.js +391 -409
  73. package/lib/umd/services/lint.js +531 -544
  74. package/lib/umd/services/lintRules.js +91 -95
  75. package/lib/umd/services/lintUtil.js +210 -218
  76. package/lib/umd/services/pathCompletion.js +171 -244
  77. package/lib/umd/services/scssCompletion.js +367 -390
  78. package/lib/umd/services/scssNavigation.js +95 -166
  79. package/lib/umd/services/selectorPrinting.js +510 -550
  80. package/lib/umd/utils/arrays.js +55 -61
  81. package/lib/umd/utils/objects.js +25 -25
  82. package/lib/umd/utils/resources.js +26 -39
  83. package/lib/umd/utils/strings.js +120 -122
  84. package/package.json +10 -10
@@ -1,495 +1,492 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the MIT License. See License.txt in the project root for license information.
4
- *--------------------------------------------------------------------------------------------*/
5
- (function (factory) {
6
- if (typeof module === "object" && typeof module.exports === "object") {
7
- var v = factory(require, exports);
8
- if (v !== undefined) module.exports = v;
9
- }
10
- else if (typeof define === "function" && define.amd) {
11
- define(["require", "exports", "../parser/cssNodes", "vscode-nls"], factory);
12
- }
13
- })(function (require, exports) {
14
- "use strict";
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.getColorValue = exports.hwbFromColor = exports.colorFromHWB = exports.hslFromColor = exports.colorFromHSL = exports.colorFrom256RGB = exports.colorFromHex = exports.hexDigit = exports.isColorValue = exports.isColorConstructor = exports.colorKeywords = exports.colors = exports.colorFunctions = void 0;
17
- var nodes = require("../parser/cssNodes");
18
- var nls = require("vscode-nls");
19
- var localize = nls.loadMessageBundle();
20
- exports.colorFunctions = [
21
- { func: 'rgb($red, $green, $blue)', desc: localize('css.builtin.rgb', 'Creates a Color from red, green, and blue values.') },
22
- { func: 'rgba($red, $green, $blue, $alpha)', desc: localize('css.builtin.rgba', 'Creates a Color from red, green, blue, and alpha values.') },
23
- { func: 'hsl($hue, $saturation, $lightness)', desc: localize('css.builtin.hsl', 'Creates a Color from hue, saturation, and lightness values.') },
24
- { func: 'hsla($hue, $saturation, $lightness, $alpha)', desc: localize('css.builtin.hsla', 'Creates a Color from hue, saturation, lightness, and alpha values.') },
25
- { func: 'hwb($hue $white $black)', desc: localize('css.builtin.hwb', 'Creates a Color from hue, white and black.') }
26
- ];
27
- exports.colors = {
28
- aliceblue: '#f0f8ff',
29
- antiquewhite: '#faebd7',
30
- aqua: '#00ffff',
31
- aquamarine: '#7fffd4',
32
- azure: '#f0ffff',
33
- beige: '#f5f5dc',
34
- bisque: '#ffe4c4',
35
- black: '#000000',
36
- blanchedalmond: '#ffebcd',
37
- blue: '#0000ff',
38
- blueviolet: '#8a2be2',
39
- brown: '#a52a2a',
40
- burlywood: '#deb887',
41
- cadetblue: '#5f9ea0',
42
- chartreuse: '#7fff00',
43
- chocolate: '#d2691e',
44
- coral: '#ff7f50',
45
- cornflowerblue: '#6495ed',
46
- cornsilk: '#fff8dc',
47
- crimson: '#dc143c',
48
- cyan: '#00ffff',
49
- darkblue: '#00008b',
50
- darkcyan: '#008b8b',
51
- darkgoldenrod: '#b8860b',
52
- darkgray: '#a9a9a9',
53
- darkgrey: '#a9a9a9',
54
- darkgreen: '#006400',
55
- darkkhaki: '#bdb76b',
56
- darkmagenta: '#8b008b',
57
- darkolivegreen: '#556b2f',
58
- darkorange: '#ff8c00',
59
- darkorchid: '#9932cc',
60
- darkred: '#8b0000',
61
- darksalmon: '#e9967a',
62
- darkseagreen: '#8fbc8f',
63
- darkslateblue: '#483d8b',
64
- darkslategray: '#2f4f4f',
65
- darkslategrey: '#2f4f4f',
66
- darkturquoise: '#00ced1',
67
- darkviolet: '#9400d3',
68
- deeppink: '#ff1493',
69
- deepskyblue: '#00bfff',
70
- dimgray: '#696969',
71
- dimgrey: '#696969',
72
- dodgerblue: '#1e90ff',
73
- firebrick: '#b22222',
74
- floralwhite: '#fffaf0',
75
- forestgreen: '#228b22',
76
- fuchsia: '#ff00ff',
77
- gainsboro: '#dcdcdc',
78
- ghostwhite: '#f8f8ff',
79
- gold: '#ffd700',
80
- goldenrod: '#daa520',
81
- gray: '#808080',
82
- grey: '#808080',
83
- green: '#008000',
84
- greenyellow: '#adff2f',
85
- honeydew: '#f0fff0',
86
- hotpink: '#ff69b4',
87
- indianred: '#cd5c5c',
88
- indigo: '#4b0082',
89
- ivory: '#fffff0',
90
- khaki: '#f0e68c',
91
- lavender: '#e6e6fa',
92
- lavenderblush: '#fff0f5',
93
- lawngreen: '#7cfc00',
94
- lemonchiffon: '#fffacd',
95
- lightblue: '#add8e6',
96
- lightcoral: '#f08080',
97
- lightcyan: '#e0ffff',
98
- lightgoldenrodyellow: '#fafad2',
99
- lightgray: '#d3d3d3',
100
- lightgrey: '#d3d3d3',
101
- lightgreen: '#90ee90',
102
- lightpink: '#ffb6c1',
103
- lightsalmon: '#ffa07a',
104
- lightseagreen: '#20b2aa',
105
- lightskyblue: '#87cefa',
106
- lightslategray: '#778899',
107
- lightslategrey: '#778899',
108
- lightsteelblue: '#b0c4de',
109
- lightyellow: '#ffffe0',
110
- lime: '#00ff00',
111
- limegreen: '#32cd32',
112
- linen: '#faf0e6',
113
- magenta: '#ff00ff',
114
- maroon: '#800000',
115
- mediumaquamarine: '#66cdaa',
116
- mediumblue: '#0000cd',
117
- mediumorchid: '#ba55d3',
118
- mediumpurple: '#9370d8',
119
- mediumseagreen: '#3cb371',
120
- mediumslateblue: '#7b68ee',
121
- mediumspringgreen: '#00fa9a',
122
- mediumturquoise: '#48d1cc',
123
- mediumvioletred: '#c71585',
124
- midnightblue: '#191970',
125
- mintcream: '#f5fffa',
126
- mistyrose: '#ffe4e1',
127
- moccasin: '#ffe4b5',
128
- navajowhite: '#ffdead',
129
- navy: '#000080',
130
- oldlace: '#fdf5e6',
131
- olive: '#808000',
132
- olivedrab: '#6b8e23',
133
- orange: '#ffa500',
134
- orangered: '#ff4500',
135
- orchid: '#da70d6',
136
- palegoldenrod: '#eee8aa',
137
- palegreen: '#98fb98',
138
- paleturquoise: '#afeeee',
139
- palevioletred: '#d87093',
140
- papayawhip: '#ffefd5',
141
- peachpuff: '#ffdab9',
142
- peru: '#cd853f',
143
- pink: '#ffc0cb',
144
- plum: '#dda0dd',
145
- powderblue: '#b0e0e6',
146
- purple: '#800080',
147
- red: '#ff0000',
148
- rebeccapurple: '#663399',
149
- rosybrown: '#bc8f8f',
150
- royalblue: '#4169e1',
151
- saddlebrown: '#8b4513',
152
- salmon: '#fa8072',
153
- sandybrown: '#f4a460',
154
- seagreen: '#2e8b57',
155
- seashell: '#fff5ee',
156
- sienna: '#a0522d',
157
- silver: '#c0c0c0',
158
- skyblue: '#87ceeb',
159
- slateblue: '#6a5acd',
160
- slategray: '#708090',
161
- slategrey: '#708090',
162
- snow: '#fffafa',
163
- springgreen: '#00ff7f',
164
- steelblue: '#4682b4',
165
- tan: '#d2b48c',
166
- teal: '#008080',
167
- thistle: '#d8bfd8',
168
- tomato: '#ff6347',
169
- turquoise: '#40e0d0',
170
- violet: '#ee82ee',
171
- wheat: '#f5deb3',
172
- white: '#ffffff',
173
- whitesmoke: '#f5f5f5',
174
- yellow: '#ffff00',
175
- yellowgreen: '#9acd32'
176
- };
177
- exports.colorKeywords = {
178
- 'currentColor': 'The value of the \'color\' property. The computed value of the \'currentColor\' keyword is the computed value of the \'color\' property. If the \'currentColor\' keyword is set on the \'color\' property itself, it is treated as \'color:inherit\' at parse time.',
179
- 'transparent': 'Fully transparent. This keyword can be considered a shorthand for rgba(0,0,0,0) which is its computed value.',
180
- };
181
- function getNumericValue(node, factor) {
182
- var val = node.getText();
183
- var m = val.match(/^([-+]?[0-9]*\.?[0-9]+)(%?)$/);
184
- if (m) {
185
- if (m[2]) {
186
- factor = 100.0;
187
- }
188
- var result = parseFloat(m[1]) / factor;
189
- if (result >= 0 && result <= 1) {
190
- return result;
191
- }
192
- }
193
- throw new Error();
194
- }
195
- function getAngle(node) {
196
- var val = node.getText();
197
- var m = val.match(/^([-+]?[0-9]*\.?[0-9]+)(deg|rad|grad|turn)?$/);
198
- if (m) {
199
- switch (m[2]) {
200
- case 'deg':
201
- return parseFloat(val) % 360;
202
- case 'rad':
203
- return (parseFloat(val) * 180 / Math.PI) % 360;
204
- case 'grad':
205
- return (parseFloat(val) * 0.9) % 360;
206
- case 'turn':
207
- return (parseFloat(val) * 360) % 360;
208
- default:
209
- if ('undefined' === typeof m[2]) {
210
- return parseFloat(val) % 360;
211
- }
212
- }
213
- }
214
- throw new Error();
215
- }
216
- function isColorConstructor(node) {
217
- var name = node.getName();
218
- if (!name) {
219
- return false;
220
- }
221
- return /^(rgb|rgba|hsl|hsla|hwb)$/gi.test(name);
222
- }
223
- exports.isColorConstructor = isColorConstructor;
224
- /**
225
- * Returns true if the node is a color value - either
226
- * defined a hex number, as rgb or rgba function, or
227
- * as color name.
228
- */
229
- function isColorValue(node) {
230
- if (node.type === nodes.NodeType.HexColorValue) {
231
- return true;
232
- }
233
- else if (node.type === nodes.NodeType.Function) {
234
- return isColorConstructor(node);
235
- }
236
- else if (node.type === nodes.NodeType.Identifier) {
237
- if (node.parent && node.parent.type !== nodes.NodeType.Term) {
238
- return false;
239
- }
240
- var candidateColor = node.getText().toLowerCase();
241
- if (candidateColor === 'none') {
242
- return false;
243
- }
244
- if (exports.colors[candidateColor]) {
245
- return true;
246
- }
247
- }
248
- return false;
249
- }
250
- exports.isColorValue = isColorValue;
251
- var Digit0 = 48;
252
- var Digit9 = 57;
253
- var A = 65;
254
- var F = 70;
255
- var a = 97;
256
- var f = 102;
257
- function hexDigit(charCode) {
258
- if (charCode < Digit0) {
259
- return 0;
260
- }
261
- if (charCode <= Digit9) {
262
- return charCode - Digit0;
263
- }
264
- if (charCode < a) {
265
- charCode += (a - A);
266
- }
267
- if (charCode >= a && charCode <= f) {
268
- return charCode - a + 10;
269
- }
270
- return 0;
271
- }
272
- exports.hexDigit = hexDigit;
273
- function colorFromHex(text) {
274
- if (text[0] !== '#') {
275
- return null;
276
- }
277
- switch (text.length) {
278
- case 4:
279
- return {
280
- red: (hexDigit(text.charCodeAt(1)) * 0x11) / 255.0,
281
- green: (hexDigit(text.charCodeAt(2)) * 0x11) / 255.0,
282
- blue: (hexDigit(text.charCodeAt(3)) * 0x11) / 255.0,
283
- alpha: 1
284
- };
285
- case 5:
286
- return {
287
- red: (hexDigit(text.charCodeAt(1)) * 0x11) / 255.0,
288
- green: (hexDigit(text.charCodeAt(2)) * 0x11) / 255.0,
289
- blue: (hexDigit(text.charCodeAt(3)) * 0x11) / 255.0,
290
- alpha: (hexDigit(text.charCodeAt(4)) * 0x11) / 255.0,
291
- };
292
- case 7:
293
- return {
294
- red: (hexDigit(text.charCodeAt(1)) * 0x10 + hexDigit(text.charCodeAt(2))) / 255.0,
295
- green: (hexDigit(text.charCodeAt(3)) * 0x10 + hexDigit(text.charCodeAt(4))) / 255.0,
296
- blue: (hexDigit(text.charCodeAt(5)) * 0x10 + hexDigit(text.charCodeAt(6))) / 255.0,
297
- alpha: 1
298
- };
299
- case 9:
300
- return {
301
- red: (hexDigit(text.charCodeAt(1)) * 0x10 + hexDigit(text.charCodeAt(2))) / 255.0,
302
- green: (hexDigit(text.charCodeAt(3)) * 0x10 + hexDigit(text.charCodeAt(4))) / 255.0,
303
- blue: (hexDigit(text.charCodeAt(5)) * 0x10 + hexDigit(text.charCodeAt(6))) / 255.0,
304
- alpha: (hexDigit(text.charCodeAt(7)) * 0x10 + hexDigit(text.charCodeAt(8))) / 255.0
305
- };
306
- }
307
- return null;
308
- }
309
- exports.colorFromHex = colorFromHex;
310
- function colorFrom256RGB(red, green, blue, alpha) {
311
- if (alpha === void 0) { alpha = 1.0; }
312
- return {
313
- red: red / 255.0,
314
- green: green / 255.0,
315
- blue: blue / 255.0,
316
- alpha: alpha
317
- };
318
- }
319
- exports.colorFrom256RGB = colorFrom256RGB;
320
- function colorFromHSL(hue, sat, light, alpha) {
321
- if (alpha === void 0) { alpha = 1.0; }
322
- hue = hue / 60.0;
323
- if (sat === 0) {
324
- return { red: light, green: light, blue: light, alpha: alpha };
325
- }
326
- else {
327
- var hueToRgb = function (t1, t2, hue) {
328
- while (hue < 0) {
329
- hue += 6;
330
- }
331
- while (hue >= 6) {
332
- hue -= 6;
333
- }
334
- if (hue < 1) {
335
- return (t2 - t1) * hue + t1;
336
- }
337
- if (hue < 3) {
338
- return t2;
339
- }
340
- if (hue < 4) {
341
- return (t2 - t1) * (4 - hue) + t1;
342
- }
343
- return t1;
344
- };
345
- var t2 = light <= 0.5 ? (light * (sat + 1)) : (light + sat - (light * sat));
346
- var t1 = light * 2 - t2;
347
- return { red: hueToRgb(t1, t2, hue + 2), green: hueToRgb(t1, t2, hue), blue: hueToRgb(t1, t2, hue - 2), alpha: alpha };
348
- }
349
- }
350
- exports.colorFromHSL = colorFromHSL;
351
- function hslFromColor(rgba) {
352
- var r = rgba.red;
353
- var g = rgba.green;
354
- var b = rgba.blue;
355
- var a = rgba.alpha;
356
- var max = Math.max(r, g, b);
357
- var min = Math.min(r, g, b);
358
- var h = 0;
359
- var s = 0;
360
- var l = (min + max) / 2;
361
- var chroma = max - min;
362
- if (chroma > 0) {
363
- s = Math.min((l <= 0.5 ? chroma / (2 * l) : chroma / (2 - (2 * l))), 1);
364
- switch (max) {
365
- case r:
366
- h = (g - b) / chroma + (g < b ? 6 : 0);
367
- break;
368
- case g:
369
- h = (b - r) / chroma + 2;
370
- break;
371
- case b:
372
- h = (r - g) / chroma + 4;
373
- break;
374
- }
375
- h *= 60;
376
- h = Math.round(h);
377
- }
378
- return { h: h, s: s, l: l, a: a };
379
- }
380
- exports.hslFromColor = hslFromColor;
381
- function colorFromHWB(hue, white, black, alpha) {
382
- if (alpha === void 0) { alpha = 1.0; }
383
- if (white + black >= 1) {
384
- var gray = white / (white + black);
385
- return { red: gray, green: gray, blue: gray, alpha: alpha };
386
- }
387
- var rgb = colorFromHSL(hue, 1, 0.5, alpha);
388
- var red = rgb.red;
389
- red *= (1 - white - black);
390
- red += white;
391
- var green = rgb.green;
392
- green *= (1 - white - black);
393
- green += white;
394
- var blue = rgb.blue;
395
- blue *= (1 - white - black);
396
- blue += white;
397
- return {
398
- red: red,
399
- green: green,
400
- blue: blue,
401
- alpha: alpha
402
- };
403
- }
404
- exports.colorFromHWB = colorFromHWB;
405
- function hwbFromColor(rgba) {
406
- var hsl = hslFromColor(rgba);
407
- var white = Math.min(rgba.red, rgba.green, rgba.blue);
408
- var black = 1 - Math.max(rgba.red, rgba.green, rgba.blue);
409
- return {
410
- h: hsl.h,
411
- w: white,
412
- b: black,
413
- a: hsl.a
414
- };
415
- }
416
- exports.hwbFromColor = hwbFromColor;
417
- function getColorValue(node) {
418
- if (node.type === nodes.NodeType.HexColorValue) {
419
- var text = node.getText();
420
- return colorFromHex(text);
421
- }
422
- else if (node.type === nodes.NodeType.Function) {
423
- var functionNode = node;
424
- var name = functionNode.getName();
425
- var colorValues = functionNode.getArguments().getChildren();
426
- if (colorValues.length === 1) {
427
- var functionArg = colorValues[0].getChildren();
428
- if (functionArg.length === 1 && functionArg[0].type === nodes.NodeType.Expression) {
429
- colorValues = functionArg[0].getChildren();
430
- if (colorValues.length === 3) {
431
- var lastValue = colorValues[2];
432
- if (lastValue instanceof nodes.BinaryExpression) {
433
- var left = lastValue.getLeft(), right = lastValue.getRight(), operator = lastValue.getOperator();
434
- if (left && right && operator && operator.matches('/')) {
435
- colorValues = [colorValues[0], colorValues[1], left, right];
436
- }
437
- }
438
- }
439
- }
440
- }
441
- if (!name || colorValues.length < 3 || colorValues.length > 4) {
442
- return null;
443
- }
444
- try {
445
- var alpha = colorValues.length === 4 ? getNumericValue(colorValues[3], 1) : 1;
446
- if (name === 'rgb' || name === 'rgba') {
447
- return {
448
- red: getNumericValue(colorValues[0], 255.0),
449
- green: getNumericValue(colorValues[1], 255.0),
450
- blue: getNumericValue(colorValues[2], 255.0),
451
- alpha: alpha
452
- };
453
- }
454
- else if (name === 'hsl' || name === 'hsla') {
455
- var h = getAngle(colorValues[0]);
456
- var s = getNumericValue(colorValues[1], 100.0);
457
- var l = getNumericValue(colorValues[2], 100.0);
458
- return colorFromHSL(h, s, l, alpha);
459
- }
460
- else if (name === 'hwb') {
461
- var h = getAngle(colorValues[0]);
462
- var w = getNumericValue(colorValues[1], 100.0);
463
- var b = getNumericValue(colorValues[2], 100.0);
464
- return colorFromHWB(h, w, b, alpha);
465
- }
466
- }
467
- catch (e) {
468
- // parse error on numeric value
469
- return null;
470
- }
471
- }
472
- else if (node.type === nodes.NodeType.Identifier) {
473
- if (node.parent && node.parent.type !== nodes.NodeType.Term) {
474
- return null;
475
- }
476
- var term = node.parent;
477
- if (term && term.parent && term.parent.type === nodes.NodeType.BinaryExpression) {
478
- var expression = term.parent;
479
- if (expression.parent && expression.parent.type === nodes.NodeType.ListEntry && expression.parent.key === expression) {
480
- return null;
481
- }
482
- }
483
- var candidateColor = node.getText().toLowerCase();
484
- if (candidateColor === 'none') {
485
- return null;
486
- }
487
- var colorHex = exports.colors[candidateColor];
488
- if (colorHex) {
489
- return colorFromHex(colorHex);
490
- }
491
- }
492
- return null;
493
- }
494
- exports.getColorValue = getColorValue;
495
- });
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License. See License.txt in the project root for license information.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ (function (factory) {
6
+ if (typeof module === "object" && typeof module.exports === "object") {
7
+ var v = factory(require, exports);
8
+ if (v !== undefined) module.exports = v;
9
+ }
10
+ else if (typeof define === "function" && define.amd) {
11
+ define(["require", "exports", "../parser/cssNodes", "vscode-nls"], factory);
12
+ }
13
+ })(function (require, exports) {
14
+ "use strict";
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.getColorValue = exports.hwbFromColor = exports.colorFromHWB = exports.hslFromColor = exports.colorFromHSL = exports.colorFrom256RGB = exports.colorFromHex = exports.hexDigit = exports.isColorValue = exports.isColorConstructor = exports.colorKeywords = exports.colors = exports.colorFunctions = void 0;
17
+ const nodes = require("../parser/cssNodes");
18
+ const nls = require("vscode-nls");
19
+ const localize = nls.loadMessageBundle();
20
+ exports.colorFunctions = [
21
+ { func: 'rgb($red, $green, $blue)', desc: localize('css.builtin.rgb', 'Creates a Color from red, green, and blue values.') },
22
+ { func: 'rgba($red, $green, $blue, $alpha)', desc: localize('css.builtin.rgba', 'Creates a Color from red, green, blue, and alpha values.') },
23
+ { func: 'hsl($hue, $saturation, $lightness)', desc: localize('css.builtin.hsl', 'Creates a Color from hue, saturation, and lightness values.') },
24
+ { func: 'hsla($hue, $saturation, $lightness, $alpha)', desc: localize('css.builtin.hsla', 'Creates a Color from hue, saturation, lightness, and alpha values.') },
25
+ { func: 'hwb($hue $white $black)', desc: localize('css.builtin.hwb', 'Creates a Color from hue, white and black.') }
26
+ ];
27
+ exports.colors = {
28
+ aliceblue: '#f0f8ff',
29
+ antiquewhite: '#faebd7',
30
+ aqua: '#00ffff',
31
+ aquamarine: '#7fffd4',
32
+ azure: '#f0ffff',
33
+ beige: '#f5f5dc',
34
+ bisque: '#ffe4c4',
35
+ black: '#000000',
36
+ blanchedalmond: '#ffebcd',
37
+ blue: '#0000ff',
38
+ blueviolet: '#8a2be2',
39
+ brown: '#a52a2a',
40
+ burlywood: '#deb887',
41
+ cadetblue: '#5f9ea0',
42
+ chartreuse: '#7fff00',
43
+ chocolate: '#d2691e',
44
+ coral: '#ff7f50',
45
+ cornflowerblue: '#6495ed',
46
+ cornsilk: '#fff8dc',
47
+ crimson: '#dc143c',
48
+ cyan: '#00ffff',
49
+ darkblue: '#00008b',
50
+ darkcyan: '#008b8b',
51
+ darkgoldenrod: '#b8860b',
52
+ darkgray: '#a9a9a9',
53
+ darkgrey: '#a9a9a9',
54
+ darkgreen: '#006400',
55
+ darkkhaki: '#bdb76b',
56
+ darkmagenta: '#8b008b',
57
+ darkolivegreen: '#556b2f',
58
+ darkorange: '#ff8c00',
59
+ darkorchid: '#9932cc',
60
+ darkred: '#8b0000',
61
+ darksalmon: '#e9967a',
62
+ darkseagreen: '#8fbc8f',
63
+ darkslateblue: '#483d8b',
64
+ darkslategray: '#2f4f4f',
65
+ darkslategrey: '#2f4f4f',
66
+ darkturquoise: '#00ced1',
67
+ darkviolet: '#9400d3',
68
+ deeppink: '#ff1493',
69
+ deepskyblue: '#00bfff',
70
+ dimgray: '#696969',
71
+ dimgrey: '#696969',
72
+ dodgerblue: '#1e90ff',
73
+ firebrick: '#b22222',
74
+ floralwhite: '#fffaf0',
75
+ forestgreen: '#228b22',
76
+ fuchsia: '#ff00ff',
77
+ gainsboro: '#dcdcdc',
78
+ ghostwhite: '#f8f8ff',
79
+ gold: '#ffd700',
80
+ goldenrod: '#daa520',
81
+ gray: '#808080',
82
+ grey: '#808080',
83
+ green: '#008000',
84
+ greenyellow: '#adff2f',
85
+ honeydew: '#f0fff0',
86
+ hotpink: '#ff69b4',
87
+ indianred: '#cd5c5c',
88
+ indigo: '#4b0082',
89
+ ivory: '#fffff0',
90
+ khaki: '#f0e68c',
91
+ lavender: '#e6e6fa',
92
+ lavenderblush: '#fff0f5',
93
+ lawngreen: '#7cfc00',
94
+ lemonchiffon: '#fffacd',
95
+ lightblue: '#add8e6',
96
+ lightcoral: '#f08080',
97
+ lightcyan: '#e0ffff',
98
+ lightgoldenrodyellow: '#fafad2',
99
+ lightgray: '#d3d3d3',
100
+ lightgrey: '#d3d3d3',
101
+ lightgreen: '#90ee90',
102
+ lightpink: '#ffb6c1',
103
+ lightsalmon: '#ffa07a',
104
+ lightseagreen: '#20b2aa',
105
+ lightskyblue: '#87cefa',
106
+ lightslategray: '#778899',
107
+ lightslategrey: '#778899',
108
+ lightsteelblue: '#b0c4de',
109
+ lightyellow: '#ffffe0',
110
+ lime: '#00ff00',
111
+ limegreen: '#32cd32',
112
+ linen: '#faf0e6',
113
+ magenta: '#ff00ff',
114
+ maroon: '#800000',
115
+ mediumaquamarine: '#66cdaa',
116
+ mediumblue: '#0000cd',
117
+ mediumorchid: '#ba55d3',
118
+ mediumpurple: '#9370d8',
119
+ mediumseagreen: '#3cb371',
120
+ mediumslateblue: '#7b68ee',
121
+ mediumspringgreen: '#00fa9a',
122
+ mediumturquoise: '#48d1cc',
123
+ mediumvioletred: '#c71585',
124
+ midnightblue: '#191970',
125
+ mintcream: '#f5fffa',
126
+ mistyrose: '#ffe4e1',
127
+ moccasin: '#ffe4b5',
128
+ navajowhite: '#ffdead',
129
+ navy: '#000080',
130
+ oldlace: '#fdf5e6',
131
+ olive: '#808000',
132
+ olivedrab: '#6b8e23',
133
+ orange: '#ffa500',
134
+ orangered: '#ff4500',
135
+ orchid: '#da70d6',
136
+ palegoldenrod: '#eee8aa',
137
+ palegreen: '#98fb98',
138
+ paleturquoise: '#afeeee',
139
+ palevioletred: '#d87093',
140
+ papayawhip: '#ffefd5',
141
+ peachpuff: '#ffdab9',
142
+ peru: '#cd853f',
143
+ pink: '#ffc0cb',
144
+ plum: '#dda0dd',
145
+ powderblue: '#b0e0e6',
146
+ purple: '#800080',
147
+ red: '#ff0000',
148
+ rebeccapurple: '#663399',
149
+ rosybrown: '#bc8f8f',
150
+ royalblue: '#4169e1',
151
+ saddlebrown: '#8b4513',
152
+ salmon: '#fa8072',
153
+ sandybrown: '#f4a460',
154
+ seagreen: '#2e8b57',
155
+ seashell: '#fff5ee',
156
+ sienna: '#a0522d',
157
+ silver: '#c0c0c0',
158
+ skyblue: '#87ceeb',
159
+ slateblue: '#6a5acd',
160
+ slategray: '#708090',
161
+ slategrey: '#708090',
162
+ snow: '#fffafa',
163
+ springgreen: '#00ff7f',
164
+ steelblue: '#4682b4',
165
+ tan: '#d2b48c',
166
+ teal: '#008080',
167
+ thistle: '#d8bfd8',
168
+ tomato: '#ff6347',
169
+ turquoise: '#40e0d0',
170
+ violet: '#ee82ee',
171
+ wheat: '#f5deb3',
172
+ white: '#ffffff',
173
+ whitesmoke: '#f5f5f5',
174
+ yellow: '#ffff00',
175
+ yellowgreen: '#9acd32'
176
+ };
177
+ exports.colorKeywords = {
178
+ 'currentColor': 'The value of the \'color\' property. The computed value of the \'currentColor\' keyword is the computed value of the \'color\' property. If the \'currentColor\' keyword is set on the \'color\' property itself, it is treated as \'color:inherit\' at parse time.',
179
+ 'transparent': 'Fully transparent. This keyword can be considered a shorthand for rgba(0,0,0,0) which is its computed value.',
180
+ };
181
+ function getNumericValue(node, factor) {
182
+ const val = node.getText();
183
+ const m = val.match(/^([-+]?[0-9]*\.?[0-9]+)(%?)$/);
184
+ if (m) {
185
+ if (m[2]) {
186
+ factor = 100.0;
187
+ }
188
+ const result = parseFloat(m[1]) / factor;
189
+ if (result >= 0 && result <= 1) {
190
+ return result;
191
+ }
192
+ }
193
+ throw new Error();
194
+ }
195
+ function getAngle(node) {
196
+ const val = node.getText();
197
+ const m = val.match(/^([-+]?[0-9]*\.?[0-9]+)(deg|rad|grad|turn)?$/);
198
+ if (m) {
199
+ switch (m[2]) {
200
+ case 'deg':
201
+ return parseFloat(val) % 360;
202
+ case 'rad':
203
+ return (parseFloat(val) * 180 / Math.PI) % 360;
204
+ case 'grad':
205
+ return (parseFloat(val) * 0.9) % 360;
206
+ case 'turn':
207
+ return (parseFloat(val) * 360) % 360;
208
+ default:
209
+ if ('undefined' === typeof m[2]) {
210
+ return parseFloat(val) % 360;
211
+ }
212
+ }
213
+ }
214
+ throw new Error();
215
+ }
216
+ function isColorConstructor(node) {
217
+ const name = node.getName();
218
+ if (!name) {
219
+ return false;
220
+ }
221
+ return /^(rgb|rgba|hsl|hsla|hwb)$/gi.test(name);
222
+ }
223
+ exports.isColorConstructor = isColorConstructor;
224
+ /**
225
+ * Returns true if the node is a color value - either
226
+ * defined a hex number, as rgb or rgba function, or
227
+ * as color name.
228
+ */
229
+ function isColorValue(node) {
230
+ if (node.type === nodes.NodeType.HexColorValue) {
231
+ return true;
232
+ }
233
+ else if (node.type === nodes.NodeType.Function) {
234
+ return isColorConstructor(node);
235
+ }
236
+ else if (node.type === nodes.NodeType.Identifier) {
237
+ if (node.parent && node.parent.type !== nodes.NodeType.Term) {
238
+ return false;
239
+ }
240
+ const candidateColor = node.getText().toLowerCase();
241
+ if (candidateColor === 'none') {
242
+ return false;
243
+ }
244
+ if (exports.colors[candidateColor]) {
245
+ return true;
246
+ }
247
+ }
248
+ return false;
249
+ }
250
+ exports.isColorValue = isColorValue;
251
+ const Digit0 = 48;
252
+ const Digit9 = 57;
253
+ const A = 65;
254
+ const F = 70;
255
+ const a = 97;
256
+ const f = 102;
257
+ function hexDigit(charCode) {
258
+ if (charCode < Digit0) {
259
+ return 0;
260
+ }
261
+ if (charCode <= Digit9) {
262
+ return charCode - Digit0;
263
+ }
264
+ if (charCode < a) {
265
+ charCode += (a - A);
266
+ }
267
+ if (charCode >= a && charCode <= f) {
268
+ return charCode - a + 10;
269
+ }
270
+ return 0;
271
+ }
272
+ exports.hexDigit = hexDigit;
273
+ function colorFromHex(text) {
274
+ if (text[0] !== '#') {
275
+ return null;
276
+ }
277
+ switch (text.length) {
278
+ case 4:
279
+ return {
280
+ red: (hexDigit(text.charCodeAt(1)) * 0x11) / 255.0,
281
+ green: (hexDigit(text.charCodeAt(2)) * 0x11) / 255.0,
282
+ blue: (hexDigit(text.charCodeAt(3)) * 0x11) / 255.0,
283
+ alpha: 1
284
+ };
285
+ case 5:
286
+ return {
287
+ red: (hexDigit(text.charCodeAt(1)) * 0x11) / 255.0,
288
+ green: (hexDigit(text.charCodeAt(2)) * 0x11) / 255.0,
289
+ blue: (hexDigit(text.charCodeAt(3)) * 0x11) / 255.0,
290
+ alpha: (hexDigit(text.charCodeAt(4)) * 0x11) / 255.0,
291
+ };
292
+ case 7:
293
+ return {
294
+ red: (hexDigit(text.charCodeAt(1)) * 0x10 + hexDigit(text.charCodeAt(2))) / 255.0,
295
+ green: (hexDigit(text.charCodeAt(3)) * 0x10 + hexDigit(text.charCodeAt(4))) / 255.0,
296
+ blue: (hexDigit(text.charCodeAt(5)) * 0x10 + hexDigit(text.charCodeAt(6))) / 255.0,
297
+ alpha: 1
298
+ };
299
+ case 9:
300
+ return {
301
+ red: (hexDigit(text.charCodeAt(1)) * 0x10 + hexDigit(text.charCodeAt(2))) / 255.0,
302
+ green: (hexDigit(text.charCodeAt(3)) * 0x10 + hexDigit(text.charCodeAt(4))) / 255.0,
303
+ blue: (hexDigit(text.charCodeAt(5)) * 0x10 + hexDigit(text.charCodeAt(6))) / 255.0,
304
+ alpha: (hexDigit(text.charCodeAt(7)) * 0x10 + hexDigit(text.charCodeAt(8))) / 255.0
305
+ };
306
+ }
307
+ return null;
308
+ }
309
+ exports.colorFromHex = colorFromHex;
310
+ function colorFrom256RGB(red, green, blue, alpha = 1.0) {
311
+ return {
312
+ red: red / 255.0,
313
+ green: green / 255.0,
314
+ blue: blue / 255.0,
315
+ alpha
316
+ };
317
+ }
318
+ exports.colorFrom256RGB = colorFrom256RGB;
319
+ function colorFromHSL(hue, sat, light, alpha = 1.0) {
320
+ hue = hue / 60.0;
321
+ if (sat === 0) {
322
+ return { red: light, green: light, blue: light, alpha };
323
+ }
324
+ else {
325
+ const hueToRgb = (t1, t2, hue) => {
326
+ while (hue < 0) {
327
+ hue += 6;
328
+ }
329
+ while (hue >= 6) {
330
+ hue -= 6;
331
+ }
332
+ if (hue < 1) {
333
+ return (t2 - t1) * hue + t1;
334
+ }
335
+ if (hue < 3) {
336
+ return t2;
337
+ }
338
+ if (hue < 4) {
339
+ return (t2 - t1) * (4 - hue) + t1;
340
+ }
341
+ return t1;
342
+ };
343
+ const t2 = light <= 0.5 ? (light * (sat + 1)) : (light + sat - (light * sat));
344
+ const t1 = light * 2 - t2;
345
+ return { red: hueToRgb(t1, t2, hue + 2), green: hueToRgb(t1, t2, hue), blue: hueToRgb(t1, t2, hue - 2), alpha };
346
+ }
347
+ }
348
+ exports.colorFromHSL = colorFromHSL;
349
+ function hslFromColor(rgba) {
350
+ const r = rgba.red;
351
+ const g = rgba.green;
352
+ const b = rgba.blue;
353
+ const a = rgba.alpha;
354
+ const max = Math.max(r, g, b);
355
+ const min = Math.min(r, g, b);
356
+ let h = 0;
357
+ let s = 0;
358
+ const l = (min + max) / 2;
359
+ const chroma = max - min;
360
+ if (chroma > 0) {
361
+ s = Math.min((l <= 0.5 ? chroma / (2 * l) : chroma / (2 - (2 * l))), 1);
362
+ switch (max) {
363
+ case r:
364
+ h = (g - b) / chroma + (g < b ? 6 : 0);
365
+ break;
366
+ case g:
367
+ h = (b - r) / chroma + 2;
368
+ break;
369
+ case b:
370
+ h = (r - g) / chroma + 4;
371
+ break;
372
+ }
373
+ h *= 60;
374
+ h = Math.round(h);
375
+ }
376
+ return { h, s, l, a };
377
+ }
378
+ exports.hslFromColor = hslFromColor;
379
+ function colorFromHWB(hue, white, black, alpha = 1.0) {
380
+ if (white + black >= 1) {
381
+ const gray = white / (white + black);
382
+ return { red: gray, green: gray, blue: gray, alpha };
383
+ }
384
+ const rgb = colorFromHSL(hue, 1, 0.5, alpha);
385
+ let red = rgb.red;
386
+ red *= (1 - white - black);
387
+ red += white;
388
+ let green = rgb.green;
389
+ green *= (1 - white - black);
390
+ green += white;
391
+ let blue = rgb.blue;
392
+ blue *= (1 - white - black);
393
+ blue += white;
394
+ return {
395
+ red: red,
396
+ green: green,
397
+ blue: blue,
398
+ alpha
399
+ };
400
+ }
401
+ exports.colorFromHWB = colorFromHWB;
402
+ function hwbFromColor(rgba) {
403
+ const hsl = hslFromColor(rgba);
404
+ const white = Math.min(rgba.red, rgba.green, rgba.blue);
405
+ const black = 1 - Math.max(rgba.red, rgba.green, rgba.blue);
406
+ return {
407
+ h: hsl.h,
408
+ w: white,
409
+ b: black,
410
+ a: hsl.a
411
+ };
412
+ }
413
+ exports.hwbFromColor = hwbFromColor;
414
+ function getColorValue(node) {
415
+ if (node.type === nodes.NodeType.HexColorValue) {
416
+ const text = node.getText();
417
+ return colorFromHex(text);
418
+ }
419
+ else if (node.type === nodes.NodeType.Function) {
420
+ const functionNode = node;
421
+ const name = functionNode.getName();
422
+ let colorValues = functionNode.getArguments().getChildren();
423
+ if (colorValues.length === 1) {
424
+ const functionArg = colorValues[0].getChildren();
425
+ if (functionArg.length === 1 && functionArg[0].type === nodes.NodeType.Expression) {
426
+ colorValues = functionArg[0].getChildren();
427
+ if (colorValues.length === 3) {
428
+ const lastValue = colorValues[2];
429
+ if (lastValue instanceof nodes.BinaryExpression) {
430
+ const left = lastValue.getLeft(), right = lastValue.getRight(), operator = lastValue.getOperator();
431
+ if (left && right && operator && operator.matches('/')) {
432
+ colorValues = [colorValues[0], colorValues[1], left, right];
433
+ }
434
+ }
435
+ }
436
+ }
437
+ }
438
+ if (!name || colorValues.length < 3 || colorValues.length > 4) {
439
+ return null;
440
+ }
441
+ try {
442
+ const alpha = colorValues.length === 4 ? getNumericValue(colorValues[3], 1) : 1;
443
+ if (name === 'rgb' || name === 'rgba') {
444
+ return {
445
+ red: getNumericValue(colorValues[0], 255.0),
446
+ green: getNumericValue(colorValues[1], 255.0),
447
+ blue: getNumericValue(colorValues[2], 255.0),
448
+ alpha
449
+ };
450
+ }
451
+ else if (name === 'hsl' || name === 'hsla') {
452
+ const h = getAngle(colorValues[0]);
453
+ const s = getNumericValue(colorValues[1], 100.0);
454
+ const l = getNumericValue(colorValues[2], 100.0);
455
+ return colorFromHSL(h, s, l, alpha);
456
+ }
457
+ else if (name === 'hwb') {
458
+ const h = getAngle(colorValues[0]);
459
+ const w = getNumericValue(colorValues[1], 100.0);
460
+ const b = getNumericValue(colorValues[2], 100.0);
461
+ return colorFromHWB(h, w, b, alpha);
462
+ }
463
+ }
464
+ catch (e) {
465
+ // parse error on numeric value
466
+ return null;
467
+ }
468
+ }
469
+ else if (node.type === nodes.NodeType.Identifier) {
470
+ if (node.parent && node.parent.type !== nodes.NodeType.Term) {
471
+ return null;
472
+ }
473
+ const term = node.parent;
474
+ if (term && term.parent && term.parent.type === nodes.NodeType.BinaryExpression) {
475
+ const expression = term.parent;
476
+ if (expression.parent && expression.parent.type === nodes.NodeType.ListEntry && expression.parent.key === expression) {
477
+ return null;
478
+ }
479
+ }
480
+ const candidateColor = node.getText().toLowerCase();
481
+ if (candidateColor === 'none') {
482
+ return null;
483
+ }
484
+ const colorHex = exports.colors[candidateColor];
485
+ if (colorHex) {
486
+ return colorFromHex(colorHex);
487
+ }
488
+ }
489
+ return null;
490
+ }
491
+ exports.getColorValue = getColorValue;
492
+ });