Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@codemirror/lang-css

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codemirror/lang-css - npm Package Compare versions

Comparing version 6.0.2 to 6.1.0

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## 6.1.0 (2023-03-06)
### New features
CSS completion can now complete variable names.
## 6.0.2 (2023-01-28)

@@ -2,0 +8,0 @@

2

dist/index.d.ts

@@ -5,3 +5,3 @@ import { LRLanguage, LanguageSupport } from '@codemirror/language';

/**
CSS property and value keyword completion source.
CSS property, variable, and value keyword completion source.
*/

@@ -8,0 +8,0 @@ declare const cssCompletionSource: CompletionSource;

import { parser } from '@lezer/css';
import { syntaxTree, LRLanguage, indentNodeProp, continuedIndent, foldNodeProp, foldInside, LanguageSupport } from '@codemirror/language';
import { NodeWeakMap, IterMode } from '@lezer/common';

@@ -130,9 +131,56 @@ let _properties = null;

].map(name => ({ type: "type", label: name }));
const identifier = /^[\w-]*/;
const identifier = /^(\w[\w-]*|-\w[\w-]*|)$/, variable = /^-(-[\w-]*)?$/;
function isVarArg(node, doc) {
var _a;
if (node.name == "(" || node.type.isError)
node = node.parent || node;
if (node.name != "ArgList")
return false;
let callee = (_a = node.parent) === null || _a === void 0 ? void 0 : _a.firstChild;
if ((callee === null || callee === void 0 ? void 0 : callee.name) != "Callee")
return false;
return doc.sliceString(callee.from, callee.to) == "var";
}
const VariablesByNode = /*@__PURE__*/new NodeWeakMap();
const declSelector = ["Declaration"];
function variableNames(doc, node) {
if (node.to - node.from > 4096) {
let known = VariablesByNode.get(node);
if (known)
return known;
let result = [], seen = new Set, cursor = node.cursor(IterMode.IncludeAnonymous);
if (cursor.firstChild())
do {
for (let option of variableNames(doc, cursor.node))
if (!seen.has(option.label)) {
seen.add(option.label);
result.push(option);
}
} while (cursor.nextSibling());
VariablesByNode.set(node, result);
return result;
}
else {
let result = [], seen = new Set;
node.cursor().iterate(node => {
var _a;
if (node.name == "VariableName" && node.matchContext(declSelector) && ((_a = node.node.nextSibling) === null || _a === void 0 ? void 0 : _a.name) == ":") {
let name = doc.sliceString(node.from, node.to);
if (!seen.has(name)) {
seen.add(name);
result.push({ label: name, type: "variable" });
}
}
});
return result;
}
}
/**
CSS property and value keyword completion source.
CSS property, variable, and value keyword completion source.
*/
const cssCompletionSource = context => {
var _a;
let { state, pos } = context, node = syntaxTree(state).resolveInner(pos, -1);
if (node.name == "PropertyName")
let isDash = node.type.isError && node.from == node.to - 1 && state.doc.sliceString(node.from, node.to) == "-";
if (node.name == "PropertyName" || isDash && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.name) == "Block")
return { from: node.from, options: properties(), validFor: identifier };

@@ -143,2 +191,6 @@ if (node.name == "ValueName")

return { from: node.from, options: pseudoClasses, validFor: identifier };
if (node.name == "VariableName" || (context.explicit || isDash) && isVarArg(node, state.doc))
return { from: node.name == "VariableName" ? node.from : pos,
options: variableNames(state.doc, syntaxTree(state).topNode),
validFor: variable };
if (node.name == "TagName") {

@@ -145,0 +197,0 @@ for (let { parent } = node; parent; parent = parent.parent)

{
"name": "@codemirror/lang-css",
"version": "6.0.2",
"version": "6.1.0",
"description": "CSS language support for the CodeMirror code editor",

@@ -5,0 +5,0 @@ "scripts": {

@@ -23,2 +23,3 @@ <!-- NOTE: README.md is generated from src/README.md -->

## API Reference
<dl>

@@ -31,3 +32,3 @@ <dt id="user-content-css">

<dt id="user-content-csslanguage">
<code><strong><a href="#user-content-csslanguage">cssLanguage</a></strong>: <a href="https://codemirror.net/docs/ref#language.LezerLanguage">LezerLanguage</a></code></dt>
<code><strong><a href="#user-content-csslanguage">cssLanguage</a></strong>: <a href="https://codemirror.net/docs/ref#language.LRLanguage">LRLanguage</a></code></dt>

@@ -38,7 +39,7 @@ <dd><p>A language provider based on the <a href="https://github.com/lezer-parser/css">Lezer CSS

</dd>
<dt id="user-content-csscompletion">
<code><strong><a href="#user-content-csscompletion">cssCompletion</a></strong>: <a href="https://codemirror.net/docs/ref#state.Extension">Extension</a></code></dt>
<dt id="user-content-csscompletionsource">
<code><strong><a href="#user-content-csscompletionsource">cssCompletionSource</a></strong>: <a href="https://codemirror.net/docs/ref#autocomplete.CompletionSource">CompletionSource</a></code></dt>
<dd><p>CSS property and value keyword completion.</p>
<dd><p>CSS property and value keyword completion source.</p>
</dd>
</dl>

Sorry, the diff of this file is not supported yet

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