vscode-css-languageservice 6.0.1 → 6.1.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 (87) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/SECURITY.md +41 -0
  3. package/lib/esm/beautify/beautify-css.js +11 -4
  4. package/lib/esm/cssLanguageService.d.ts +38 -37
  5. package/lib/esm/cssLanguageService.js +73 -72
  6. package/lib/esm/cssLanguageTypes.d.ts +238 -238
  7. package/lib/esm/cssLanguageTypes.js +42 -42
  8. package/lib/esm/data/webCustomData.js +22089 -21959
  9. package/lib/esm/languageFacts/builtinData.js +142 -142
  10. package/lib/esm/languageFacts/colors.js +469 -469
  11. package/lib/esm/languageFacts/dataManager.js +88 -88
  12. package/lib/esm/languageFacts/dataProvider.js +73 -73
  13. package/lib/esm/languageFacts/entry.js +137 -137
  14. package/lib/esm/languageFacts/facts.js +8 -8
  15. package/lib/esm/parser/cssErrors.js +48 -48
  16. package/lib/esm/parser/cssNodes.js +1511 -1502
  17. package/lib/esm/parser/cssParser.js +1606 -1534
  18. package/lib/esm/parser/cssScanner.js +592 -592
  19. package/lib/esm/parser/cssSymbolScope.js +311 -311
  20. package/lib/esm/parser/lessParser.js +715 -714
  21. package/lib/esm/parser/lessScanner.js +57 -57
  22. package/lib/esm/parser/scssErrors.js +18 -18
  23. package/lib/esm/parser/scssParser.js +806 -796
  24. package/lib/esm/parser/scssScanner.js +95 -95
  25. package/lib/esm/services/cssCodeActions.js +77 -77
  26. package/lib/esm/services/cssCompletion.js +1054 -1054
  27. package/lib/esm/services/cssFolding.js +190 -190
  28. package/lib/esm/services/cssFormatter.js +136 -136
  29. package/lib/esm/services/cssHover.js +148 -148
  30. package/lib/esm/services/cssNavigation.js +441 -378
  31. package/lib/esm/services/cssSelectionRange.js +47 -47
  32. package/lib/esm/services/cssValidation.js +41 -41
  33. package/lib/esm/services/lessCompletion.js +378 -378
  34. package/lib/esm/services/lint.js +518 -518
  35. package/lib/esm/services/lintRules.js +76 -76
  36. package/lib/esm/services/lintUtil.js +196 -196
  37. package/lib/esm/services/pathCompletion.js +157 -157
  38. package/lib/esm/services/scssCompletion.js +354 -354
  39. package/lib/esm/services/scssNavigation.js +82 -82
  40. package/lib/esm/services/selectorPrinting.js +492 -492
  41. package/lib/esm/utils/arrays.js +40 -40
  42. package/lib/esm/utils/objects.js +11 -11
  43. package/lib/esm/utils/resources.js +11 -11
  44. package/lib/esm/utils/strings.js +102 -102
  45. package/lib/umd/beautify/beautify-css.js +11 -4
  46. package/lib/umd/cssLanguageService.d.ts +38 -37
  47. package/lib/umd/cssLanguageService.js +104 -99
  48. package/lib/umd/cssLanguageTypes.d.ts +238 -238
  49. package/lib/umd/cssLanguageTypes.js +89 -89
  50. package/lib/umd/data/webCustomData.js +22102 -21972
  51. package/lib/umd/languageFacts/builtinData.js +154 -154
  52. package/lib/umd/languageFacts/colors.js +492 -492
  53. package/lib/umd/languageFacts/dataManager.js +101 -101
  54. package/lib/umd/languageFacts/dataProvider.js +86 -86
  55. package/lib/umd/languageFacts/entry.js +152 -152
  56. package/lib/umd/languageFacts/facts.js +33 -29
  57. package/lib/umd/parser/cssErrors.js +61 -61
  58. package/lib/umd/parser/cssNodes.js +1597 -1587
  59. package/lib/umd/parser/cssParser.js +1619 -1547
  60. package/lib/umd/parser/cssScanner.js +606 -606
  61. package/lib/umd/parser/cssSymbolScope.js +328 -328
  62. package/lib/umd/parser/lessParser.js +728 -727
  63. package/lib/umd/parser/lessScanner.js +70 -70
  64. package/lib/umd/parser/scssErrors.js +31 -31
  65. package/lib/umd/parser/scssParser.js +819 -809
  66. package/lib/umd/parser/scssScanner.js +108 -108
  67. package/lib/umd/services/cssCodeActions.js +90 -90
  68. package/lib/umd/services/cssCompletion.js +1067 -1067
  69. package/lib/umd/services/cssFolding.js +203 -203
  70. package/lib/umd/services/cssFormatter.js +150 -150
  71. package/lib/umd/services/cssHover.js +161 -161
  72. package/lib/umd/services/cssNavigation.js +454 -391
  73. package/lib/umd/services/cssSelectionRange.js +60 -60
  74. package/lib/umd/services/cssValidation.js +54 -54
  75. package/lib/umd/services/lessCompletion.js +391 -391
  76. package/lib/umd/services/lint.js +531 -531
  77. package/lib/umd/services/lintRules.js +91 -91
  78. package/lib/umd/services/lintUtil.js +210 -210
  79. package/lib/umd/services/pathCompletion.js +171 -171
  80. package/lib/umd/services/scssCompletion.js +367 -367
  81. package/lib/umd/services/scssNavigation.js +95 -95
  82. package/lib/umd/services/selectorPrinting.js +510 -510
  83. package/lib/umd/utils/arrays.js +55 -55
  84. package/lib/umd/utils/objects.js +25 -25
  85. package/lib/umd/utils/resources.js +26 -26
  86. package/lib/umd/utils/strings.js +120 -120
  87. package/package.json +13 -12
@@ -1,492 +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
- 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
- });
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
+ });