@master/css-language-service 2.0.0-rc.67 → 2.0.0-rc.69

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 (30) hide show
  1. package/dist/core.cjs +1 -1
  2. package/dist/core.mjs +2 -2
  3. package/dist/features/edit-syntax-colors.cjs +1 -1
  4. package/dist/features/render-syntax-colors.cjs +68 -67
  5. package/dist/features/render-syntax-colors.mjs +68 -67
  6. package/dist/utils/convert-color-token.cjs +45 -13
  7. package/dist/utils/convert-color-token.d.ts +1 -0
  8. package/dist/utils/convert-color-token.mjs +42 -13
  9. package/dist/utils/get-color-completion-items.cjs +1 -1
  10. package/dist/utils/get-color-completion-items.mjs +2 -2
  11. package/dist/utils/get-css-data-documentation.cjs +2 -4
  12. package/dist/utils/get-css-data-documentation.mjs +2 -4
  13. package/dist/utils/get-main-completion-items.cjs +8 -8
  14. package/dist/utils/get-main-completion-items.mjs +9 -9
  15. package/dist/utils/get-pseudo-class-completion-items.cjs +1 -1
  16. package/dist/utils/get-pseudo-class-completion-items.mjs +2 -2
  17. package/dist/utils/get-pseudo-element-completion-items.cjs +1 -1
  18. package/dist/utils/get-pseudo-element-completion-items.mjs +2 -2
  19. package/dist/utils/get-query-completion-items.cjs +1 -1
  20. package/dist/utils/get-query-completion-items.mjs +2 -2
  21. package/dist/utils/get-utility-info.cjs +2 -1
  22. package/dist/utils/get-utility-info.mjs +2 -1
  23. package/dist/utils/get-value-completion-items.cjs +14 -15
  24. package/dist/utils/get-value-completion-items.mjs +15 -16
  25. package/dist/utils/query-syntax-completions.cjs +1 -1
  26. package/dist/utils/query-syntax-completions.mjs +2 -2
  27. package/package.json +1 -1
  28. package/dist/utils/convert-color-space.cjs +0 -40
  29. package/dist/utils/convert-color-space.d.ts +0 -2
  30. package/dist/utils/convert-color-space.mjs +0 -38
