@master/css-language-service 2.0.0-rc.5 → 2.0.0-rc.50

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 (93) hide show
  1. package/dist/common.cjs +57 -0
  2. package/dist/common.d.ts +9 -0
  3. package/dist/common.mjs +48 -0
  4. package/dist/core.cjs +246 -0
  5. package/dist/core.d.ts +29 -0
  6. package/dist/core.mjs +244 -0
  7. package/dist/features/edit-syntax-colors.cjs +19 -0
  8. package/dist/features/edit-syntax-colors.d.ts +4 -0
  9. package/dist/features/edit-syntax-colors.mjs +17 -0
  10. package/dist/features/inspect-syntax.cjs +70 -0
  11. package/dist/features/inspect-syntax.d.ts +4 -0
  12. package/dist/features/inspect-syntax.mjs +68 -0
  13. package/dist/features/render-syntax-colors.cjs +88 -0
  14. package/dist/features/render-syntax-colors.d.ts +4 -0
  15. package/dist/features/render-syntax-colors.mjs +86 -0
  16. package/dist/features/suggest-syntax.cjs +20 -0
  17. package/dist/features/suggest-syntax.d.ts +4 -0
  18. package/dist/features/suggest-syntax.mjs +18 -0
  19. package/dist/index.cjs +29 -0
  20. package/dist/index.d.ts +7 -5
  21. package/dist/index.mjs +7 -0
  22. package/dist/settings.cjs +84 -0
  23. package/dist/settings.d.ts +19 -9
  24. package/dist/settings.mjs +82 -0
  25. package/dist/utils/beautify-css.cjs +13 -0
  26. package/dist/utils/beautify-css.d.ts +1 -0
  27. package/dist/utils/beautify-css.mjs +11 -0
  28. package/dist/utils/convert-color-space.cjs +40 -0
  29. package/dist/utils/convert-color-space.d.ts +2 -0
  30. package/dist/utils/convert-color-space.mjs +38 -0
  31. package/dist/utils/convert-color-token.cjs +28 -0
  32. package/dist/utils/convert-color-token.d.ts +3 -0
  33. package/dist/utils/convert-color-token.mjs +26 -0
  34. package/dist/utils/create-doc.cjs +26 -0
  35. package/dist/utils/create-doc.d.ts +16 -0
  36. package/dist/utils/create-doc.mjs +21 -0
  37. package/dist/utils/css-data-provider.cjs +9 -0
  38. package/dist/utils/css-data-provider.d.ts +3 -0
  39. package/dist/utils/css-data-provider.mjs +7 -0
  40. package/dist/utils/find-matching-brackets.cjs +29 -0
  41. package/dist/utils/find-matching-brackets.d.ts +1 -0
  42. package/dist/utils/find-matching-brackets.mjs +27 -0
  43. package/dist/utils/get-color-completion-items.cjs +30 -0
  44. package/dist/utils/get-color-completion-items.d.ts +3 -0
  45. package/dist/utils/get-color-completion-items.mjs +28 -0
  46. package/dist/utils/get-css-data-documentation.cjs +90 -0
  47. package/dist/utils/get-css-data-documentation.d.ts +5 -0
  48. package/dist/utils/get-css-data-documentation.mjs +88 -0
  49. package/dist/utils/get-main-completion-items.cjs +105 -0
  50. package/dist/utils/get-main-completion-items.d.ts +3 -0
  51. package/dist/utils/get-main-completion-items.mjs +103 -0
  52. package/dist/utils/get-position.cjs +12 -0
  53. package/dist/utils/get-position.d.ts +1 -0
  54. package/dist/utils/get-position.mjs +10 -0
  55. package/dist/utils/get-pseudo-class-completion-items.cjs +65 -0
  56. package/dist/utils/get-pseudo-class-completion-items.d.ts +3 -0
  57. package/dist/utils/get-pseudo-class-completion-items.mjs +63 -0
  58. package/dist/utils/get-pseudo-element-completion-items.cjs +56 -0
  59. package/dist/utils/get-pseudo-element-completion-items.d.ts +3 -0
  60. package/dist/utils/get-pseudo-element-completion-items.mjs +54 -0
  61. package/dist/utils/get-query-completion-items.cjs +102 -0
  62. package/dist/utils/get-query-completion-items.d.ts +3 -0
  63. package/dist/utils/get-query-completion-items.mjs +100 -0
  64. package/dist/utils/get-range.cjs +21 -0
  65. package/dist/utils/get-range.d.ts +2 -0
  66. package/dist/utils/get-range.mjs +19 -0
  67. package/dist/utils/get-utility-info.cjs +32 -0
  68. package/dist/utils/get-utility-info.d.ts +7 -0
  69. package/dist/utils/get-utility-info.mjs +30 -0
  70. package/dist/utils/get-value-completion-items.cjs +185 -0
  71. package/dist/utils/get-value-completion-items.d.ts +3 -0
  72. package/dist/utils/get-value-completion-items.mjs +183 -0
  73. package/dist/utils/query-syntax-completions.cjs +115 -0
  74. package/dist/utils/query-syntax-completions.d.ts +3 -0
  75. package/dist/utils/query-syntax-completions.mjs +113 -0
  76. package/dist/utils/regex.cjs +5 -0
  77. package/dist/utils/regex.mjs +3 -0
  78. package/dist/utils/sort-completion-items.cjs +11 -0
  79. package/dist/utils/sort-completion-items.d.ts +2 -0
  80. package/dist/utils/sort-completion-items.mjs +9 -0
  81. package/package.json +1 -1
  82. package/dist/constant.d.ts +0 -33
  83. package/dist/index.bundle.js +0 -33
  84. package/dist/position-check.d.ts +0 -20
  85. package/dist/providers/color.d.ts +0 -5
  86. package/dist/providers/completion.d.ts +0 -14
  87. package/dist/providers/hover.d.ts +0 -2
  88. package/dist/settings.bundle.js +0 -1
  89. package/dist/utils/get-css-entry-markdown-description.d.ts +0 -1
  90. package/dist/utils/hex-to-rgb.d.ts +0 -2
  91. package/dist/utils/oklab-to-rgb.d.ts +0 -1
  92. package/dist/utils/oklch-to-oklab.d.ts +0 -1
  93. package/dist/utils/to-two-digit-hex.d.ts +0 -1
