@master/css-language-service 2.0.0-rc.73 → 2.0.0-rc.75
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,40 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { AtRule, CSSLanguageRuntime, MasterCSS, Variable } from "@master/css-language";
|
|
2
|
+
import { CompletionItem } from "vscode-languageserver-protocol";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/completion-index.d.ts
|
|
5
|
+
interface ClassCompletionEntry extends CompletionItem {
|
|
6
|
+
documentationClassName?: string;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
interface PatternValueCandidate {
|
|
9
|
+
value: string;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
interface ScopedVariableCandidate {
|
|
12
|
+
name: string;
|
|
13
|
+
variable: Variable;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
interface AnimationUtilityCandidate {
|
|
16
|
+
detailPrefix?: string;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
interface SelectorVariantCandidate {
|
|
19
|
+
token: string;
|
|
20
|
+
selector: string;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
interface CompletionIndex {
|
|
23
|
+
runtime: CSSLanguageRuntime;
|
|
24
|
+
keyAliases: CSSLanguageRuntime['builtinKeyAliases'];
|
|
25
|
+
classEntries: ClassCompletionEntry[];
|
|
26
|
+
componentNames: string[];
|
|
27
|
+
utilityNames: string[];
|
|
28
|
+
nativeUtilityKeys: Map<string, string>;
|
|
29
|
+
scopedVariablesByKey: Map<string, ScopedVariableCandidate[]>;
|
|
30
|
+
patternValuesByKey: Map<string, PatternValueCandidate[]>;
|
|
31
|
+
animationUtilitiesByKey: Map<string, AnimationUtilityCandidate[]>;
|
|
32
|
+
nativeVariableNamespacesByProperty: Map<string, string[]>;
|
|
33
|
+
variables: Variable[];
|
|
34
|
+
pseudoClassNames: string[];
|
|
35
|
+
pseudoClassSelectors: SelectorVariantCandidate[];
|
|
36
|
+
pseudoElementNames: string[];
|
|
37
|
+
pseudoElementSelectors: SelectorVariantCandidate[];
|
|
38
|
+
atRules: [string, AtRule][];
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
declare function createCompletionIndex(css?: MasterCSS, runtime?: CSSLanguageRuntime): CompletionIndex;
|
|
41
|
+
declare function matchesIndexedName(field: string, name: string): boolean;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { AnimationUtilityCandidate, ClassCompletionEntry, CompletionIndex, PatternValueCandidate, ScopedVariableCandidate, SelectorVariantCandidate, createCompletionIndex, matchesIndexedName };
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import sortCompletionItems from "./sort-completion-items.js";
|
|
2
|
+
import getUtilityInfo from "./get-utility-info.js";
|
|
3
|
+
import { createDefaultCSS, defaultCSSLanguageRuntime, getMdnPseudoClassNames, getMdnPseudoElementNames } from "@master/css-language";
|
|
4
|
+
import { CompletionItemKind } from "vscode-languageserver-protocol";
|
|
5
|
+
//#region src/utils/completion-index.ts
|
|
6
|
+
const ANIMATION_REFERENCE_PROPERTIES = /* @__PURE__ */ new Set(["animation", "animation-name"]);
|
|
7
|
+
function utilityMayReferenceAnimations(utility) {
|
|
8
|
+
const emit = utility.emit;
|
|
9
|
+
switch (emit.type) {
|
|
10
|
+
case "declarations": return emit.declarations.some((property) => ANIMATION_REFERENCE_PROPERTIES.has(property));
|
|
11
|
+
case "property": return ANIMATION_REFERENCE_PROPERTIES.has(emit.property);
|
|
12
|
+
case "template": return Object.keys(emit.declarations).some((property) => ANIMATION_REFERENCE_PROPERTIES.has(property));
|
|
13
|
+
case "static": return emit.rules.some((rule) => Object.keys(rule.declarations).some((property) => ANIMATION_REFERENCE_PROPERTIES.has(property)));
|
|
14
|
+
default: return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function isPureNativePropertyUtility(utility) {
|
|
18
|
+
return utility.emit.type === "property" && utility.id === utility.emit.property && utility.name === utility.emit.property;
|
|
19
|
+
}
|
|
20
|
+
function addMapValue(map, key, value) {
|
|
21
|
+
const values = map.get(key);
|
|
22
|
+
if (values) values.push(value);
|
|
23
|
+
else map.set(key, [value]);
|
|
24
|
+
}
|
|
25
|
+
function collectClassEntries(css, runtime) {
|
|
26
|
+
const completionItems = [];
|
|
27
|
+
const addedKeys = /* @__PURE__ */ new Set();
|
|
28
|
+
const addedCompletionLabels = /* @__PURE__ */ new Set();
|
|
29
|
+
const propertyCompletionItem = {
|
|
30
|
+
kind: CompletionItemKind.Property,
|
|
31
|
+
command: {
|
|
32
|
+
title: "triggerSuggest",
|
|
33
|
+
command: "editor.action.triggerSuggest"
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const addPropertyCompletionItem = (key, detail) => {
|
|
37
|
+
const label = key + ":";
|
|
38
|
+
if (addedCompletionLabels.has(label)) return;
|
|
39
|
+
addedCompletionLabels.add(label);
|
|
40
|
+
completionItems.push({
|
|
41
|
+
...propertyCompletionItem,
|
|
42
|
+
...detail ? { detail } : {},
|
|
43
|
+
label,
|
|
44
|
+
sortText: key
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
const addSemanticCompletionItem = (label, detail) => {
|
|
48
|
+
if (addedCompletionLabels.has(label)) return;
|
|
49
|
+
addedCompletionLabels.add(label);
|
|
50
|
+
completionItems.push({
|
|
51
|
+
label,
|
|
52
|
+
kind: CompletionItemKind.Value,
|
|
53
|
+
documentationClassName: label,
|
|
54
|
+
...detail ? { detail } : {}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
for (const eachDefinedUtility of css.definedUtilities) if (eachDefinedUtility.type === runtime.UtilityType.Semantic) {
|
|
58
|
+
const isComponent = eachDefinedUtility.layer === "components";
|
|
59
|
+
const { detail } = getUtilityInfo(eachDefinedUtility);
|
|
60
|
+
for (const matcher of eachDefinedUtility.matchers) if (matcher.type === "static") addSemanticCompletionItem(matcher.name, isComponent ? "component" : detail);
|
|
61
|
+
else if (matcher.type === "pattern") for (const value of matcher.values) addSemanticCompletionItem(matcher.prefix + value, isComponent ? "component" : void 0);
|
|
62
|
+
} else {
|
|
63
|
+
for (const matcher of eachDefinedUtility.matchers) {
|
|
64
|
+
if (matcher.type !== "pattern") continue;
|
|
65
|
+
for (const value of matcher.values) addSemanticCompletionItem(matcher.prefix + value);
|
|
66
|
+
}
|
|
67
|
+
eachDefinedUtility.keys?.forEach((key) => {
|
|
68
|
+
addedKeys.delete(key);
|
|
69
|
+
addPropertyCompletionItem(key);
|
|
70
|
+
});
|
|
71
|
+
if (eachDefinedUtility.aliasGroups?.length) for (const aliasGroup of eachDefinedUtility.aliasGroups) {
|
|
72
|
+
if (addedKeys.has(aliasGroup)) continue;
|
|
73
|
+
addedKeys.add(aliasGroup);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (const [key, canonicalKey] of Object.entries(runtime.builtinKeyAliases)) addPropertyCompletionItem(key, canonicalKey);
|
|
77
|
+
for (const namespace of runtime.builtinNativeValueNamespaces) for (const property of namespace.properties) addPropertyCompletionItem(property);
|
|
78
|
+
addedKeys.forEach((aliasGroup) => {
|
|
79
|
+
/**
|
|
80
|
+
* Ambiguous keys are added to the completion list
|
|
81
|
+
* @example text: t:
|
|
82
|
+
*/
|
|
83
|
+
if (addedCompletionLabels.has(aliasGroup + ":")) return;
|
|
84
|
+
completionItems.push({
|
|
85
|
+
...propertyCompletionItem,
|
|
86
|
+
detail: "ambiguous key",
|
|
87
|
+
label: aliasGroup + ":",
|
|
88
|
+
sortText: aliasGroup
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
return sortCompletionItems(completionItems);
|
|
92
|
+
}
|
|
93
|
+
function createPseudoClassSelectors(css) {
|
|
94
|
+
const selectors = /* @__PURE__ */ new Map([[":of", ":of"]]);
|
|
95
|
+
for (const [token, branches] of css.variants) {
|
|
96
|
+
const selector = branches.find((branch) => branch.selector)?.selector;
|
|
97
|
+
if (selector && token.startsWith(":") && !token.startsWith("::")) selectors.set(token, selector);
|
|
98
|
+
}
|
|
99
|
+
return Array.from(selectors, ([token, selector]) => ({
|
|
100
|
+
token,
|
|
101
|
+
selector
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
function createPseudoElementSelectors(css) {
|
|
105
|
+
const selectors = [];
|
|
106
|
+
for (const [token, branches] of css.variants) {
|
|
107
|
+
const selector = branches.find((branch) => branch.selector)?.selector;
|
|
108
|
+
if (selector && token.startsWith("::")) selectors.push({
|
|
109
|
+
token,
|
|
110
|
+
selector
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return selectors;
|
|
114
|
+
}
|
|
115
|
+
function createNativeVariableNamespacesByProperty(runtime) {
|
|
116
|
+
const namespacesByProperty = /* @__PURE__ */ new Map();
|
|
117
|
+
for (const namespace of runtime.builtinNativeValueNamespaces) {
|
|
118
|
+
const variableNamespaces = (namespace.variableAliasRefs || []).map((ref) => ref[0] === "=" || ref[0] === "~" ? ref.slice(1) : "").filter(Boolean);
|
|
119
|
+
if (!variableNamespaces.length) continue;
|
|
120
|
+
for (const property of namespace.properties) {
|
|
121
|
+
const namespaces = namespacesByProperty.get(property);
|
|
122
|
+
if (namespaces) namespaces.push(...variableNamespaces);
|
|
123
|
+
else namespacesByProperty.set(property, [...variableNamespaces]);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return namespacesByProperty;
|
|
127
|
+
}
|
|
128
|
+
function createCompletionIndex(css = createDefaultCSS(), runtime = defaultCSSLanguageRuntime) {
|
|
129
|
+
const componentNames = [];
|
|
130
|
+
const utilityNames = [];
|
|
131
|
+
const nativeUtilityKeys = /* @__PURE__ */ new Map();
|
|
132
|
+
const scopedVariablesByKey = /* @__PURE__ */ new Map();
|
|
133
|
+
const patternValuesByKey = /* @__PURE__ */ new Map();
|
|
134
|
+
const animationUtilitiesByKey = /* @__PURE__ */ new Map();
|
|
135
|
+
for (const utility of css.definedUtilities) {
|
|
136
|
+
const staticNames = utility.type === runtime.UtilityType.Semantic ? utilityNames : void 0;
|
|
137
|
+
for (const matcher of utility.matchers) if (matcher.type === "static") {
|
|
138
|
+
staticNames?.push(matcher.name);
|
|
139
|
+
if (utility.type === runtime.UtilityType.Semantic && utility.layer === "components") componentNames.push(matcher.name);
|
|
140
|
+
} else if (matcher.type === "pattern") {
|
|
141
|
+
const patternNames = matcher.values.map((value) => matcher.prefix + value);
|
|
142
|
+
utilityNames.push(...patternNames);
|
|
143
|
+
if (utility.type === runtime.UtilityType.Semantic && utility.layer === "components") componentNames.push(...patternNames);
|
|
144
|
+
if (matcher.prefix.endsWith(":")) {
|
|
145
|
+
const key = matcher.prefix.slice(0, -1);
|
|
146
|
+
for (const value of matcher.values) addMapValue(patternValuesByKey, key, { value });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (const key of utility.keys || []) if (!nativeUtilityKeys.has(key)) nativeUtilityKeys.set(key, utility.emit.type === "property" ? utility.emit.property : utility.id);
|
|
150
|
+
if (utility.variables?.size) {
|
|
151
|
+
const keys = new Set([
|
|
152
|
+
utility.key,
|
|
153
|
+
utility.subkey,
|
|
154
|
+
...utility.keys || [],
|
|
155
|
+
...utility.aliasGroups || []
|
|
156
|
+
].filter((key) => Boolean(key)));
|
|
157
|
+
for (const key of keys) utility.variables.forEach((variable, name) => {
|
|
158
|
+
addMapValue(scopedVariablesByKey, key, {
|
|
159
|
+
name,
|
|
160
|
+
variable
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
if (utility.keys?.length && utilityMayReferenceAnimations(utility)) {
|
|
165
|
+
const detailPrefix = isPureNativePropertyUtility(utility) ? utility.id : void 0;
|
|
166
|
+
for (const key of utility.keys) addMapValue(animationUtilitiesByKey, key, { detailPrefix });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
runtime,
|
|
171
|
+
keyAliases: runtime.builtinKeyAliases,
|
|
172
|
+
classEntries: collectClassEntries(css, runtime),
|
|
173
|
+
componentNames,
|
|
174
|
+
utilityNames,
|
|
175
|
+
nativeUtilityKeys,
|
|
176
|
+
scopedVariablesByKey,
|
|
177
|
+
patternValuesByKey,
|
|
178
|
+
animationUtilitiesByKey,
|
|
179
|
+
nativeVariableNamespacesByProperty: createNativeVariableNamespacesByProperty(runtime),
|
|
180
|
+
variables: Array.from(css.variables.values()),
|
|
181
|
+
pseudoClassNames: getMdnPseudoClassNames(),
|
|
182
|
+
pseudoClassSelectors: createPseudoClassSelectors(css),
|
|
183
|
+
pseudoElementNames: getMdnPseudoElementNames(),
|
|
184
|
+
pseudoElementSelectors: createPseudoElementSelectors(css),
|
|
185
|
+
atRules: Array.from(css.atRules.entries())
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function matchesIndexedName(field, name) {
|
|
189
|
+
if (!field.startsWith(name)) return false;
|
|
190
|
+
const nextCharacter = field.charAt(name.length);
|
|
191
|
+
if (nextCharacter === "_") return true;
|
|
192
|
+
const lastCharacter = name.charAt(name.length - 1);
|
|
193
|
+
return /\w/.test(lastCharacter) !== /\w/.test(nextCharacter);
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
export { createCompletionIndex, matchesIndexedName };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { MasterCSS } from "@master/css-language";
|
|
2
|
+
import { ColorPresentationParams } from "vscode-languageserver-protocol";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/convert-color-token.d.ts
|
|
5
|
+
declare function convertColorByToken(color: ColorPresentationParams['color'], colorToken: string, css: MasterCSS): string | undefined;
|
|
6
|
+
declare function normalizeCSSColorFunctionName(fn: string): string;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { convertColorByToken as default, normalizeCSSColorFunctionName };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Color from "colorjs.io";
|
|
2
|
+
//#region src/utils/convert-color-token.ts
|
|
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) return;
|
|
19
|
+
return new Color({
|
|
20
|
+
space: "srgb",
|
|
21
|
+
coords: [
|
|
22
|
+
color.red,
|
|
23
|
+
color.green,
|
|
24
|
+
color.blue
|
|
25
|
+
],
|
|
26
|
+
alpha: color.alpha
|
|
27
|
+
}).to(outputSpace).toString({
|
|
28
|
+
format: "css",
|
|
29
|
+
precision: 4,
|
|
30
|
+
inGamut: false
|
|
31
|
+
}).replace(" / ", "/").replaceAll(" ", "|");
|
|
32
|
+
}
|
|
33
|
+
function normalizeCSSColorFunctionName(fn) {
|
|
34
|
+
switch (fn) {
|
|
35
|
+
case "rgb":
|
|
36
|
+
case "rgba": return "srgb";
|
|
37
|
+
case "hsla": return "hsl";
|
|
38
|
+
case "display-p3":
|
|
39
|
+
case "p3": return "p3";
|
|
40
|
+
case "rec2020":
|
|
41
|
+
case "rec.2020": return "rec2020";
|
|
42
|
+
case "color": return "";
|
|
43
|
+
default: return fn;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { convertColorByToken as default, normalizeCSSColorFunctionName };
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/utils/create-css-markdown-documentation.d.ts
|
|
2
|
+
interface CSSMarkdownDocumentation {
|
|
3
|
+
kind: 'markdown';
|
|
4
|
+
value: string;
|
|
4
5
|
}
|
|
5
|
-
|
|
6
|
+
declare function createCSSMarkdownDocumentation(css: string): CSSMarkdownDocumentation | undefined;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { CSSMarkdownDocumentation, createCSSMarkdownDocumentation as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import beautifyCSS from "./beautify-css.js";
|
|
2
|
+
//#region src/utils/create-css-markdown-documentation.ts
|
|
3
|
+
function createCSSMarkdownDocumentation(css) {
|
|
4
|
+
if (!css) return;
|
|
5
|
+
const cssLines = beautifyCSS(css).split("\n");
|
|
6
|
+
if (cssLines[0] === "") cssLines.shift();
|
|
7
|
+
return {
|
|
8
|
+
kind: "markdown",
|
|
9
|
+
value: "```css\n" + cssLines.join("\n") + "\n```"
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { createCSSMarkdownDocumentation as default };
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { TextDocument } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/create-doc.d.ts
|
|
4
|
+
declare const languageIdOfExt: {
|
|
5
|
+
ts: string;
|
|
6
|
+
tsx: string;
|
|
7
|
+
js: string;
|
|
8
|
+
jsx: string;
|
|
9
|
+
css: string;
|
|
10
|
+
scss: string;
|
|
11
|
+
less: string;
|
|
12
|
+
html: string;
|
|
13
|
+
json: string;
|
|
14
|
+
vue: string;
|
|
15
|
+
svelte: string;
|
|
16
|
+
astro: string;
|
|
15
17
|
};
|
|
16
|
-
|
|
18
|
+
declare function createDoc(ext: keyof typeof languageIdOfExt, content: string): TextDocument;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { createDoc as default, languageIdOfExt };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
2
|
+
//#region src/utils/create-doc.ts
|
|
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
|
+
//#endregion
|
|
21
|
+
export { createDoc as default, languageIdOfExt };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { MasterCSS } from "@master/css-language";
|
|
2
|
+
import { CompletionItem } from "vscode-languageserver-protocol";
|
|
3
|
+
import { CompletionIndex } from "./completion-index.js";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/get-class-completion-items.d.ts
|
|
6
|
+
declare function getClassCompletionItems(css?: MasterCSS, completionIndex?: CompletionIndex): CompletionItem[];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getClassCompletionItems as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import createCSSMarkdownDocumentation from "./create-css-markdown-documentation.js";
|
|
2
|
+
import { createCompletionIndex } from "./completion-index.js";
|
|
3
|
+
import { createDefaultCSS, generateCSS } from "@master/css-language";
|
|
4
|
+
//#region src/utils/get-class-completion-items.ts
|
|
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 ? { documentation: createCSSMarkdownDocumentation(generateCSS([documentationClassName], css, completionIndex.runtime)) } : {}
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { getClassCompletionItems as default };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import { MasterCSS } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { MasterCSS } from "@master/css-language";
|
|
2
|
+
import { CompletionItem } from "vscode-languageserver-protocol";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/get-color-completion-items.d.ts
|
|
5
|
+
declare function getColorCompletionItems(css?: MasterCSS): CompletionItem[];
|
|
6
|
+
//#endregion
|
|
7
|
+
export { getColorCompletionItems as default };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import sortCompletionItems from "./sort-completion-items.js";
|
|
2
|
+
import { createDefaultCSS } from "@master/css-language";
|
|
3
|
+
import { CompletionItemKind } from "vscode-languageserver-protocol";
|
|
4
|
+
//#region src/utils/get-color-completion-items.ts
|
|
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: String(valueToken),
|
|
13
|
+
documentation: String(valueToken),
|
|
14
|
+
kind: CompletionItemKind.Color,
|
|
15
|
+
sortText: eachVariableName.replace(/(.+?)-(\d+)/, (match, prefix, num) => prefix + "-" + ("00000" + num).slice(-5))
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return sortCompletionItems(completionItems);
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { getColorCompletionItems as default };
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/utils/get-position.d.ts
|
|
2
|
+
declare function getPosition(searchString: string, text: string): import("vscode-languageserver-textdocument").Position;
|
|
3
|
+
//#endregion
|
|
4
|
+
export { getPosition as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
2
|
+
//#region src/utils/get-position.ts
|
|
3
|
+
function getPosition(searchString, text) {
|
|
4
|
+
const document = TextDocument.create("mockuri://test", "plaintext", 1, text);
|
|
5
|
+
const offset = text.indexOf(searchString);
|
|
6
|
+
return document.positionAt(offset);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { getPosition as default };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { MasterCSS } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { MasterCSS } from "@master/css-language";
|
|
2
|
+
import { CompletionItem } from "vscode-languageserver-protocol";
|
|
3
|
+
import { CompletionIndex } from "./completion-index.js";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/get-pseudo-class-completion-items.d.ts
|
|
6
|
+
declare function getPseudoClassCompletionItems(css: MasterCSS | undefined, syntax: string, completionIndex?: CompletionIndex): CompletionItem[];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getPseudoClassCompletionItems as default };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import createCSSMarkdownDocumentation from "./create-css-markdown-documentation.js";
|
|
2
|
+
import sortCompletionItems from "./sort-completion-items.js";
|
|
3
|
+
import { createCompletionIndex } from "./completion-index.js";
|
|
4
|
+
import { createDefaultCSS, generateCSS } from "@master/css-language";
|
|
5
|
+
import { CompletionItemKind } from "vscode-languageserver-protocol";
|
|
6
|
+
//#region src/utils/get-pseudo-class-completion-items.ts
|
|
7
|
+
const kind = CompletionItemKind.Function;
|
|
8
|
+
const functionalPseudoClassNames = /* @__PURE__ */ new Set([
|
|
9
|
+
":current",
|
|
10
|
+
":dir",
|
|
11
|
+
":has",
|
|
12
|
+
":has-slotted",
|
|
13
|
+
":host",
|
|
14
|
+
":host-context",
|
|
15
|
+
":is",
|
|
16
|
+
":lang",
|
|
17
|
+
":local-link",
|
|
18
|
+
":not",
|
|
19
|
+
":nth",
|
|
20
|
+
":nth-child",
|
|
21
|
+
":nth-col",
|
|
22
|
+
":nth-last",
|
|
23
|
+
":nth-last-child",
|
|
24
|
+
":nth-last-col",
|
|
25
|
+
":nth-last-of-type",
|
|
26
|
+
":nth-of-type",
|
|
27
|
+
":of",
|
|
28
|
+
":state",
|
|
29
|
+
":where"
|
|
30
|
+
]);
|
|
31
|
+
function normalizeFunctionalPseudoClass(name) {
|
|
32
|
+
return functionalPseudoClassNames.has(name) ? name + "()" : name;
|
|
33
|
+
}
|
|
34
|
+
function getPseudoClassCompletionItems(css = createDefaultCSS(), syntax, completionIndex = createCompletionIndex(css)) {
|
|
35
|
+
const completionItems = completionIndex.pseudoClassNames.map((pseudoClassName) => {
|
|
36
|
+
const name = normalizeFunctionalPseudoClass(pseudoClassName);
|
|
37
|
+
let sortText = name.startsWith(":-") ? "yyyy" + name.slice(2) : "yy" + name.replace(/^:/, "");
|
|
38
|
+
if (sortText.endsWith("()")) sortText = "y" + sortText;
|
|
39
|
+
return {
|
|
40
|
+
label: name,
|
|
41
|
+
sortText,
|
|
42
|
+
documentation: createCSSMarkdownDocumentation(generateCSS([syntax + name.slice(1)], css, completionIndex.runtime)),
|
|
43
|
+
kind
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
for (const { token: name, selector } of completionIndex.pseudoClassSelectors) {
|
|
47
|
+
if (name.startsWith("::")) continue;
|
|
48
|
+
const value = selector.replace(/&/g, "");
|
|
49
|
+
const label = normalizeFunctionalPseudoClass(name);
|
|
50
|
+
let sortText = label.startsWith(":-") ? "yyyy" + label.slice(2) : "yy" + label.replace(/^:/, "");
|
|
51
|
+
if (sortText.endsWith("()")) sortText = "y" + sortText;
|
|
52
|
+
const completionItem = {
|
|
53
|
+
label,
|
|
54
|
+
documentation: createCSSMarkdownDocumentation(generateCSS([syntax + label.slice(1)], css, completionIndex.runtime)),
|
|
55
|
+
sortText,
|
|
56
|
+
kind,
|
|
57
|
+
detail: String(value)
|
|
58
|
+
};
|
|
59
|
+
completionItems.push(completionItem);
|
|
60
|
+
}
|
|
61
|
+
return sortCompletionItems(completionItems);
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { getPseudoClassCompletionItems as default };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { MasterCSS } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { MasterCSS } from "@master/css-language";
|
|
2
|
+
import { CompletionItem } from "vscode-languageserver-protocol";
|
|
3
|
+
import { CompletionIndex } from "./completion-index.js";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/get-pseudo-element-completion-items.d.ts
|
|
6
|
+
declare function getPseudoElementCompletionItems(css: MasterCSS | undefined, syntax: string, completionIndex?: CompletionIndex): CompletionItem[];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getPseudoElementCompletionItems as default };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import createCSSMarkdownDocumentation from "./create-css-markdown-documentation.js";
|
|
2
|
+
import sortCompletionItems from "./sort-completion-items.js";
|
|
3
|
+
import { createCompletionIndex } from "./completion-index.js";
|
|
4
|
+
import { createDefaultCSS, generateCSS } from "@master/css-language";
|
|
5
|
+
import { CompletionItemKind } from "vscode-languageserver-protocol";
|
|
6
|
+
//#region src/utils/get-pseudo-element-completion-items.ts
|
|
7
|
+
const kind = CompletionItemKind.Function;
|
|
8
|
+
function getPseudoElementCompletionItems(css = createDefaultCSS(), syntax, completionIndex = createCompletionIndex(css)) {
|
|
9
|
+
const completionItems = completionIndex.pseudoElementNames.map((pseudoElementName) => {
|
|
10
|
+
const name = /::(?:part|slotted)/.test(pseudoElementName) ? pseudoElementName + "()" : pseudoElementName;
|
|
11
|
+
let sortText = name.startsWith("::-") ? "zzzz" + name.slice(3) : "zz" + name.replace(/^::/, "");
|
|
12
|
+
if (sortText.endsWith("()")) sortText = "z" + sortText;
|
|
13
|
+
return {
|
|
14
|
+
label: name,
|
|
15
|
+
sortText,
|
|
16
|
+
documentation: createCSSMarkdownDocumentation(generateCSS([syntax + name.slice(2)], css, completionIndex.runtime)),
|
|
17
|
+
kind
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
for (const variant of completionIndex.pseudoElementSelectors) {
|
|
21
|
+
const selectorName = variant.token;
|
|
22
|
+
const selectorValue = variant.selector.replace(/&/g, "");
|
|
23
|
+
const name = selectorName.endsWith("(") ? selectorName + ")" : selectorName;
|
|
24
|
+
const value = typeof selectorValue === "string" ? selectorValue.endsWith("(") ? selectorValue + ")" : selectorValue : selectorValue;
|
|
25
|
+
let sortText = name.startsWith("::-") ? "zzzz" + name.slice(3) : "zz" + name.replace(/^::/, "");
|
|
26
|
+
if (sortText.endsWith("()")) sortText = "z" + sortText;
|
|
27
|
+
const completionItem = {
|
|
28
|
+
label: name,
|
|
29
|
+
documentation: createCSSMarkdownDocumentation(generateCSS([syntax + name.slice(2)], css, completionIndex.runtime)),
|
|
30
|
+
sortText,
|
|
31
|
+
kind,
|
|
32
|
+
detail: String(value)
|
|
33
|
+
};
|
|
34
|
+
completionItems.push(completionItem);
|
|
35
|
+
}
|
|
36
|
+
return sortCompletionItems(completionItems);
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { getPseudoElementCompletionItems as default };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { MasterCSS } from
|
|
2
|
-
import { CompletionItem } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { MasterCSS } from "@master/css-language";
|
|
2
|
+
import { CompletionItem } from "vscode-languageserver-protocol";
|
|
3
|
+
import { CompletionIndex } from "./completion-index.js";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/get-query-completion-items.d.ts
|
|
6
|
+
declare function getQueryCompletionItems(css: MasterCSS | undefined, triggerCharacter: string | undefined, syntax: string, completionIndex?: CompletionIndex): CompletionItem[];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getQueryCompletionItems as default };
|