package/dist/core.cjs CHANGED
@@ -19,7 +19,7 @@ class CSSLanguageService extends EventEmitter {
19
19
  constructor(customSettings){
20
20
  super(), this.customSettings = customSettings;
21
21
  this.settings = extend(settings, customSettings);
22
- this.css = new css.MasterCSS(this.settings.config);
22
+ this.css = css.createCSS(this.settings.config);
23
23
  }
24
24
  inspectSyntax(...params) {
25
25
  if (this.settings.inspectSyntax && this.isDocumentAccepted(params[0])) return inspectSyntax?.call(this, ...params);
package/dist/core.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { MasterCSS } from '@master/css';
1
+ import { createCSS } from '@master/css';
2
2
  import extend from '@techor/extend';
3
3
  import EventEmitter from 'node:events';
4
4
  import settings from './settings.mjs';
@@ -17,7 +17,7 @@ class CSSLanguageService extends EventEmitter {
17
17
  constructor(customSettings){
18
18
  super(), this.customSettings = customSettings;
19
19
  this.settings = extend(settings, customSettings);
20
- this.css = new MasterCSS(this.settings.config);
20
+ this.css = createCSS(this.settings.config);
21
21
  }
22
22
  inspectSyntax(...params) {
23
23
  if (this.settings.inspectSyntax && this.isDocumentAccepted(params[0])) return inspectSyntax?.call(this, ...params);
@@ -5,7 +5,7 @@ var convertColorToken = require('../utils/convert-color-token.cjs');
5
5
  function editSyntaxColors(document, color, range) {
6
6
  const colorPresentations = [];
7
7
  const selectedColorToken = document.getText(range);
8
- const targetColorToken = convertColorToken(color, selectedColorToken, this.css);
8
+ const targetColorToken = convertColorToken.default(color, selectedColorToken, this.css);
9
9
  if (targetColorToken) colorPresentations.push({
10
10
  label: targetColorToken,
11
11
  textEdit: {
@@ -1,79 +1,80 @@
1
1
  'use strict';
2
2
 
3
3
  var regex = require('../utils/regex.cjs');
4
- var culori = require('culori');
4
+ var Color = require('colorjs.io');
5
5
  var css = require('@master/css');
6
6
 
7
7
  async function renderSyntaxColors(document) {
8
8
  const text = document.getText() ?? '';
9
9
  const colorInformations = [];
10
- for (const instanceMatch of text.matchAll(regex.instancePattern)){
11
- if (instanceMatch.index === undefined) break;
12
- const instanceStartIndex = instanceMatch.index;
13
- const syntax = instanceMatch[0];
14
- const rule = this.css.generate(syntax)[0];
15
- if (rule && rule.type !== css.SyntaxRuleType.Utility) {
16
- const keyTokenLength = rule.keyToken?.length ?? 0;
17
- let currentLength = 0;
18
- const resolveValueComponent = (valueComponent)=>{
19
- if (valueComponent.text === undefined) return; // text is always existing, just for type
20
- const startOffset = instanceStartIndex + keyTokenLength + currentLength;
21
- // TODO: check number mt:30
22
- const valueComponentTokenLength = valueComponent.token.length;
23
- let color;
24
- switch(valueComponent.type){
25
- case 'function':
26
- if ([
27
- 'rgb',
28
- 'rgba',
29
- 'hsl',
30
- 'hsla',
31
- 'hwb',
32
- 'lab',
33
- 'lch',
34
- 'oklab',
35
- 'oklch',
36
- 'color'
37
- ].includes(valueComponent.name)) {
38
- color = culori.parse(valueComponent.text);
39
- } else if (valueComponent.children.length) {
40
- currentLength += valueComponent.name.length + 1 // function name + '('
41
- ;
42
- valueComponent.children.forEach(resolveValueComponent);
43
- }
44
- break;
45
- case 'variable':
46
- if (valueComponent.variable?.type === 'color') {
47
- color = culori.parse(valueComponent.text);
48
- }
49
- break;
50
- case 'string':
51
- if (valueComponent.text !== '#' && valueComponent.text?.startsWith('#')) {
52
- color = culori.parse(valueComponent.text);
53
- }
54
- break;
55
- }
56
- // check if rgba is valid
57
- if (color) {
58
- const rgbaColor = color.mode !== 'rgb' ? culori.converter('rgb')(color) : color;
59
- colorInformations.push({
60
- range: {
61
- start: document.positionAt(startOffset),
62
- end: document.positionAt(startOffset + valueComponentTokenLength)
63
- },
64
- color: {
65
- red: rgbaColor.r,
66
- green: rgbaColor.g,
67
- blue: rgbaColor.b,
68
- alpha: rgbaColor.alpha === undefined ? 1 : rgbaColor.alpha
69
- }
70
- });
71
- }
72
- currentLength += valueComponentTokenLength || 0;
73
- };
74
- rule.valueComponents.forEach(resolveValueComponent);
10
+ try {
11
+ for (const instanceMatch of text.matchAll(regex.instancePattern)){
12
+ if (instanceMatch.index === undefined) break;
13
+ const instanceStartIndex = instanceMatch.index;
14
+ const syntax = instanceMatch[0];
15
+ const rule = this.css.generate(syntax)[0];
16
+ if (rule && rule.type !== css.SyntaxRuleType.Utility) {
17
+ const keyTokenLength = rule.keyToken?.length ?? 0;
18
+ let currentLength = 0;
19
+ const resolveValueComponent = (valueComponent)=>{
20
+ if (valueComponent.text === undefined) return; // text is always existing, just for type
21
+ const startOffset = instanceStartIndex + keyTokenLength + currentLength;
22
+ // TODO: check number mt:30
23
+ const valueComponentTokenLength = valueComponent.token.length;
24
+ let color;
25
+ switch(valueComponent.type){
26
+ case 'function':
27
+ if ([
28
+ 'rgb',
29
+ 'rgba',
30
+ 'hsl',
31
+ 'hsla',
32
+ 'hwb',
33
+ 'lab',
34
+ 'lch',
35
+ 'oklab',
36
+ 'oklch',
37
+ 'color'
38
+ ].includes(valueComponent.name)) {
39
+ color = new Color(valueComponent.text);
40
+ } else if (valueComponent.children.length) {
41
+ currentLength += valueComponent.name.length + 1; // function name + '('
42
+ valueComponent.children.forEach(resolveValueComponent);
43
+ }
44
+ break;
45
+ case 'variable':
46
+ if (valueComponent.variable?.type === 'color') {
47
+ color = new Color(valueComponent.text);
48
+ }
49
+ break;
50
+ case 'string':
51
+ if (valueComponent.text !== '#' && valueComponent.text?.startsWith('#')) {
52
+ color = new Color(valueComponent.text);
53
+ }
54
+ break;
55
+ }
56
+ // check if rgba is valid
57
+ if (color) {
58
+ const rgbaColor = color.to('srgb');
59
+ colorInformations.push({
60
+ range: {
61
+ start: document.positionAt(startOffset),
62
+ end: document.positionAt(startOffset + valueComponentTokenLength)
63
+ },
64
+ color: {
65
+ red: rgbaColor.r,
66
+ green: rgbaColor.g,
67
+ blue: rgbaColor.b,
68
+ alpha: Number(rgbaColor.alpha)
69
+ }
70
+ });
71
+ }
72
+ currentLength += valueComponentTokenLength || 0;
73
+ };
74
+ rule.valueComponents.forEach(resolveValueComponent);
75
+ }
75
76
  }
76
- }
77
+ } catch (e) {}
77
78
  const colorIndexSet = new Set();
78
79
  return colorInformations.filter((item)=>{
79
80
  if (colorIndexSet.has(item.range.start)) {
@@ -1,77 +1,78 @@
1
1
  import { instancePattern } from '../utils/regex.mjs';
2
- import { parse, converter } from 'culori';
2
+ import Color from 'colorjs.io';
3
3
  import { SyntaxRuleType } from '@master/css';
4
4
 
5
5
  async function renderSyntaxColors(document) {
6
6
  const text = document.getText() ?? '';
7
7
  const colorInformations = [];
8
- for (const instanceMatch of text.matchAll(instancePattern)){
9
- if (instanceMatch.index === undefined) break;
10
- const instanceStartIndex = instanceMatch.index;
11
- const syntax = instanceMatch[0];
12
- const rule = this.css.generate(syntax)[0];
13
- if (rule && rule.type !== SyntaxRuleType.Utility) {
14
- const keyTokenLength = rule.keyToken?.length ?? 0;
15
- let currentLength = 0;
16
- const resolveValueComponent = (valueComponent)=>{
17
- if (valueComponent.text === undefined) return; // text is always existing, just for type
18
- const startOffset = instanceStartIndex + keyTokenLength + currentLength;
19
- // TODO: check number mt:30
20
- const valueComponentTokenLength = valueComponent.token.length;
21
- let color;
22
- switch(valueComponent.type){
23
- case 'function':
24
- if ([
25
- 'rgb',
26
- 'rgba',
27
- 'hsl',
28
- 'hsla',
29
- 'hwb',
30
- 'lab',
31
- 'lch',
32
- 'oklab',
33
- 'oklch',
34
- 'color'
35
- ].includes(valueComponent.name)) {
36
- color = parse(valueComponent.text);
37
- } else if (valueComponent.children.length) {
38
- currentLength += valueComponent.name.length + 1 // function name + '('
39
- ;
40
- valueComponent.children.forEach(resolveValueComponent);
41
- }
42
- break;
43
- case 'variable':
44
- if (valueComponent.variable?.type === 'color') {
45
- color = parse(valueComponent.text);
46
- }
47
- break;
48
- case 'string':
49
- if (valueComponent.text !== '#' && valueComponent.text?.startsWith('#')) {
50
- color = parse(valueComponent.text);
51
- }
52
- break;
53
- }
54
- // check if rgba is valid
55
- if (color) {
56
- const rgbaColor = color.mode !== 'rgb' ? converter('rgb')(color) : color;
57
- colorInformations.push({
58
- range: {
59
- start: document.positionAt(startOffset),
60
- end: document.positionAt(startOffset + valueComponentTokenLength)
61
- },
62
- color: {
63
- red: rgbaColor.r,
64
- green: rgbaColor.g,
65
- blue: rgbaColor.b,
66
- alpha: rgbaColor.alpha === undefined ? 1 : rgbaColor.alpha
67
- }
68
- });
69
- }
70
- currentLength += valueComponentTokenLength || 0;
71
- };
72
- rule.valueComponents.forEach(resolveValueComponent);
8
+ try {
9
+ for (const instanceMatch of text.matchAll(instancePattern)){
10
+ if (instanceMatch.index === undefined) break;
11
+ const instanceStartIndex = instanceMatch.index;
12
+ const syntax = instanceMatch[0];
13
+ const rule = this.css.generate(syntax)[0];
14
+ if (rule && rule.type !== SyntaxRuleType.Utility) {
15
+ const keyTokenLength = rule.keyToken?.length ?? 0;
16
+ let currentLength = 0;
17
+ const resolveValueComponent = (valueComponent)=>{
18
+ if (valueComponent.text === undefined) return; // text is always existing, just for type
19
+ const startOffset = instanceStartIndex + keyTokenLength + currentLength;
20
+ // TODO: check number mt:30
21
+ const valueComponentTokenLength = valueComponent.token.length;
22
+ let color;
23
+ switch(valueComponent.type){
24
+ case 'function':
25
+ if ([
26
+ 'rgb',
27
+ 'rgba',
28
+ 'hsl',
29
+ 'hsla',
30
+ 'hwb',
31
+ 'lab',
32
+ 'lch',
33
+ 'oklab',
34
+ 'oklch',
35
+ 'color'
36
+ ].includes(valueComponent.name)) {
37
+ color = new Color(valueComponent.text);
38
+ } else if (valueComponent.children.length) {
39
+ currentLength += valueComponent.name.length + 1; // function name + '('
40
+ valueComponent.children.forEach(resolveValueComponent);
41
+ }
42
+ break;
43
+ case 'variable':
44
+ if (valueComponent.variable?.type === 'color') {
45
+ color = new Color(valueComponent.text);
46
+ }
47
+ break;
48
+ case 'string':
49
+ if (valueComponent.text !== '#' && valueComponent.text?.startsWith('#')) {
50
+ color = new Color(valueComponent.text);
51
+ }
52
+ break;
53
+ }
54
+ // check if rgba is valid
55
+ if (color) {
56
+ const rgbaColor = color.to('srgb');
57
+ colorInformations.push({
58
+ range: {
59
+ start: document.positionAt(startOffset),
60
+ end: document.positionAt(startOffset + valueComponentTokenLength)
61
+ },
62
+ color: {
63
+ red: rgbaColor.r,
64
+ green: rgbaColor.g,
65
+ blue: rgbaColor.b,
66
+ alpha: Number(rgbaColor.alpha)
67
+ }
68
+ });
69
+ }
70
+ currentLength += valueComponentTokenLength || 0;
71
+ };
72
+ rule.valueComponents.forEach(resolveValueComponent);
73
+ }
73
74
  }
74
- }
75
+ } catch (e) {}
75
76
  const colorIndexSet = new Set();
76
77
  return colorInformations.filter((item)=>{
77
78
  if (colorIndexSet.has(item.range.start)) {
@@ -1,28 +1,60 @@
1
1
  'use strict';
2
2
 
3
- var convertColorSpace = require('./convert-color-space.cjs');
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var Color = require('colorjs.io');
4
6
 
5
7
  function convertColorByToken(color, colorToken, css) {
6
8
  const valueComponent = css.generate('color:' + colorToken)[0]?.valueComponents[0];
7
- let outputColorSpace = 'hex';
9
+ let outputSpace = 'srgb';
8
10
  switch(valueComponent?.type){
9
11
  case 'function':
10
- outputColorSpace = valueComponent.name;
12
+ outputSpace = valueComponent.name;
11
13
  break;
12
14
  case 'variable':
13
- outputColorSpace = valueComponent.variable?.space;
15
+ outputSpace = valueComponent.variable?.space;
14
16
  break;
15
17
  case 'string':
16
- outputColorSpace = 'hex';
18
+ outputSpace = 'srgb';
17
19
  break;
18
20
  }
19
- return convertColorSpace({
20
- r: color.red,
21
- g: color.green,
22
- b: color.blue,
23
- alpha: color.alpha,
24
- mode: 'rgb'
25
- }, outputColorSpace);
21
+ outputSpace = normalizeCSSColorFunctionName(outputSpace);
22
+ if (!outputSpace) {
23
+ return;
24
+ }
25
+ return new Color({
26
+ space: 'srgb',
27
+ coords: [
28
+ color.red,
29
+ color.green,
30
+ color.blue
31
+ ],
32
+ alpha: color.alpha
33
+ }).to(outputSpace).toString({
34
+ format: 'css',
35
+ precision: 4,
36
+ inGamut: false
37
+ }).replace(' / ', '/').replaceAll(' ', '|');
38
+ }
39
+ function normalizeCSSColorFunctionName(fn) {
40
+ switch(fn){
41
+ case 'rgb':
42
+ case 'rgba':
43
+ return 'srgb';
44
+ case 'hsla':
45
+ return 'hsl';
46
+ case 'display-p3':
47
+ case 'p3':
48
+ return 'p3';
49
+ case 'rec2020':
50
+ case 'rec.2020':
51
+ return 'rec2020';
52
+ case 'color':
53
+ return '';
54
+ default:
55
+ return fn;
56
+ }
26
57
  }
27
58
 
28
- module.exports = convertColorByToken;
59
+ exports.default = convertColorByToken;
60
+ exports.normalizeCSSColorFunctionName = normalizeCSSColorFunctionName;
@@ -1,3 +1,4 @@
1
1
  import type { MasterCSS } from '@master/css';
2
2
  import type { ColorPresentationParams } from 'vscode-languageserver-protocol';
3
3
  export default function convertColorByToken(color: ColorPresentationParams['color'], colorToken: string, css: MasterCSS): string | undefined;
4
+ export declare function normalizeCSSColorFunctionName(fn: string): string;
@@ -1,26 +1,55 @@
1
- import convertColorSpace from './convert-color-space.mjs';
1
+ import Color from 'colorjs.io';
2
2
 
3
3
  function convertColorByToken(color, colorToken, css) {
4
4
  const valueComponent = css.generate('color:' + colorToken)[0]?.valueComponents[0];
5
- let outputColorSpace = 'hex';
5
+ let outputSpace = 'srgb';
6
6
  switch(valueComponent?.type){
7
7
  case 'function':
8
- outputColorSpace = valueComponent.name;
8
+ outputSpace = valueComponent.name;
9
9
  break;
10
10
  case 'variable':
11
- outputColorSpace = valueComponent.variable?.space;
11
+ outputSpace = valueComponent.variable?.space;
12
12
  break;
13
13
  case 'string':
14
- outputColorSpace = 'hex';
14
+ outputSpace = 'srgb';
15
15
  break;
16
16
  }
17
- return convertColorSpace({
18
- r: color.red,
19
- g: color.green,
20
- b: color.blue,
21
- alpha: color.alpha,
22
- mode: 'rgb'
23
- }, outputColorSpace);
17
+ outputSpace = normalizeCSSColorFunctionName(outputSpace);
18
+ if (!outputSpace) {
19
+ return;
20
+ }
21
+ return new Color({
22
+ space: 'srgb',
23
+ coords: [
24
+ color.red,
25
+ color.green,
26
+ color.blue
27
+ ],
28
+ alpha: color.alpha
29
+ }).to(outputSpace).toString({
30
+ format: 'css',
31
+ precision: 4,
32
+ inGamut: false
33
+ }).replace(' / ', '/').replaceAll(' ', '|');
34
+ }
35
+ function normalizeCSSColorFunctionName(fn) {
36
+ switch(fn){
37
+ case 'rgb':
38
+ case 'rgba':
39
+ return 'srgb';
40
+ case 'hsla':
41
+ return 'hsl';
42
+ case 'display-p3':
43
+ case 'p3':
44
+ return 'p3';
45
+ case 'rec2020':
46
+ case 'rec.2020':
47
+ return 'rec2020';
48
+ case 'color':
49
+ return '';
50
+ default:
51
+ return fn;
52
+ }
24
53
  }
25
54
 
26
- export { convertColorByToken as default };
55
+ export { convertColorByToken as default, normalizeCSSColorFunctionName };
@@ -4,7 +4,7 @@ var css = require('@master/css');
4
4
  var vscodeLanguageserverProtocol = require('vscode-languageserver-protocol');
5
5
  var sortCompletionItems = require('./sort-completion-items.cjs');
6
6
 
7
- function getColorCompletionItems(css$1 = new css.MasterCSS()) {
7
+ function getColorCompletionItems(css$1 = css.createCSS()) {
8
8
  const completionItems = [];
9
9
  css$1.variables.forEach((eachVariable, eachVariableName)=>{
10
10
  if (eachVariable.type === 'color') {
@@ -1,8 +1,8 @@
1
- import { MasterCSS } from '@master/css';
1
+ import { createCSS } from '@master/css';
2
2
  import { CompletionItemKind } from 'vscode-languageserver-protocol';
3
3
  import sortCompletionItems from './sort-completion-items.mjs';
4
4
 
5
- function getColorCompletionItems(css = new MasterCSS()) {
5
+ function getColorCompletionItems(css = createCSS()) {
6
6
  const completionItems = [];
7
7
  css.variables.forEach((eachVariable, eachVariableName)=>{
8
8
  if (eachVariable.type === 'color') {
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var beautifyCss = require('./beautify-css.cjs');
4
- var css = require('@master/css');
5
4
 
6
5
  function getCSSDataDocumentation(data, additional) {
7
6
  const values = [];
@@ -30,7 +29,7 @@ function getCSSDataDocumentation(data, additional) {
30
29
  if (additional?.docs) {
31
30
  references.unshift({
32
31
  name: 'Master CSS',
33
- url: new URL(additional.docs, css.OFFICIAL_URL).href
32
+ url: new URL(additional.docs, 'https://rc.css.master.co').href
34
33
  });
35
34
  }
36
35
  if (references.length) {
@@ -64,8 +63,7 @@ function getEntryStatus(status) {
64
63
  }
65
64
  }
66
65
  function textToMarkedString(text) {
67
- text = text.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&') // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
68
- ;
66
+ text = text.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&'); // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
69
67
  return text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
70
68
  }
71
69
  function getBrowserLabel(browsers = []) {
@@ -1,5 +1,4 @@
1
1
  import beautifyCSS from './beautify-css.mjs';
2
- import { OFFICIAL_URL } from '@master/css';
3
2
 
4
3
  function getCSSDataDocumentation(data, additional) {
5
4
  const values = [];
@@ -28,7 +27,7 @@ function getCSSDataDocumentation(data, additional) {
28
27
  if (additional?.docs) {
29
28
  references.unshift({
30
29
  name: 'Master CSS',
31
- url: new URL(additional.docs, OFFICIAL_URL).href
30
+ url: new URL(additional.docs, 'https://rc.css.master.co').href
32
31
  });
33
32
  }
34
33
  if (references.length) {
@@ -62,8 +61,7 @@ function getEntryStatus(status) {
62
61
  }
63
62
  }
64
63
  function textToMarkedString(text) {
65
- text = text.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&') // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
66
- ;
64
+ text = text.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&'); // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
67
65
  return text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
68
66
  }
69
67
  function getBrowserLabel(browsers = []) {
@@ -7,7 +7,7 @@ var sortCompletionItems = require('./sort-completion-items.cjs');
7
7
  var getUtilityInfo = require('./get-utility-info.cjs');
8
8
  var cssDataProvider = require('./css-data-provider.cjs');
9
9
 
10
- function getMainCompletionItems(css$1 = new css.MasterCSS()) {
10
+ function getMainCompletionItems(css$1 = css.createCSS()) {
11
11
  const completionItems = [];
12
12
  const addedKeys = new Set();
13
13
  for (const eachDefinedRule of css$1.definedRules){
@@ -58,25 +58,25 @@ function getMainCompletionItems(css$1 = new css.MasterCSS()) {
58
58
  });
59
59
  });
60
60
  }
61
- if (eachDefinedRule.definition?.ambiguousKeys?.length) {
62
- for (const ambiguousKey of eachDefinedRule.definition.ambiguousKeys){
63
- if (addedKeys.has(ambiguousKey)) {
61
+ if (eachDefinedRule.definition?.aliasGroups?.length) {
62
+ for (const aliasGroup of eachDefinedRule.definition.aliasGroups){
63
+ if (addedKeys.has(aliasGroup)) {
64
64
  continue;
65
65
  }
66
- addedKeys.add(ambiguousKey);
66
+ addedKeys.add(aliasGroup);
67
67
  }
68
68
  }
69
69
  }
70
70
  }
71
- addedKeys.forEach((ambiguousKey)=>{
71
+ addedKeys.forEach((aliasGroup)=>{
72
72
  /**
73
73
  * Ambiguous keys are added to the completion list
74
74
  * @example text: t:
75
75
  */ completionItems.push({
76
76
  kind: vscodeLanguageserverProtocol.CompletionItemKind.Property,
77
77
  detail: 'ambiguous key',
78
- label: ambiguousKey + ':',
79
- sortText: ambiguousKey,
78
+ label: aliasGroup + ':',
79
+ sortText: aliasGroup,
80
80
  command: {
81
81
  title: 'triggerSuggest',
82
82
  command: 'editor.action.triggerSuggest'
@@ -1,11 +1,11 @@
1
1
  import { CompletionItemKind } from 'vscode-languageserver-protocol';
2
- import { MasterCSS, SyntaxRuleType, generateCSS, isCoreRule } from '@master/css';
2
+ import { createCSS, SyntaxRuleType, generateCSS, isCoreRule } from '@master/css';
3
3
  import { getCSSDataDocumentation } from './get-css-data-documentation.mjs';
4
4
  import sortCompletionItems from './sort-completion-items.mjs';
5
5
  import getUtilityInfo from './get-utility-info.mjs';
6
6
  import cssDataProvider from './css-data-provider.mjs';
7
7
 
8
- function getMainCompletionItems(css = new MasterCSS()) {
8
+ function getMainCompletionItems(css = createCSS()) {
9
9
  const completionItems = [];
10
10
  const addedKeys = new Set();
11
11
  for (const eachDefinedRule of css.definedRules){
@@ -56,25 +56,25 @@ function getMainCompletionItems(css = new MasterCSS()) {
56
56
  });
57
57
  });
58
58
  }
59
- if (eachDefinedRule.definition?.ambiguousKeys?.length) {
60
- for (const ambiguousKey of eachDefinedRule.definition.ambiguousKeys){
61
- if (addedKeys.has(ambiguousKey)) {
59
+ if (eachDefinedRule.definition?.aliasGroups?.length) {
60
+ for (const aliasGroup of eachDefinedRule.definition.aliasGroups){
61
+ if (addedKeys.has(aliasGroup)) {
62
62
  continue;
63
63
  }
64
- addedKeys.add(ambiguousKey);
64
+ addedKeys.add(aliasGroup);
65
65
  }
66
66
  }
67
67
  }
68
68
  }
69
- addedKeys.forEach((ambiguousKey)=>{
69
+ addedKeys.forEach((aliasGroup)=>{
70
70
  /**
71
71
  * Ambiguous keys are added to the completion list
72
72
  * @example text: t:
73
73
  */ completionItems.push({
74
74
  kind: CompletionItemKind.Property,
75
75
  detail: 'ambiguous key',
76
- label: ambiguousKey + ':',
77
- sortText: ambiguousKey,
76
+ label: aliasGroup + ':',
77
+ sortText: aliasGroup,
78
78
  command: {
79
79
  title: 'triggerSuggest',
80
80
  command: 'editor.action.triggerSuggest'
@@ -7,7 +7,7 @@ var sortCompletionItems = require('./sort-completion-items.cjs');
7
7
  var getCssDataDocumentation = require('./get-css-data-documentation.cjs');
8
8
 
9
9
  const kind = vscodeLanguageserverProtocol.CompletionItemKind.Function;
10
- function getPseudoClassCompletionItems(css$1 = new css.MasterCSS(), syntax) {
10
+ function getPseudoClassCompletionItems(css$1 = css.createCSS(), syntax) {
11
11
  const pseudoClassDataList = cssDataProvider.providePseudoClasses().filter((data)=>{
12
12
  // exclude @page pseudo-classes
13
13
  if ([
@@ -1,11 +1,11 @@
1
- import { MasterCSS, generateCSS } from '@master/css';
1
+ import { createCSS, generateCSS } from '@master/css';
2
2
  import cssDataProvider from './css-data-provider.mjs';
3
3
  import { CompletionItemKind } from 'vscode-languageserver-protocol';
4
4
  import sortCompletionItems from './sort-completion-items.mjs';
5
5
  import { getCSSDataDocumentation } from './get-css-data-documentation.mjs';
6
6
 
7
7
  const kind = CompletionItemKind.Function;
8
- function getPseudoClassCompletionItems(css = new MasterCSS(), syntax) {
8
+ function getPseudoClassCompletionItems(css = createCSS(), syntax) {
9
9
  const pseudoClassDataList = cssDataProvider.providePseudoClasses().filter((data)=>{
10
10
  // exclude @page pseudo-classes
11
11
  if ([
@@ -7,7 +7,7 @@ var sortCompletionItems = require('./sort-completion-items.cjs');
7
7
  var getCssDataDocumentation = require('./get-css-data-documentation.cjs');
8
8
 
9
9
  const kind = vscodeLanguageserverProtocol.CompletionItemKind.Function;
10
- function getPseudoElementCompletionItems(css$1 = new css.MasterCSS(), syntax) {
10
+ function getPseudoElementCompletionItems(css$1 = css.createCSS(), syntax) {
11
11
  const pseudoElementDataList = cssDataProvider.providePseudoElements();
12
12
  const completionItems = pseudoElementDataList.map((data)=>{
13
13
  // fix https://github.com/microsoft/vscode-custom-data/issues/78
@@ -1,11 +1,11 @@
1
- import { MasterCSS, generateCSS } from '@master/css';
1
+ import { createCSS, generateCSS } from '@master/css';
2
2
  import cssDataProvider from './css-data-provider.mjs';
3
3
  import { CompletionItemKind } from 'vscode-languageserver-protocol';
4
4
  import sortCompletionItems from './sort-completion-items.mjs';
5
5
  import { getCSSDataDocumentation } from './get-css-data-documentation.mjs';
6
6
 
7
7
  const kind = CompletionItemKind.Function;
8
- function getPseudoElementCompletionItems(css = new MasterCSS(), syntax) {
8
+ function getPseudoElementCompletionItems(css = createCSS(), syntax) {
9
9
  const pseudoElementDataList = cssDataProvider.providePseudoElements();
10
10
  const completionItems = pseudoElementDataList.map((data)=>{
11
11
  // fix https://github.com/microsoft/vscode-custom-data/issues/78
@@ -6,7 +6,7 @@ var sortCompletionItems = require('./sort-completion-items.cjs');
6
6
  var getCssDataDocumentation = require('./get-css-data-documentation.cjs');
7
7
  var cssDataProvider = require('./css-data-provider.cjs');
8
8
 
9
- function getQueryCompletionItems(css$1 = new css.MasterCSS(), triggerCharacter = css.AT_SIGN, syntax) {
9
+ function getQueryCompletionItems(css$1 = css.createCSS(), triggerCharacter = css.AT_SIGN, syntax) {
10
10
  const atDataList = cssDataProvider.provideAtDirectives();
11
11
  const completionItems = [];
12
12
  if (!css.QUERY_COMPARISON_OPERATORS.includes(triggerCharacter)) {
@@ -1,10 +1,10 @@
1
- import { MasterCSS, AT_SIGN, QUERY_COMPARISON_OPERATORS, generateCSS, QUERY_LOGICAL_OPERATORS, generateAt, parseAt, getSingleAtNumberRuleNode } from '@master/css';
1
+ import { createCSS, AT_SIGN, QUERY_COMPARISON_OPERATORS, generateCSS, QUERY_LOGICAL_OPERATORS, generateAt, parseAt, getSingleAtNumberRuleNode } from '@master/css';
2
2
  import { CompletionItemKind } from 'vscode-languageserver-protocol';
3
3
  import sortCompletionItems from './sort-completion-items.mjs';
4
4
  import { getCSSDataDocumentation } from './get-css-data-documentation.mjs';
5
5
  import cssDataProvider from './css-data-provider.mjs';
6
6
 
7
- function getQueryCompletionItems(css = new MasterCSS(), triggerCharacter = AT_SIGN, syntax) {
7
+ function getQueryCompletionItems(css = createCSS(), triggerCharacter = AT_SIGN, syntax) {
8
8
  const atDataList = cssDataProvider.provideAtDirectives();
9
9
  const completionItems = [];
10
10
  if (!QUERY_COMPARISON_OPERATORS.includes(triggerCharacter)) {
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ var css = require('@master/css');
3
4
  var cssDataProvider = require('./css-data-provider.cjs');
4
5
 
5
- function getUtilityInfo(syntax, css = new MasterCSS()) {
6
+ function getUtilityInfo(syntax, css$1 = css.createCSS()) {
6
7
  const nativeProperties = cssDataProvider.provideProperties();
7
8
  const declarations = syntax.definition.declarations;
8
9
  const propsLength = Object.keys(declarations || {}).length;
@@ -1,6 +1,7 @@
1
+ import { createCSS } from '@master/css';
1
2
  import cssDataProvider from './css-data-provider.mjs';
2
3
 
3
- function getUtilityInfo(syntax, css = new MasterCSS()) {
4
+ function getUtilityInfo(syntax, css = createCSS()) {
4
5
  const nativeProperties = cssDataProvider.provideProperties();
5
6
  const declarations = syntax.definition.declarations;
6
7
  const propsLength = Object.keys(declarations || {}).length;
@@ -10,7 +10,7 @@ const SCOPED_VARIABLE_PRIORITY = 'aaaa';
10
10
  const AMBIGUOUS_PRIORITY = 'bbbb';
11
11
  const NATIVE_PRIORITY = 'ccccc';
12
12
  const GLOBAL_VARIABLE_PRIORITY = 'zzzz';
13
- function getValueCompletionItems(css$1 = new css.MasterCSS(), ruleKey) {
13
+ function getValueCompletionItems(css$1 = css.createCSS(), ruleKey) {
14
14
  const nativeProperties = cssDataProvider.provideProperties();
15
15
  const completionItems = [];
16
16
  const nativeKey = css$1.definedRules.find(({ keys })=>keys.includes(ruleKey))?.id;
@@ -78,10 +78,9 @@ function getValueCompletionItems(css$1 = new css.MasterCSS(), ruleKey) {
78
78
  /**
79
79
  * Scoped variables
80
80
  * @example box: + content -> box-sizing:content
81
- */ if (eachDefinedRule.definition.key === ruleKey || eachDefinedRule.definition.subkey === ruleKey || eachDefinedRule.definition.ambiguousKeys?.includes(ruleKey)) {
82
- for(const variableName in eachDefinedRule.variables){
83
- if (completionItems.find(({ label })=>label === variableName)) continue;
84
- const variable = eachDefinedRule.variables[variableName];
81
+ */ if (eachDefinedRule.definition.key === ruleKey || eachDefinedRule.definition.subkey === ruleKey || eachDefinedRule.definition.aliasGroups?.includes(ruleKey)) {
82
+ eachDefinedRule.variables?.forEach((variable, variableName)=>{
83
+ if (completionItems.find(({ label })=>label === variableName)) return;
85
84
  const completionItem = generateVariableCompletionItem(variable, {
86
85
  scoped: true
87
86
  });
@@ -91,12 +90,12 @@ function getValueCompletionItems(css$1 = new css.MasterCSS(), ruleKey) {
91
90
  completionItem.detail = '(scope) ' + completionItem.detail;
92
91
  completionItems.push(completionItem);
93
92
  }
94
- }
93
+ });
95
94
  }
96
95
  /**
97
96
  * @example animation:fade
98
97
  */ if (eachDefinedRule.keys.includes(ruleKey) && eachDefinedRule.definition.includeAnimations) {
99
- css$1.animations.forEach((animation, animationName)=>{
98
+ css$1.animations.forEach((_, animationName)=>{
100
99
  const isNative = eachDefinedRule.definition.type && [
101
100
  css.SyntaxRuleType.Native,
102
101
  css.SyntaxRuleType.NativeShorthand
@@ -118,30 +117,30 @@ function getValueCompletionItems(css$1 = new css.MasterCSS(), ruleKey) {
118
117
  * Ambiguous values
119
118
  * @example text: -> center, left, right, justify
120
119
  * @example t: -> center, left, right, justify
121
- */ if (eachDefinedRule.definition.ambiguousKeys?.includes(ruleKey) && eachDefinedRule.definition.ambiguousValues?.length) {
120
+ */ if (eachDefinedRule.definition.aliasGroups?.includes(ruleKey) && eachDefinedRule.definition.values?.length) {
122
121
  const nativePropertyData = nativeProperties.find((x)=>x.name === eachDefinedRule.id);
123
- for (const ambiguousValue of eachDefinedRule.definition.ambiguousValues){
124
- if (typeof ambiguousValue !== 'string') continue;
125
- const nativeValueData = nativePropertyData?.values?.find((x)=>x.name === ambiguousValue);
122
+ for (const value of eachDefinedRule.definition.values){
123
+ if (typeof value !== 'string') continue;
124
+ const nativeValueData = nativePropertyData?.values?.find((x)=>x.name === value);
126
125
  const isNative = eachDefinedRule.definition.type && [
127
126
  css.SyntaxRuleType.Native,
128
127
  css.SyntaxRuleType.NativeShorthand
129
128
  ].includes(eachDefinedRule.definition.type);
130
129
  completionItems.push({
131
- label: ambiguousValue,
130
+ label: value,
132
131
  kind: vscodeLanguageserverProtocol.CompletionItemKind.Value,
133
- sortText: AMBIGUOUS_PRIORITY + ambiguousValue,
132
+ sortText: AMBIGUOUS_PRIORITY + value,
134
133
  documentation: getCssDataDocumentation.getCSSDataDocumentation({
135
134
  ...nativeValueData || {},
136
135
  // use nativePropertyData.reference because nativeValueData does not have references
137
136
  references: nativePropertyData?.references
138
137
  }, {
139
138
  generatedCSS: css.generateCSS([
140
- ruleKey + ':' + ambiguousValue
139
+ ruleKey + ':' + value
141
140
  ], css$1),
142
141
  docs: '/reference/' + css.isCoreRule(eachDefinedRule.id) && eachDefinedRule.id
143
142
  }),
144
- detail: isNative ? eachDefinedRule.id + ': ' + ambiguousValue : ambiguousValue
143
+ detail: isNative ? eachDefinedRule.id + ': ' + value : value
145
144
  });
146
145
  }
147
146
  }
@@ -1,6 +1,6 @@
1
1
  import { CompletionItemKind } from 'vscode-languageserver-protocol';
2
2
  import cssDataProvider from './css-data-provider.mjs';
3
- import { MasterCSS, SyntaxRuleType, isCoreRule, generateCSS } from '@master/css';
3
+ import { createCSS, SyntaxRuleType, isCoreRule, generateCSS } from '@master/css';
4
4
  import { getCSSDataDocumentation } from './get-css-data-documentation.mjs';
5
5
  import sortCompletionItems from './sort-completion-items.mjs';
6
6
 
@@ -8,7 +8,7 @@ const SCOPED_VARIABLE_PRIORITY = 'aaaa';
8
8
  const AMBIGUOUS_PRIORITY = 'bbbb';
9
9
  const NATIVE_PRIORITY = 'ccccc';
10
10
  const GLOBAL_VARIABLE_PRIORITY = 'zzzz';
11
- function getValueCompletionItems(css = new MasterCSS(), ruleKey) {
11
+ function getValueCompletionItems(css = createCSS(), ruleKey) {
12
12
  const nativeProperties = cssDataProvider.provideProperties();
13
13
  const completionItems = [];
14
14
  const nativeKey = css.definedRules.find(({ keys })=>keys.includes(ruleKey))?.id;
@@ -76,10 +76,9 @@ function getValueCompletionItems(css = new MasterCSS(), ruleKey) {
76
76
  /**
77
77
  * Scoped variables
78
78
  * @example box: + content -> box-sizing:content
79
- */ if (eachDefinedRule.definition.key === ruleKey || eachDefinedRule.definition.subkey === ruleKey || eachDefinedRule.definition.ambiguousKeys?.includes(ruleKey)) {
80
- for(const variableName in eachDefinedRule.variables){
81
- if (completionItems.find(({ label })=>label === variableName)) continue;
82
- const variable = eachDefinedRule.variables[variableName];
79
+ */ if (eachDefinedRule.definition.key === ruleKey || eachDefinedRule.definition.subkey === ruleKey || eachDefinedRule.definition.aliasGroups?.includes(ruleKey)) {
80
+ eachDefinedRule.variables?.forEach((variable, variableName)=>{
81
+ if (completionItems.find(({ label })=>label === variableName)) return;
83
82
  const completionItem = generateVariableCompletionItem(variable, {
84
83
  scoped: true
85
84
  });
@@ -89,12 +88,12 @@ function getValueCompletionItems(css = new MasterCSS(), ruleKey) {
89
88
  completionItem.detail = '(scope) ' + completionItem.detail;
90
89
  completionItems.push(completionItem);
91
90
  }
92
- }
91
+ });
93
92
  }
94
93
  /**
95
94
  * @example animation:fade
96
95
  */ if (eachDefinedRule.keys.includes(ruleKey) && eachDefinedRule.definition.includeAnimations) {
97
- css.animations.forEach((animation, animationName)=>{
96
+ css.animations.forEach((_, animationName)=>{
98
97
  const isNative = eachDefinedRule.definition.type && [
99
98
  SyntaxRuleType.Native,
100
99
  SyntaxRuleType.NativeShorthand
@@ -116,30 +115,30 @@ function getValueCompletionItems(css = new MasterCSS(), ruleKey) {
116
115
  * Ambiguous values
117
116
  * @example text: -> center, left, right, justify
118
117
  * @example t: -> center, left, right, justify
119
- */ if (eachDefinedRule.definition.ambiguousKeys?.includes(ruleKey) && eachDefinedRule.definition.ambiguousValues?.length) {
118
+ */ if (eachDefinedRule.definition.aliasGroups?.includes(ruleKey) && eachDefinedRule.definition.values?.length) {
120
119
  const nativePropertyData = nativeProperties.find((x)=>x.name === eachDefinedRule.id);
121
- for (const ambiguousValue of eachDefinedRule.definition.ambiguousValues){
122
- if (typeof ambiguousValue !== 'string') continue;
123
- const nativeValueData = nativePropertyData?.values?.find((x)=>x.name === ambiguousValue);
120
+ for (const value of eachDefinedRule.definition.values){
121
+ if (typeof value !== 'string') continue;
122
+ const nativeValueData = nativePropertyData?.values?.find((x)=>x.name === value);
124
123
  const isNative = eachDefinedRule.definition.type && [
125
124
  SyntaxRuleType.Native,
126
125
  SyntaxRuleType.NativeShorthand
127
126
  ].includes(eachDefinedRule.definition.type);
128
127
  completionItems.push({
129
- label: ambiguousValue,
128
+ label: value,
130
129
  kind: CompletionItemKind.Value,
131
- sortText: AMBIGUOUS_PRIORITY + ambiguousValue,
130
+ sortText: AMBIGUOUS_PRIORITY + value,
132
131
  documentation: getCSSDataDocumentation({
133
132
  ...nativeValueData || {},
134
133
  // use nativePropertyData.reference because nativeValueData does not have references
135
134
  references: nativePropertyData?.references
136
135
  }, {
137
136
  generatedCSS: generateCSS([
138
- ruleKey + ':' + ambiguousValue
137
+ ruleKey + ':' + value
139
138
  ], css),
140
139
  docs: '/reference/' + isCoreRule(eachDefinedRule.id) && eachDefinedRule.id
141
140
  }),
142
- detail: isNative ? eachDefinedRule.id + ': ' + ambiguousValue : ambiguousValue
141
+ detail: isNative ? eachDefinedRule.id + ': ' + value : value
143
142
  });
144
143
  }
145
144
  }
@@ -10,7 +10,7 @@ var getValueCompletionItems = require('./get-value-completion-items.cjs');
10
10
  var getQueryCompletionItems = require('./get-query-completion-items.cjs');
11
11
  var getCssDataDocumentation = require('./get-css-data-documentation.cjs');
12
12
 
13
- function querySyntaxCompletions(q = '', css$1 = new css.MasterCSS()) {
13
+ function querySyntaxCompletions(q = '', css$1 = css.createCSS()) {
14
14
  const fields = q.split(' ');
15
15
  let field = fields[fields.length - 1];
16
16
  const triggerCharacter = q.charAt(q.length - 1);
@@ -1,14 +1,14 @@
1
1
  import { CompletionItemKind } from 'vscode-languageserver-protocol';
2
2
  import getPseudoClassCompletionItems from './get-pseudo-class-completion-items.mjs';
3
3
  import getPseudoElementCompletionItems from './get-pseudo-element-completion-items.mjs';
4
- import { MasterCSS, SELECTOR_SIGNS, ANIMATION_SIGN, TRANSITION_SIGN, AT_SIGN, QUERY_COMPARISON_OPERATORS, QUERY_LOGICAL_OPERATORS, generateCSS } from '@master/css';
4
+ import { createCSS, SELECTOR_SIGNS, ANIMATION_SIGN, TRANSITION_SIGN, AT_SIGN, QUERY_COMPARISON_OPERATORS, QUERY_LOGICAL_OPERATORS, generateCSS } from '@master/css';
5
5
  import { GROUP_TRIGGER_CHARACTER, SELECTOR_TRIGGER_CHARACTERS } from '../common.mjs';
6
6
  import getMainCompletionItems from './get-main-completion-items.mjs';
7
7
  import getValueCompletionItems from './get-value-completion-items.mjs';
8
8
  import getQueryCompletionItems from './get-query-completion-items.mjs';
9
9
  import { getCSSDataDocumentation } from './get-css-data-documentation.mjs';
10
10
 
11
- function querySyntaxCompletions(q = '', css = new MasterCSS()) {
11
+ function querySyntaxCompletions(q = '', css = createCSS()) {
12
12
  const fields = q.split(' ');
13
13
  let field = fields[fields.length - 1];
14
14
  const triggerCharacter = q.charAt(q.length - 1);
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@master/css-language-service","type":"module","scripts":{"build":"techor build \"src/**/*.ts\"","dev":"pnpm build --watch","type-check":"tsc --noEmit","lint":"eslint","test":"vitest"},"description":"Master CSS Language Service","author":"Aoyue Design LLC.","license":"MIT","repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/language-service"},"dependencies":{"@babel/parser":"^7.27.0","@master/css":"^2.0.0-rc.67","@techor/extend":"^3.2.0","color-convert":"^2.0.1","color-rgba":"^3.0.0","color-space":"^2.3.1","culori":"^4.0.1","js-beautify":"^1.15.4","lodash.escaperegexp":"^4.1.2","minimatch":"^10.0.1","pex-color":"^2.2.0","vscode-css-languageservice":"^6.3.4","vscode-languageserver-protocol":"^3.17.5","vscode-languageserver-textdocument":"^1.0.12"},"devDependencies":{"@types/chroma-js":"^2.4.5","@types/color-convert":"^2.0.4","@types/color-rgba":"^2.1.3","@types/culori":"^2.1.1","@types/lodash.escaperegexp":"^4.1.9","@types/vscode":"^1.99.1","shared":"^2.0.0-rc.67","vscode-languageserver":"^9.0.1"},"sideEffects":false,"main":"./dist/index.cjs","module":"./dist/index.mjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"}},"files":["dist"],"publishConfig":{"access":"public","provenance":true},"version":"2.0.0-rc.67"}
1
+ {"name":"@master/css-language-service","type":"module","scripts":{"build":"techor build \"src/**/*.ts\"","dev":"pnpm build --watch","type-check":"tsc --noEmit","lint":"eslint","test":"vitest"},"description":"Master CSS Language Service","author":"Aoyue Design LLC.","license":"MIT","repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/language-service"},"dependencies":{"@babel/parser":"^7.27.0","@master/css":"^2.0.0-rc.69","@techor/extend":"^3.2.5","color-convert":"^2.0.1","color-rgba":"^3.0.0","color-space":"^2.3.1","colorjs.io":"^0.5.2","js-beautify":"^1.15.4","lodash.escaperegexp":"^4.1.2","minimatch":"^10.0.1","pex-color":"^2.2.0","vscode-css-languageservice":"^6.3.4","vscode-languageserver-protocol":"^3.17.5","vscode-languageserver-textdocument":"^1.0.12"},"devDependencies":{"@types/chroma-js":"^2.4.5","@types/color-convert":"^2.0.4","@types/color-rgba":"^2.1.3","@types/culori":"^2.1.1","@types/lodash.escaperegexp":"^4.1.9","@types/vscode":"^1.99.1","shared":"^2.0.0-rc.69","vscode-languageserver":"^9.0.1"},"sideEffects":false,"main":"./dist/index.cjs","module":"./dist/index.mjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs"}},"files":["dist"],"publishConfig":{"access":"public","provenance":true},"version":"2.0.0-rc.69"}
@@ -1,40 +0,0 @@
1
- 'use strict';
2
-
3
- var culori = require('culori');
4
-
5
- function convertColorSpace(rgb, targetSpace) {
6
- const alphaUsed = rgb.alpha !== 1;
7
- const alphaToken = alphaUsed ? `/${rgb.alpha}` : '';
8
- if (rgb.r === 0 && rgb.g === 0 && rgb.b === 0) return 'black' + alphaToken;
9
- if (rgb.r === 1 && rgb.g === 1 && rgb.b === 1) return 'white' + alphaToken;
10
- switch(targetSpace){
11
- case 'hex':
12
- return alphaUsed ? culori.serializeHex8(rgb) : culori.serializeHex(rgb);
13
- case 'rgba':
14
- case 'rgb':
15
- return `rgb(${Math.round(rgb.r * 255)}|${Math.round(rgb.g * 255)}|${Math.round(rgb.b * 255)}${alphaToken})`;
16
- case 'hsla':
17
- case 'hsl':
18
- const hsl = culori.modeHsl.fromMode.rgb(rgb);
19
- return `hsl(${Math.round(hsl.h || 0)}|${Math.round(hsl.s * 100)}%|${Math.round(hsl.l * 100)}%${alphaToken})`;
20
- case 'hwb':
21
- const hwb = culori.modeHwb.fromMode.rgb(rgb);
22
- return `hwb(${Math.round(hwb.h || 0)}|${Math.round(hwb.w * 100)}%|${Math.round(hwb.b * 100)}%${alphaToken})`;
23
- case 'lab':
24
- const lab = culori.modeLab.fromMode.rgb(rgb);
25
- return `lab(${Math.round(lab.l)}%|${Math.round(lab.a)}|${Math.round(lab.b || 0)}${alphaToken})`;
26
- case 'lch':
27
- const lch = culori.modeLch.fromMode.rgb(rgb);
28
- return `lch(${Math.round(lch.l)}%|${Math.round(lch.c)}|${Math.round(lch.h || 0)}${alphaToken})`;
29
- case 'oklab':
30
- const oklab = culori.modeOklab.fromMode.rgb(rgb);
31
- return `oklab(${Math.round(oklab.l * 100)}%|${oklab.a.toFixed(4)}|${oklab.b.toFixed(4)}${alphaToken})`;
32
- case 'oklch':
33
- const oklch = culori.modeOklch.fromMode.rgb(rgb);
34
- return `oklch(${Math.round(oklch.l * 100)}%|${oklch.c.toFixed(4)}|${Math.round(oklch.h || 0)}${alphaToken})`;
35
- }
36
- // color()
37
- return culori.formatCss(rgb).replace(' / ', '/').replace(' ', '|');
38
- }
39
-
40
- module.exports = convertColorSpace;
@@ -1,2 +0,0 @@
1
- import { type Rgb } from 'culori';
2
- export default function convertColorSpace(rgb: Rgb, targetSpace: any): string | undefined;
@@ -1,38 +0,0 @@
1
- import { modeOklch, modeOklab, modeLch, modeLab, modeHwb, modeHsl, serializeHex8, serializeHex, formatCss } from 'culori';
2
-
3
- function convertColorSpace(rgb, targetSpace) {
4
- const alphaUsed = rgb.alpha !== 1;
5
- const alphaToken = alphaUsed ? `/${rgb.alpha}` : '';
6
- if (rgb.r === 0 && rgb.g === 0 && rgb.b === 0) return 'black' + alphaToken;
7
- if (rgb.r === 1 && rgb.g === 1 && rgb.b === 1) return 'white' + alphaToken;
8
- switch(targetSpace){
9
- case 'hex':
10
- return alphaUsed ? serializeHex8(rgb) : serializeHex(rgb);
11
- case 'rgba':
12
- case 'rgb':
13
- return `rgb(${Math.round(rgb.r * 255)}|${Math.round(rgb.g * 255)}|${Math.round(rgb.b * 255)}${alphaToken})`;
14
- case 'hsla':
15
- case 'hsl':
16
- const hsl = modeHsl.fromMode.rgb(rgb);
17
- return `hsl(${Math.round(hsl.h || 0)}|${Math.round(hsl.s * 100)}%|${Math.round(hsl.l * 100)}%${alphaToken})`;
18
- case 'hwb':
19
- const hwb = modeHwb.fromMode.rgb(rgb);
20
- return `hwb(${Math.round(hwb.h || 0)}|${Math.round(hwb.w * 100)}%|${Math.round(hwb.b * 100)}%${alphaToken})`;
21
- case 'lab':
22
- const lab = modeLab.fromMode.rgb(rgb);
23
- return `lab(${Math.round(lab.l)}%|${Math.round(lab.a)}|${Math.round(lab.b || 0)}${alphaToken})`;
24
- case 'lch':
25
- const lch = modeLch.fromMode.rgb(rgb);
26
- return `lch(${Math.round(lch.l)}%|${Math.round(lch.c)}|${Math.round(lch.h || 0)}${alphaToken})`;
27
- case 'oklab':
28
- const oklab = modeOklab.fromMode.rgb(rgb);
29
- return `oklab(${Math.round(oklab.l * 100)}%|${oklab.a.toFixed(4)}|${oklab.b.toFixed(4)}${alphaToken})`;
30
- case 'oklch':
31
- const oklch = modeOklch.fromMode.rgb(rgb);
32
- return `oklch(${Math.round(oklch.l * 100)}%|${oklch.c.toFixed(4)}|${Math.round(oklch.h || 0)}${alphaToken})`;
33
- }
34
- // color()
35
- return formatCss(rgb).replace(' / ', '/').replace(' ', '|');
36
- }
37
-
38
- export { convertColorSpace as default };