@master/css-language-service 2.0.0-rc.8 → 2.0.0-rc.81

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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +129 -0
  3. package/dist/common.d.ts +2 -0
  4. package/dist/common.js +2 -0
  5. package/dist/core.d.ts +39 -0
  6. package/dist/core.js +111 -0
  7. package/dist/features/edit-syntax-colors.d.ts +8 -0
  8. package/dist/features/edit-syntax-colors.js +16 -0
  9. package/dist/features/format-directives.d.ts +7 -0
  10. package/dist/features/format-directives.js +72 -0
  11. package/dist/features/inspect-syntax.d.ts +8 -0
  12. package/dist/features/inspect-syntax.js +37 -0
  13. package/dist/features/render-semantic-tokens.d.ts +9 -0
  14. package/dist/features/render-semantic-tokens.js +10 -0
  15. package/dist/features/render-syntax-colors.d.ts +8 -0
  16. package/dist/features/render-syntax-colors.js +93 -0
  17. package/dist/features/suggest-syntax.d.ts +9 -0
  18. package/dist/features/suggest-syntax.js +11 -0
  19. package/dist/index.d.ts +8 -5
  20. package/dist/index.js +8 -0
  21. package/dist/settings.d.ts +20 -9
  22. package/dist/settings.js +59 -0
  23. package/dist/utils/beautify-css.d.ts +4 -0
  24. package/dist/utils/beautify-css.js +10 -0
  25. package/dist/utils/completion-index.d.ts +43 -0
  26. package/dist/utils/completion-index.js +196 -0
  27. package/dist/utils/convert-color-token.d.ts +8 -0
  28. package/dist/utils/convert-color-token.js +47 -0
  29. package/dist/utils/create-css-markdown-documentation.d.ts +8 -0
  30. package/dist/utils/create-css-markdown-documentation.js +13 -0
  31. package/dist/utils/create-doc.d.ts +20 -0
  32. package/dist/utils/create-doc.js +21 -0
  33. package/dist/utils/get-class-completion-items.d.ts +8 -0
  34. package/dist/utils/get-class-completion-items.js +15 -0
  35. package/dist/utils/get-color-completion-items.d.ts +7 -0
  36. package/dist/utils/get-color-completion-items.js +22 -0
  37. package/dist/utils/get-position.d.ts +4 -0
  38. package/dist/utils/get-position.js +9 -0
  39. package/dist/utils/get-pseudo-class-completion-items.d.ts +8 -0
  40. package/dist/utils/get-pseudo-class-completion-items.js +64 -0
  41. package/dist/utils/get-pseudo-element-completion-items.d.ts +8 -0
  42. package/dist/utils/get-pseudo-element-completion-items.js +39 -0
  43. package/dist/utils/get-query-completion-items.d.ts +8 -0
  44. package/dist/utils/get-query-completion-items.js +62 -0
  45. package/dist/utils/get-range.d.ts +6 -0
  46. package/dist/utils/get-range.js +21 -0
  47. package/dist/utils/get-utility-info.d.ts +8 -0
  48. package/dist/utils/get-utility-info.js +16 -0
  49. package/dist/utils/get-value-completion-items.d.ts +8 -0
  50. package/dist/utils/get-value-completion-items.js +165 -0
  51. package/dist/utils/query-syntax-completions.d.ts +8 -0
  52. package/dist/utils/query-syntax-completions.js +78 -0
  53. package/dist/utils/regex.d.ts +4 -1
  54. package/dist/utils/regex.js +4 -0
  55. package/dist/utils/sort-completion-items.d.ts +6 -0
  56. package/dist/utils/sort-completion-items.js +10 -0
  57. package/package.json +61 -1
  58. package/dist/constant.d.ts +0 -33
  59. package/dist/index.bundle.js +0 -33
  60. package/dist/position-check.d.ts +0 -20
  61. package/dist/providers/color.d.ts +0 -5
  62. package/dist/providers/completion.d.ts +0 -14
  63. package/dist/providers/hover.d.ts +0 -2
  64. package/dist/settings.bundle.js +0 -1
  65. package/dist/utils/get-css-entry-markdown-description.d.ts +0 -1
  66. package/dist/utils/hex-to-rgb.d.ts +0 -2
  67. package/dist/utils/oklab-to-rgb.d.ts +0 -1
  68. package/dist/utils/oklch-to-oklab.d.ts +0 -1
  69. package/dist/utils/to-two-digit-hex.d.ts +0 -1
@@ -1,9 +1,20 @@
1
- export declare const settings: {
2
- languages: string[];
3
- classMatch: string[];
4
- exclude: string[];
5
- suggestions: boolean;
6
- inspect: boolean;
7
- previewColors: boolean;
8
- config: string;
9
- };
1
+ import { LanguageSettings } from "@master/css-language";
2
+ import { MasterCSSManifest } from "@master/css";
3
+
4
+ //#region src/settings.d.ts
5
+ /**
6
+ * @example styles https://regex101.com/r/HLPdsw/1
7
+ **/
8
+ declare const settings: Settings;
9
+ declare interface Settings extends LanguageSettings {
10
+ includedLanguages?: string[];
11
+ exclude?: string[];
12
+ manifest?: MasterCSSManifest;
13
+ suggestSyntax?: boolean;
14
+ inspectSyntax?: boolean;
15
+ renderSyntaxColors?: boolean;
16
+ editSyntaxColors?: boolean;
17
+ formatDirectives?: boolean;
18
+ }
19
+ //#endregion
20
+ export { Settings, settings as default };
@@ -0,0 +1,59 @@
1
+ import { languageSettings } from "@master/css-language";
2
+ //#region src/settings.ts
3
+ /**
4
+ * @example styles https://regex101.com/r/HLPdsw/1
5
+ **/
6
+ const settings = {
7
+ includedLanguages: [
8
+ "html",
9
+ "php",
10
+ "javascript",
11
+ "typescript",
12
+ "javascriptreact",
13
+ "typescriptreact",
14
+ "css",
15
+ "scss",
16
+ "less",
17
+ "vue",
18
+ "svelte",
19
+ "rust",
20
+ "astro",
21
+ "markdown",
22
+ "mdx",
23
+ "astro"
24
+ ],
25
+ /**
26
+ * @example <div class="a b">
27
+ * @example <div className="a b">
28
+ */
29
+ classAttributes: languageSettings.classAttributes,
30
+ /**
31
+ * @example <div class={active ? 'a' : 'b'}>
32
+ * @example <div className={active ? 'a' : 'b'}>
33
+ */
34
+ classAttributeBindings: languageSettings.classAttributeBindings,
35
+ /**
36
+ * @example const classes = 'a b'
37
+ * @example { classes: { btn: 'a b' } }
38
+ */
39
+ classDeclarations: languageSettings.classDeclarations,
40
+ /**
41
+ * @example clsx('a b')
42
+ * @example styled`a b`
43
+ * @example .classList.add('a')
44
+ */
45
+ classFunctions: languageSettings.classFunctions,
46
+ exclude: [
47
+ "**/.git/**",
48
+ "**/node_modules/**",
49
+ "**/.hg/**"
50
+ ],
51
+ suggestSyntax: true,
52
+ inspectSyntax: true,
53
+ renderSyntaxColors: true,
54
+ editSyntaxColors: true,
55
+ formatDirectives: true,
56
+ embeddedSyntaxHighlighting: "active"
57
+ };
58
+ //#endregion
59
+ export { settings as default };
@@ -0,0 +1,4 @@
1
+ //#region src/utils/beautify-css.d.ts
2
+ declare function beautifyCSS(text: string): any;
3
+ //#endregion
4
+ export { beautifyCSS as default };
@@ -0,0 +1,10 @@
1
+ import { css_beautify } from "js-beautify/js/lib/beautify-css.js";
2
+ //#region src/utils/beautify-css.ts
3
+ function beautifyCSS(text) {
4
+ return css_beautify(text.replace(/@(media|container|supports|layer)\(/g, "@$1 ("), {
5
+ newline_between_rules: false,
6
+ indent_size: 2
7
+ });
8
+ }
9
+ //#endregion
10
+ export { beautifyCSS as default };
@@ -0,0 +1,43 @@
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;
7
+ }
8
+ interface PatternValueCandidate {
9
+ value: string;
10
+ }
11
+ interface ScopedVariableCandidate {
12
+ name: string;
13
+ variable: Variable;
14
+ }
15
+ interface AnimationUtilityCandidate {
16
+ detailPrefix?: string;
17
+ }
18
+ interface SelectorVariantCandidate {
19
+ token: string;
20
+ selector: string;
21
+ }
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][];
39
+ }
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 };
@@ -0,0 +1,8 @@
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 };
@@ -0,0 +1,8 @@
1
+ //#region src/utils/create-css-markdown-documentation.d.ts
2
+ interface CSSMarkdownDocumentation {
3
+ kind: 'markdown';
4
+ value: string;
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 };
@@ -0,0 +1,20 @@
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;
17
+ };
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 };
@@ -0,0 +1,8 @@
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 };
@@ -0,0 +1,7 @@
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 };
@@ -0,0 +1,4 @@
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 };
@@ -0,0 +1,8 @@
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 };
@@ -0,0 +1,8 @@
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 };