@@ -0,0 +1,40 @@
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;
@@ -0,0 +1,2 @@
1
+ import { type Rgb } from 'culori';
2
+ export default function convertColorSpace(rgb: Rgb, targetSpace: any): string | undefined;
@@ -0,0 +1,38 @@
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 };
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ var convertColorSpace = require('./convert-color-space.cjs');
4
+
5
+ function convertColorByToken(color, colorToken, css) {
6
+ const valueComponent = css.generate('color:' + colorToken)[0]?.valueComponents[0];
7
+ let outputColorSpace = 'hex';
8
+ switch(valueComponent?.type){
9
+ case 'function':
10
+ outputColorSpace = valueComponent.name;
11
+ break;
12
+ case 'variable':
13
+ outputColorSpace = valueComponent.variable?.space;
14
+ break;
15
+ case 'string':
16
+ outputColorSpace = 'hex';
17
+ break;
18
+ }
19
+ return convertColorSpace({
20
+ r: color.red,
21
+ g: color.green,
22
+ b: color.blue,
23
+ alpha: color.alpha,
24
+ mode: 'rgb'
25
+ }, outputColorSpace);
26
+ }
27
+
28
+ module.exports = convertColorByToken;
@@ -0,0 +1,3 @@
1
+ import type { MasterCSS } from '@master/css';
2
+ import type { ColorPresentationParams } from 'vscode-languageserver-protocol';
3
+ export default function convertColorByToken(color: ColorPresentationParams['color'], colorToken: string, css: MasterCSS): string | undefined;
@@ -0,0 +1,26 @@
1
+ import convertColorSpace from './convert-color-space.mjs';
2
+
3
+ function convertColorByToken(color, colorToken, css) {
4
+ const valueComponent = css.generate('color:' + colorToken)[0]?.valueComponents[0];
5
+ let outputColorSpace = 'hex';
6
+ switch(valueComponent?.type){
7
+ case 'function':
8
+ outputColorSpace = valueComponent.name;
9
+ break;
10
+ case 'variable':
11
+ outputColorSpace = valueComponent.variable?.space;
12
+ break;
13
+ case 'string':
14
+ outputColorSpace = 'hex';
15
+ break;
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);
24
+ }
25
+
26
+ export { convertColorByToken as default };
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var vscodeLanguageserverTextdocument = require('vscode-languageserver-textdocument');
6
+
7
+ const languageIdOfExt = {
8
+ ts: 'typescript',
9
+ tsx: 'typescriptreact',
10
+ js: 'javascript',
11
+ jsx: 'javascriptreact',
12
+ css: 'css',
13
+ scss: 'scss',
14
+ less: 'less',
15
+ html: 'html',
16
+ json: 'json',
17
+ vue: 'vue',
18
+ svelte: 'svelte',
19
+ astro: 'astro'
20
+ };
21
+ function createDoc(ext, content) {
22
+ return vscodeLanguageserverTextdocument.TextDocument.create(`file:///abc.${ext}`, languageIdOfExt[ext], 0, content);
23
+ }
24
+
25
+ exports.default = createDoc;
26
+ exports.languageIdOfExt = languageIdOfExt;
@@ -0,0 +1,16 @@
1
+ import { TextDocument } from 'vscode-languageserver-textdocument';
2
+ export declare const languageIdOfExt: {
3
+ ts: string;
4
+ tsx: string;
5
+ js: string;
6
+ jsx: string;
7
+ css: string;
8
+ scss: string;
9
+ less: string;
10
+ html: string;
11
+ json: string;
12
+ vue: string;
13
+ svelte: string;
14
+ astro: string;
15
+ };
16
+ export default function createDoc(ext: keyof typeof languageIdOfExt, content: string): TextDocument;
@@ -0,0 +1,21 @@
1
+ import { TextDocument } from 'vscode-languageserver-textdocument';
2
+
3
+ const languageIdOfExt = {
4
+ ts: 'typescript',
5
+ tsx: 'typescriptreact',
6
+ js: 'javascript',
7
+ jsx: 'javascriptreact',
8
+ css: 'css',
9
+ scss: 'scss',
10
+ less: 'less',
11
+ html: 'html',
12
+ json: 'json',
13
+ vue: 'vue',
14
+ svelte: 'svelte',
15
+ astro: 'astro'
16
+ };
17
+ function createDoc(ext, content) {
18
+ return TextDocument.create(`file:///abc.${ext}`, languageIdOfExt[ext], 0, content);
19
+ }
20
+
21
+ export { createDoc as default, languageIdOfExt };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var dataProvider = require('vscode-css-languageservice/lib/umd/languageFacts/dataProvider');
4
+ var webCustomData = require('vscode-css-languageservice/lib/umd/data/webCustomData');
5
+
6
+ // @ts-expect-error
7
+ const cssDataProvider = new dataProvider.CSSDataProvider(webCustomData.cssData);
8
+
9
+ module.exports = cssDataProvider;
@@ -0,0 +1,3 @@
1
+ import type { ICSSDataProvider } from 'vscode-css-languageservice/lib/umd/cssLanguageTypes';
2
+ declare const cssDataProvider: ICSSDataProvider;
3
+ export default cssDataProvider;
@@ -0,0 +1,7 @@
1
+ import { CSSDataProvider } from 'vscode-css-languageservice/lib/umd/languageFacts/dataProvider';
2
+ import { cssData } from 'vscode-css-languageservice/lib/umd/data/webCustomData';
3
+
4
+ // @ts-expect-error
5
+ const cssDataProvider = new CSSDataProvider(cssData);
6
+
7
+ export { cssDataProvider as default };
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ function findMatchingPairs(input, startIndex, start, end) {
4
+ let endIndex;
5
+ // {} [] ()
6
+ if (start !== end) {
7
+ let count = 1;
8
+ for(let i = startIndex; i < input.length; i++){
9
+ if (input[i] === start) {
10
+ count++;
11
+ } else if (input[i] === end) {
12
+ count--;
13
+ if (count === 0) {
14
+ endIndex = i;
15
+ break;
16
+ }
17
+ }
18
+ }
19
+ } else {
20
+ for(let i = startIndex; i < input.length; i++){
21
+ if (input[i] === start && input[i - 1] !== '\\') {
22
+ return i;
23
+ }
24
+ }
25
+ }
26
+ return endIndex;
27
+ }
28
+
29
+ module.exports = findMatchingPairs;
@@ -0,0 +1 @@
1
+ export default function findMatchingPairs(input: string, startIndex: number, start: string, end: string): number | undefined;
@@ -0,0 +1,27 @@
1
+ function findMatchingPairs(input, startIndex, start, end) {
2
+ let endIndex;
3
+ // {} [] ()
4
+ if (start !== end) {
5
+ let count = 1;
6
+ for(let i = startIndex; i < input.length; i++){
7
+ if (input[i] === start) {
8
+ count++;
9
+ } else if (input[i] === end) {
10
+ count--;
11
+ if (count === 0) {
12
+ endIndex = i;
13
+ break;
14
+ }
15
+ }
16
+ }
17
+ } else {
18
+ for(let i = startIndex; i < input.length; i++){
19
+ if (input[i] === start && input[i - 1] !== '\\') {
20
+ return i;
21
+ }
22
+ }
23
+ }
24
+ return endIndex;
25
+ }
26
+
27
+ export { findMatchingPairs as default };
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ var css = require('@master/css');
4
+ var vscodeLanguageserverProtocol = require('vscode-languageserver-protocol');
5
+ var sortCompletionItems = require('./sort-completion-items.cjs');
6
+
7
+ function getColorCompletionItems(css$1 = new css.MasterCSS()) {
8
+ const completionItems = [];
9
+ for(const eachVariableName in css$1.variables){
10
+ const eachVariable = css$1.variables[eachVariableName];
11
+ if (eachVariable.type === 'color') {
12
+ // todo: packages/core should support getTextByVariable(variable)
13
+ const valueToken = eachVariable.space && eachVariable.value ? `${eachVariable.space}(${eachVariable.value})` : eachVariable.value;
14
+ completionItems.push({
15
+ label: eachVariableName,
16
+ // detail is shown in the detail pane
17
+ // todo: eachVariable.token should be recorded as original config variable
18
+ detail: valueToken,
19
+ // documentation is shown in the hover
20
+ // todo: should convert and space to rgba
21
+ documentation: eachVariable.space && eachVariable.value ? `${eachVariable.space}(${eachVariable.value.split(' ').join(',')})` : eachVariable.value,
22
+ kind: vscodeLanguageserverProtocol.CompletionItemKind.Color,
23
+ sortText: eachVariableName.replace(/(.+?)-(\d+)/, (match, prefix, num)=>prefix + '-' + ('00000' + num).slice(-5))
24
+ });
25
+ }
26
+ }
27
+ return sortCompletionItems(completionItems);
28
+ }
29
+
30
+ module.exports = getColorCompletionItems;
@@ -0,0 +1,3 @@
1
+ import { MasterCSS } from '@master/css';
2
+ import { type CompletionItem } from 'vscode-languageserver-protocol';
3
+ export default function getColorCompletionItems(css?: MasterCSS): CompletionItem[];
@@ -0,0 +1,28 @@
1
+ import { MasterCSS } from '@master/css';
2
+ import { CompletionItemKind } from 'vscode-languageserver-protocol';
3
+ import sortCompletionItems from './sort-completion-items.mjs';
4
+
5
+ function getColorCompletionItems(css = new MasterCSS()) {
6
+ const completionItems = [];
7
+ for(const eachVariableName in css.variables){
8
+ const eachVariable = css.variables[eachVariableName];
9
+ if (eachVariable.type === 'color') {
10
+ // todo: packages/core should support getTextByVariable(variable)
11
+ const valueToken = eachVariable.space && eachVariable.value ? `${eachVariable.space}(${eachVariable.value})` : eachVariable.value;
12
+ completionItems.push({
13
+ label: eachVariableName,
14
+ // detail is shown in the detail pane
15
+ // todo: eachVariable.token should be recorded as original config variable
16
+ detail: valueToken,
17
+ // documentation is shown in the hover
18
+ // todo: should convert and space to rgba
19
+ documentation: eachVariable.space && eachVariable.value ? `${eachVariable.space}(${eachVariable.value.split(' ').join(',')})` : eachVariable.value,
20
+ kind: CompletionItemKind.Color,
21
+ sortText: eachVariableName.replace(/(.+?)-(\d+)/, (match, prefix, num)=>prefix + '-' + ('00000' + num).slice(-5))
22
+ });
23
+ }
24
+ }
25
+ return sortCompletionItems(completionItems);
26
+ }
27
+
28
+ export { getColorCompletionItems as default };
@@ -0,0 +1,90 @@
1
+ 'use strict';
2
+
3
+ var beautifyCss = require('./beautify-css.cjs');
4
+ var css = require('@master/css');
5
+
6
+ function getCSSDataDocumentation(data, additional) {
7
+ const values = [];
8
+ const references = data?.references ? [
9
+ ...data.references
10
+ ] : [];
11
+ if (data?.status) {
12
+ values.push(getEntryStatus(data.status));
13
+ }
14
+ if (additional?.generatedCSS) {
15
+ values.push('```css\n' + beautifyCss(additional.generatedCSS).split('\n').slice(1).join('\n') + '\n```');
16
+ }
17
+ if (data?.description) if (typeof data.description === 'string') {
18
+ values.push(textToMarkedString(data.description));
19
+ } else {
20
+ values.push(data.description.kind === 'markdown' ? data.description.value : textToMarkedString(data.description.value));
21
+ }
22
+ const browserLabel = getBrowserLabel(data?.browsers);
23
+ if (browserLabel) {
24
+ values.push('(' + textToMarkedString(browserLabel) + ')');
25
+ }
26
+ if (data && 'syntax' in data && data.syntax) {
27
+ values.push(`Syntax: ${textToMarkedString(data.syntax)}`);
28
+ }
29
+ // todo: can i use
30
+ if (additional?.docs) {
31
+ references.unshift({
32
+ name: 'Master CSS',
33
+ url: new URL(additional.docs, css.OFFICIAL_URL).href
34
+ });
35
+ }
36
+ if (references.length) {
37
+ values.push(references.map((r)=>{
38
+ return `[${r.name}](${r.url})`;
39
+ }).join(' | '));
40
+ }
41
+ return values?.length ? {
42
+ kind: 'markdown',
43
+ value: values.join('\n\n')
44
+ } : undefined;
45
+ }
46
+ const browserNames = {
47
+ E: 'Edge',
48
+ FF: 'Firefox',
49
+ S: 'Safari',
50
+ C: 'Chrome',
51
+ IE: 'IE',
52
+ O: 'Opera'
53
+ };
54
+ function getEntryStatus(status) {
55
+ switch(status){
56
+ case 'experimental':
57
+ return '⚠️ Property is experimental. Be cautious when using it.️\n\n';
58
+ case 'nonstandard':
59
+ return '🚨️ Property is nonstandard. Avoid using it.\n\n';
60
+ case 'obsolete':
61
+ return '🚨️️️ Property is obsolete. Avoid using it.\n\n';
62
+ default:
63
+ return '';
64
+ }
65
+ }
66
+ function textToMarkedString(text) {
67
+ text = text.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&') // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
68
+ ;
69
+ return text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
70
+ }
71
+ function getBrowserLabel(browsers = []) {
72
+ if (browsers.length === 0) {
73
+ return null;
74
+ }
75
+ return browsers.map((b)=>{
76
+ let value = '';
77
+ const matches = b.match(/([A-Z]+)(\d+)?/) ?? '';
78
+ const name = matches[1];
79
+ const version = matches[2];
80
+ if (name in browserNames) {
81
+ value += browserNames[name];
82
+ }
83
+ if (version) {
84
+ value += ' ' + version;
85
+ }
86
+ return value;
87
+ }).join(', ');
88
+ }
89
+
90
+ exports.getCSSDataDocumentation = getCSSDataDocumentation;
@@ -0,0 +1,5 @@
1
+ import type { IPropertyData, IValueData, MarkupContent } from 'vscode-css-languageservice';
2
+ export declare function getCSSDataDocumentation(data?: IPropertyData | IValueData, additional?: {
3
+ generatedCSS?: string;
4
+ docs?: string | false;
5
+ }): MarkupContent | undefined;
@@ -0,0 +1,88 @@
1
+ import beautifyCSS from './beautify-css.mjs';
2
+ import { OFFICIAL_URL } from '@master/css';
3
+
4
+ function getCSSDataDocumentation(data, additional) {
5
+ const values = [];
6
+ const references = data?.references ? [
7
+ ...data.references
8
+ ] : [];
9
+ if (data?.status) {
10
+ values.push(getEntryStatus(data.status));
11
+ }
12
+ if (additional?.generatedCSS) {
13
+ values.push('```css\n' + beautifyCSS(additional.generatedCSS).split('\n').slice(1).join('\n') + '\n```');
14
+ }
15
+ if (data?.description) if (typeof data.description === 'string') {
16
+ values.push(textToMarkedString(data.description));
17
+ } else {
18
+ values.push(data.description.kind === 'markdown' ? data.description.value : textToMarkedString(data.description.value));
19
+ }
20
+ const browserLabel = getBrowserLabel(data?.browsers);
21
+ if (browserLabel) {
22
+ values.push('(' + textToMarkedString(browserLabel) + ')');
23
+ }
24
+ if (data && 'syntax' in data && data.syntax) {
25
+ values.push(`Syntax: ${textToMarkedString(data.syntax)}`);
26
+ }
27
+ // todo: can i use
28
+ if (additional?.docs) {
29
+ references.unshift({
30
+ name: 'Master CSS',
31
+ url: new URL(additional.docs, OFFICIAL_URL).href
32
+ });
33
+ }
34
+ if (references.length) {
35
+ values.push(references.map((r)=>{
36
+ return `[${r.name}](${r.url})`;
37
+ }).join(' | '));
38
+ }
39
+ return values?.length ? {
40
+ kind: 'markdown',
41
+ value: values.join('\n\n')
42
+ } : undefined;
43
+ }
44
+ const browserNames = {
45
+ E: 'Edge',
46
+ FF: 'Firefox',
47
+ S: 'Safari',
48
+ C: 'Chrome',
49
+ IE: 'IE',
50
+ O: 'Opera'
51
+ };
52
+ function getEntryStatus(status) {
53
+ switch(status){
54
+ case 'experimental':
55
+ return '⚠️ Property is experimental. Be cautious when using it.️\n\n';
56
+ case 'nonstandard':
57
+ return '🚨️ Property is nonstandard. Avoid using it.\n\n';
58
+ case 'obsolete':
59
+ return '🚨️️️ Property is obsolete. Avoid using it.\n\n';
60
+ default:
61
+ return '';
62
+ }
63
+ }
64
+ function textToMarkedString(text) {
65
+ text = text.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&') // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
66
+ ;
67
+ return text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
68
+ }
69
+ function getBrowserLabel(browsers = []) {
70
+ if (browsers.length === 0) {
71
+ return null;
72
+ }
73
+ return browsers.map((b)=>{
74
+ let value = '';
75
+ const matches = b.match(/([A-Z]+)(\d+)?/) ?? '';
76
+ const name = matches[1];
77
+ const version = matches[2];
78
+ if (name in browserNames) {
79
+ value += browserNames[name];
80
+ }
81
+ if (version) {
82
+ value += ' ' + version;
83
+ }
84
+ return value;
85
+ }).join(', ');
86
+ }
87
+
88
+ export { getCSSDataDocumentation };
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+
3
+ var vscodeLanguageserverProtocol = require('vscode-languageserver-protocol');
4
+ var css = require('@master/css');
5
+ var getCssDataDocumentation = require('./get-css-data-documentation.cjs');
6
+ var sortCompletionItems = require('./sort-completion-items.cjs');
7
+ var getUtilityInfo = require('./get-utility-info.cjs');
8
+ var cssDataProvider = require('./css-data-provider.cjs');
9
+
10
+ function getMainCompletionItems(css$1 = new css.MasterCSS()) {
11
+ const completionItems = [];
12
+ const addedKeys = new Set();
13
+ for (const eachDefinedRule of css$1.definedRules){
14
+ if (eachDefinedRule.definition.type === css.SyntaxRuleType.Utility) {
15
+ const { data, detail, docs } = getUtilityInfo(eachDefinedRule, css$1);
16
+ const utilityName = eachDefinedRule.id.slice(1);
17
+ completionItems.push({
18
+ label: utilityName,
19
+ kind: vscodeLanguageserverProtocol.CompletionItemKind.Value,
20
+ documentation: getCssDataDocumentation.getCSSDataDocumentation(data, {
21
+ generatedCSS: css.generateCSS([
22
+ utilityName
23
+ ], css$1),
24
+ docs
25
+ }),
26
+ detail
27
+ });
28
+ } else {
29
+ const nativeProperties = cssDataProvider.provideProperties();
30
+ const nativeCSSPropertyData = nativeProperties.find(({ name })=>name === eachDefinedRule.id);
31
+ const eachCompletionItem = {
32
+ kind: vscodeLanguageserverProtocol.CompletionItemKind.Property,
33
+ documentation: getCssDataDocumentation.getCSSDataDocumentation(nativeCSSPropertyData, {
34
+ docs: '/reference/' + css.isCoreRule(eachDefinedRule.id) && eachDefinedRule.id
35
+ }),
36
+ detail: nativeCSSPropertyData?.syntax
37
+ };
38
+ eachDefinedRule.keys.forEach((key)=>{
39
+ addedKeys.delete(key);
40
+ completionItems.push({
41
+ ...eachCompletionItem,
42
+ label: key + ':',
43
+ sortText: key,
44
+ command: {
45
+ title: 'triggerSuggest',
46
+ command: 'editor.action.triggerSuggest'
47
+ }
48
+ });
49
+ });
50
+ /**
51
+ * @example @ animation and ~ transition
52
+ */ if (eachDefinedRule.definition?.sign && eachDefinedRule.definition.includeAnimations) {
53
+ for(const animationName in css$1.animations){
54
+ completionItems.push({
55
+ ...eachCompletionItem,
56
+ label: eachDefinedRule.definition.sign + animationName + '|1s',
57
+ kind: vscodeLanguageserverProtocol.CompletionItemKind.Value
58
+ });
59
+ }
60
+ }
61
+ if (eachDefinedRule.definition?.ambiguousKeys?.length) {
62
+ for (const ambiguousKey of eachDefinedRule.definition.ambiguousKeys){
63
+ if (addedKeys.has(ambiguousKey)) {
64
+ continue;
65
+ }
66
+ addedKeys.add(ambiguousKey);
67
+ }
68
+ }
69
+ }
70
+ }
71
+ addedKeys.forEach((ambiguousKey)=>{
72
+ /**
73
+ * Ambiguous keys are added to the completion list
74
+ * @example text: t:
75
+ */ completionItems.push({
76
+ kind: vscodeLanguageserverProtocol.CompletionItemKind.Property,
77
+ detail: 'ambiguous key',
78
+ label: ambiguousKey + ':',
79
+ sortText: ambiguousKey,
80
+ command: {
81
+ title: 'triggerSuggest',
82
+ command: 'editor.action.triggerSuggest'
83
+ }
84
+ });
85
+ });
86
+ if (css$1.config.components) {
87
+ for(const styleName in css$1.config.components){
88
+ const styleClasses = css$1.components[styleName];
89
+ completionItems.push({
90
+ label: styleName,
91
+ kind: vscodeLanguageserverProtocol.CompletionItemKind.Value,
92
+ documentation: getCssDataDocumentation.getCSSDataDocumentation({}, {
93
+ generatedCSS: css.generateCSS([
94
+ styleName
95
+ ], css$1),
96
+ docs: '/guide/components'
97
+ }),
98
+ detail: styleClasses.join(' ') + ' (style)'
99
+ });
100
+ }
101
+ }
102
+ return sortCompletionItems(completionItems);
103
+ }
104
+
105
+ module.exports = getMainCompletionItems;
@@ -0,0 +1,3 @@
1
+ import { type CompletionItem } from 'vscode-languageserver-protocol';
2
+ import { MasterCSS } from '@master/css';
3
+ export default function getMainCompletionItems(css?: MasterCSS): CompletionItem[];