New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vscode-css-languageservice

Package Overview
Dependencies
Maintainers
4
Versions
187
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vscode-css-languageservice - npm Package Compare versions

Comparing version 2.1.6 to 2.1.7

5

CHANGELOG.md

@@ -0,1 +1,6 @@

2.1.7 / 2017-09-21
==================
* New API `LanguageService.getColorPresentations` returning presentations for a given color.
* New API type `ColorPresentation` added.
2.1.4 / 2017-08-28

@@ -2,0 +7,0 @@ ==================

23

lib/cssLanguageService.d.ts

@@ -1,3 +0,4 @@

import { TextDocument, Position, CompletionList, Hover, Range, SymbolInformation, Diagnostic, Location, DocumentHighlight, CodeActionContext, Command, WorkspaceEdit } from 'vscode-languageserver-types';
import { TextDocument, Position, CompletionList, Hover, Range, SymbolInformation, Diagnostic, Location, DocumentHighlight, CodeActionContext, Command, WorkspaceEdit, TextEdit } from 'vscode-languageserver-types';
export declare type Stylesheet = {};
export { TextEdit, Range };
export interface Color {

@@ -13,2 +14,21 @@ red: number;

}
export interface ColorPresentation {
/**
* The label of this color presentation. It will be shown on the color
* picker header. By default this is also the text that is inserted when selecting
* this color presentation.
*/
label: string;
/**
* An [edit](#TextEdit) which is applied to a document when selecting
* this presentation for the color. When `falsy` the [label](#ColorPresentation.label)
* is used.
*/
textEdit?: TextEdit;
/**
* An optional array of additional [text edits](#TextEdit) that are applied when
* selecting this color presentation. Edits must not overlap with the main [edit](#ColorPresentation.textEdit) nor with themselves.
*/
additionalTextEdits?: TextEdit[];
}
export interface LanguageService {

@@ -28,2 +48,3 @@ configure(raw: LanguageSettings): void;

findDocumentColors(document: TextDocument, stylesheet: Stylesheet): ColorInformation[];
getColorPresentations(document: TextDocument, stylesheet: Stylesheet, colorInfo: ColorInformation): ColorPresentation[];
doRename(document: TextDocument, position: Position, newName: string, stylesheet: Stylesheet): WorkspaceEdit;

@@ -30,0 +51,0 @@ }

@@ -7,3 +7,3 @@ (function (factory) {

else if (typeof define === "function" && define.amd) {
define(["require", "exports", "./parser/cssParser", "./services/cssCompletion", "./services/cssHover", "./services/cssNavigation", "./services/cssCodeActions", "./services/cssValidation", "./parser/scssParser", "./services/scssCompletion", "./parser/lessParser", "./services/lessCompletion"], factory);
define(["require", "exports", "vscode-languageserver-types", "./parser/cssParser", "./services/cssCompletion", "./services/cssHover", "./services/cssNavigation", "./services/cssCodeActions", "./services/cssValidation", "./parser/scssParser", "./services/scssCompletion", "./parser/lessParser", "./services/lessCompletion"], factory);
}

@@ -17,2 +17,5 @@ })(function (require, exports) {

Object.defineProperty(exports, "__esModule", { value: true });
var vscode_languageserver_types_1 = require("vscode-languageserver-types");
exports.Range = vscode_languageserver_types_1.Range;
exports.TextEdit = vscode_languageserver_types_1.TextEdit;
var cssParser_1 = require("./parser/cssParser");

@@ -42,2 +45,3 @@ var cssCompletion_1 = require("./services/cssCompletion");

findDocumentColors: navigation.findDocumentColors.bind(navigation),
getColorPresentations: navigation.getColorPresentations.bind(navigation),
doRename: navigation.doRename.bind(navigation),

@@ -44,0 +48,0 @@ };

@@ -139,2 +139,31 @@ (function (factory) {

};
CSSNavigation.prototype.getColorPresentations = function (document, stylesheet, colorInfo) {
var result = [];
var color = colorInfo.color;
var red256 = Math.round(color.red * 255), green256 = Math.round(color.green * 255), blue256 = Math.round(color.blue * 255);
var label;
if (color.alpha === 1) {
label = "rgb(" + red256 + ", " + green256 + ", " + blue256 + ")";
}
else {
label = "rgba(" + red256 + ", " + green256 + ", " + blue256 + ", " + color.alpha + ")";
}
result.push({ label: label, textEdit: vscode_languageserver_types_1.TextEdit.replace(colorInfo.range, label) });
if (color.alpha === 1) {
label = "#" + toTwoDigitHex(red256) + toTwoDigitHex(green256) + toTwoDigitHex(blue256);
}
else {
label = "#" + toTwoDigitHex(red256) + toTwoDigitHex(green256) + toTwoDigitHex(blue256) + toTwoDigitHex(Math.round(color.alpha * 255));
}
result.push({ label: label, textEdit: vscode_languageserver_types_1.TextEdit.replace(colorInfo.range, label) });
var hsl = languageFacts_1.hslFromColor(color);
if (hsl.a === 1) {
label = "hsl(" + hsl.h + ", " + Math.round(hsl.s * 100) + "%, " + Math.round(hsl.l * 100) + "%)";
}
else {
label = "hsla(" + hsl.h + ", " + Math.round(hsl.s * 100) + "%, " + Math.round(hsl.l * 100) + "%, " + hsl.a + ")";
}
result.push({ label: label, textEdit: vscode_languageserver_types_1.TextEdit.replace(colorInfo.range, label) });
return result;
};
CSSNavigation.prototype.doRename = function (document, position, newName, stylesheet) {

@@ -185,3 +214,8 @@ var highlights = this.findDocumentHighlights(document, position, stylesheet);

}
function toTwoDigitHex(n) {
var r = n.toString(16);
return r.length !== 2 ? '0' + r : r;
}
;
});
//# sourceMappingURL=cssNavigation.js.map

