@master/css-language-service 2.0.0-rc.14 → 2.0.0-rc.16

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.
@@ -0,0 +1,283 @@
1
+ import { masterCssOtherKeys, masterCssKeyValues, masterCssSelectors, masterCssElements, masterCssType, masterCssMedia, masterCssCommonValues } from '../constant.mjs';
2
+ import { MasterCSS } from '@master/css';
3
+ import { cssData } from 'vscode-css-languageservice/lib/umd/data/webCustomData';
4
+ import { CSSDataProvider } from 'vscode-css-languageservice/lib/umd/languageFacts/dataProvider';
5
+
6
+ let cssKeys = [];
7
+ cssKeys = cssKeys.concat(masterCssOtherKeys);
8
+ masterCssKeyValues.forEach((x)=>{
9
+ cssKeys = cssKeys.concat(x.key);
10
+ });
11
+ const masterCssKeys = [
12
+ ...new Set(cssKeys)
13
+ ];
14
+ // temporary
15
+ function checkConfigColorsBlock(document, position) {
16
+ const lineText = (document?.getText({
17
+ start: {
18
+ line: position.line,
19
+ character: 0
20
+ },
21
+ end: {
22
+ line: position.line,
23
+ character: position.character
24
+ }
25
+ }) ?? '').trim();
26
+ if ((lineText.match(/'|"|`/g)?.length ?? 0) % 2 === 0) {
27
+ return false;
28
+ }
29
+ for(let i = position.line; i > 0; i--){
30
+ const text = document.getText({
31
+ start: {
32
+ line: i - 1,
33
+ character: 0
34
+ },
35
+ end: {
36
+ line: i,
37
+ character: 0
38
+ }
39
+ });
40
+ if (text.includes('}')) {
41
+ return false;
42
+ } else if (text.includes('colors:')) {
43
+ return true;
44
+ }
45
+ }
46
+ return false;
47
+ }
48
+ function getLastInstance(lineText, position, language) {
49
+ const classPattern = /(?:[^"{'\s])+(?=>\s|\b)/g;
50
+ let classMatch;
51
+ let lastKey = '';
52
+ let triggerKey = lineText.charAt(lineText.length - 1);
53
+ let isStart = position.character == 1 || lineText.charAt(lineText.length - 2) === ' ' || lineText.charAt(lineText.length - 2) === '' || lineText.charAt(lineText.length - 2) === '"' || lineText.charAt(lineText.length - 2) === '\'' || lineText.charAt(lineText.length - 2) === '{';
54
+ if (lineText.match(classPattern) === null) {
55
+ return {
56
+ isInstance: false,
57
+ lastKey: '',
58
+ triggerKey: '',
59
+ isStart: false,
60
+ language: language
61
+ };
62
+ } else {
63
+ while((classMatch = classPattern.exec(lineText)) !== null){
64
+ lastKey = classMatch[0];
65
+ }
66
+ }
67
+ if (lineText.charAt(lineText.length - 2) === ':' && lineText.charAt(lineText.length - 1) === ':') {
68
+ triggerKey = '::';
69
+ isStart = false;
70
+ }
71
+ return {
72
+ isInstance: true,
73
+ lastKey: lastKey,
74
+ triggerKey: triggerKey,
75
+ isStart: isStart,
76
+ language: language
77
+ };
78
+ }
79
+ function getConfigColorsCompletionItem(css = new MasterCSS()) {
80
+ let masterStyleCompletionItem = [];
81
+ masterStyleCompletionItem = masterStyleCompletionItem.concat(getColorsItem(css));
82
+ return masterStyleCompletionItem;
83
+ }
84
+ function getCompletionItem(instance, triggerKey, isStart, language, css = new MasterCSS()) {
85
+ const cssDataProvider = new CSSDataProvider(cssData);
86
+ const cssProperties = cssDataProvider.provideProperties();
87
+ let masterStyleCompletionItem = [];
88
+ const haveValue = instance.split(':').length;
89
+ let key = instance.split(':')[0];
90
+ key = key.trim();
91
+ const instanceLength = instance.split(':|@').length;
92
+ const last = instance.split(':|@')[instanceLength - 1];
93
+ const mediaPattern = /[^\\s"]+@+([^\\s:"@]+)/g;
94
+ const elementsPattern = /[^\\s"]+::+([^\\s:"@]+)/g;
95
+ let isColorful = false;
96
+ const isMedia = !(mediaPattern.exec(instance) === null && triggerKey !== '@');
97
+ const isElements = !(elementsPattern.exec(instance) === null && triggerKey !== '::');
98
+ const masterCssKeyCompletionItems = [];
99
+ let masterCssValues = [];
100
+ const masterCustomSelectors = Object.keys(css.config?.selectors ?? {}).map((x)=>x.endsWith('(') ? `${x})` : x).filter((x)=>x.match(/:[^:]+/) && !masterCssSelectors.find((existedSelector)=>(typeof existedSelector === 'string' ? existedSelector : existedSelector.label) === `:${x}`)).map((x)=>{
101
+ x = x.substring(1);
102
+ if (x.endsWith(')')) {
103
+ return {
104
+ label: x,
105
+ kind: 3
106
+ };
107
+ }
108
+ return x;
109
+ });
110
+ const masterCustomElements = Object.keys(css.config?.selectors ?? {}).map((x)=>x.endsWith('(') ? `${x})` : x).filter((x)=>x.match(/::[^:]+/) && !masterCssElements.find((existedElement)=>(typeof existedElement === 'string' ? existedElement : existedElement.label) === `::${x}`)).map((x)=>{
111
+ x = x.substring(2);
112
+ if (x.endsWith(')')) {
113
+ return {
114
+ label: x,
115
+ kind: 3
116
+ };
117
+ }
118
+ return x;
119
+ });
120
+ masterCssKeyValues.forEach((x)=>{
121
+ const fullKey = x.key[0];
122
+ const originalCssProperty = cssProperties.find((x)=>x.name == fullKey);
123
+ const originalCssValues = originalCssProperty?.values ?? [];
124
+ for (const masterKey of x.key){
125
+ if (!masterCssKeyCompletionItems.find((existedValue)=>existedValue.label === masterKey + ':')) {
126
+ masterCssKeyCompletionItems.push({
127
+ label: masterKey + ':',
128
+ kind: 10,
129
+ documentation: originalCssProperty?.description ?? '',
130
+ command: {
131
+ title: 'triggerSuggest',
132
+ command: 'editor.action.triggerSuggest'
133
+ }
134
+ });
135
+ }
136
+ }
137
+ if (x.key.includes(key)) {
138
+ // constant.ts custom values
139
+ masterCssValues = masterCssValues.concat(x.values.filter((cssValue)=>!masterCssValues.find((existedValue)=>(typeof existedValue === 'string' ? existedValue : existedValue.label) === (typeof cssValue === 'string' ? cssValue : cssValue.label))));
140
+ masterCssValues = masterCssValues.concat(originalCssValues.filter((cssValue, index)=>cssValue.description || !cssValue.description && originalCssValues.indexOf(cssValue) === index).map((cssValue)=>({
141
+ label: cssValue.name.replace(/,\s/g, ',').replace(/\s/g, '|').replace(/["']/g, ''),
142
+ kind: 10,
143
+ documentation: cssValue?.description ?? ''
144
+ })).filter((cssValue)=>!masterCssValues.find((existedValue)=>(typeof existedValue === 'string' ? existedValue : existedValue.label) === (typeof cssValue === 'string' ? cssValue : cssValue.label))));
145
+ if (css.config?.variables?.[fullKey]) {
146
+ const masterCustomVariables = Object.keys(css.config?.variables[fullKey]);
147
+ masterCssValues = masterCssValues.concat(masterCustomVariables.filter((customValue)=>!masterCssValues.find((existedValue)=>(typeof existedValue === 'string' ? existedValue : existedValue.label) === customValue)));
148
+ }
149
+ if (x.colored) {
150
+ isColorful = true;
151
+ const needPushList = masterCssType.find((y)=>y.type === 'color')?.values.filter((z)=>!masterCssValues.find((a)=>(typeof a === 'string' ? a : a.label) === (typeof z === 'string' ? z : z.label)));
152
+ if (needPushList) {
153
+ masterCssValues = masterCssValues.concat(needPushList);
154
+ }
155
+ }
156
+ }
157
+ });
158
+ if ((isStart == true || !masterCssKeys.includes(key)) && triggerKey !== '@' && triggerKey !== ':') {
159
+ masterStyleCompletionItem = masterStyleCompletionItem.concat(masterCssKeyCompletionItems);
160
+ masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(Object.keys(css.config?.semantics ?? {}), 10));
161
+ if (language == 'tsx' || language == 'vue' || language == 'jsx') {
162
+ return HaveDash(key, masterStyleCompletionItem);
163
+ }
164
+ return masterStyleCompletionItem;
165
+ } else if (isStart == true) {
166
+ return [];
167
+ }
168
+ if (masterCssKeys.includes(key) && key !== null && isElements === true) {
169
+ masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCssElements, 10));
170
+ masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCustomElements, 10));
171
+ if ((language == 'tsx' || language == 'vue' || language == 'jsx') && triggerKey !== '@' && triggerKey !== ':') {
172
+ return HaveDash(last, masterStyleCompletionItem);
173
+ }
174
+ return masterStyleCompletionItem;
175
+ }
176
+ if (masterCssKeys.includes(key) && key !== null && isMedia === true) {
177
+ masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCssMedia, 10));
178
+ // todo: refactor theme
179
+ masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem([
180
+ 'light',
181
+ 'dark'
182
+ ], 10));
183
+ if ((language == 'tsx' || language == 'vue' || language == 'jsx') && triggerKey !== '@' && triggerKey !== ':') {
184
+ return HaveDash('@' + last, masterStyleCompletionItem);
185
+ }
186
+ return masterStyleCompletionItem;
187
+ }
188
+ if (Object.keys(css.config?.semantics ?? {}).includes(key) && !masterCssKeyValues.find((x)=>x.key.includes(key))) {
189
+ masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCssSelectors, 10));
190
+ masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCustomSelectors, 10));
191
+ if ((language == 'tsx' || language == 'vue' || language == 'jsx') && triggerKey !== '@' && triggerKey !== ':') {
192
+ return HaveDash(last, masterStyleCompletionItem);
193
+ }
194
+ return masterStyleCompletionItem;
195
+ } else if (masterCssKeys.includes(key) && haveValue <= 2 && !(haveValue == 2 && triggerKey === ':')) {
196
+ masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCssValues, 10));
197
+ masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCssCommonValues, 13).map((x)=>{
198
+ x.sortText = 'z' + x;
199
+ return x;
200
+ }));
201
+ if (isColorful) {
202
+ masterStyleCompletionItem = masterStyleCompletionItem.concat(getColorsItem(css));
203
+ }
204
+ if ((language == 'tsx' || language == 'vue' || language == 'jsx') && triggerKey !== '@' && triggerKey !== ':') {
205
+ return HaveDash(last, masterStyleCompletionItem);
206
+ }
207
+ return masterStyleCompletionItem;
208
+ }
209
+ if (masterCssKeys.includes(key) && (haveValue == 2 && triggerKey === ':' || haveValue >= 3) || masterCssKeyValues.find((x)=>x.values.includes(key))) {
210
+ masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCssSelectors, 3));
211
+ masterStyleCompletionItem = masterStyleCompletionItem.concat(getReturnItem(masterCustomSelectors, 10));
212
+ }
213
+ if ((language == 'tsx' || language == 'vue' || language == 'jsx') && triggerKey !== '@' && triggerKey !== ':') {
214
+ return HaveDash(last, masterStyleCompletionItem);
215
+ }
216
+ return masterStyleCompletionItem;
217
+ }
218
+ function getReturnItem(items, kind, insertText = '') {
219
+ const masterStyleCompletionItem = [];
220
+ items.forEach((x)=>{
221
+ if (typeof x === 'string') {
222
+ masterStyleCompletionItem.push({
223
+ label: x + insertText,
224
+ kind: kind,
225
+ insertText: x + insertText,
226
+ insertTextMode: 2,
227
+ command: insertText === ':' ? {
228
+ title: 'triggerSuggest',
229
+ command: 'editor.action.triggerSuggest'
230
+ } : undefined
231
+ });
232
+ } else {
233
+ masterStyleCompletionItem.push({
234
+ insertText: x.label + insertText,
235
+ insertTextMode: 2,
236
+ command: insertText === ':' ? {
237
+ title: 'triggerSuggest',
238
+ command: 'editor.action.triggerSuggest'
239
+ } : undefined,
240
+ ...x
241
+ });
242
+ }
243
+ });
244
+ return masterStyleCompletionItem;
245
+ }
246
+ function getColorsItem(css = new MasterCSS()) {
247
+ const masterStyleCompletionItem = [];
248
+ // todo: refactor css.variables
249
+ for(const eachVariableName in css.variables){
250
+ const eachVariable = css.variables[eachVariableName];
251
+ if (eachVariable.type === 'color') {
252
+ masterStyleCompletionItem.push({
253
+ label: eachVariableName,
254
+ documentation: eachVariable.value,
255
+ kind: 16,
256
+ sortText: eachVariableName
257
+ });
258
+ }
259
+ }
260
+ return masterStyleCompletionItem;
261
+ }
262
+ function HaveDash(str, itemList) {
263
+ const completionItem = [];
264
+ if (str.split('-').length - 1 <= 0) {
265
+ return itemList;
266
+ } else {
267
+ const start = str.split('-')[0] + '-';
268
+ itemList.map((x)=>{
269
+ if (x.label.includes(start)) {
270
+ completionItem.push({
271
+ label: x.label,
272
+ kind: x.kind,
273
+ insertText: x.insertText?.substring(start.length),
274
+ insertTextMode: x.insertTextMode,
275
+ command: x.command
276
+ });
277
+ }
278
+ });
279
+ return completionItem;
280
+ }
281
+ }
282
+
283
+ export { checkConfigColorsBlock, getCompletionItem, getConfigColorsCompletionItem, getLastInstance, getReturnItem };
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+
3
+ var css = require('@master/css');
4
+ var getCssEntryMarkdownDescription = require('../utils/get-css-entry-markdown-description.cjs');
5
+ var beautifyCss = require('js-beautify/js/lib/beautify-css');
6
+ var webCustomData = require('vscode-css-languageservice/lib/umd/data/webCustomData');
7
+ var dataProvider = require('vscode-css-languageservice/lib/umd/languageFacts/dataProvider');
8
+
9
+ function doHover(instance, range, config) {
10
+ const css$1 = new css.MasterCSS(config);
11
+ css$1.add(instance);
12
+ const contents = [];
13
+ if (css$1.text) {
14
+ const cssPreview = getCssPreview(instance, css$1.text);
15
+ if (cssPreview) {
16
+ contents.push(cssPreview);
17
+ }
18
+ }
19
+ const cssHoverInfo = getCssHoverInfo(instance, css$1.rules[0]);
20
+ if (cssHoverInfo) {
21
+ contents.push(cssHoverInfo);
22
+ }
23
+ return {
24
+ contents,
25
+ range: range
26
+ };
27
+ }
28
+ function getCssPreview(instance, renderText) {
29
+ return {
30
+ language: 'css',
31
+ value: beautifyCss.css_beautify(renderText, {
32
+ newline_between_rules: true,
33
+ end_with_newline: true
34
+ })
35
+ };
36
+ }
37
+ function getCssHoverInfo(instance, rule) {
38
+ const cssDataProvider = new dataProvider.CSSDataProvider(webCustomData.cssData);
39
+ const cssProperties = cssDataProvider.provideProperties();
40
+ let cssHoverInfo = null;
41
+ const fullKey = rule.id;
42
+ const originalCssProperty = cssProperties.find((x)=>x.name == fullKey);
43
+ if ([
44
+ css.Layer.Core,
45
+ css.Layer.CoreNative,
46
+ css.Layer.CoreShorthand,
47
+ css.Layer.CoreNativeShorthand
48
+ ].includes(rule.layer) && originalCssProperty) {
49
+ if (!originalCssProperty.references?.find((x)=>x.name === 'Master Reference')) {
50
+ originalCssProperty.references = [
51
+ ...originalCssProperty?.references ?? [],
52
+ {
53
+ name: 'Master Reference',
54
+ url: `https://rc.css.master.co/docs/${fullKey}`
55
+ }
56
+ ];
57
+ }
58
+ cssHoverInfo = getCssEntryMarkdownDescription.getCssEntryMarkdownDescription(originalCssProperty);
59
+ }
60
+ return cssHoverInfo;
61
+ }
62
+
63
+ exports.doHover = doHover;
@@ -0,0 +1,61 @@
1
+ import { MasterCSS, Layer } from '@master/css';
2
+ import { getCssEntryMarkdownDescription } from '../utils/get-css-entry-markdown-description.mjs';
3
+ import { css_beautify } from 'js-beautify/js/lib/beautify-css';
4
+ import { cssData } from 'vscode-css-languageservice/lib/umd/data/webCustomData';
5
+ import { CSSDataProvider } from 'vscode-css-languageservice/lib/umd/languageFacts/dataProvider';
6
+
7
+ function doHover(instance, range, config) {
8
+ const css = new MasterCSS(config);
9
+ css.add(instance);
10
+ const contents = [];
11
+ if (css.text) {
12
+ const cssPreview = getCssPreview(instance, css.text);
13
+ if (cssPreview) {
14
+ contents.push(cssPreview);
15
+ }
16
+ }
17
+ const cssHoverInfo = getCssHoverInfo(instance, css.rules[0]);
18
+ if (cssHoverInfo) {
19
+ contents.push(cssHoverInfo);
20
+ }
21
+ return {
22
+ contents,
23
+ range: range
24
+ };
25
+ }
26
+ function getCssPreview(instance, renderText) {
27
+ return {
28
+ language: 'css',
29
+ value: css_beautify(renderText, {
30
+ newline_between_rules: true,
31
+ end_with_newline: true
32
+ })
33
+ };
34
+ }
35
+ function getCssHoverInfo(instance, rule) {
36
+ const cssDataProvider = new CSSDataProvider(cssData);
37
+ const cssProperties = cssDataProvider.provideProperties();
38
+ let cssHoverInfo = null;
39
+ const fullKey = rule.id;
40
+ const originalCssProperty = cssProperties.find((x)=>x.name == fullKey);
41
+ if ([
42
+ Layer.Core,
43
+ Layer.CoreNative,
44
+ Layer.CoreShorthand,
45
+ Layer.CoreNativeShorthand
46
+ ].includes(rule.layer) && originalCssProperty) {
47
+ if (!originalCssProperty.references?.find((x)=>x.name === 'Master Reference')) {
48
+ originalCssProperty.references = [
49
+ ...originalCssProperty?.references ?? [],
50
+ {
51
+ name: 'Master Reference',
52
+ url: `https://rc.css.master.co/docs/${fullKey}`
53
+ }
54
+ ];
55
+ }
56
+ cssHoverInfo = getCssEntryMarkdownDescription(originalCssProperty);
57
+ }
58
+ return cssHoverInfo;
59
+ }
60
+
61
+ export { doHover };
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ const settings = {
4
+ languages: [
5
+ 'html',
6
+ 'php',
7
+ 'javascript',
8
+ 'typescript',
9
+ 'javascriptreact',
10
+ 'typescriptreact',
11
+ 'vue',
12
+ 'svelte',
13
+ 'rust'
14
+ ],
15
+ classMatch: [
16
+ '(class(?:Name)?\\s?=\\s?)((?:"[^"]+")|(?:\'[^\']+\')|(?:`[^`]+`))',
17
+ '(class(?:Name)?={)([^}]*)}',
18
+ '(?:(\\$|(?:(?:element|el|style)\\.[^\\s.`]+)`)([^`]+)`)',
19
+ '(style\\.(?:.*)\\()([^)]*)\\)',
20
+ '(classList.(?:add|remove|replace|replace|toggle)\\()([^)]*)\\)',
21
+ '(template\\s*\\:\\s*)((?:"[^"]+")|(?:\'[^\']+\')|(?:`[^`]+`))',
22
+ '(?<=styles\\s*(?:=|:)\\s*{[\\s\\S]*)([^\']*)(\'[^\']*\')',
23
+ '(?<=styles\\s*(?:=|:)\\s*{[\\s\\S]*)([^"]*)("[^"]*")',
24
+ '(?<=styles\\s*(?:=|:)\\s*{[\\s\\S]*)([^`]*)(`[^`]*`)'
25
+ ],
26
+ exclude: [
27
+ '**/.git/**',
28
+ '**/node_modules/**',
29
+ '**/.hg/**'
30
+ ],
31
+ suggestions: true,
32
+ inspect: true,
33
+ previewColors: true,
34
+ config: 'master.css'
35
+ };
36
+
37
+ exports.settings = settings;
@@ -0,0 +1,35 @@
1
+ const settings = {
2
+ languages: [
3
+ 'html',
4
+ 'php',
5
+ 'javascript',
6
+ 'typescript',
7
+ 'javascriptreact',
8
+ 'typescriptreact',
9
+ 'vue',
10
+ 'svelte',
11
+ 'rust'
12
+ ],
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]*)([^`]*)(`[^`]*`)'
23
+ ],
24
+ exclude: [
25
+ '**/.git/**',
26
+ '**/node_modules/**',
27
+ '**/.hg/**'
28
+ ],
29
+ suggestions: true,
30
+ inspect: true,
31
+ previewColors: true,
32
+ config: 'master.css'
33
+ };
34
+
35
+ export { settings };
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ function getCssEntryMarkdownDescription(entry) {
4
+ if (!entry?.description || entry?.description === '') {
5
+ return '';
6
+ }
7
+ let result = '';
8
+ if (entry.status) {
9
+ result += getEntryStatus(entry.status);
10
+ }
11
+ if (typeof entry.description === 'string') {
12
+ result += textToMarkedString(entry.description);
13
+ } else {
14
+ result += entry.description.kind === 'markdown' ? entry.description.value : textToMarkedString(entry.description.value);
15
+ }
16
+ const browserLabel = getBrowserLabel(entry.browsers);
17
+ if (browserLabel) {
18
+ result += '\n\n(' + textToMarkedString(browserLabel) + ')';
19
+ }
20
+ if ('syntax' in entry && entry.syntax) {
21
+ result += `\n\nSyntax: ${textToMarkedString(entry.syntax)}`;
22
+ }
23
+ if (entry.references && entry.references.length > 0) {
24
+ if (result.length > 0) {
25
+ result += '\n\n';
26
+ }
27
+ result += entry.references.map((r)=>{
28
+ return `[${r.name}](${r.url})`;
29
+ }).join(' | ');
30
+ }
31
+ return result;
32
+ }
33
+ const browserNames = {
34
+ E: 'Edge',
35
+ FF: 'Firefox',
36
+ S: 'Safari',
37
+ C: 'Chrome',
38
+ IE: 'IE',
39
+ O: 'Opera'
40
+ };
41
+ function getEntryStatus(status) {
42
+ switch(status){
43
+ case 'experimental':
44
+ return '⚠️ Property is experimental. Be cautious when using it.️\n\n';
45
+ case 'nonstandard':
46
+ return '🚨️ Property is nonstandard. Avoid using it.\n\n';
47
+ case 'obsolete':
48
+ return '🚨️️️ Property is obsolete. Avoid using it.\n\n';
49
+ default:
50
+ return '';
51
+ }
52
+ }
53
+ function textToMarkedString(text) {
54
+ text = text.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&') // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
55
+ ;
56
+ return text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
57
+ }
58
+ function getBrowserLabel(browsers = []) {
59
+ if (browsers.length === 0) {
60
+ return null;
61
+ }
62
+ return browsers.map((b)=>{
63
+ let result = '';
64
+ const matches = b.match(/([A-Z]+)(\d+)?/) ?? '';
65
+ const name = matches[1];
66
+ const version = matches[2];
67
+ if (name in browserNames) {
68
+ result += browserNames[name];
69
+ }
70
+ if (version) {
71
+ result += ' ' + version;
72
+ }
73
+ return result;
74
+ }).join(', ');
75
+ }
76
+
77
+ exports.getCssEntryMarkdownDescription = getCssEntryMarkdownDescription;
@@ -0,0 +1,75 @@
1
+ function getCssEntryMarkdownDescription(entry) {
2
+ if (!entry?.description || entry?.description === '') {
3
+ return '';
4
+ }
5
+ let result = '';
6
+ if (entry.status) {
7
+ result += getEntryStatus(entry.status);
8
+ }
9
+ if (typeof entry.description === 'string') {
10
+ result += textToMarkedString(entry.description);
11
+ } else {
12
+ result += entry.description.kind === 'markdown' ? entry.description.value : textToMarkedString(entry.description.value);
13
+ }
14
+ const browserLabel = getBrowserLabel(entry.browsers);
15
+ if (browserLabel) {
16
+ result += '\n\n(' + textToMarkedString(browserLabel) + ')';
17
+ }
18
+ if ('syntax' in entry && entry.syntax) {
19
+ result += `\n\nSyntax: ${textToMarkedString(entry.syntax)}`;
20
+ }
21
+ if (entry.references && entry.references.length > 0) {
22
+ if (result.length > 0) {
23
+ result += '\n\n';
24
+ }
25
+ result += entry.references.map((r)=>{
26
+ return `[${r.name}](${r.url})`;
27
+ }).join(' | ');
28
+ }
29
+ return result;
30
+ }
31
+ const browserNames = {
32
+ E: 'Edge',
33
+ FF: 'Firefox',
34
+ S: 'Safari',
35
+ C: 'Chrome',
36
+ IE: 'IE',
37
+ O: 'Opera'
38
+ };
39
+ function getEntryStatus(status) {
40
+ switch(status){
41
+ case 'experimental':
42
+ return '⚠️ Property is experimental. Be cautious when using it.️\n\n';
43
+ case 'nonstandard':
44
+ return '🚨️ Property is nonstandard. Avoid using it.\n\n';
45
+ case 'obsolete':
46
+ return '🚨️️️ Property is obsolete. Avoid using it.\n\n';
47
+ default:
48
+ return '';
49
+ }
50
+ }
51
+ function textToMarkedString(text) {
52
+ text = text.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&') // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
53
+ ;
54
+ return text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
55
+ }
56
+ function getBrowserLabel(browsers = []) {
57
+ if (browsers.length === 0) {
58
+ return null;
59
+ }
60
+ return browsers.map((b)=>{
61
+ let result = '';
62
+ const matches = b.match(/([A-Z]+)(\d+)?/) ?? '';
63
+ const name = matches[1];
64
+ const version = matches[2];
65
+ if (name in browserNames) {
66
+ result += browserNames[name];
67
+ }
68
+ if (version) {
69
+ result += ' ' + version;
70
+ }
71
+ return result;
72
+ }).join(', ');
73
+ }
74
+
75
+ export { getCssEntryMarkdownDescription };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ function hexToRgb(hex) {
4
+ const aRgbHex = hex.replace('#', '').match(/.{1,2}/g);
5
+ return {
6
+ red: parseInt(aRgbHex?.[0] ?? '0', 16),
7
+ green: parseInt(aRgbHex?.[1] ?? '0', 16),
8
+ blue: parseInt(aRgbHex?.[2] ?? '0', 16),
9
+ alpha: parseInt(aRgbHex?.[3] ?? 'FF', 16)
10
+ };
11
+ }
12
+
13
+ exports.hexToRgb = hexToRgb;
@@ -0,0 +1,11 @@
1
+ function hexToRgb(hex) {
2
+ const aRgbHex = hex.replace('#', '').match(/.{1,2}/g);
3
+ return {
4
+ red: parseInt(aRgbHex?.[0] ?? '0', 16),
5
+ green: parseInt(aRgbHex?.[1] ?? '0', 16),
6
+ blue: parseInt(aRgbHex?.[2] ?? '0', 16),
7
+ alpha: parseInt(aRgbHex?.[3] ?? 'FF', 16)
8
+ };
9
+ }
10
+
11
+ export { hexToRgb };