@master/css-language-service 2.0.0-rc.73 → 2.0.0-rc.74
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.
- package/LICENSE +21 -0
- package/dist/common.d.ts +2 -1
- package/dist/common.js +2 -0
- package/dist/core.d.ts +35 -32
- package/dist/core.js +107 -0
- package/dist/features/edit-syntax-colors.d.ts +8 -4
- package/dist/features/edit-syntax-colors.js +16 -0
- package/dist/features/inspect-syntax.d.ts +8 -4
- package/dist/features/inspect-syntax.js +37 -0
- package/dist/features/render-semantic-tokens.d.ts +9 -5
- package/dist/features/render-semantic-tokens.js +10 -0
- package/dist/features/render-syntax-colors.d.ts +8 -4
- package/dist/features/render-syntax-colors.js +93 -0
- package/dist/features/suggest-syntax.d.ts +9 -5
- package/dist/features/suggest-syntax.js +11 -0
- package/dist/index.d.ts +8 -7
- package/dist/index.js +8 -0
- package/dist/settings.d.ts +14 -11
- package/dist/settings.js +58 -0
- package/dist/utils/beautify-css.d.ts +4 -1
- package/dist/utils/beautify-css.js +10 -0
- package/dist/utils/completion-index.d.ts +37 -34
- package/dist/utils/completion-index.js +196 -0
- package/dist/utils/convert-color-token.d.ts +8 -4
- package/dist/utils/convert-color-token.js +47 -0
- package/dist/utils/create-css-markdown-documentation.d.ts +7 -4
- package/dist/utils/create-css-markdown-documentation.js +13 -0
- package/dist/utils/create-doc.d.ts +19 -15
- package/dist/utils/create-doc.js +21 -0
- package/dist/utils/get-class-completion-items.d.ts +8 -4
- package/dist/utils/get-class-completion-items.js +15 -0
- package/dist/utils/get-color-completion-items.d.ts +7 -3
- package/dist/utils/get-color-completion-items.js +22 -0
- package/dist/utils/get-position.d.ts +4 -1
- package/dist/utils/get-position.js +9 -0
- package/dist/utils/get-pseudo-class-completion-items.d.ts +8 -4
- package/dist/utils/get-pseudo-class-completion-items.js +64 -0
- package/dist/utils/get-pseudo-element-completion-items.d.ts +8 -4
- package/dist/utils/get-pseudo-element-completion-items.js +39 -0
- package/dist/utils/get-query-completion-items.d.ts +8 -4
- package/dist/utils/get-query-completion-items.js +62 -0
- package/dist/utils/get-range.d.ts +6 -2
- package/dist/utils/get-range.js +21 -0
- package/dist/utils/get-utility-info.d.ts +7 -3
- package/dist/utils/get-utility-info.js +16 -0
- package/dist/utils/get-value-completion-items.d.ts +8 -4
- package/dist/utils/get-value-completion-items.js +161 -0
- package/dist/utils/query-syntax-completions.d.ts +8 -4
- package/dist/utils/query-syntax-completions.js +78 -0
- package/dist/utils/regex.d.ts +4 -1
- package/dist/utils/{regex.mjs → regex.js} +2 -1
- package/dist/utils/sort-completion-items.d.ts +6 -2
- package/dist/utils/sort-completion-items.js +10 -0
- package/package.json +61 -1
- package/dist/common.mjs +0 -1
- package/dist/core.mjs +0 -116
- package/dist/features/edit-syntax-colors.mjs +0 -17
- package/dist/features/inspect-syntax.mjs +0 -54
- package/dist/features/render-semantic-tokens.mjs +0 -10
- package/dist/features/render-syntax-colors.mjs +0 -101
- package/dist/features/suggest-syntax.mjs +0 -18
- package/dist/index.mjs +0 -7
- package/dist/settings.mjs +0 -53
- package/dist/utils/beautify-css.mjs +0 -11
- package/dist/utils/completion-index.mjs +0 -269
- package/dist/utils/convert-color-token.mjs +0 -55
- package/dist/utils/create-css-markdown-documentation.mjs +0 -15
- package/dist/utils/create-doc.mjs +0 -21
- package/dist/utils/get-class-completion-items.mjs +0 -19
- package/dist/utils/get-color-completion-items.mjs +0 -24
- package/dist/utils/get-position.mjs +0 -10
- package/dist/utils/get-pseudo-class-completion-items.mjs +0 -68
- package/dist/utils/get-pseudo-element-completion-items.mjs +0 -43
- package/dist/utils/get-query-completion-items.mjs +0 -77
- package/dist/utils/get-range.mjs +0 -21
- package/dist/utils/get-utility-info.mjs +0 -19
- package/dist/utils/get-value-completion-items.mjs +0 -202
- package/dist/utils/query-syntax-completions.mjs +0 -94
- package/dist/utils/sort-completion-items.mjs +0 -11
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import createCSSMarkdownDocumentation from '../utils/create-css-markdown-documentation.mjs';
|
|
2
|
-
import { generateCSS } from '@master/css-language';
|
|
3
|
-
|
|
4
|
-
function inspectSyntax(document, position) {
|
|
5
|
-
const classPosition = this.getClassPosition(document, position);
|
|
6
|
-
if (!classPosition) return;
|
|
7
|
-
const { token } = classPosition;
|
|
8
|
-
const range = {
|
|
9
|
-
start: document.positionAt(classPosition.range.start),
|
|
10
|
-
end: document.positionAt(classPosition.range.end)
|
|
11
|
-
};
|
|
12
|
-
const utilities = this.css.generate(token);
|
|
13
|
-
const component = utilities.find((utility)=>utility.type === this.runtime.UtilityType.Semantic && utility.layerName === 'components');
|
|
14
|
-
if (component) {
|
|
15
|
-
const documentation = createCSSMarkdownDocumentation(generateCSS([
|
|
16
|
-
token
|
|
17
|
-
], this.css, this.runtime));
|
|
18
|
-
if (documentation) {
|
|
19
|
-
return {
|
|
20
|
-
contents: {
|
|
21
|
-
kind: documentation.kind,
|
|
22
|
-
value: `(components) ` + documentation.value
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
} else {
|
|
27
|
-
const utility = utilities[0];
|
|
28
|
-
if (utility) {
|
|
29
|
-
if (utility.type === this.runtime.UtilityType.Semantic) {
|
|
30
|
-
const documentation = createCSSMarkdownDocumentation(generateCSS([
|
|
31
|
-
token
|
|
32
|
-
], this.css, this.runtime));
|
|
33
|
-
if (documentation) {
|
|
34
|
-
return {
|
|
35
|
-
contents: documentation,
|
|
36
|
-
range
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
const documentation = createCSSMarkdownDocumentation(generateCSS([
|
|
41
|
-
token
|
|
42
|
-
], this.css, this.runtime));
|
|
43
|
-
if (documentation) {
|
|
44
|
-
return {
|
|
45
|
-
contents: documentation,
|
|
46
|
-
range
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export { inspectSyntax as default };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { renderSemanticTokens as renderSemanticTokens$1, renderSemanticTokensAtPosition as renderSemanticTokensAtPosition$1 } from '@master/css-language';
|
|
2
|
-
|
|
3
|
-
function renderSemanticTokensAtPosition(document, position) {
|
|
4
|
-
return renderSemanticTokensAtPosition$1(this.css, document, this.getClassContextPositions(document, position), position, this.settings);
|
|
5
|
-
}
|
|
6
|
-
function renderSemanticTokens(document) {
|
|
7
|
-
return renderSemanticTokens$1(this.css, document, this.getClassPositions(document), this.settings);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export { renderSemanticTokens as default, renderSemanticTokensAtPosition };
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { instancePattern } from '../utils/regex.mjs';
|
|
2
|
-
import Color from 'colorjs.io';
|
|
3
|
-
|
|
4
|
-
function resolveVariableColorValue(variable, variables) {
|
|
5
|
-
let current = variable;
|
|
6
|
-
for(let i = 0; i < 8; i++){
|
|
7
|
-
const value = current?.value;
|
|
8
|
-
if (value === undefined) return;
|
|
9
|
-
const text = String(value);
|
|
10
|
-
const alias = /^\$([a-zA-Z0-9-]+)(?: ?\/ ?.+?)?$|^var\(--([_a-zA-Z0-9-]+)\)$/.exec(text);
|
|
11
|
-
const aliasName = alias?.[1] ?? alias?.[2];
|
|
12
|
-
if (!aliasName) return text;
|
|
13
|
-
current = variables.get(aliasName);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async function renderSyntaxColors(document) {
|
|
17
|
-
const text = document.getText() ?? '';
|
|
18
|
-
const colorInformations = [];
|
|
19
|
-
try {
|
|
20
|
-
for (const instanceMatch of text.matchAll(instancePattern)){
|
|
21
|
-
if (instanceMatch.index === undefined) break;
|
|
22
|
-
const instanceStartIndex = instanceMatch.index;
|
|
23
|
-
const syntax = instanceMatch[0];
|
|
24
|
-
const rule = this.css.generate(syntax)[0];
|
|
25
|
-
if (rule && rule.type !== this.runtime.UtilityType.Semantic) {
|
|
26
|
-
const keyTokenLength = rule.keyToken?.length ?? 0;
|
|
27
|
-
let currentLength = 0;
|
|
28
|
-
const resolveValueComponent = (valueComponent)=>{
|
|
29
|
-
if (valueComponent.text === undefined) return; // text is always existing, just for type
|
|
30
|
-
const startOffset = instanceStartIndex + keyTokenLength + currentLength;
|
|
31
|
-
// TODO: check number mt:1.875rem
|
|
32
|
-
const valueComponentTokenLength = valueComponent.token.length;
|
|
33
|
-
let color;
|
|
34
|
-
switch(valueComponent.type){
|
|
35
|
-
case 'function':
|
|
36
|
-
if ([
|
|
37
|
-
'rgb',
|
|
38
|
-
'rgba',
|
|
39
|
-
'hsl',
|
|
40
|
-
'hsla',
|
|
41
|
-
'hwb',
|
|
42
|
-
'lab',
|
|
43
|
-
'lch',
|
|
44
|
-
'oklab',
|
|
45
|
-
'oklch',
|
|
46
|
-
'color'
|
|
47
|
-
].includes(valueComponent.name)) {
|
|
48
|
-
color = new Color(valueComponent.text);
|
|
49
|
-
} else if (valueComponent.children.length) {
|
|
50
|
-
currentLength += valueComponent.name.length + 1; // function name + '('
|
|
51
|
-
valueComponent.children.forEach(resolveValueComponent);
|
|
52
|
-
}
|
|
53
|
-
break;
|
|
54
|
-
case 'variable':
|
|
55
|
-
if (valueComponent.variable?.namespace?.startsWith('color') && valueComponent.variable.value !== undefined) {
|
|
56
|
-
color = new Color(resolveVariableColorValue(valueComponent.variable, this.css.variables) || String(valueComponent.variable.value));
|
|
57
|
-
if (valueComponent.alpha !== undefined) {
|
|
58
|
-
color.alpha *= valueComponent.alpha;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
case 'string':
|
|
63
|
-
if (valueComponent.text !== '#' && valueComponent.text?.startsWith('#')) {
|
|
64
|
-
color = new Color(valueComponent.text);
|
|
65
|
-
}
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
// check if rgba is valid
|
|
69
|
-
if (color) {
|
|
70
|
-
const rgbaColor = color.to('srgb');
|
|
71
|
-
colorInformations.push({
|
|
72
|
-
range: {
|
|
73
|
-
start: document.positionAt(startOffset),
|
|
74
|
-
end: document.positionAt(startOffset + valueComponentTokenLength)
|
|
75
|
-
},
|
|
76
|
-
color: {
|
|
77
|
-
red: rgbaColor.r ?? 0,
|
|
78
|
-
green: rgbaColor.g ?? 0,
|
|
79
|
-
blue: rgbaColor.b ?? 0,
|
|
80
|
-
alpha: Number(rgbaColor.alpha)
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
currentLength += valueComponentTokenLength || 0;
|
|
85
|
-
};
|
|
86
|
-
rule.valueComponents.forEach(resolveValueComponent);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} catch (e) {}
|
|
90
|
-
const colorIndexSet = new Set();
|
|
91
|
-
return colorInformations.filter((item)=>{
|
|
92
|
-
if (colorIndexSet.has(item.range.start)) {
|
|
93
|
-
return false;
|
|
94
|
-
} else {
|
|
95
|
-
colorIndexSet.add(item.range.start);
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export { renderSyntaxColors as default };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import querySyntaxCompletions from '../utils/query-syntax-completions.mjs';
|
|
2
|
-
|
|
3
|
-
function suggestSyntax(document, position, context, completionIndex) {
|
|
4
|
-
const classPosition = this.getClassPosition(document, position);
|
|
5
|
-
if (classPosition !== undefined) {
|
|
6
|
-
const q = context?.triggerCharacter === ' ' ? '' : document.getText({
|
|
7
|
-
start: document.positionAt(classPosition.range.start),
|
|
8
|
-
end: position
|
|
9
|
-
});
|
|
10
|
-
return querySyntaxCompletions(q, this.css, completionIndex);
|
|
11
|
-
}
|
|
12
|
-
// todo
|
|
13
|
-
// else if (isInstance === true && checkConfigColorsBlock(document, position) === true) {
|
|
14
|
-
// return getColorCompletionItems(this.css)
|
|
15
|
-
// }
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { suggestSyntax as default };
|
package/dist/index.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { default as CSSLanguageService, default } from './core.mjs';
|
|
2
|
-
export { default as settings } from './settings.mjs';
|
|
3
|
-
export { default as inspectSyntax } from './features/inspect-syntax.mjs';
|
|
4
|
-
export { default as renderSyntaxColors } from './features/render-syntax-colors.mjs';
|
|
5
|
-
export { default as editSyntaxColors } from './features/edit-syntax-colors.mjs';
|
|
6
|
-
export { default as suggestSyntax } from './features/suggest-syntax.mjs';
|
|
7
|
-
export { AT_TRIGGER_CHARACTER, DECLARATION_SEPARATOR_TRIGGER_CHARACTER, GROUP_TRIGGER_CHARACTER, INVOKED_TRIGGER_CHARACTERS, QUERY_TRIGGER_CHARACTERS, SELECTOR_TRIGGER_CHARACTERS, VALUE_TRIGGER_CHARACTERS } from '@master/css-language';
|
package/dist/settings.mjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { languageSettings } from '@master/css-language';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @example styles https://regex101.com/r/HLPdsw/1
|
|
5
|
-
**/ const settings = {
|
|
6
|
-
includedLanguages: [
|
|
7
|
-
"html",
|
|
8
|
-
"php",
|
|
9
|
-
"javascript",
|
|
10
|
-
"typescript",
|
|
11
|
-
"javascriptreact",
|
|
12
|
-
"typescriptreact",
|
|
13
|
-
"css",
|
|
14
|
-
"scss",
|
|
15
|
-
"less",
|
|
16
|
-
"vue",
|
|
17
|
-
"svelte",
|
|
18
|
-
"rust",
|
|
19
|
-
"astro",
|
|
20
|
-
"markdown",
|
|
21
|
-
"mdx",
|
|
22
|
-
"astro"
|
|
23
|
-
],
|
|
24
|
-
/**
|
|
25
|
-
* @example <div class="a b">
|
|
26
|
-
* @example <div className="a b">
|
|
27
|
-
*/ classAttributes: languageSettings.classAttributes,
|
|
28
|
-
/**
|
|
29
|
-
* @example <div class={active ? 'a' : 'b'}>
|
|
30
|
-
* @example <div className={active ? 'a' : 'b'}>
|
|
31
|
-
*/ classAttributeBindings: languageSettings.classAttributeBindings,
|
|
32
|
-
/**
|
|
33
|
-
* @example const classes = 'a b'
|
|
34
|
-
* @example { classes: { btn: 'a b' } }
|
|
35
|
-
*/ classDeclarations: languageSettings.classDeclarations,
|
|
36
|
-
/**
|
|
37
|
-
* @example clsx('a b')
|
|
38
|
-
* @example styled`a b`
|
|
39
|
-
* @example .classList.add('a')
|
|
40
|
-
*/ classFunctions: languageSettings.classFunctions,
|
|
41
|
-
exclude: [
|
|
42
|
-
"**/.git/**",
|
|
43
|
-
"**/node_modules/**",
|
|
44
|
-
"**/.hg/**"
|
|
45
|
-
],
|
|
46
|
-
suggestSyntax: true,
|
|
47
|
-
inspectSyntax: true,
|
|
48
|
-
renderSyntaxColors: true,
|
|
49
|
-
editSyntaxColors: true,
|
|
50
|
-
embeddedSyntaxHighlighting: 'active'
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export { settings as default };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { css_beautify } from 'js-beautify/js/lib/beautify-css.js';
|
|
2
|
-
|
|
3
|
-
// @ts-expect-error
|
|
4
|
-
function beautifyCSS(text) {
|
|
5
|
-
return css_beautify(text.replace(/@(media|container|supports|layer)\(/g, '@$1 ('), {
|
|
6
|
-
newline_between_rules: false,
|
|
7
|
-
indent_size: 2
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { beautifyCSS as default };
|
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import { CompletionItemKind } from 'vscode-languageserver-protocol';
|
|
2
|
-
import { defaultCSSLanguageRuntime, getMdnPseudoElementNames, getMdnPseudoClassNames, createDefaultCSS } from '@master/css-language';
|
|
3
|
-
import getUtilityInfo from './get-utility-info.mjs';
|
|
4
|
-
import sortCompletionItems from './sort-completion-items.mjs';
|
|
5
|
-
|
|
6
|
-
const ANIMATION_REFERENCE_PROPERTIES = new Set([
|
|
7
|
-
'animation',
|
|
8
|
-
'animation-name'
|
|
9
|
-
]);
|
|
10
|
-
function utilityMayReferenceAnimations(utility) {
|
|
11
|
-
const emit = utility.emit;
|
|
12
|
-
switch(emit.type){
|
|
13
|
-
case 'declarations':
|
|
14
|
-
return emit.declarations.some((property)=>ANIMATION_REFERENCE_PROPERTIES.has(property));
|
|
15
|
-
case 'property':
|
|
16
|
-
return ANIMATION_REFERENCE_PROPERTIES.has(emit.property);
|
|
17
|
-
case 'template':
|
|
18
|
-
return Object.keys(emit.declarations).some((property)=>ANIMATION_REFERENCE_PROPERTIES.has(property));
|
|
19
|
-
case 'static':
|
|
20
|
-
return emit.rules.some((rule)=>Object.keys(rule.declarations).some((property)=>ANIMATION_REFERENCE_PROPERTIES.has(property)));
|
|
21
|
-
default:
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function isPureNativePropertyUtility(utility) {
|
|
26
|
-
return utility.emit.type === 'property' && utility.id === utility.emit.property && utility.name === utility.emit.property;
|
|
27
|
-
}
|
|
28
|
-
function addMapValue(map, key, value) {
|
|
29
|
-
const values = map.get(key);
|
|
30
|
-
if (values) {
|
|
31
|
-
values.push(value);
|
|
32
|
-
} else {
|
|
33
|
-
map.set(key, [
|
|
34
|
-
value
|
|
35
|
-
]);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function collectClassEntries(css, runtime) {
|
|
39
|
-
const completionItems = [];
|
|
40
|
-
const addedKeys = new Set();
|
|
41
|
-
const addedCompletionLabels = new Set();
|
|
42
|
-
const propertyCompletionItem = {
|
|
43
|
-
kind: CompletionItemKind.Property,
|
|
44
|
-
command: {
|
|
45
|
-
title: 'triggerSuggest',
|
|
46
|
-
command: 'editor.action.triggerSuggest'
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const addPropertyCompletionItem = (key, detail)=>{
|
|
50
|
-
const label = key + ':';
|
|
51
|
-
if (addedCompletionLabels.has(label)) return;
|
|
52
|
-
addedCompletionLabels.add(label);
|
|
53
|
-
completionItems.push({
|
|
54
|
-
...propertyCompletionItem,
|
|
55
|
-
...detail ? {
|
|
56
|
-
detail
|
|
57
|
-
} : {},
|
|
58
|
-
label,
|
|
59
|
-
sortText: key
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
const addSemanticCompletionItem = (label, detail)=>{
|
|
63
|
-
if (addedCompletionLabels.has(label)) return;
|
|
64
|
-
addedCompletionLabels.add(label);
|
|
65
|
-
completionItems.push({
|
|
66
|
-
label,
|
|
67
|
-
kind: CompletionItemKind.Value,
|
|
68
|
-
documentationClassName: label,
|
|
69
|
-
...detail ? {
|
|
70
|
-
detail
|
|
71
|
-
} : {}
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
for (const eachDefinedUtility of css.definedUtilities){
|
|
75
|
-
if (eachDefinedUtility.type === runtime.UtilityType.Semantic) {
|
|
76
|
-
const isComponent = eachDefinedUtility.layer === 'components';
|
|
77
|
-
const { detail } = getUtilityInfo(eachDefinedUtility);
|
|
78
|
-
for (const matcher of eachDefinedUtility.matchers){
|
|
79
|
-
if (matcher.type === 'static') {
|
|
80
|
-
addSemanticCompletionItem(matcher.name, isComponent ? 'component' : detail);
|
|
81
|
-
} else if (matcher.type === 'pattern') {
|
|
82
|
-
for (const value of matcher.values){
|
|
83
|
-
addSemanticCompletionItem(matcher.prefix + value, isComponent ? 'component' : undefined);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
} else {
|
|
88
|
-
for (const matcher of eachDefinedUtility.matchers){
|
|
89
|
-
if (matcher.type !== 'pattern') continue;
|
|
90
|
-
for (const value of matcher.values){
|
|
91
|
-
addSemanticCompletionItem(matcher.prefix + value);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
eachDefinedUtility.keys?.forEach((key)=>{
|
|
95
|
-
addedKeys.delete(key);
|
|
96
|
-
addPropertyCompletionItem(key);
|
|
97
|
-
});
|
|
98
|
-
if (eachDefinedUtility.aliasGroups?.length) {
|
|
99
|
-
for (const aliasGroup of eachDefinedUtility.aliasGroups){
|
|
100
|
-
if (addedKeys.has(aliasGroup)) {
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
addedKeys.add(aliasGroup);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
for (const [key, canonicalKey] of Object.entries(runtime.builtinKeyAliases)){
|
|
109
|
-
addPropertyCompletionItem(key, canonicalKey);
|
|
110
|
-
}
|
|
111
|
-
for (const namespace of runtime.builtinNativeValueNamespaces){
|
|
112
|
-
for (const property of namespace.properties){
|
|
113
|
-
addPropertyCompletionItem(property);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
addedKeys.forEach((aliasGroup)=>{
|
|
117
|
-
/**
|
|
118
|
-
* Ambiguous keys are added to the completion list
|
|
119
|
-
* @example text: t:
|
|
120
|
-
*/ if (addedCompletionLabels.has(aliasGroup + ':')) return;
|
|
121
|
-
completionItems.push({
|
|
122
|
-
...propertyCompletionItem,
|
|
123
|
-
detail: 'ambiguous key',
|
|
124
|
-
label: aliasGroup + ':',
|
|
125
|
-
sortText: aliasGroup
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
return sortCompletionItems(completionItems);
|
|
129
|
-
}
|
|
130
|
-
function createPseudoClassSelectors(css) {
|
|
131
|
-
const selectors = new Map([
|
|
132
|
-
[
|
|
133
|
-
':of',
|
|
134
|
-
':of'
|
|
135
|
-
]
|
|
136
|
-
]);
|
|
137
|
-
for (const [token, branches] of css.variants){
|
|
138
|
-
const selector = branches.find((branch)=>branch.selector)?.selector;
|
|
139
|
-
if (selector && token.startsWith(':') && !token.startsWith('::')) {
|
|
140
|
-
selectors.set(token, selector);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return Array.from(selectors, ([token, selector])=>({
|
|
144
|
-
token,
|
|
145
|
-
selector
|
|
146
|
-
}));
|
|
147
|
-
}
|
|
148
|
-
function createPseudoElementSelectors(css) {
|
|
149
|
-
const selectors = [];
|
|
150
|
-
for (const [token, branches] of css.variants){
|
|
151
|
-
const selector = branches.find((branch)=>branch.selector)?.selector;
|
|
152
|
-
if (selector && token.startsWith('::')) {
|
|
153
|
-
selectors.push({
|
|
154
|
-
token,
|
|
155
|
-
selector
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return selectors;
|
|
160
|
-
}
|
|
161
|
-
function createNativeVariableNamespacesByProperty(runtime) {
|
|
162
|
-
const namespacesByProperty = new Map();
|
|
163
|
-
for (const namespace of runtime.builtinNativeValueNamespaces){
|
|
164
|
-
const variableNamespaces = (namespace.variableAliasRefs || []).map((ref)=>ref[0] === '=' || ref[0] === '~' ? ref.slice(1) : '').filter(Boolean);
|
|
165
|
-
if (!variableNamespaces.length) continue;
|
|
166
|
-
for (const property of namespace.properties){
|
|
167
|
-
const namespaces = namespacesByProperty.get(property);
|
|
168
|
-
if (namespaces) {
|
|
169
|
-
namespaces.push(...variableNamespaces);
|
|
170
|
-
} else {
|
|
171
|
-
namespacesByProperty.set(property, [
|
|
172
|
-
...variableNamespaces
|
|
173
|
-
]);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return namespacesByProperty;
|
|
178
|
-
}
|
|
179
|
-
function createCompletionIndex(css = createDefaultCSS(), runtime = defaultCSSLanguageRuntime) {
|
|
180
|
-
const componentNames = [];
|
|
181
|
-
const utilityNames = [];
|
|
182
|
-
const nativeUtilityKeys = new Map();
|
|
183
|
-
const scopedVariablesByKey = new Map();
|
|
184
|
-
const patternValuesByKey = new Map();
|
|
185
|
-
const animationUtilitiesByKey = new Map();
|
|
186
|
-
for (const utility of css.definedUtilities){
|
|
187
|
-
const staticNames = utility.type === runtime.UtilityType.Semantic ? utilityNames : undefined;
|
|
188
|
-
for (const matcher of utility.matchers){
|
|
189
|
-
if (matcher.type === 'static') {
|
|
190
|
-
staticNames?.push(matcher.name);
|
|
191
|
-
if (utility.type === runtime.UtilityType.Semantic && utility.layer === 'components') {
|
|
192
|
-
componentNames.push(matcher.name);
|
|
193
|
-
}
|
|
194
|
-
} else if (matcher.type === 'pattern') {
|
|
195
|
-
const patternNames = matcher.values.map((value)=>matcher.prefix + value);
|
|
196
|
-
utilityNames.push(...patternNames);
|
|
197
|
-
if (utility.type === runtime.UtilityType.Semantic && utility.layer === 'components') {
|
|
198
|
-
componentNames.push(...patternNames);
|
|
199
|
-
}
|
|
200
|
-
if (matcher.prefix.endsWith(':')) {
|
|
201
|
-
const key = matcher.prefix.slice(0, -1);
|
|
202
|
-
for (const value of matcher.values){
|
|
203
|
-
addMapValue(patternValuesByKey, key, {
|
|
204
|
-
value
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
for (const key of utility.keys || []){
|
|
211
|
-
if (!nativeUtilityKeys.has(key)) {
|
|
212
|
-
nativeUtilityKeys.set(key, utility.emit.type === 'property' ? utility.emit.property : utility.id);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
if (utility.variables?.size) {
|
|
216
|
-
const keys = new Set([
|
|
217
|
-
utility.key,
|
|
218
|
-
utility.subkey,
|
|
219
|
-
...utility.keys || [],
|
|
220
|
-
...utility.aliasGroups || []
|
|
221
|
-
].filter((key)=>Boolean(key)));
|
|
222
|
-
for (const key of keys){
|
|
223
|
-
utility.variables.forEach((variable, name)=>{
|
|
224
|
-
addMapValue(scopedVariablesByKey, key, {
|
|
225
|
-
name,
|
|
226
|
-
variable
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
if (utility.keys?.length && utilityMayReferenceAnimations(utility)) {
|
|
232
|
-
const detailPrefix = isPureNativePropertyUtility(utility) ? utility.id : undefined;
|
|
233
|
-
for (const key of utility.keys){
|
|
234
|
-
addMapValue(animationUtilitiesByKey, key, {
|
|
235
|
-
detailPrefix
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return {
|
|
241
|
-
runtime,
|
|
242
|
-
keyAliases: runtime.builtinKeyAliases,
|
|
243
|
-
classEntries: collectClassEntries(css, runtime),
|
|
244
|
-
componentNames,
|
|
245
|
-
utilityNames,
|
|
246
|
-
nativeUtilityKeys,
|
|
247
|
-
scopedVariablesByKey,
|
|
248
|
-
patternValuesByKey,
|
|
249
|
-
animationUtilitiesByKey,
|
|
250
|
-
nativeVariableNamespacesByProperty: createNativeVariableNamespacesByProperty(runtime),
|
|
251
|
-
variables: Array.from(css.variables.values()),
|
|
252
|
-
pseudoClassNames: getMdnPseudoClassNames(),
|
|
253
|
-
pseudoClassSelectors: createPseudoClassSelectors(css),
|
|
254
|
-
pseudoElementNames: getMdnPseudoElementNames(),
|
|
255
|
-
pseudoElementSelectors: createPseudoElementSelectors(css),
|
|
256
|
-
atRules: Array.from(css.atRules.entries())
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
function matchesIndexedName(field, name) {
|
|
260
|
-
if (!field.startsWith(name)) return false;
|
|
261
|
-
const nextCharacter = field.charAt(name.length);
|
|
262
|
-
if (nextCharacter === '_') return true;
|
|
263
|
-
const lastCharacter = name.charAt(name.length - 1);
|
|
264
|
-
const lastIsWord = /\w/.test(lastCharacter);
|
|
265
|
-
const nextIsWord = /\w/.test(nextCharacter);
|
|
266
|
-
return lastIsWord !== nextIsWord;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export { createCompletionIndex, matchesIndexedName };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import Color from 'colorjs.io';
|
|
2
|
-
|
|
3
|
-
function convertColorByToken(color, colorToken, css) {
|
|
4
|
-
const valueComponent = css.generate('color:' + colorToken)[0]?.valueComponents[0];
|
|
5
|
-
let outputSpace = 'srgb';
|
|
6
|
-
switch(valueComponent?.type){
|
|
7
|
-
case 'function':
|
|
8
|
-
outputSpace = valueComponent.name;
|
|
9
|
-
break;
|
|
10
|
-
case 'variable':
|
|
11
|
-
outputSpace = String(valueComponent.variable?.value || '').match(/^([a-zA-Z][\w-]*)\(/)?.[1] || outputSpace;
|
|
12
|
-
break;
|
|
13
|
-
case 'string':
|
|
14
|
-
outputSpace = 'srgb';
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
outputSpace = normalizeCSSColorFunctionName(outputSpace);
|
|
18
|
-
if (!outputSpace) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
return new Color({
|
|
22
|
-
space: 'srgb',
|
|
23
|
-
coords: [
|
|
24
|
-
color.red,
|
|
25
|
-
color.green,
|
|
26
|
-
color.blue
|
|
27
|
-
],
|
|
28
|
-
alpha: color.alpha
|
|
29
|
-
}).to(outputSpace).toString({
|
|
30
|
-
format: 'css',
|
|
31
|
-
precision: 4,
|
|
32
|
-
inGamut: false
|
|
33
|
-
}).replace(' / ', '/').replaceAll(' ', '|');
|
|
34
|
-
}
|
|
35
|
-
function normalizeCSSColorFunctionName(fn) {
|
|
36
|
-
switch(fn){
|
|
37
|
-
case 'rgb':
|
|
38
|
-
case 'rgba':
|
|
39
|
-
return 'srgb';
|
|
40
|
-
case 'hsla':
|
|
41
|
-
return 'hsl';
|
|
42
|
-
case 'display-p3':
|
|
43
|
-
case 'p3':
|
|
44
|
-
return 'p3';
|
|
45
|
-
case 'rec2020':
|
|
46
|
-
case 'rec.2020':
|
|
47
|
-
return 'rec2020';
|
|
48
|
-
case 'color':
|
|
49
|
-
return '';
|
|
50
|
-
default:
|
|
51
|
-
return fn;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export { convertColorByToken as default, normalizeCSSColorFunctionName };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import beautifyCSS from './beautify-css.mjs';
|
|
2
|
-
|
|
3
|
-
function createCSSMarkdownDocumentation(css) {
|
|
4
|
-
if (!css) return;
|
|
5
|
-
const cssLines = beautifyCSS(css).split('\n');
|
|
6
|
-
if (cssLines[0] === '') {
|
|
7
|
-
cssLines.shift();
|
|
8
|
-
}
|
|
9
|
-
return {
|
|
10
|
-
kind: 'markdown',
|
|
11
|
-
value: '```css\n' + cssLines.join('\n') + '\n```'
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { createCSSMarkdownDocumentation as default };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
-
|
|
3
|
-
const languageIdOfExt = {
|
|
4
|
-
ts: 'typescript',
|
|
5
|
-
tsx: 'typescriptreact',
|
|
6
|
-
js: 'javascript',
|
|
7
|
-
jsx: 'javascriptreact',
|
|
8
|
-
css: 'css',
|
|
9
|
-
scss: 'scss',
|
|
10
|
-
less: 'less',
|
|
11
|
-
html: 'html',
|
|
12
|
-
json: 'json',
|
|
13
|
-
vue: 'vue',
|
|
14
|
-
svelte: 'svelte',
|
|
15
|
-
astro: 'astro'
|
|
16
|
-
};
|
|
17
|
-
function createDoc(ext, content) {
|
|
18
|
-
return TextDocument.create(`file:///abc.${ext}`, languageIdOfExt[ext], 0, content);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { createDoc as default, languageIdOfExt };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { generateCSS, createDefaultCSS } from '@master/css-language';
|
|
2
|
-
import createCSSMarkdownDocumentation from './create-css-markdown-documentation.mjs';
|
|
3
|
-
import { createCompletionIndex } from './completion-index.mjs';
|
|
4
|
-
|
|
5
|
-
function getClassCompletionItems(css = createDefaultCSS(), completionIndex = createCompletionIndex(css)) {
|
|
6
|
-
return completionIndex.classEntries.map((entry)=>{
|
|
7
|
-
const { documentationClassName, ...completionItem } = entry;
|
|
8
|
-
return {
|
|
9
|
-
...completionItem,
|
|
10
|
-
...documentationClassName ? {
|
|
11
|
-
documentation: createCSSMarkdownDocumentation(generateCSS([
|
|
12
|
-
documentationClassName
|
|
13
|
-
], css, completionIndex.runtime))
|
|
14
|
-
} : {}
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { getClassCompletionItems as default };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { createDefaultCSS } from '@master/css-language';
|
|
2
|
-
import { CompletionItemKind } from 'vscode-languageserver-protocol';
|
|
3
|
-
import sortCompletionItems from './sort-completion-items.mjs';
|
|
4
|
-
|
|
5
|
-
function getColorCompletionItems(css = createDefaultCSS()) {
|
|
6
|
-
const completionItems = [];
|
|
7
|
-
css.variables.forEach((eachVariable, eachVariableName)=>{
|
|
8
|
-
if (eachVariable.namespace?.startsWith('color')) {
|
|
9
|
-
const valueToken = eachVariable.value ?? eachVariable.name;
|
|
10
|
-
completionItems.push({
|
|
11
|
-
label: eachVariableName,
|
|
12
|
-
// detail is shown in the detail pane
|
|
13
|
-
detail: String(valueToken),
|
|
14
|
-
// documentation is shown in the hover
|
|
15
|
-
documentation: String(valueToken),
|
|
16
|
-
kind: CompletionItemKind.Color,
|
|
17
|
-
sortText: eachVariableName.replace(/(.+?)-(\d+)/, (match, prefix, num)=>prefix + '-' + ('00000' + num).slice(-5))
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
return sortCompletionItems(completionItems);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { getColorCompletionItems as default };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
-
|
|
3
|
-
function getPosition(searchString, text) {
|
|
4
|
-
const document = TextDocument.create('mockuri://test', 'plaintext', 1, text);
|
|
5
|
-
const offset = text.indexOf(searchString);
|
|
6
|
-
const position = document.positionAt(offset);
|
|
7
|
-
return position;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export { getPosition as default };
|