98

lib/services/languageFacts.js

@@ -7,3 +7,3 @@ (function (factory) {

else if (typeof define === "function" && define.amd) {
define(["require", "exports", "../parser/cssNodes", "../data/browsers", "vscode-nls", "../utils/strings"], factory);
define(["require", "exports", "../parser/cssNodes", "../data/browsers", "vscode-nls"], factory);
}

@@ -20,3 +20,2 @@ })(function (require, exports) {

var nls = require("vscode-nls");
var strings_1 = require("../utils/strings");
var localize = nls.loadMessageBundle();

@@ -441,2 +440,33 @@ exports.colors = {

exports.colorFromHSL = colorFromHSL;
;
function hslFromColor(rgba) {
var r = rgba.red;
var g = rgba.green;
var b = rgba.blue;
var a = rgba.alpha;
var max = Math.max(r, g, b);
var min = Math.min(r, g, b);
var h = 0;
var s = 0;
var l = (min + max) / 2;
var chroma = max - min;
if (chroma > 0) {
s = Math.min((l <= 0.5 ? chroma / (2 * l) : chroma / (2 - (2 * l))), 1);
switch (max) {
case r:
h = (g - b) / chroma + (g < b ? 6 : 0);
break;
case g:
h = (b - r) / chroma + 2;
break;
case b:
h = (r - g) / chroma + 4;
break;
}
h *= 60;
h = Math.round(h);
}
return { h: h, s: s, l: l, a: a };
}
exports.hslFromColor = hslFromColor;
function getColorValue(node) {

@@ -451,19 +481,25 @@ if (node.type === nodes.NodeType.HexColorValue) {

var colorValues = functionNode.getArguments().getChildren();
if (!name && colorValues.length < 3 && colorValues.length > 4) {
if (!name || colorValues.length < 3 || colorValues.length > 4) {
return null;
}
var alpha = colorValues.length == 4 ? getNumericValue(colorValues[3], 1) : 1;
if (name === 'rgb' || name == 'rgba') {
return {
red: getNumericValue(colorValues[0], 255.0),
green: getNumericValue(colorValues[1], 255.0),
blue: getNumericValue(colorValues[2], 255.0),
alpha: alpha
};
try {
var alpha = colorValues.length == 4 ? getNumericValue(colorValues[3], 1) : 1;
if (name === 'rgb' || name == 'rgba') {
return {
red: getNumericValue(colorValues[0], 255.0),
green: getNumericValue(colorValues[1], 255.0),
blue: getNumericValue(colorValues[2], 255.0),
alpha: alpha
};
}
else if (name === 'hsl' || name == 'hsla') {
var h = getAngle(colorValues[0]);
var s = getNumericValue(colorValues[1], 100.0);
var l = getNumericValue(colorValues[2], 100.0);
return colorFromHSL(h, s, l, alpha);
}
}
else if (name === 'hsl' || name == 'hsla') {
var h = getAngle(colorValues[0]);
var s = getNumericValue(colorValues[1], 100.0);
var l = getNumericValue(colorValues[2], 100.0);
return colorFromHSL(h, s, l, alpha);
catch (e) {
// parse error on numeric value
return null;
}

@@ -488,11 +524,9 @@ }

function getNumericValue(node, factor) {
try {
var val = node.getText();
var result = void 0;
if (val[val.length - 1] === '%') {
result = parseInt(val.substr(0, val.length - 1)) / 100.0;
var val = node.getText();
var m = val.match(/^([-+]?[0-9]*\.?[0-9]+)(%?)$/);
if (m) {
if (m[2]) {
factor = 100.0;
}
else {
result = parseFloat(val) / factor;
}
var result = parseFloat(m[1]) / factor;
if (result >= 0 && result <= 1) {

@@ -502,17 +536,11 @@ return result;

}
catch (e) {
}
return 0; // error case
throw new Error();
}
function getAngle(node) {
try {
var val = node.getText();
if (strings_1.endsWith(val, 'deg')) {
val = val.substr(0, val.length - 3);
}
var val = node.getText();
var m = val.match(/^([-+]?[0-9]*\.?[0-9]+)(deg)?$/);
if (m) {
return parseFloat(val) % 360;
}
catch (e) {
}
return 0; // error case
throw new Error();
}

@@ -519,0 +547,0 @@ /**

{
"name": "vscode-css-languageservice",
"version": "2.1.6",
"version": "2.1.7",
"description": "Language service for CSS, LESS and SCSS",

@@ -5,0 +5,0 @@ "main": "./lib/cssLanguageService.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc