@master/css-language-service 2.0.0-rc.25 → 2.0.0-rc.27

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 (111) 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 +188 -0
  5. package/dist/core.d.ts +30 -0
  6. package/dist/core.mjs +186 -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 +23 -15
  20. package/dist/index.d.ts +7 -5
  21. package/dist/index.mjs +7 -5
  22. package/dist/settings.cjs +130 -29
  23. package/dist/settings.d.ts +16 -8
  24. package/dist/settings.mjs +130 -29
  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 +1 -1
  77. package/dist/utils/regex.mjs +1 -1
  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.cjs +0 -3064
  83. package/dist/constant.d.ts +0 -33
  84. package/dist/constant.mjs +0 -3055
  85. package/dist/position-check.cjs +0 -37
  86. package/dist/position-check.d.ts +0 -7
  87. package/dist/position-check.mjs +0 -35
  88. package/dist/providers/color.cjs +0 -319
  89. package/dist/providers/color.d.ts +0 -5
  90. package/dist/providers/color.mjs +0 -315
  91. package/dist/providers/completion.cjs +0 -309
  92. package/dist/providers/completion.d.ts +0 -14
  93. package/dist/providers/completion.mjs +0 -303
  94. package/dist/providers/hover.cjs +0 -65
  95. package/dist/providers/hover.d.ts +0 -2
  96. package/dist/providers/hover.mjs +0 -63
  97. package/dist/utils/get-css-entry-markdown-description.cjs +0 -77
  98. package/dist/utils/get-css-entry-markdown-description.d.ts +0 -1
  99. package/dist/utils/get-css-entry-markdown-description.mjs +0 -75
  100. package/dist/utils/hex-to-rgb.cjs +0 -13
  101. package/dist/utils/hex-to-rgb.d.ts +0 -2
  102. package/dist/utils/hex-to-rgb.mjs +0 -11
  103. package/dist/utils/oklab-to-rgb.cjs +0 -33
  104. package/dist/utils/oklab-to-rgb.d.ts +0 -1
  105. package/dist/utils/oklab-to-rgb.mjs +0 -31
  106. package/dist/utils/oklch-to-oklab.cjs +0 -11
  107. package/dist/utils/oklch-to-oklab.d.ts +0 -1
  108. package/dist/utils/oklch-to-oklab.mjs +0 -9
  109. package/dist/utils/to-two-digit-hex.cjs +0 -8
  110. package/dist/utils/to-two-digit-hex.d.ts +0 -1
  111. package/dist/utils/to-two-digit-hex.mjs +0 -6
