@master/css-language-service 2.0.0-rc.2 → 2.0.0-rc.21
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.
- package/dist/constant.cjs +3064 -0
- package/dist/constant.mjs +3055 -0
- package/dist/index.cjs +21 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +5 -0
- package/dist/position-check.cjs +37 -0
- package/dist/position-check.d.ts +5 -18
- package/dist/position-check.mjs +35 -0
- package/dist/providers/color.cjs +319 -0
- package/dist/providers/color.mjs +315 -0
- package/dist/providers/completion.cjs +289 -0
- package/dist/providers/completion.mjs +283 -0
- package/dist/providers/hover.cjs +65 -0
- package/dist/providers/hover.mjs +63 -0
- package/dist/settings.cjs +37 -0
- package/dist/settings.mjs +35 -0
- package/dist/utils/get-css-entry-markdown-description.cjs +77 -0
- package/dist/utils/get-css-entry-markdown-description.mjs +75 -0
- package/dist/utils/hex-to-rgb.cjs +13 -0
- package/dist/utils/hex-to-rgb.mjs +11 -0
- package/dist/utils/oklab-to-rgb.cjs +33 -0
- package/dist/utils/oklab-to-rgb.mjs +31 -0
- package/dist/utils/oklch-to-oklab.cjs +11 -0
- package/dist/utils/oklch-to-oklab.mjs +9 -0
- package/dist/utils/regex.cjs +5 -0
- package/dist/utils/regex.mjs +3 -0
- package/dist/utils/to-two-digit-hex.cjs +8 -0
- package/dist/utils/to-two-digit-hex.mjs +6 -0
- package/package.json +1 -1
- package/dist/index.bundle.js +0 -33
- package/dist/settings.bundle.js +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var color = require('./providers/color.cjs');
|
|
4
|
+
var completion = require('./providers/completion.cjs');
|
|
5
|
+
var hover = require('./providers/hover.cjs');
|
|
6
|
+
var positionCheck = require('./position-check.cjs');
|
|
7
|
+
var settings = require('./settings.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.getColorPresentation = color.getColorPresentation;
|
|
12
|
+
exports.getColorValue = color.getColorValue;
|
|
13
|
+
exports.getDocumentColors = color.getDocumentColors;
|
|
14
|
+
exports.checkConfigColorsBlock = completion.checkConfigColorsBlock;
|
|
15
|
+
exports.getCompletionItem = completion.getCompletionItem;
|
|
16
|
+
exports.getConfigColorsCompletionItem = completion.getConfigColorsCompletionItem;
|
|
17
|
+
exports.getLastInstance = completion.getLastInstance;
|
|
18
|
+
exports.getReturnItem = completion.getReturnItem;
|
|
19
|
+
exports.doHover = hover.doHover;
|
|
20
|
+
exports.positionCheck = positionCheck.positionCheck;
|
|
21
|
+
exports.settings = settings.settings;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
export * from './providers/color';
|
|
2
|
+
export * from './providers/completion';
|
|
3
|
+
export * from './providers/hover';
|
|
4
|
+
export * from './position-check';
|
|
5
|
+
export * from './settings';
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { getColorPresentation, getColorValue, getDocumentColors } from './providers/color.mjs';
|
|
2
|
+
export { checkConfigColorsBlock, getCompletionItem, getConfigColorsCompletionItem, getLastInstance, getReturnItem } from './providers/completion.mjs';
|
|
3
|
+
export { doHover } from './providers/hover.mjs';
|
|
4
|
+
export { positionCheck } from './position-check.mjs';
|
|
5
|
+
export { settings } from './settings.mjs';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var regex = require('./utils/regex.cjs');
|
|
4
|
+
|
|
5
|
+
function positionCheck(text, positionIndex, startIndex, RegExpList) {
|
|
6
|
+
let result;
|
|
7
|
+
let instanceMatch;
|
|
8
|
+
let classMatch;
|
|
9
|
+
for (const classRegexString of RegExpList){
|
|
10
|
+
const classPattern = new RegExp(classRegexString, 'g');
|
|
11
|
+
while((classMatch = classPattern.exec(text)) !== null){
|
|
12
|
+
if ((classMatch.index <= positionIndex - startIndex && classMatch.index + classMatch[0].length >= positionIndex - startIndex) == true) {
|
|
13
|
+
const classContentStartIndex = classMatch.index + classMatch[1].length;
|
|
14
|
+
regex.instancePattern.lastIndex = 0;
|
|
15
|
+
while((instanceMatch = regex.instancePattern.exec(classMatch[2])) !== null){
|
|
16
|
+
const instanceStartIndex = classContentStartIndex + instanceMatch.index;
|
|
17
|
+
const instanceEndIndex = classContentStartIndex + instanceMatch.index + instanceMatch[0].length;
|
|
18
|
+
if (instanceStartIndex <= positionIndex - startIndex && instanceEndIndex >= positionIndex - startIndex) {
|
|
19
|
+
result = {
|
|
20
|
+
index: {
|
|
21
|
+
start: instanceStartIndex,
|
|
22
|
+
end: instanceEndIndex
|
|
23
|
+
},
|
|
24
|
+
instanceContent: instanceMatch[0]
|
|
25
|
+
};
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
} else if (classMatch.index > positionIndex - startIndex) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.positionCheck = positionCheck;
|
package/dist/position-check.d.ts
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
export declare function positionCheck(text: string, positionIndex: number, startIndex: number, RegExpList: string[]): {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
classString: string;
|
|
6
|
-
instance: {
|
|
7
|
-
index: {
|
|
8
|
-
start: number;
|
|
9
|
-
end: number;
|
|
10
|
-
};
|
|
11
|
-
instanceString: string;
|
|
2
|
+
index: {
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
12
5
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
start: number;
|
|
16
|
-
end: number;
|
|
17
|
-
};
|
|
18
|
-
instanceString: string;
|
|
19
|
-
}[];
|
|
20
|
-
};
|
|
6
|
+
instanceContent: string;
|
|
7
|
+
} | null;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { instancePattern } from './utils/regex.mjs';
|
|
2
|
+
|
|
3
|
+
function positionCheck(text, positionIndex, startIndex, RegExpList) {
|
|
4
|
+
let result;
|
|
5
|
+
let instanceMatch;
|
|
6
|
+
let classMatch;
|
|
7
|
+
for (const classRegexString of RegExpList){
|
|
8
|
+
const classPattern = new RegExp(classRegexString, 'g');
|
|
9
|
+
while((classMatch = classPattern.exec(text)) !== null){
|
|
10
|
+
if ((classMatch.index <= positionIndex - startIndex && classMatch.index + classMatch[0].length >= positionIndex - startIndex) == true) {
|
|
11
|
+
const classContentStartIndex = classMatch.index + classMatch[1].length;
|
|
12
|
+
instancePattern.lastIndex = 0;
|
|
13
|
+
while((instanceMatch = instancePattern.exec(classMatch[2])) !== null){
|
|
14
|
+
const instanceStartIndex = classContentStartIndex + instanceMatch.index;
|
|
15
|
+
const instanceEndIndex = classContentStartIndex + instanceMatch.index + instanceMatch[0].length;
|
|
16
|
+
if (instanceStartIndex <= positionIndex - startIndex && instanceEndIndex >= positionIndex - startIndex) {
|
|
17
|
+
result = {
|
|
18
|
+
index: {
|
|
19
|
+
start: instanceStartIndex,
|
|
20
|
+
end: instanceEndIndex
|
|
21
|
+
},
|
|
22
|
+
instanceContent: instanceMatch[0]
|
|
23
|
+
};
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
} else if (classMatch.index > positionIndex - startIndex) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { positionCheck };
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var css = require('@master/css');
|
|
4
|
+
var hexToRgb = require('../utils/hex-to-rgb.cjs');
|
|
5
|
+
var regex = require('../utils/regex.cjs');
|
|
6
|
+
var toTwoDigitHex = require('../utils/to-two-digit-hex.cjs');
|
|
7
|
+
var colorConvert = require('color-convert');
|
|
8
|
+
var oklabToRgb = require('../utils/oklab-to-rgb.cjs');
|
|
9
|
+
var oklchToOklab = require('../utils/oklch-to-oklab.cjs');
|
|
10
|
+
|
|
11
|
+
async function getDocumentColors(text, css$1 = new css.MasterCSS()) {
|
|
12
|
+
const colors = [];
|
|
13
|
+
let instanceMatch;
|
|
14
|
+
while((instanceMatch = regex.instancePattern.exec(text)) !== null){
|
|
15
|
+
const instanceStartIndex = instanceMatch.index;
|
|
16
|
+
// todo: refactor theme
|
|
17
|
+
// const theme = css.themeNames.find(x => instanceMatch?.[0]?.endsWith(`@${x}`)) ?? ''
|
|
18
|
+
const theme = '';
|
|
19
|
+
const colorPattern = /(?<=[|:\s"'`]|^)(?:#?[\w-]+(?:-[\d]{1,2})?(?:\/.?[\d]*)?(?:\([^\s)]+\))?(?![:]))/g;
|
|
20
|
+
let colorMatch;
|
|
21
|
+
//check color
|
|
22
|
+
while((colorMatch = colorPattern.exec(instanceMatch[0])) !== null){
|
|
23
|
+
const colorValue = parseColorString(colorMatch[0], theme, css$1);
|
|
24
|
+
if (colorValue) {
|
|
25
|
+
const colorIndex = {
|
|
26
|
+
index: {
|
|
27
|
+
start: instanceStartIndex + colorMatch.index,
|
|
28
|
+
end: instanceStartIndex + colorMatch.index + colorMatch[0].length
|
|
29
|
+
},
|
|
30
|
+
color: colorValue
|
|
31
|
+
};
|
|
32
|
+
colors.push(colorIndex);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return colors;
|
|
37
|
+
}
|
|
38
|
+
function percentageConverter(value, max = 1) {
|
|
39
|
+
if (value === 'none') {
|
|
40
|
+
return 0;
|
|
41
|
+
} else if (value.endsWith('%')) {
|
|
42
|
+
return max * Number(value.replace('%', '')) / 100;
|
|
43
|
+
} else {
|
|
44
|
+
return Number(value);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function degConverter(value) {
|
|
48
|
+
if (value === 'none') {
|
|
49
|
+
return 0;
|
|
50
|
+
} else if (value.endsWith('turn')) {
|
|
51
|
+
return Number(value.replace('turn', '')) * 360;
|
|
52
|
+
} else if (value.endsWith('grad')) {
|
|
53
|
+
return Number(value.replace('grad', '')) * 0.9;
|
|
54
|
+
} else if (value.endsWith('rad')) {
|
|
55
|
+
return Number(value.replace('rad', '')) * 57.2957795;
|
|
56
|
+
} else if (value.endsWith('deg')) {
|
|
57
|
+
return Number(value.replace('deg', ''));
|
|
58
|
+
} else {
|
|
59
|
+
return Number(value);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function parseColorString(colorString, theme, css$1 = new css.MasterCSS()) {
|
|
63
|
+
const rgbaColorPattern = /rgb(?:a)?\(([\d.]+)[,|]([\d.]+)[,|]([\d.]+)(?:[,/]([\d.]+(?:%)?))?\)/g;
|
|
64
|
+
const hslaColorPattern = /hsl(?:a)?\(([\d.]+(?:deg|turn|grad|rad)?|none)[,|]([\d.]+%|none)[,|]([\d.]+%|none)(?:[,/]([\d.]+(?:%)?))?\)/g;
|
|
65
|
+
const hwbColorPattern = /hwb\(([\d.]+(?:deg|turn|grad|rad)?|none)[|]([\d.]+%|none)[|]([\d.]+%|none)(?:[/]([\d.]+(?:%)?))?\)/g;
|
|
66
|
+
const oklchColorPattern = /oklch\(([\d.]+(?:%)?|none)[|]([\d.]+(?:%)?|none)[|]([\d.]+(?:deg|turn|grad|rad)?|none)(?:[/]([\d.]+(?:%)?))?\)/g;
|
|
67
|
+
const lchColorPattern = /lch\(([\d.]+(?:%)?|none)[|]([\d.]+(?:%)?|none)[|]([\d.]+(?:deg|turn|grad|rad)?|none)(?:[/]([\d.]+(?:%)?))?\)/g;
|
|
68
|
+
const oklabColorPattern = /oklab\(([\d.]+(?:%)?|none)[|](-?[\d.]+(?:%)?|none)[|](-?[\d.]+(?:%)?|none)(?:[/]([\d.]+(?:%)?))?\)/g;
|
|
69
|
+
const labColorPattern = /lab\(([\d.]+(?:%)?|none)[|](-?[\d.]+(?:%)?|none)[|](-?[\d.]+(?:%)?|none)(?:[/]([\d.]+(?:%)?))?\)/g;
|
|
70
|
+
const cmykColorPattern = /device-cmyk\(([\d.]+(?:%)?|none)[|]([\d.]+(?:%)?|none)[|]([\d.]+(?:%)?|none)[|]([\d.]+(?:%)?|none)(?:[/]([\d.]+(?:%)?))?(?:,\w+\(.*\))?\)/g;
|
|
71
|
+
const hexColorPattern = /#([0-9a-fA-F]{6,8})/g;
|
|
72
|
+
const colorFunctionPattern = /color?\((?:srgb|srgb-linear|display-p3|a98-rgb|prophoto-rgb|rec2020|xyz|xyz-d50|xyz-d65)[|]([\d.]+)[|]([\d.]+)[|]([\d.]+)(?:[/]([\d.]+(?:%)?))?\)/g;
|
|
73
|
+
let colorMatch2;
|
|
74
|
+
//#region for rgb、hls
|
|
75
|
+
if (colorMatch2 = rgbaColorPattern.exec(colorString)) {
|
|
76
|
+
return getColorValue({
|
|
77
|
+
red: Number(colorMatch2[1]),
|
|
78
|
+
green: Number(colorMatch2[2]),
|
|
79
|
+
blue: Number(colorMatch2[3]),
|
|
80
|
+
alpha: colorMatch2[4] == undefined ? 1 : percentageConverter(colorMatch2[4])
|
|
81
|
+
});
|
|
82
|
+
} else if (colorMatch2 = hslaColorPattern.exec(colorString)) {
|
|
83
|
+
const rgb = colorConvert.hsl.rgb([
|
|
84
|
+
degConverter(colorMatch2[1]),
|
|
85
|
+
percentageConverter(colorMatch2[2], 100),
|
|
86
|
+
percentageConverter(colorMatch2[3], 100)
|
|
87
|
+
]);
|
|
88
|
+
return getColorValue({
|
|
89
|
+
red: rgb[0],
|
|
90
|
+
green: rgb[1],
|
|
91
|
+
blue: rgb[2],
|
|
92
|
+
alpha: colorMatch2[4] == undefined ? 1 : percentageConverter(colorMatch2[4])
|
|
93
|
+
});
|
|
94
|
+
} else if (colorMatch2 = hwbColorPattern.exec(colorString)) {
|
|
95
|
+
const rgb = colorConvert.hwb.rgb([
|
|
96
|
+
degConverter(colorMatch2[1]),
|
|
97
|
+
percentageConverter(colorMatch2[2], 100),
|
|
98
|
+
percentageConverter(colorMatch2[3], 100)
|
|
99
|
+
]);
|
|
100
|
+
return getColorValue({
|
|
101
|
+
red: rgb[0],
|
|
102
|
+
green: rgb[1],
|
|
103
|
+
blue: rgb[2],
|
|
104
|
+
alpha: colorMatch2[4] == undefined ? 1 : percentageConverter(colorMatch2[4])
|
|
105
|
+
});
|
|
106
|
+
} else if (colorMatch2 = oklchColorPattern.exec(colorString)) {
|
|
107
|
+
const oklab = oklchToOklab.oklchToOklab([
|
|
108
|
+
percentageConverter(colorMatch2[1]),
|
|
109
|
+
percentageConverter(colorMatch2[2], 0.4),
|
|
110
|
+
degConverter(colorMatch2[3])
|
|
111
|
+
]);
|
|
112
|
+
const rgb = oklabToRgb.oklabToRgb(oklab);
|
|
113
|
+
return getColorValue({
|
|
114
|
+
red: rgb[0],
|
|
115
|
+
green: rgb[1],
|
|
116
|
+
blue: rgb[2],
|
|
117
|
+
alpha: colorMatch2[4] == undefined ? 1 : percentageConverter(colorMatch2[4])
|
|
118
|
+
});
|
|
119
|
+
} else if (colorMatch2 = lchColorPattern.exec(colorString)) {
|
|
120
|
+
const rgb = colorConvert.lch.rgb([
|
|
121
|
+
percentageConverter(colorMatch2[1], 100),
|
|
122
|
+
percentageConverter(colorMatch2[2], 150),
|
|
123
|
+
degConverter(colorMatch2[3])
|
|
124
|
+
]);
|
|
125
|
+
return getColorValue({
|
|
126
|
+
red: rgb[0],
|
|
127
|
+
green: rgb[1],
|
|
128
|
+
blue: rgb[2],
|
|
129
|
+
alpha: colorMatch2[4] == undefined ? 1 : percentageConverter(colorMatch2[4])
|
|
130
|
+
});
|
|
131
|
+
} else if (colorMatch2 = oklabColorPattern.exec(colorString)) {
|
|
132
|
+
const rgb = oklabToRgb.oklabToRgb([
|
|
133
|
+
percentageConverter(colorMatch2[1]),
|
|
134
|
+
percentageConverter(colorMatch2[2], 0.4),
|
|
135
|
+
percentageConverter(colorMatch2[3], 0.4)
|
|
136
|
+
]);
|
|
137
|
+
return getColorValue({
|
|
138
|
+
red: rgb[0],
|
|
139
|
+
green: rgb[1],
|
|
140
|
+
blue: rgb[2],
|
|
141
|
+
alpha: colorMatch2[4] == undefined ? 1 : percentageConverter(colorMatch2[4])
|
|
142
|
+
});
|
|
143
|
+
} else if (colorMatch2 = labColorPattern.exec(colorString)) {
|
|
144
|
+
const rgb = colorConvert.lab.rgb([
|
|
145
|
+
percentageConverter(colorMatch2[1], 100),
|
|
146
|
+
percentageConverter(colorMatch2[2], 125),
|
|
147
|
+
percentageConverter(colorMatch2[3], 125)
|
|
148
|
+
]);
|
|
149
|
+
return getColorValue({
|
|
150
|
+
red: rgb[0],
|
|
151
|
+
green: rgb[1],
|
|
152
|
+
blue: rgb[2],
|
|
153
|
+
alpha: colorMatch2[4] == undefined ? 1 : percentageConverter(colorMatch2[4])
|
|
154
|
+
});
|
|
155
|
+
} else if (colorMatch2 = cmykColorPattern.exec(colorString)) {
|
|
156
|
+
const rgb = colorConvert.cmyk.rgb([
|
|
157
|
+
percentageConverter(colorMatch2[1], 100),
|
|
158
|
+
percentageConverter(colorMatch2[2], 100),
|
|
159
|
+
percentageConverter(colorMatch2[3], 100),
|
|
160
|
+
percentageConverter(colorMatch2[4], 100)
|
|
161
|
+
]);
|
|
162
|
+
return getColorValue({
|
|
163
|
+
red: rgb[0],
|
|
164
|
+
green: rgb[1],
|
|
165
|
+
blue: rgb[2],
|
|
166
|
+
alpha: colorMatch2[5] == undefined ? 1 : percentageConverter(colorMatch2[5])
|
|
167
|
+
});
|
|
168
|
+
} else if (colorMatch2 = hexColorPattern.exec(colorString)) {
|
|
169
|
+
return getColorValue(hexToRgb.hexToRgb(colorMatch2[1]));
|
|
170
|
+
} else if (colorMatch2 = colorFunctionPattern.exec(colorString)) {
|
|
171
|
+
return getColorValue({
|
|
172
|
+
red: Number(colorMatch2[1]) * 255,
|
|
173
|
+
green: Number(colorMatch2[2]) * 255,
|
|
174
|
+
blue: Number(colorMatch2[3]) * 255,
|
|
175
|
+
alpha: colorMatch2[4] == undefined ? 1 : percentageConverter(colorMatch2[4])
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
//#endregion for rgb、hls
|
|
179
|
+
//#region for mastercss color
|
|
180
|
+
let colorAlpha = 1;
|
|
181
|
+
let colorName = colorString;
|
|
182
|
+
const allCSSColorNames = [];
|
|
183
|
+
// todo: refactor css.variables
|
|
184
|
+
for(const eachVariableName in css$1.variables){
|
|
185
|
+
const eachVariable = css$1.variables[eachVariableName];
|
|
186
|
+
if (eachVariable.type === 'color') allCSSColorNames.push(eachVariableName);
|
|
187
|
+
}
|
|
188
|
+
if (colorString.split('/').length == 2) {
|
|
189
|
+
colorAlpha = Number('0' + colorString.split('/')[1]);
|
|
190
|
+
}
|
|
191
|
+
if (colorString.split('-').length == 1) {
|
|
192
|
+
colorName = colorString.split('/')[0];
|
|
193
|
+
colorName = colorName.endsWith('_') ? colorName.replace('_', '') : colorName;
|
|
194
|
+
}
|
|
195
|
+
if (allCSSColorNames.find((x)=>x == colorName)) {
|
|
196
|
+
return getColorsRGBA(colorName, colorAlpha, theme, css$1);
|
|
197
|
+
}
|
|
198
|
+
//#endregion for mastercss color
|
|
199
|
+
}
|
|
200
|
+
function getColorsRGBA(colorName, colorAlpha = 1, theme = '', css$1 = new css.MasterCSS()) {
|
|
201
|
+
try {
|
|
202
|
+
// todo: refactor colorNumberMap
|
|
203
|
+
const colorNumberMap = css$1.variables[colorName];
|
|
204
|
+
const levelRgb = hexToRgb.hexToRgb(colorNumberMap[theme] ?? colorNumberMap[''] ?? Object.values(colorNumberMap)[0]);
|
|
205
|
+
return {
|
|
206
|
+
red: levelRgb.red / 255,
|
|
207
|
+
green: levelRgb.green / 255,
|
|
208
|
+
blue: levelRgb.blue / 255,
|
|
209
|
+
alpha: colorAlpha
|
|
210
|
+
};
|
|
211
|
+
} catch (ex) {
|
|
212
|
+
return {
|
|
213
|
+
red: 0,
|
|
214
|
+
green: 0,
|
|
215
|
+
blue: 0,
|
|
216
|
+
alpha: 1
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function getColorValue(color) {
|
|
221
|
+
return {
|
|
222
|
+
red: color.red / 255.0,
|
|
223
|
+
green: color.green / 255.0,
|
|
224
|
+
blue: color.blue / 255.0,
|
|
225
|
+
alpha: color.alpha
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function getColorPresentation(params, isColorRender = false) {
|
|
229
|
+
const result = [];
|
|
230
|
+
const color = params.color;
|
|
231
|
+
const range = params.range;
|
|
232
|
+
const red256 = Math.round(color.red * 255), green256 = Math.round(color.green * 255), blue256 = Math.round(color.blue * 255);
|
|
233
|
+
let label;
|
|
234
|
+
if (isColorRender) {
|
|
235
|
+
if (color.alpha === 1) {
|
|
236
|
+
label = `'#${toTwoDigitHex.toTwoDigitHex(red256)}${toTwoDigitHex.toTwoDigitHex(green256)}${toTwoDigitHex.toTwoDigitHex(blue256)}`;
|
|
237
|
+
} else {
|
|
238
|
+
label = `'#${toTwoDigitHex.toTwoDigitHex(red256)}${toTwoDigitHex.toTwoDigitHex(green256)}${toTwoDigitHex.toTwoDigitHex(blue256)}${toTwoDigitHex.toTwoDigitHex(Math.round(color.alpha * 255))}`;
|
|
239
|
+
}
|
|
240
|
+
result.push({
|
|
241
|
+
label: label,
|
|
242
|
+
textEdit: {
|
|
243
|
+
range: range,
|
|
244
|
+
newText: label
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
if (color.alpha === 1) {
|
|
250
|
+
label = `rgb(${red256},${green256},${blue256})`;
|
|
251
|
+
} else {
|
|
252
|
+
label = `rgba(${red256},${green256},${blue256},${color.alpha})`;
|
|
253
|
+
}
|
|
254
|
+
result.push({
|
|
255
|
+
label: label,
|
|
256
|
+
textEdit: {
|
|
257
|
+
range: range,
|
|
258
|
+
newText: label
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
if (color.alpha === 1) {
|
|
262
|
+
label = `#${toTwoDigitHex.toTwoDigitHex(red256)}${toTwoDigitHex.toTwoDigitHex(green256)}${toTwoDigitHex.toTwoDigitHex(blue256)}`;
|
|
263
|
+
} else {
|
|
264
|
+
label = `#${toTwoDigitHex.toTwoDigitHex(red256)}${toTwoDigitHex.toTwoDigitHex(green256)}${toTwoDigitHex.toTwoDigitHex(blue256)}${toTwoDigitHex.toTwoDigitHex(Math.round(color.alpha * 255))}`;
|
|
265
|
+
}
|
|
266
|
+
result.push({
|
|
267
|
+
label: label,
|
|
268
|
+
textEdit: {
|
|
269
|
+
range: range,
|
|
270
|
+
newText: label
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
const hsl = colorConvert.rgb.hsl(red256, green256, blue256);
|
|
274
|
+
if (color.alpha === 1) {
|
|
275
|
+
label = `hsl(${hsl[0]},${Math.round(hsl[1])}%,${Math.round(hsl[2])}%)`;
|
|
276
|
+
} else {
|
|
277
|
+
label = `hsla(${hsl[0]},${Math.round(hsl[1])}%,${Math.round(hsl[2])}%,${color.alpha})`;
|
|
278
|
+
}
|
|
279
|
+
result.push({
|
|
280
|
+
label: label,
|
|
281
|
+
textEdit: {
|
|
282
|
+
range: range,
|
|
283
|
+
newText: label
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
// const hwb = rgb.hwb(red256, green256, blue256)
|
|
287
|
+
// if (color.alpha === 1) {
|
|
288
|
+
// label = `hwb(${hwb[0]}|${hwb[1]}%|${hwb[2]}%)`
|
|
289
|
+
// } else {
|
|
290
|
+
// label = `hwb(${hwb[0]}|${hwb[1]}%|${hwb[2]}%/${color.alpha})`
|
|
291
|
+
// }
|
|
292
|
+
// result.push({ label: label, textEdit: { range: range, newText: label } })
|
|
293
|
+
// const lab = rgb.lab(red256, green256, blue256)
|
|
294
|
+
// if (color.alpha === 1) {
|
|
295
|
+
// label = `lab(${lab[0]}%|${lab[1]}|${lab[2]})`
|
|
296
|
+
// } else {
|
|
297
|
+
// label = `lab(${lab[0]}%|${lab[1]}|${lab[2]}/${color.alpha})`
|
|
298
|
+
// }
|
|
299
|
+
// result.push({ label: label, textEdit: { range: range, newText: label } })
|
|
300
|
+
// const lch = rgb.lch(red256, green256, blue256)
|
|
301
|
+
// if (color.alpha === 1) {
|
|
302
|
+
// label = `lch(${lch[0]}%|${lch[1]}|${lch[2]})`
|
|
303
|
+
// } else {
|
|
304
|
+
// label = `lch(${lch[0]}%|${lch[1]}|${lch[2]}/${color.alpha})`
|
|
305
|
+
// }
|
|
306
|
+
// result.push({ label: label, textEdit: { range: range, newText: label } })
|
|
307
|
+
// const cmyk = rgb.cmyk(red256, green256, blue256)
|
|
308
|
+
// if (color.alpha === 1) {
|
|
309
|
+
// label = `device-cmyk(${cmyk[0]}%|${cmyk[1]}%|${cmyk[2]}%|${cmyk[3]}%)`
|
|
310
|
+
// } else {
|
|
311
|
+
// label = `device-cmyk(${cmyk[0]}%|${cmyk[1]}%|${cmyk[2]}%|${cmyk[3]}%/${color.alpha})`
|
|
312
|
+
// }
|
|
313
|
+
// result.push({ label: label, textEdit: { range: range, newText: label } })
|
|
314
|
+
return result;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
exports.getColorPresentation = getColorPresentation;
|
|
318
|
+
exports.getColorValue = getColorValue;
|
|
319
|
+
exports.getDocumentColors = getDocumentColors;
|