vscode-css-languageservice
Advanced tools
Comparing version 5.1.12 to 5.1.13
@@ -12,3 +12,4 @@ /*--------------------------------------------------------------------------------------------- | ||
{ func: 'hsl($hue, $saturation, $lightness)', desc: localize('css.builtin.hsl', 'Creates a Color from hue, saturation, and lightness values.') }, | ||
{ func: 'hsla($hue, $saturation, $lightness, $alpha)', desc: localize('css.builtin.hsla', 'Creates a Color from hue, saturation, lightness, and alpha values.') } | ||
{ func: 'hsla($hue, $saturation, $lightness, $alpha)', desc: localize('css.builtin.hsla', 'Creates a Color from hue, saturation, lightness, and alpha values.') }, | ||
{ func: 'hwb($hue $white $black)', desc: localize('css.builtin.hwb', 'Creates a Color from hue, white and black.') } | ||
]; | ||
@@ -209,3 +210,3 @@ export var colors = { | ||
} | ||
return /^(rgb|rgba|hsl|hsla)$/gi.test(name); | ||
return /^(rgb|rgba|hsl|hsla|hwb)$/gi.test(name); | ||
} | ||
@@ -363,2 +364,36 @@ /** | ||
} | ||
export function colorFromHWB(hue, white, black, alpha) { | ||
if (alpha === void 0) { alpha = 1.0; } | ||
if (white + black >= 1) { | ||
var gray = white / (white + black); | ||
return { red: gray, green: gray, blue: gray, alpha: alpha }; | ||
} | ||
var rgb = colorFromHSL(hue, 1, 0.5, alpha); | ||
var red = rgb.red; | ||
red *= (1 - white - black); | ||
red += white; | ||
var green = rgb.green; | ||
green *= (1 - white - black); | ||
green += white; | ||
var blue = rgb.blue; | ||
blue *= (1 - white - black); | ||
blue += white; | ||
return { | ||
red: red, | ||
green: green, | ||
blue: blue, | ||
alpha: alpha | ||
}; | ||
} | ||
export function hwbFromColor(rgba) { | ||
var hsl = hslFromColor(rgba); | ||
var white = Math.min(rgba.red, rgba.green, rgba.blue); | ||
var black = 1 - Math.max(rgba.red, rgba.green, rgba.blue); | ||
return { | ||
h: hsl.h, | ||
w: white, | ||
b: black, | ||
a: hsl.a | ||
}; | ||
} | ||
export function getColorValue(node) { | ||
@@ -407,2 +442,8 @@ if (node.type === nodes.NodeType.HexColorValue) { | ||
} | ||
else if (name === 'hwb') { | ||
var h = getAngle(colorValues[0]); | ||
var w = getNumericValue(colorValues[1], 100.0); | ||
var b = getNumericValue(colorValues[2], 100.0); | ||
return colorFromHWB(h, w, b, alpha); | ||
} | ||
} | ||
@@ -409,0 +450,0 @@ catch (e) { |
@@ -46,3 +46,3 @@ /*--------------------------------------------------------------------------------------------- | ||
import { Symbols } from '../parser/cssSymbolScope'; | ||
import { getColorValue, hslFromColor } from '../languageFacts/facts'; | ||
import { getColorValue, hslFromColor, hwbFromColor } from '../languageFacts/facts'; | ||
import { startsWith } from '../utils/strings'; | ||
@@ -307,2 +307,10 @@ import { dirname, joinPath } from '../utils/resources'; | ||
result.push({ label: label, textEdit: TextEdit.replace(range, label) }); | ||
var hwb = hwbFromColor(color); | ||
if (hwb.a === 1) { | ||
label = "hwb(".concat(hwb.h, " ").concat(Math.round(hwb.w * 100), "% ").concat(Math.round(hwb.b * 100), "%)"); | ||
} | ||
else { | ||
label = "hwb(".concat(hwb.h, " ").concat(Math.round(hwb.w * 100), "% ").concat(Math.round(hwb.b * 100), "% / ").concat(hwb.a, ")"); | ||
} | ||
result.push({ label: label, textEdit: TextEdit.replace(range, label) }); | ||
return result; | ||
@@ -309,0 +317,0 @@ }; |
@@ -365,3 +365,4 @@ /*--------------------------------------------------------------------------------------------- | ||
var calculateScore = function (node) { | ||
for (var _i = 0, _a = node.getChildren(); _i < _a.length; _i++) { | ||
var specificity = new Specificity(); | ||
elementLoop: for (var _i = 0, _a = node.getChildren(); _i < _a.length; _i++) { | ||
var element = _a[_i]; | ||
@@ -387,19 +388,62 @@ switch (element.type) { | ||
specificity.tag++; // pseudo element | ||
break; | ||
} | ||
else { | ||
//ignore psuedo class NOT | ||
if (text.match(/^:not/i)) { | ||
break; | ||
// where and child selectors have zero specificity | ||
if (text.match(/^:where/i)) { | ||
continue elementLoop; | ||
} | ||
// the most specific child selector | ||
if (text.match(/^:(not|has|is)/i) && element.getChildren().length > 0) { | ||
var mostSpecificListItem = new Specificity(); | ||
for (var _b = 0, _c = element.getChildren(); _b < _c.length; _b++) { | ||
var containerElement = _c[_b]; | ||
var list = void 0; | ||
if (containerElement.type === nodes.NodeType.Undefined) { // containerElement is a list of selectors | ||
list = containerElement.getChildren(); | ||
} | ||
else { // containerElement is a selector | ||
list = [containerElement]; | ||
} | ||
for (var _d = 0, _e = containerElement.getChildren(); _d < _e.length; _d++) { | ||
var childElement = _e[_d]; | ||
var itemSpecificity = calculateScore(childElement); | ||
if (itemSpecificity.id > mostSpecificListItem.id) { | ||
mostSpecificListItem = itemSpecificity; | ||
continue; | ||
} | ||
else if (itemSpecificity.id < mostSpecificListItem.id) { | ||
continue; | ||
} | ||
if (itemSpecificity.attr > mostSpecificListItem.attr) { | ||
mostSpecificListItem = itemSpecificity; | ||
continue; | ||
} | ||
else if (itemSpecificity.attr < mostSpecificListItem.attr) { | ||
continue; | ||
} | ||
if (itemSpecificity.tag > mostSpecificListItem.tag) { | ||
mostSpecificListItem = itemSpecificity; | ||
continue; | ||
} | ||
} | ||
} | ||
specificity.attr++; //pseudo class | ||
specificity.id += mostSpecificListItem.id; | ||
specificity.attr += mostSpecificListItem.attr; | ||
specificity.tag += mostSpecificListItem.tag; | ||
continue elementLoop; | ||
} | ||
specificity.attr++; //pseudo class | ||
break; | ||
} | ||
if (element.getChildren().length > 0) { | ||
calculateScore(element); | ||
var itemSpecificity = calculateScore(element); | ||
specificity.id += itemSpecificity.id; | ||
specificity.attr += itemSpecificity.attr; | ||
specificity.tag += itemSpecificity.tag; | ||
} | ||
} | ||
return specificity; | ||
}; | ||
var specificity = new Specificity(); | ||
calculateScore(node); | ||
var specificity = calculateScore(node); | ||
; | ||
return localize('specificity', "[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): ({0}, {1}, {2})", specificity.id, specificity.attr, specificity.tag); | ||
@@ -406,0 +450,0 @@ }; |
@@ -16,3 +16,3 @@ /*--------------------------------------------------------------------------------------------- | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getColorValue = exports.hslFromColor = exports.colorFromHSL = exports.colorFrom256RGB = exports.colorFromHex = exports.hexDigit = exports.isColorValue = exports.isColorConstructor = exports.colorKeywords = exports.colors = exports.colorFunctions = void 0; | ||
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; | ||
var nodes = require("../parser/cssNodes"); | ||
@@ -25,3 +25,4 @@ var nls = require("vscode-nls"); | ||
{ func: 'hsl($hue, $saturation, $lightness)', desc: localize('css.builtin.hsl', 'Creates a Color from hue, saturation, and lightness values.') }, | ||
{ func: 'hsla($hue, $saturation, $lightness, $alpha)', desc: localize('css.builtin.hsla', 'Creates a Color from hue, saturation, lightness, and alpha values.') } | ||
{ func: 'hsla($hue, $saturation, $lightness, $alpha)', desc: localize('css.builtin.hsla', 'Creates a Color from hue, saturation, lightness, and alpha values.') }, | ||
{ func: 'hwb($hue $white $black)', desc: localize('css.builtin.hwb', 'Creates a Color from hue, white and black.') } | ||
]; | ||
@@ -222,3 +223,3 @@ exports.colors = { | ||
} | ||
return /^(rgb|rgba|hsl|hsla)$/gi.test(name); | ||
return /^(rgb|rgba|hsl|hsla|hwb)$/gi.test(name); | ||
} | ||
@@ -383,2 +384,38 @@ exports.isColorConstructor = isColorConstructor; | ||
exports.hslFromColor = hslFromColor; | ||
function colorFromHWB(hue, white, black, alpha) { | ||
if (alpha === void 0) { alpha = 1.0; } | ||
if (white + black >= 1) { | ||
var gray = white / (white + black); | ||
return { red: gray, green: gray, blue: gray, alpha: alpha }; | ||
} | ||
var rgb = colorFromHSL(hue, 1, 0.5, alpha); | ||
var red = rgb.red; | ||
red *= (1 - white - black); | ||
red += white; | ||
var green = rgb.green; | ||
green *= (1 - white - black); | ||
green += white; | ||
var blue = rgb.blue; | ||
blue *= (1 - white - black); | ||
blue += white; | ||
return { | ||
red: red, | ||
green: green, | ||
blue: blue, | ||
alpha: alpha | ||
}; | ||
} | ||
exports.colorFromHWB = colorFromHWB; | ||
function hwbFromColor(rgba) { | ||
var hsl = hslFromColor(rgba); | ||
var white = Math.min(rgba.red, rgba.green, rgba.blue); | ||
var black = 1 - Math.max(rgba.red, rgba.green, rgba.blue); | ||
return { | ||
h: hsl.h, | ||
w: white, | ||
b: black, | ||
a: hsl.a | ||
}; | ||
} | ||
exports.hwbFromColor = hwbFromColor; | ||
function getColorValue(node) { | ||
@@ -427,2 +464,8 @@ if (node.type === nodes.NodeType.HexColorValue) { | ||
} | ||
else if (name === 'hwb') { | ||
var h = getAngle(colorValues[0]); | ||
var w = getNumericValue(colorValues[1], 100.0); | ||
var b = getNumericValue(colorValues[2], 100.0); | ||
return colorFromHWB(h, w, b, alpha); | ||
} | ||
} | ||
@@ -429,0 +472,0 @@ catch (e) { |
@@ -317,2 +317,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
result.push({ label: label, textEdit: cssLanguageTypes_1.TextEdit.replace(range, label) }); | ||
var hwb = (0, facts_1.hwbFromColor)(color); | ||
if (hwb.a === 1) { | ||
label = "hwb(".concat(hwb.h, " ").concat(Math.round(hwb.w * 100), "% ").concat(Math.round(hwb.b * 100), "%)"); | ||
} | ||
else { | ||
label = "hwb(".concat(hwb.h, " ").concat(Math.round(hwb.w * 100), "% ").concat(Math.round(hwb.b * 100), "% / ").concat(hwb.a, ")"); | ||
} | ||
result.push({ label: label, textEdit: cssLanguageTypes_1.TextEdit.replace(range, label) }); | ||
return result; | ||
@@ -319,0 +327,0 @@ }; |
@@ -377,3 +377,4 @@ var __extends = (this && this.__extends) || (function () { | ||
var calculateScore = function (node) { | ||
for (var _i = 0, _a = node.getChildren(); _i < _a.length; _i++) { | ||
var specificity = new Specificity(); | ||
elementLoop: for (var _i = 0, _a = node.getChildren(); _i < _a.length; _i++) { | ||
var element = _a[_i]; | ||
@@ -399,19 +400,62 @@ switch (element.type) { | ||
specificity.tag++; // pseudo element | ||
break; | ||
} | ||
else { | ||
//ignore psuedo class NOT | ||
if (text.match(/^:not/i)) { | ||
break; | ||
// where and child selectors have zero specificity | ||
if (text.match(/^:where/i)) { | ||
continue elementLoop; | ||
} | ||
// the most specific child selector | ||
if (text.match(/^:(not|has|is)/i) && element.getChildren().length > 0) { | ||
var mostSpecificListItem = new Specificity(); | ||
for (var _b = 0, _c = element.getChildren(); _b < _c.length; _b++) { | ||
var containerElement = _c[_b]; | ||
var list = void 0; | ||
if (containerElement.type === nodes.NodeType.Undefined) { // containerElement is a list of selectors | ||
list = containerElement.getChildren(); | ||
} | ||
else { // containerElement is a selector | ||
list = [containerElement]; | ||
} | ||
for (var _d = 0, _e = containerElement.getChildren(); _d < _e.length; _d++) { | ||
var childElement = _e[_d]; | ||
var itemSpecificity = calculateScore(childElement); | ||
if (itemSpecificity.id > mostSpecificListItem.id) { | ||
mostSpecificListItem = itemSpecificity; | ||
continue; | ||
} | ||
else if (itemSpecificity.id < mostSpecificListItem.id) { | ||
continue; | ||
} | ||
if (itemSpecificity.attr > mostSpecificListItem.attr) { | ||
mostSpecificListItem = itemSpecificity; | ||
continue; | ||
} | ||
else if (itemSpecificity.attr < mostSpecificListItem.attr) { | ||
continue; | ||
} | ||
if (itemSpecificity.tag > mostSpecificListItem.tag) { | ||
mostSpecificListItem = itemSpecificity; | ||
continue; | ||
} | ||
} | ||
} | ||
specificity.attr++; //pseudo class | ||
specificity.id += mostSpecificListItem.id; | ||
specificity.attr += mostSpecificListItem.attr; | ||
specificity.tag += mostSpecificListItem.tag; | ||
continue elementLoop; | ||
} | ||
specificity.attr++; //pseudo class | ||
break; | ||
} | ||
if (element.getChildren().length > 0) { | ||
calculateScore(element); | ||
var itemSpecificity = calculateScore(element); | ||
specificity.id += itemSpecificity.id; | ||
specificity.attr += itemSpecificity.attr; | ||
specificity.tag += itemSpecificity.tag; | ||
} | ||
} | ||
return specificity; | ||
}; | ||
var specificity = new Specificity(); | ||
calculateScore(node); | ||
var specificity = calculateScore(node); | ||
; | ||
return localize('specificity', "[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): ({0}, {1}, {2})", specificity.id, specificity.attr, specificity.tag); | ||
@@ -418,0 +462,0 @@ }; |
{ | ||
"name": "vscode-css-languageservice", | ||
"version": "5.1.12", | ||
"version": "5.1.13", | ||
"description": "Language service for CSS, LESS and SCSS", | ||
@@ -5,0 +5,0 @@ "main": "./lib/umd/cssLanguageService.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2968765
69617