@master/css-language-service 2.0.0-rc.72 → 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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/dist/common.d.ts +2 -1
  3. package/dist/common.js +2 -0
  4. package/dist/core.d.ts +35 -32
  5. package/dist/core.js +107 -0
  6. package/dist/features/edit-syntax-colors.d.ts +8 -4
  7. package/dist/features/edit-syntax-colors.js +16 -0
  8. package/dist/features/inspect-syntax.d.ts +8 -4
  9. package/dist/features/inspect-syntax.js +37 -0
  10. package/dist/features/render-semantic-tokens.d.ts +9 -5
  11. package/dist/features/render-semantic-tokens.js +10 -0
  12. package/dist/features/render-syntax-colors.d.ts +8 -4
  13. package/dist/features/render-syntax-colors.js +93 -0
  14. package/dist/features/suggest-syntax.d.ts +9 -5
  15. package/dist/features/suggest-syntax.js +11 -0
  16. package/dist/index.d.ts +8 -7
  17. package/dist/index.js +8 -0
  18. package/dist/settings.d.ts +14 -11
  19. package/dist/settings.js +58 -0
  20. package/dist/utils/beautify-css.d.ts +4 -1
  21. package/dist/utils/beautify-css.js +10 -0
  22. package/dist/utils/completion-index.d.ts +37 -34
  23. package/dist/utils/completion-index.js +196 -0
  24. package/dist/utils/convert-color-token.d.ts +8 -4
  25. package/dist/utils/convert-color-token.js +47 -0
  26. package/dist/utils/create-css-markdown-documentation.d.ts +7 -4
  27. package/dist/utils/create-css-markdown-documentation.js +13 -0
  28. package/dist/utils/create-doc.d.ts +19 -15
  29. package/dist/utils/create-doc.js +21 -0
  30. package/dist/utils/get-class-completion-items.d.ts +8 -4
  31. package/dist/utils/get-class-completion-items.js +15 -0
  32. package/dist/utils/get-color-completion-items.d.ts +7 -3
  33. package/dist/utils/get-color-completion-items.js +22 -0
  34. package/dist/utils/get-position.d.ts +4 -1
  35. package/dist/utils/get-position.js +9 -0
  36. package/dist/utils/get-pseudo-class-completion-items.d.ts +8 -4
  37. package/dist/utils/get-pseudo-class-completion-items.js +64 -0
  38. package/dist/utils/get-pseudo-element-completion-items.d.ts +8 -4
  39. package/dist/utils/get-pseudo-element-completion-items.js +39 -0
  40. package/dist/utils/get-query-completion-items.d.ts +8 -4
  41. package/dist/utils/get-query-completion-items.js +62 -0
  42. package/dist/utils/get-range.d.ts +6 -2
  43. package/dist/utils/get-range.js +21 -0
  44. package/dist/utils/get-utility-info.d.ts +7 -3
  45. package/dist/utils/get-utility-info.js +16 -0
  46. package/dist/utils/get-value-completion-items.d.ts +8 -4
  47. package/dist/utils/get-value-completion-items.js +161 -0
  48. package/dist/utils/query-syntax-completions.d.ts +8 -4
  49. package/dist/utils/query-syntax-completions.js +78 -0
  50. package/dist/utils/regex.d.ts +4 -1
  51. package/dist/utils/{regex.mjs → regex.js} +2 -1
  52. package/dist/utils/sort-completion-items.d.ts +6 -2
  53. package/dist/utils/sort-completion-items.js +10 -0
  54. package/package.json +61 -1
  55. package/dist/common.mjs +0 -1
  56. package/dist/core.mjs +0 -116
  57. package/dist/features/edit-syntax-colors.mjs +0 -17
  58. package/dist/features/inspect-syntax.mjs +0 -54
  59. package/dist/features/render-semantic-tokens.mjs +0 -10
  60. package/dist/features/render-syntax-colors.mjs +0 -101
  61. package/dist/features/suggest-syntax.mjs +0 -18
  62. package/dist/index.mjs +0 -7
  63. package/dist/settings.mjs +0 -53
  64. package/dist/utils/beautify-css.mjs +0 -11
  65. package/dist/utils/completion-index.mjs +0 -269
  66. package/dist/utils/convert-color-token.mjs +0 -55
  67. package/dist/utils/create-css-markdown-documentation.mjs +0 -15
  68. package/dist/utils/create-doc.mjs +0 -21
  69. package/dist/utils/get-class-completion-items.mjs +0 -19
  70. package/dist/utils/get-color-completion-items.mjs +0 -24
  71. package/dist/utils/get-position.mjs +0 -10
  72. package/dist/utils/get-pseudo-class-completion-items.mjs +0 -68
  73. package/dist/utils/get-pseudo-element-completion-items.mjs +0 -43
  74. package/dist/utils/get-query-completion-items.mjs +0 -77
  75. package/dist/utils/get-range.mjs +0 -21
  76. package/dist/utils/get-utility-info.mjs +0 -19
  77. package/dist/utils/get-value-completion-items.mjs +0 -202
  78. package/dist/utils/query-syntax-completions.mjs +0 -94
  79. package/dist/utils/sort-completion-items.mjs +0 -11
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Aoyue Design LLC.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/dist/common.d.ts CHANGED
@@ -1 +1,2 @@
1
- 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';
1
+ import { 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";
2
+ export { AT_TRIGGER_CHARACTER, DECLARATION_SEPARATOR_TRIGGER_CHARACTER, GROUP_TRIGGER_CHARACTER, INVOKED_TRIGGER_CHARACTERS, QUERY_TRIGGER_CHARACTERS, SELECTOR_TRIGGER_CHARACTERS, VALUE_TRIGGER_CHARACTERS };
package/dist/common.js ADDED
@@ -0,0 +1,2 @@
1
+ import { 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";
2
+ export { AT_TRIGGER_CHARACTER, DECLARATION_SEPARATOR_TRIGGER_CHARACTER, GROUP_TRIGGER_CHARACTER, INVOKED_TRIGGER_CHARACTERS, QUERY_TRIGGER_CHARACTERS, SELECTOR_TRIGGER_CHARACTERS, VALUE_TRIGGER_CHARACTERS };
package/dist/core.d.ts CHANGED
@@ -1,34 +1,37 @@
1
- import { type CSSLanguageRuntime, type MasterCSS, type ClassPosition } from '@master/css-language';
2
- import EventEmitter from 'node:events';
3
- import type { Position } from 'vscode-languageserver-protocol';
4
- import { type Settings } from './settings';
5
- import inspectSyntax from './features/inspect-syntax';
6
- import renderSyntaxColors from './features/render-syntax-colors';
7
- import editSyntaxColors from './features/edit-syntax-colors';
8
- import renderSemanticTokens, { renderSemanticTokensAtPosition } from './features/render-semantic-tokens';
9
- import suggestSyntax from './features/suggest-syntax';
10
- import { TextDocument } from 'vscode-languageserver-textdocument';
11
- export type { ClassPosition };
12
- export interface CSSLanguageServiceOptions {
13
- runtime?: CSSLanguageRuntime;
1
+ import { CSSLanguageRuntime, ClassPosition, MasterCSS } from "@master/css-language";
2
+ import EventEmitter from "node:events";
3
+ import { Position } from "vscode-languageserver-protocol";
4
+ import { TextDocument } from "vscode-languageserver-textdocument";
5
+ import { Settings } from "./settings.js";
6
+ import inspectSyntax from "./features/inspect-syntax.js";
7
+ import renderSyntaxColors from "./features/render-syntax-colors.js";
8
+ import editSyntaxColors from "./features/edit-syntax-colors.js";
9
+ import renderSemanticTokens$1, { renderSemanticTokensAtPosition as renderSemanticTokensAtPosition$1 } from "./features/render-semantic-tokens.js";
10
+ import suggestSyntax from "./features/suggest-syntax.js";
11
+
12
+ //#region src/core.d.ts
13
+ interface CSSLanguageServiceOptions {
14
+ runtime?: CSSLanguageRuntime;
14
15
  }
15
- export default class CSSLanguageService extends EventEmitter {
16
- customSettings?: Settings | undefined;
17
- css: MasterCSS;
18
- runtime: CSSLanguageRuntime;
19
- settings: Settings;
20
- private completionIndex?;
21
- private classPositionCache;
22
- constructor(customSettings?: Settings | undefined, options?: CSSLanguageServiceOptions);
23
- private getCompletionIndex;
24
- inspectSyntax(...params: Parameters<typeof inspectSyntax>): import("vscode-languageserver-protocol").Hover | undefined;
25
- renderSyntaxColors(...params: Parameters<typeof renderSyntaxColors>): Promise<import("vscode-languageserver-protocol").ColorInformation[] | undefined> | undefined;
26
- editSyntaxColors(...params: Parameters<typeof editSyntaxColors>): import("vscode-languageserver-protocol").ColorPresentation[] | undefined;
27
- renderSemanticTokens(...params: Parameters<typeof renderSemanticTokens>): import("vscode-languageserver-protocol").SemanticTokens | undefined;
28
- renderSemanticTokensAtPosition(...params: Parameters<typeof renderSemanticTokensAtPosition>): import("vscode-languageserver-protocol").SemanticTokens | undefined;
29
- suggestSyntax(document: Parameters<typeof suggestSyntax>[0], position: Parameters<typeof suggestSyntax>[1], context: Parameters<typeof suggestSyntax>[2]): import("vscode-languageserver-protocol").CompletionItem[] | undefined;
30
- getClassPositions(textDocument: TextDocument): ClassPosition[];
31
- getClassPosition(textDocument: TextDocument, position: Position): ClassPosition | undefined;
32
- getClassContextPositions(textDocument: TextDocument, position: Position): ClassPosition[];
33
- isDocumentAccepted(doc: TextDocument): boolean;
16
+ declare class CSSLanguageService extends EventEmitter {
17
+ customSettings?: Settings | undefined;
18
+ css: MasterCSS;
19
+ runtime: CSSLanguageRuntime;
20
+ settings: Settings;
21
+ private completionIndex?;
22
+ private classPositionCache;
23
+ constructor(customSettings?: Settings | undefined, options?: CSSLanguageServiceOptions);
24
+ private getCompletionIndex;
25
+ inspectSyntax(...params: Parameters<typeof inspectSyntax>): import("vscode-languageserver-protocol").Hover | undefined;
26
+ renderSyntaxColors(...params: Parameters<typeof renderSyntaxColors>): Promise<import("vscode-languageserver-protocol").ColorInformation[] | undefined> | undefined;
27
+ editSyntaxColors(...params: Parameters<typeof editSyntaxColors>): import("vscode-languageserver-protocol").ColorPresentation[] | undefined;
28
+ renderSemanticTokens(...params: Parameters<typeof renderSemanticTokens$1>): import("vscode-languageserver-protocol").SemanticTokens | undefined;
29
+ renderSemanticTokensAtPosition(...params: Parameters<typeof renderSemanticTokensAtPosition$1>): import("vscode-languageserver-protocol").SemanticTokens | undefined;
30
+ suggestSyntax(document: Parameters<typeof suggestSyntax>[0], position: Parameters<typeof suggestSyntax>[1], context: Parameters<typeof suggestSyntax>[2]): import("vscode-languageserver-protocol").CompletionItem[] | undefined;
31
+ getClassPositions(textDocument: TextDocument): ClassPosition[];
32
+ getClassPosition(textDocument: TextDocument, position: Position): ClassPosition | undefined;
33
+ getClassContextPositions(textDocument: TextDocument, position: Position): ClassPosition[];
34
+ isDocumentAccepted(doc: TextDocument): boolean;
34
35
  }
36
+ //#endregion
37
+ export { CSSLanguageServiceOptions, type ClassPosition, CSSLanguageService as default };
package/dist/core.js ADDED
@@ -0,0 +1,107 @@
1
+ import settings from "./settings.js";
2
+ import inspectSyntax from "./features/inspect-syntax.js";
3
+ import renderSyntaxColors from "./features/render-syntax-colors.js";
4
+ import editSyntaxColors from "./features/edit-syntax-colors.js";
5
+ import renderSemanticTokens$1, { renderSemanticTokensAtPosition as renderSemanticTokensAtPosition$1 } from "./features/render-semantic-tokens.js";
6
+ import { createCompletionIndex } from "./utils/completion-index.js";
7
+ import suggestSyntax from "./features/suggest-syntax.js";
8
+ import { ClassPositionCache, defaultCSSLanguageRuntime, getClassPositions } from "@master/css-language";
9
+ import { defu } from "defu";
10
+ import EventEmitter from "node:events";
11
+ import { minimatch } from "minimatch";
12
+ //#region src/core.ts
13
+ var CSSLanguageService = class extends EventEmitter {
14
+ customSettings;
15
+ css;
16
+ runtime;
17
+ settings;
18
+ completionIndex;
19
+ classPositionCache = new ClassPositionCache();
20
+ constructor(customSettings, options = {}) {
21
+ super();
22
+ this.customSettings = customSettings;
23
+ this.runtime = options.runtime ?? defaultCSSLanguageRuntime;
24
+ this.settings = defu(customSettings, settings);
25
+ this.css = this.runtime.MasterCSS.create({
26
+ manifest: this.settings.manifest || this.runtime.defaultManifest,
27
+ nativeDeclarationMatcher: this.runtime.nativeDeclarationMatcher
28
+ });
29
+ }
30
+ getCompletionIndex() {
31
+ this.completionIndex ??= createCompletionIndex(this.css, this.runtime);
32
+ return this.completionIndex;
33
+ }
34
+ inspectSyntax(...params) {
35
+ if (this.settings.inspectSyntax && this.isDocumentAccepted(params[0])) return inspectSyntax?.call(this, ...params);
36
+ }
37
+ renderSyntaxColors(...params) {
38
+ if (this.settings.renderSyntaxColors && this.isDocumentAccepted(params[0])) return renderSyntaxColors?.call(this, ...params);
39
+ }
40
+ editSyntaxColors(...params) {
41
+ if (this.settings.editSyntaxColors && this.isDocumentAccepted(params[0])) return editSyntaxColors?.call(this, ...params);
42
+ }
43
+ renderSemanticTokens(...params) {
44
+ if (this.isDocumentAccepted(params[0])) return renderSemanticTokens$1?.call(this, ...params);
45
+ }
46
+ renderSemanticTokensAtPosition(...params) {
47
+ if (this.isDocumentAccepted(params[0])) return renderSemanticTokensAtPosition$1?.call(this, ...params);
48
+ }
49
+ suggestSyntax(document, position, context) {
50
+ if (this.settings.suggestSyntax && this.isDocumentAccepted(document)) return suggestSyntax?.call(this, document, position, context, this.getCompletionIndex());
51
+ }
52
+ getClassPositions(textDocument) {
53
+ return getClassPositions(textDocument, this.settings, { cache: this.classPositionCache });
54
+ }
55
+ getClassPosition(textDocument, position) {
56
+ const cachedOxcClassPosition = getClassPositions(textDocument, this.settings, {
57
+ position,
58
+ includeEmpty: true,
59
+ provider: "oxc",
60
+ oxcMode: "cache-only",
61
+ cache: this.classPositionCache
62
+ })[0];
63
+ if (cachedOxcClassPosition) return cachedOxcClassPosition;
64
+ const regexClassPosition = getClassPositions(textDocument, this.settings, {
65
+ position,
66
+ includeEmpty: true,
67
+ provider: "regex"
68
+ })[0];
69
+ if (regexClassPosition && !regexClassPosition.raw.includes("${")) return regexClassPosition;
70
+ return getClassPositions(textDocument, this.settings, {
71
+ position,
72
+ includeEmpty: true,
73
+ provider: "oxc",
74
+ cache: this.classPositionCache
75
+ })[0] ?? regexClassPosition;
76
+ }
77
+ getClassContextPositions(textDocument, position) {
78
+ const cachedOxcClassPositions = getClassPositions(textDocument, this.settings, {
79
+ position,
80
+ provider: "oxc",
81
+ oxcMode: "cache-only",
82
+ positionMatch: "context",
83
+ cache: this.classPositionCache
84
+ });
85
+ if (cachedOxcClassPositions.length) return cachedOxcClassPositions;
86
+ const regexClassPositions = getClassPositions(textDocument, this.settings, {
87
+ position,
88
+ provider: "regex",
89
+ positionMatch: "context"
90
+ });
91
+ if (regexClassPositions.length && regexClassPositions.every(({ raw }) => !raw.includes("${"))) return regexClassPositions;
92
+ const oxcClassPositions = getClassPositions(textDocument, this.settings, {
93
+ position,
94
+ provider: "oxc",
95
+ positionMatch: "context",
96
+ cache: this.classPositionCache
97
+ });
98
+ return oxcClassPositions.length ? oxcClassPositions : regexClassPositions;
99
+ }
100
+ isDocumentAccepted(doc) {
101
+ if (!this.settings.exclude) return true;
102
+ for (const exclude of this.settings.exclude) if (minimatch(doc.uri, exclude)) return false;
103
+ return true;
104
+ }
105
+ };
106
+ //#endregion
107
+ export { CSSLanguageService as default };
@@ -1,4 +1,8 @@
1
- import type { TextDocument } from 'vscode-languageserver-textdocument';
2
- import CSSLanguageService from '../core';
3
- import type { ColorPresentationParams, ColorPresentation } from 'vscode-languageserver-protocol';
4
- export default function editSyntaxColors(this: CSSLanguageService, document: TextDocument, color: ColorPresentationParams['color'], range: ColorPresentationParams['range']): ColorPresentation[];
1
+ import { ColorPresentation, ColorPresentationParams } from "vscode-languageserver-protocol";
2
+ import { TextDocument } from "vscode-languageserver-textdocument";
3
+ import CSSLanguageService from "../core.js";
4
+
5
+ //#region src/features/edit-syntax-colors.d.ts
6
+ declare function editSyntaxColors(this: CSSLanguageService, document: TextDocument, color: ColorPresentationParams['color'], range: ColorPresentationParams['range']): ColorPresentation[];
7
+ //#endregion
8
+ export { editSyntaxColors as default };
@@ -0,0 +1,16 @@
1
+ import convertColorByToken from "../utils/convert-color-token.js";
2
+ //#region src/features/edit-syntax-colors.ts
3
+ function editSyntaxColors(document, color, range) {
4
+ const colorPresentations = [];
5
+ const targetColorToken = convertColorByToken(color, document.getText(range), this.css);
6
+ if (targetColorToken) colorPresentations.push({
7
+ label: targetColorToken,
8
+ textEdit: {
9
+ range,
10
+ newText: targetColorToken
11
+ }
12
+ });
13
+ return colorPresentations;
14
+ }
15
+ //#endregion
16
+ export { editSyntaxColors as default };
@@ -1,4 +1,8 @@
1
- import type { Hover, HoverParams } from 'vscode-languageserver-protocol';
2
- import type CSSLanguageService from '../core';
3
- import type { TextDocument } from 'vscode-languageserver-textdocument';
4
- export default function inspectSyntax(this: CSSLanguageService, document: TextDocument, position: HoverParams['position']): Hover | undefined;
1
+ import { Hover, HoverParams } from "vscode-languageserver-protocol";
2
+ import { TextDocument } from "vscode-languageserver-textdocument";
3
+ import CSSLanguageService from "../core.js";
4
+
5
+ //#region src/features/inspect-syntax.d.ts
6
+ declare function inspectSyntax(this: CSSLanguageService, document: TextDocument, position: HoverParams['position']): Hover | undefined;
7
+ //#endregion
8
+ export { inspectSyntax as default };
@@ -0,0 +1,37 @@
1
+ import createCSSMarkdownDocumentation from "../utils/create-css-markdown-documentation.js";
2
+ import { generateCSS } from "@master/css-language";
3
+ //#region src/features/inspect-syntax.ts
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
+ if (utilities.find((utility) => utility.type === this.runtime.UtilityType.Semantic && utility.layerName === "components")) {
14
+ const documentation = createCSSMarkdownDocumentation(generateCSS([token], this.css, this.runtime));
15
+ if (documentation) return { contents: {
16
+ kind: documentation.kind,
17
+ value: `(components) ` + documentation.value
18
+ } };
19
+ } else {
20
+ const utility = utilities[0];
21
+ if (utility) if (utility.type === this.runtime.UtilityType.Semantic) {
22
+ const documentation = createCSSMarkdownDocumentation(generateCSS([token], this.css, this.runtime));
23
+ if (documentation) return {
24
+ contents: documentation,
25
+ range
26
+ };
27
+ } else {
28
+ const documentation = createCSSMarkdownDocumentation(generateCSS([token], this.css, this.runtime));
29
+ if (documentation) return {
30
+ contents: documentation,
31
+ range
32
+ };
33
+ }
34
+ }
35
+ }
36
+ //#endregion
37
+ export { inspectSyntax as default };
@@ -1,5 +1,9 @@
1
- import type CSSLanguageService from '../core';
2
- import type { TextDocument } from 'vscode-languageserver-textdocument';
3
- import type { SemanticTokens } from 'vscode-languageserver-protocol';
4
- export declare function renderSemanticTokensAtPosition(this: CSSLanguageService, document: TextDocument, position: Parameters<CSSLanguageService['getClassPosition']>[1]): SemanticTokens | undefined;
5
- export default function renderSemanticTokens(this: CSSLanguageService, document: TextDocument): SemanticTokens | undefined;
1
+ import { SemanticTokens } from "vscode-languageserver-protocol";
2
+ import { TextDocument } from "vscode-languageserver-textdocument";
3
+ import CSSLanguageService from "../core.js";
4
+
5
+ //#region src/features/render-semantic-tokens.d.ts
6
+ declare function renderSemanticTokensAtPosition(this: CSSLanguageService, document: TextDocument, position: Parameters<CSSLanguageService['getClassPosition']>[1]): SemanticTokens | undefined;
7
+ declare function renderSemanticTokens(this: CSSLanguageService, document: TextDocument): SemanticTokens | undefined;
8
+ //#endregion
9
+ export { renderSemanticTokens as default, renderSemanticTokensAtPosition };
@@ -0,0 +1,10 @@
1
+ import { renderSemanticTokens as renderSemanticTokens$1, renderSemanticTokensAtPosition as renderSemanticTokensAtPosition$1 } from "@master/css-language";
2
+ //#region src/features/render-semantic-tokens.ts
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
+ //#endregion
10
+ export { renderSemanticTokens as default, renderSemanticTokensAtPosition };
@@ -1,4 +1,8 @@
1
- import type { ColorInformation } from 'vscode-languageserver-protocol';
2
- import CSSLanguageService from '../core';
3
- import type { TextDocument } from 'vscode-languageserver-textdocument';
4
- export default function renderSyntaxColors(this: CSSLanguageService, document: TextDocument): Promise<ColorInformation[] | undefined>;
1
+ import { ColorInformation } from "vscode-languageserver-protocol";
2
+ import { TextDocument } from "vscode-languageserver-textdocument";
3
+ import CSSLanguageService from "../core.js";
4
+
5
+ //#region src/features/render-syntax-colors.d.ts
6
+ declare function renderSyntaxColors(this: CSSLanguageService, document: TextDocument): Promise<ColorInformation[] | undefined>;
7
+ //#endregion
8
+ export { renderSyntaxColors as default };
@@ -0,0 +1,93 @@
1
+ import { instancePattern } from "../utils/regex.js";
2
+ import Color from "colorjs.io";
3
+ //#region src/features/render-syntax-colors.ts
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 === void 0) 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 === void 0) 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 === void 0) return;
30
+ const startOffset = instanceStartIndex + keyTokenLength + currentLength;
31
+ const valueComponentTokenLength = valueComponent.token.length;
32
+ let color;
33
+ switch (valueComponent.type) {
34
+ case "function":
35
+ if ([
36
+ "rgb",
37
+ "rgba",
38
+ "hsl",
39
+ "hsla",
40
+ "hwb",
41
+ "lab",
42
+ "lch",
43
+ "oklab",
44
+ "oklch",
45
+ "color"
46
+ ].includes(valueComponent.name)) color = new Color(valueComponent.text);
47
+ else if (valueComponent.children.length) {
48
+ currentLength += valueComponent.name.length + 1;
49
+ valueComponent.children.forEach(resolveValueComponent);
50
+ }
51
+ break;
52
+ case "variable":
53
+ if (valueComponent.variable?.namespace?.startsWith("color") && valueComponent.variable.value !== void 0) {
54
+ color = new Color(resolveVariableColorValue(valueComponent.variable, this.css.variables) || String(valueComponent.variable.value));
55
+ if (valueComponent.alpha !== void 0) color.alpha *= valueComponent.alpha;
56
+ }
57
+ break;
58
+ case "string":
59
+ if (valueComponent.text !== "#" && valueComponent.text?.startsWith("#")) color = new Color(valueComponent.text);
60
+ break;
61
+ }
62
+ if (color) {
63
+ const rgbaColor = color.to("srgb");
64
+ colorInformations.push({
65
+ range: {
66
+ start: document.positionAt(startOffset),
67
+ end: document.positionAt(startOffset + valueComponentTokenLength)
68
+ },
69
+ color: {
70
+ red: rgbaColor.r ?? 0,
71
+ green: rgbaColor.g ?? 0,
72
+ blue: rgbaColor.b ?? 0,
73
+ alpha: Number(rgbaColor.alpha)
74
+ }
75
+ });
76
+ }
77
+ currentLength += valueComponentTokenLength || 0;
78
+ };
79
+ rule.valueComponents.forEach(resolveValueComponent);
80
+ }
81
+ }
82
+ } catch (e) {}
83
+ const colorIndexSet = /* @__PURE__ */ new Set();
84
+ return colorInformations.filter((item) => {
85
+ if (colorIndexSet.has(item.range.start)) return false;
86
+ else {
87
+ colorIndexSet.add(item.range.start);
88
+ return true;
89
+ }
90
+ });
91
+ }
92
+ //#endregion
93
+ export { renderSyntaxColors as default };
@@ -1,5 +1,9 @@
1
- import type { CompletionItem, CompletionParams } from 'vscode-languageserver-protocol';
2
- import type { TextDocument } from 'vscode-languageserver-textdocument';
3
- import CSSLanguageService from '../core';
4
- import type { CompletionIndex } from '../utils/completion-index';
5
- export default function suggestSyntax(this: CSSLanguageService, document: TextDocument, position: CompletionParams['position'], context: CompletionParams['context'], completionIndex?: CompletionIndex): CompletionItem[] | undefined;
1
+ import { CompletionItem, CompletionParams } from "vscode-languageserver-protocol";
2
+ import { TextDocument } from "vscode-languageserver-textdocument";
3
+ import CSSLanguageService from "../core.js";
4
+ import { CompletionIndex } from "../utils/completion-index.js";
5
+
6
+ //#region src/features/suggest-syntax.d.ts
7
+ declare function suggestSyntax(this: CSSLanguageService, document: TextDocument, position: CompletionParams['position'], context: CompletionParams['context'], completionIndex?: CompletionIndex): CompletionItem[] | undefined;
8
+ //#endregion
9
+ export { suggestSyntax as default };
@@ -0,0 +1,11 @@
1
+ import querySyntaxCompletions from "../utils/query-syntax-completions.js";
2
+ //#region src/features/suggest-syntax.ts
3
+ function suggestSyntax(document, position, context, completionIndex) {
4
+ const classPosition = this.getClassPosition(document, position);
5
+ if (classPosition !== void 0) return querySyntaxCompletions(context?.triggerCharacter === " " ? "" : document.getText({
6
+ start: document.positionAt(classPosition.range.start),
7
+ end: position
8
+ }), this.css, completionIndex);
9
+ }
10
+ //#endregion
11
+ export { suggestSyntax as default };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- export { default, default as CSSLanguageService, type CSSLanguageServiceOptions } from './core';
2
- export { default as settings, type Settings } from './settings';
3
- export * from './common';
4
- export { default as inspectSyntax } from './features/inspect-syntax';
5
- export { default as renderSyntaxColors } from './features/render-syntax-colors';
6
- export { default as editSyntaxColors } from './features/edit-syntax-colors';
7
- export { default as suggestSyntax } from './features/suggest-syntax';
1
+ import settings, { Settings } from "./settings.js";
2
+ import inspectSyntax from "./features/inspect-syntax.js";
3
+ import renderSyntaxColors from "./features/render-syntax-colors.js";
4
+ import editSyntaxColors from "./features/edit-syntax-colors.js";
5
+ import suggestSyntax from "./features/suggest-syntax.js";
6
+ import CSSLanguageService, { CSSLanguageServiceOptions, default as core_default } from "./core.js";
7
+ export * from "./common.js";
8
+ export { CSSLanguageService, type CSSLanguageServiceOptions, type Settings, core_default as default, editSyntaxColors, inspectSyntax, renderSyntaxColors, settings, suggestSyntax };
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import { AT_TRIGGER_CHARACTER, DECLARATION_SEPARATOR_TRIGGER_CHARACTER, GROUP_TRIGGER_CHARACTER, INVOKED_TRIGGER_CHARACTERS, QUERY_TRIGGER_CHARACTERS, SELECTOR_TRIGGER_CHARACTERS, VALUE_TRIGGER_CHARACTERS } from "./common.js";
2
+ import settings from "./settings.js";
3
+ import inspectSyntax from "./features/inspect-syntax.js";
4
+ import renderSyntaxColors from "./features/render-syntax-colors.js";
5
+ import editSyntaxColors from "./features/edit-syntax-colors.js";
6
+ import suggestSyntax from "./features/suggest-syntax.js";
7
+ import CSSLanguageService from "./core.js";
8
+ export { AT_TRIGGER_CHARACTER, CSSLanguageService, DECLARATION_SEPARATOR_TRIGGER_CHARACTER, GROUP_TRIGGER_CHARACTER, INVOKED_TRIGGER_CHARACTERS, QUERY_TRIGGER_CHARACTERS, SELECTOR_TRIGGER_CHARACTERS, VALUE_TRIGGER_CHARACTERS, CSSLanguageService as default, editSyntaxColors, inspectSyntax, renderSyntaxColors, settings, suggestSyntax };
@@ -1,16 +1,19 @@
1
- import { type LanguageSettings } from '@master/css-language';
2
- import type { MasterCSSManifest } from '@master/css';
1
+ import { LanguageSettings } from "@master/css-language";
2
+ import { MasterCSSManifest } from "@master/css";
3
+
4
+ //#region src/settings.d.ts
3
5
  /**
4
6
  * @example styles https://regex101.com/r/HLPdsw/1
5
7
  **/
6
8
  declare const settings: Settings;
7
- export default settings;
8
- export declare interface Settings extends LanguageSettings {
9
- includedLanguages?: string[];
10
- exclude?: string[];
11
- manifest?: MasterCSSManifest;
12
- suggestSyntax?: boolean;
13
- inspectSyntax?: boolean;
14
- renderSyntaxColors?: boolean;
15
- editSyntaxColors?: boolean;
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;
16
17
  }
18
+ //#endregion
19
+ export { Settings, settings as default };
@@ -0,0 +1,58 @@
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
+ embeddedSyntaxHighlighting: "active"
56
+ };
57
+ //#endregion
58
+ export { settings as default };
@@ -1 +1,4 @@
1
- export default function beautifyCSS(text: string): any;
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 };