package/dist/settings.mjs CHANGED
@@ -1,35 +1,136 @@
1
- const settings = {
2
- languages: [
3
- 'html',
4
- 'php',
5
- 'javascript',
6
- 'typescript',
7
- 'javascriptreact',
8
- 'typescriptreact',
9
- 'vue',
10
- 'svelte',
11
- 'rust'
1
+ /* eslint-disable quotes */ /**
2
+ * @example styles https://regex101.com/r/HLPdsw/1
3
+ **/ const settings = {
4
+ includedLanguages: [
5
+ "html",
6
+ "php",
7
+ "javascript",
8
+ "typescript",
9
+ "javascriptreact",
10
+ "typescriptreact",
11
+ "vue",
12
+ "svelte",
13
+ "rust",
14
+ "astro",
15
+ "markdown",
16
+ "mdx",
17
+ "astro"
12
18
  ],
13
- classMatch: [
14
- '(class(?:Name)?\\s?=\\s?)((?:"[^"]+")|(?:\'[^\']+\')|(?:`[^`]+`))',
15
- '(class(?:Name)?={)([^}]*)}',
16
- '(?:(\\$|(?:(?:element|el|style)\\.[^\\s.`]+)`)([^`]+)`)',
17
- '(style\\.(?:.*)\\()([^)]*)\\)',
18
- '(classList.(?:add|remove|replace|replace|toggle)\\()([^)]*)\\)',
19
- '(template\\s*\\:\\s*)((?:"[^"]+")|(?:\'[^\']+\')|(?:`[^`]+`))',
20
- '(?<=styles\\s*(?:=|:)\\s*{[\\s\\S]*)([^\']*)(\'[^\']*\')',
21
- '(?<=styles\\s*(?:=|:)\\s*{[\\s\\S]*)([^"]*)("[^"]*")',
22
- '(?<=styles\\s*(?:=|:)\\s*{[\\s\\S]*)([^`]*)(`[^`]*`)'
19
+ classStrings: [
20
+ [
21
+ "\\sclass=",
22
+ "\""
23
+ ],
24
+ [
25
+ "\\sclass=",
26
+ "'"
27
+ ],
28
+ [
29
+ "\\sclassName=",
30
+ "\""
31
+ ],
32
+ [
33
+ "\\sclassName=",
34
+ "'"
35
+ ],
36
+ [
37
+ "\\sstyled(?:\\s+)?(?:\\.\\w+)?",
38
+ "`"
39
+ ],
40
+ [
41
+ "\\sstyles(?:\\s+)?(?::|=)(?:\\s+)?",
42
+ "\""
43
+ ],
44
+ [
45
+ "\\sstyles(?:\\s+)?(?::|=)(?:\\s+)?",
46
+ "'"
47
+ ],
48
+ [
49
+ "\\sstyles(?:\\s+)?(?::|=)(?:\\s+)?",
50
+ "`"
51
+ ]
52
+ ],
53
+ classAssignments: [
54
+ [
55
+ "\\sclassName=",
56
+ "{",
57
+ "}"
58
+ ],
59
+ [
60
+ "\\sclass=",
61
+ "{",
62
+ "}"
63
+ ],
64
+ [
65
+ "\\sclass:list=",
66
+ "{",
67
+ "}"
68
+ ],
69
+ [
70
+ "\\sstyles(?:\\s+)?(?::|=)(?:\\s+)?",
71
+ "{",
72
+ "}"
73
+ ],
74
+ [
75
+ "\\s:class=",
76
+ "\"",
77
+ "\""
78
+ ],
79
+ [
80
+ "\\sv-bind:class=",
81
+ "\"",
82
+ "\""
83
+ ],
84
+ [
85
+ "\\s[class]=",
86
+ "\"",
87
+ "\""
88
+ ],
89
+ [
90
+ "\\s[className]=",
91
+ "\"",
92
+ "\""
93
+ ],
94
+ [
95
+ "\\s[ngClass]=",
96
+ "\"",
97
+ "\""
98
+ ],
99
+ [
100
+ "\\sclsx",
101
+ "(",
102
+ ")"
103
+ ],
104
+ [
105
+ "\\scva",
106
+ "(",
107
+ ")"
108
+ ],
109
+ [
110
+ "\\.class",
111
+ "(",
112
+ ")"
113
+ ],
114
+ [
115
+ "\\sstyled(?:\\s+)?(?:\\.\\w+)?",
116
+ "(",
117
+ ")"
118
+ ],
119
+ [
120
+ "\\.classList(?:\\s+)?(?:\\.(add|remove|toggle|replace))",
121
+ "(",
122
+ ")"
123
+ ]
23
124
  ],
24
125
  exclude: [
25
- '**/.git/**',
26
- '**/node_modules/**',
27
- '**/.hg/**'
126
+ "**/.git/**",
127
+ "**/node_modules/**",
128
+ "**/.hg/**"
28
129
  ],
29
- suggestions: true,
30
- inspect: true,
31
- previewColors: true,
32
- config: 'master.css'
130
+ suggestSyntax: true,
131
+ inspectSyntax: true,
132
+ renderSyntaxColors: true,
133
+ editSyntaxColors: true
33
134
  };
34
135
 
35
- export { settings };
136
+ export { settings as default };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var beautifyCss = require('js-beautify/js/lib/beautify-css');
4
+
5
+ // @ts-expect-error
6
+ function beautifyCSS(text) {
7
+ return beautifyCss.css_beautify(text, {
8
+ newline_between_rules: false,
9
+ indent_size: 2
10
+ });
11
+ }
12
+
13
+ module.exports = beautifyCSS;
@@ -0,0 +1 @@
1
+ export default function beautifyCSS(text: string): any;
@@ -0,0 +1,11 @@
1
+ import { css_beautify } from 'js-beautify/js/lib/beautify-css';
2
+
3
+ // @ts-expect-error
4
+ function beautifyCSS(text) {
5
+ return css_beautify(text, {
6
+ newline_between_rules: false,
7
+ indent_size: 2
8
+ });
9
+ }
10
+
11
+ export { beautifyCSS as default };
@@ -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/css 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/css 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) + '\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(`/docs/${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;