@tbela99/css-parser 0.3.0 → 0.4.1
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/{LICENSE → LICENSE.md} +1 -1
- package/README.md +191 -80
- package/dist/config.json.js +20 -1
- package/dist/index-umd-web.js +3210 -1352
- package/dist/index.cjs +3211 -1353
- package/dist/index.d.ts +910 -0
- package/dist/lib/ast/expand.js +1 -1
- package/dist/lib/ast/features/calc.js +1 -2
- package/dist/lib/ast/features/inlinecssvariables.js +1 -1
- package/dist/lib/ast/features/shorthand.js +1 -1
- package/dist/lib/ast/math/expression.js +38 -3
- package/dist/lib/ast/math/math.js +2 -2
- package/dist/lib/ast/minify.js +0 -1
- package/dist/lib/ast/types.js +1 -0
- package/dist/lib/ast/utils/minifyfeature.js +4 -3
- package/dist/lib/parser/declaration/list.js +1 -1
- package/dist/lib/parser/declaration/map.js +129 -26
- package/dist/lib/parser/declaration/set.js +1 -1
- package/dist/lib/parser/parse.js +325 -303
- package/dist/lib/parser/tokenize.js +220 -223
- package/dist/lib/parser/utils/declaration.js +1 -1
- package/dist/lib/parser/utils/syntax.js +159 -23
- package/dist/lib/parser/utils/type.js +2 -2
- package/dist/lib/renderer/color/a98rgb.js +64 -0
- package/dist/lib/renderer/color/color.js +521 -0
- package/dist/lib/renderer/color/colormix.js +337 -0
- package/dist/lib/renderer/color/hex.js +92 -0
- package/dist/lib/renderer/color/hsl.js +118 -0
- package/dist/lib/renderer/color/hsv.js +20 -0
- package/dist/lib/renderer/color/hwb.js +101 -0
- package/dist/lib/renderer/color/lab.js +136 -0
- package/dist/lib/renderer/color/lch.js +79 -0
- package/dist/lib/renderer/color/oklab.js +121 -0
- package/dist/lib/renderer/color/oklch.js +65 -0
- package/dist/lib/renderer/color/p3.js +57 -0
- package/dist/lib/renderer/color/prophotorgb.js +56 -0
- package/dist/lib/renderer/color/rec2020.js +70 -0
- package/dist/lib/renderer/color/relativecolor.js +152 -0
- package/dist/lib/renderer/color/rgb.js +44 -0
- package/dist/lib/renderer/color/srgb.js +261 -0
- package/dist/lib/renderer/color/utils/components.js +20 -0
- package/dist/lib/renderer/color/utils/constants.js +191 -0
- package/dist/lib/renderer/color/utils/matrix.js +35 -0
- package/dist/lib/renderer/color/xyz.js +64 -0
- package/dist/lib/renderer/color/xyzd50.js +33 -0
- package/dist/lib/renderer/render.js +61 -32
- package/dist/node/index.js +1 -1
- package/dist/node/load.js +1 -1
- package/dist/web/index.js +1 -1
- package/package.json +15 -14
- package/dist/lib/ast/features/utils/math.js +0 -95
- package/dist/lib/iterable/set.js +0 -48
- package/dist/lib/iterable/weakmap.js +0 -53
- package/dist/lib/renderer/utils/calccolor.js +0 -238
- package/dist/lib/renderer/utils/color.js +0 -371
- package/dist/lib/renderer/utils/hex.js +0 -124
- package/dist/lib/renderer/utils/hsl.js +0 -49
- package/dist/lib/renderer/utils/hsv.js +0 -15
- package/dist/lib/renderer/utils/hwb.js +0 -50
- package/dist/lib/renderer/utils/rgb.js +0 -66
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import { COLORS_NAMES, getNumber, getAngle } from './color.js';
|
|
2
|
-
import { EnumToken } from '../../ast/types.js';
|
|
3
|
-
import '../../ast/minify.js';
|
|
4
|
-
import { walkValues } from '../../ast/walk.js';
|
|
5
|
-
import '../../parser/parse.js';
|
|
6
|
-
import { reduceNumber } from '../render.js';
|
|
7
|
-
import { hwb2rgb, hsl2rgb } from './rgb.js';
|
|
8
|
-
import { rgb2hwb, hsl2hwb } from './hwb.js';
|
|
9
|
-
import { rgb2hsl, hwb2hsl } from './hsl.js';
|
|
10
|
-
import { evaluate } from '../../ast/math/expression.js';
|
|
11
|
-
|
|
12
|
-
function parseRelativeColor(relativeKeys, original, rExp, gExp, bExp, aExp) {
|
|
13
|
-
const type = relativeKeys.join('');
|
|
14
|
-
let r;
|
|
15
|
-
let g;
|
|
16
|
-
let b;
|
|
17
|
-
let alpha = null;
|
|
18
|
-
let keys = {};
|
|
19
|
-
let values = {};
|
|
20
|
-
let children;
|
|
21
|
-
switch (original.kin) {
|
|
22
|
-
case 'lit':
|
|
23
|
-
case 'hex':
|
|
24
|
-
let value = original.val.toLowerCase();
|
|
25
|
-
if (original.kin == 'lit') {
|
|
26
|
-
if (original.val.toLowerCase() in COLORS_NAMES) {
|
|
27
|
-
value = COLORS_NAMES[original.val.toLowerCase()];
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (value.length == 4) {
|
|
34
|
-
value = '#' + value[1] + value[1] + value[2] + value[2] + value[3] + value[3];
|
|
35
|
-
}
|
|
36
|
-
else if (value.length == 5) {
|
|
37
|
-
value = '#' + value[1] + value[1] + value[2] + value[2] + value[3] + value[3] + value[4] + value[4];
|
|
38
|
-
}
|
|
39
|
-
r = parseInt(value.slice(1, 3), 16);
|
|
40
|
-
g = parseInt(value.slice(3, 5), 16);
|
|
41
|
-
b = parseInt(value.slice(5, 7), 16);
|
|
42
|
-
alpha = value.length == 9 ? parseInt(value.slice(7, 9), 16) : null;
|
|
43
|
-
break;
|
|
44
|
-
case 'rgb':
|
|
45
|
-
case 'rgba':
|
|
46
|
-
children = original.chi.filter((t) => t.typ == EnumToken.NumberTokenType || t.typ == EnumToken.IdenTokenType || t.typ == EnumToken.PercentageTokenType);
|
|
47
|
-
if (children.every((t) => (t.typ == EnumToken.IdenTokenType && t.val == 'none') || t.typ == EnumToken.NumberTokenType)) {
|
|
48
|
-
r = children[0].typ == EnumToken.IdenTokenType && children[0].val == 'none' ? 0 : +children[0].val;
|
|
49
|
-
g = children[1].typ == EnumToken.IdenTokenType && children[1].val == 'none' ? 0 : +children[1].val;
|
|
50
|
-
b = children[2].typ == EnumToken.IdenTokenType && children[2].val == 'none' ? 0 : +children[2].val;
|
|
51
|
-
alpha = children.length < 4 ? null : children[3].typ == EnumToken.IdenTokenType && children[3].val == 'none' ? 0 : +children[3].val;
|
|
52
|
-
}
|
|
53
|
-
else if (children.every((t) => t.typ == EnumToken.PercentageTokenType || (t.typ == EnumToken.IdenTokenType && t.val == 'none') || (t.typ == EnumToken.NumberTokenType && t.val == '0'))) {
|
|
54
|
-
// @ts-ignore
|
|
55
|
-
r = children[0].typ == EnumToken.IdenTokenType && children[0].val == 'none' ? 0 : children[0].val * 255 / 100;
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
g = children[1].typ == EnumToken.IdenTokenType && children[1].val == 'none' ? 0 : children[1].val * 255 / 100;
|
|
58
|
-
// @ts-ignore
|
|
59
|
-
b = children[2].typ == EnumToken.IdenTokenType && children[2].val == 'none' ? 0 : children[2].val * 255 / 100;
|
|
60
|
-
alpha = children.length < 4 ? null : children[3].typ == EnumToken.IdenTokenType && children[3].val == 'none' ? 0 : +children[3].val / 100;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
break;
|
|
66
|
-
case 'hsl':
|
|
67
|
-
case 'hsla':
|
|
68
|
-
case 'hwb':
|
|
69
|
-
children = original.chi.filter((t) => t.typ == EnumToken.AngleTokenType || t.typ == EnumToken.NumberTokenType || t.typ == EnumToken.IdenTokenType || t.typ == EnumToken.PercentageTokenType);
|
|
70
|
-
if (children.length == 3 || children.length == 4) {
|
|
71
|
-
[r, g, b, alpha] = children;
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
default:
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
const from = ['rgb', 'rgba', 'hex', 'lit'].includes(original.kin) ? 'rgb' : original.kin;
|
|
81
|
-
if (from != type) {
|
|
82
|
-
if (type == 'hsl' || type == 'hwb') {
|
|
83
|
-
if (from == 'rgb') {
|
|
84
|
-
[r, g, b] = (type == 'hwb' ? rgb2hwb : rgb2hsl)(r, g, b);
|
|
85
|
-
// @ts-ignore
|
|
86
|
-
r *= 360;
|
|
87
|
-
// @ts-ignore
|
|
88
|
-
g *= 100;
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
b *= 100;
|
|
91
|
-
values = {
|
|
92
|
-
[relativeKeys[0]]: { typ: EnumToken.AngleTokenType, val: r, unit: 'deg' },
|
|
93
|
-
[relativeKeys[1]]: { typ: EnumToken.PercentageTokenType, val: g },
|
|
94
|
-
[relativeKeys[2]]: { typ: EnumToken.PercentageTokenType, val: b }
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
else if (from == 'hwb' || from == 'hsl') {
|
|
98
|
-
if (type == 'hsl') {
|
|
99
|
-
if (from == 'hwb') {
|
|
100
|
-
[r, g, b] = hwb2hsl(getAngle(r), getNumber(g), getNumber(b));
|
|
101
|
-
// @ts-ignore
|
|
102
|
-
r *= 360;
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
g *= 100;
|
|
105
|
-
// @ts-ignore
|
|
106
|
-
b *= 100;
|
|
107
|
-
// @ts-ignore
|
|
108
|
-
values = {
|
|
109
|
-
[relativeKeys[0]]: { typ: EnumToken.AngleTokenType, val: r, unit: 'deg' },
|
|
110
|
-
[relativeKeys[1]]: { typ: EnumToken.PercentageTokenType, val: g },
|
|
111
|
-
[relativeKeys[2]]: { typ: EnumToken.PercentageTokenType, val: b }
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
else if (type == 'hwb') {
|
|
116
|
-
if (from == 'hsl') {
|
|
117
|
-
[r, g, b] = hsl2hwb(getAngle(r), getNumber(g), getNumber(b));
|
|
118
|
-
// @ts-ignore
|
|
119
|
-
r *= 360;
|
|
120
|
-
// @ts-ignore
|
|
121
|
-
g *= 100;
|
|
122
|
-
// @ts-ignore
|
|
123
|
-
b *= 100;
|
|
124
|
-
// @ts-ignore
|
|
125
|
-
values = {
|
|
126
|
-
[relativeKeys[0]]: { typ: EnumToken.AngleTokenType, val: r, unit: 'deg' },
|
|
127
|
-
[relativeKeys[1]]: { typ: EnumToken.PercentageTokenType, val: g },
|
|
128
|
-
[relativeKeys[2]]: { typ: EnumToken.PercentageTokenType, val: b }
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
else if (type == 'rgb') {
|
|
138
|
-
if (from == 'hsl' || from == 'hwb') {
|
|
139
|
-
[r, g, b] = (from == 'hwb' ? hwb2rgb : hsl2rgb)(getAngle(r), getNumber(g), getNumber(b));
|
|
140
|
-
// @ts-ignore
|
|
141
|
-
values = {
|
|
142
|
-
[relativeKeys[0]]: { typ: EnumToken.NumberTokenType, val: r },
|
|
143
|
-
[relativeKeys[1]]: { typ: EnumToken.NumberTokenType, val: g },
|
|
144
|
-
[relativeKeys[2]]: { typ: EnumToken.NumberTokenType, val: b }
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
values = {
|
|
154
|
-
[relativeKeys[0]]: r,
|
|
155
|
-
[relativeKeys[1]]: g,
|
|
156
|
-
[relativeKeys[2]]: b
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
if (aExp != null && aExp.typ == EnumToken.IdenTokenType && aExp.val == 'none') {
|
|
160
|
-
aExp = null;
|
|
161
|
-
}
|
|
162
|
-
keys = {
|
|
163
|
-
[relativeKeys[0]]: rExp,
|
|
164
|
-
[relativeKeys[1]]: gExp,
|
|
165
|
-
[relativeKeys[2]]: bExp,
|
|
166
|
-
alpha: aExp ?? { typ: EnumToken.IdenTokenType, val: 'alpha' }
|
|
167
|
-
};
|
|
168
|
-
// @ts-ignore
|
|
169
|
-
values.alpha = alpha != null && typeof alpha == 'object' ? alpha : b.typ == EnumToken.PercentageTokenType ? { typ: EnumToken.PercentageTokenType, val: String(alpha ?? 100) } : { typ: EnumToken.NumberTokenType, val: String(alpha ?? 1) };
|
|
170
|
-
return computeComponentValue(keys, values);
|
|
171
|
-
}
|
|
172
|
-
function computeComponentValue(expr, values) {
|
|
173
|
-
for (const [key, exp] of Object.entries(expr)) {
|
|
174
|
-
if (exp == null) {
|
|
175
|
-
if (key in values) {
|
|
176
|
-
if (typeof values[key] == 'number') {
|
|
177
|
-
expr[key] = {
|
|
178
|
-
typ: EnumToken.NumberTokenType,
|
|
179
|
-
val: reduceNumber(values[key])
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
expr[key] = values[key];
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
else if ([EnumToken.NumberTokenType, EnumToken.PercentageTokenType, EnumToken.AngleTokenType, EnumToken.LengthTokenType].includes(exp.typ)) ;
|
|
188
|
-
else if (exp.typ == EnumToken.IdenTokenType && exp.val in values) {
|
|
189
|
-
if (typeof values[exp.val] == 'number') {
|
|
190
|
-
expr[key] = {
|
|
191
|
-
typ: EnumToken.NumberTokenType,
|
|
192
|
-
val: reduceNumber(values[exp.val])
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
expr[key] = values[exp.val];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
else if (exp.typ == EnumToken.FunctionTokenType && exp.val == 'calc') {
|
|
200
|
-
for (let { value, parent } of walkValues(exp.chi)) {
|
|
201
|
-
if (value.typ == EnumToken.IdenTokenType) {
|
|
202
|
-
if (!(value.val in values)) {
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
if (parent == null) {
|
|
206
|
-
parent = exp;
|
|
207
|
-
}
|
|
208
|
-
if (parent.typ == EnumToken.BinaryExpressionTokenType) {
|
|
209
|
-
if (parent.l == value) {
|
|
210
|
-
parent.l = values[value.val];
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
parent.r = values[value.val];
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
for (let i = 0; i < parent.chi.length; i++) {
|
|
218
|
-
if (parent.chi[i] == value) {
|
|
219
|
-
parent.chi.splice(i, 1, values[value.val]);
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
const result = evaluate(exp.chi);
|
|
227
|
-
if (result.length == 1 && result[0].typ != EnumToken.BinaryExpressionTokenType) {
|
|
228
|
-
expr[key] = result[0];
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return expr;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export { parseRelativeColor };
|
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
import { EnumToken } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../parser/parse.js';
|
|
4
|
-
import '../sourcemap/lib/encode.js';
|
|
5
|
-
|
|
6
|
-
// name to color
|
|
7
|
-
const COLORS_NAMES = Object.seal({
|
|
8
|
-
'aliceblue': '#f0f8ff',
|
|
9
|
-
'antiquewhite': '#faebd7',
|
|
10
|
-
'aqua': '#00ffff',
|
|
11
|
-
'aquamarine': '#7fffd4',
|
|
12
|
-
'azure': '#f0ffff',
|
|
13
|
-
'beige': '#f5f5dc',
|
|
14
|
-
'bisque': '#ffe4c4',
|
|
15
|
-
'black': '#000000',
|
|
16
|
-
'blanchedalmond': '#ffebcd',
|
|
17
|
-
'blue': '#0000ff',
|
|
18
|
-
'blueviolet': '#8a2be2',
|
|
19
|
-
'brown': '#a52a2a',
|
|
20
|
-
'burlywood': '#deb887',
|
|
21
|
-
'cadetblue': '#5f9ea0',
|
|
22
|
-
'chartreuse': '#7fff00',
|
|
23
|
-
'chocolate': '#d2691e',
|
|
24
|
-
'coral': '#ff7f50',
|
|
25
|
-
'cornflowerblue': '#6495ed',
|
|
26
|
-
'cornsilk': '#fff8dc',
|
|
27
|
-
'crimson': '#dc143c',
|
|
28
|
-
'cyan': '#00ffff',
|
|
29
|
-
'darkblue': '#00008b',
|
|
30
|
-
'darkcyan': '#008b8b',
|
|
31
|
-
'darkgoldenrod': '#b8860b',
|
|
32
|
-
'darkgray': '#a9a9a9',
|
|
33
|
-
'darkgrey': '#a9a9a9',
|
|
34
|
-
'darkgreen': '#006400',
|
|
35
|
-
'darkkhaki': '#bdb76b',
|
|
36
|
-
'darkmagenta': '#8b008b',
|
|
37
|
-
'darkolivegreen': '#556b2f',
|
|
38
|
-
'darkorange': '#ff8c00',
|
|
39
|
-
'darkorchid': '#9932cc',
|
|
40
|
-
'darkred': '#8b0000',
|
|
41
|
-
'darksalmon': '#e9967a',
|
|
42
|
-
'darkseagreen': '#8fbc8f',
|
|
43
|
-
'darkslateblue': '#483d8b',
|
|
44
|
-
'darkslategray': '#2f4f4f',
|
|
45
|
-
'darkslategrey': '#2f4f4f',
|
|
46
|
-
'darkturquoise': '#00ced1',
|
|
47
|
-
'darkviolet': '#9400d3',
|
|
48
|
-
'deeppink': '#ff1493',
|
|
49
|
-
'deepskyblue': '#00bfff',
|
|
50
|
-
'dimgray': '#696969',
|
|
51
|
-
'dimgrey': '#696969',
|
|
52
|
-
'dodgerblue': '#1e90ff',
|
|
53
|
-
'firebrick': '#b22222',
|
|
54
|
-
'floralwhite': '#fffaf0',
|
|
55
|
-
'forestgreen': '#228b22',
|
|
56
|
-
'fuchsia': '#ff00ff',
|
|
57
|
-
'gainsboro': '#dcdcdc',
|
|
58
|
-
'ghostwhite': '#f8f8ff',
|
|
59
|
-
'gold': '#ffd700',
|
|
60
|
-
'goldenrod': '#daa520',
|
|
61
|
-
'gray': '#808080',
|
|
62
|
-
'grey': '#808080',
|
|
63
|
-
'green': '#008000',
|
|
64
|
-
'greenyellow': '#adff2f',
|
|
65
|
-
'honeydew': '#f0fff0',
|
|
66
|
-
'hotpink': '#ff69b4',
|
|
67
|
-
'indianred': '#cd5c5c',
|
|
68
|
-
'indigo': '#4b0082',
|
|
69
|
-
'ivory': '#fffff0',
|
|
70
|
-
'khaki': '#f0e68c',
|
|
71
|
-
'lavender': '#e6e6fa',
|
|
72
|
-
'lavenderblush': '#fff0f5',
|
|
73
|
-
'lawngreen': '#7cfc00',
|
|
74
|
-
'lemonchiffon': '#fffacd',
|
|
75
|
-
'lightblue': '#add8e6',
|
|
76
|
-
'lightcoral': '#f08080',
|
|
77
|
-
'lightcyan': '#e0ffff',
|
|
78
|
-
'lightgoldenrodyellow': '#fafad2',
|
|
79
|
-
'lightgray': '#d3d3d3',
|
|
80
|
-
'lightgrey': '#d3d3d3',
|
|
81
|
-
'lightgreen': '#90ee90',
|
|
82
|
-
'lightpink': '#ffb6c1',
|
|
83
|
-
'lightsalmon': '#ffa07a',
|
|
84
|
-
'lightseagreen': '#20b2aa',
|
|
85
|
-
'lightskyblue': '#87cefa',
|
|
86
|
-
'lightslategray': '#778899',
|
|
87
|
-
'lightslategrey': '#778899',
|
|
88
|
-
'lightsteelblue': '#b0c4de',
|
|
89
|
-
'lightyellow': '#ffffe0',
|
|
90
|
-
'lime': '#00ff00',
|
|
91
|
-
'limegreen': '#32cd32',
|
|
92
|
-
'linen': '#faf0e6',
|
|
93
|
-
'magenta': '#ff00ff',
|
|
94
|
-
'maroon': '#800000',
|
|
95
|
-
'mediumaquamarine': '#66cdaa',
|
|
96
|
-
'mediumblue': '#0000cd',
|
|
97
|
-
'mediumorchid': '#ba55d3',
|
|
98
|
-
'mediumpurple': '#9370d8',
|
|
99
|
-
'mediumseagreen': '#3cb371',
|
|
100
|
-
'mediumslateblue': '#7b68ee',
|
|
101
|
-
'mediumspringgreen': '#00fa9a',
|
|
102
|
-
'mediumturquoise': '#48d1cc',
|
|
103
|
-
'mediumvioletred': '#c71585',
|
|
104
|
-
'midnightblue': '#191970',
|
|
105
|
-
'mintcream': '#f5fffa',
|
|
106
|
-
'mistyrose': '#ffe4e1',
|
|
107
|
-
'moccasin': '#ffe4b5',
|
|
108
|
-
'navajowhite': '#ffdead',
|
|
109
|
-
'navy': '#000080',
|
|
110
|
-
'oldlace': '#fdf5e6',
|
|
111
|
-
'olive': '#808000',
|
|
112
|
-
'olivedrab': '#6b8e23',
|
|
113
|
-
'orange': '#ffa500',
|
|
114
|
-
'orangered': '#ff4500',
|
|
115
|
-
'orchid': '#da70d6',
|
|
116
|
-
'palegoldenrod': '#eee8aa',
|
|
117
|
-
'palegreen': '#98fb98',
|
|
118
|
-
'paleturquoise': '#afeeee',
|
|
119
|
-
'palevioletred': '#d87093',
|
|
120
|
-
'papayawhip': '#ffefd5',
|
|
121
|
-
'peachpuff': '#ffdab9',
|
|
122
|
-
'peru': '#cd853f',
|
|
123
|
-
'pink': '#ffc0cb',
|
|
124
|
-
'plum': '#dda0dd',
|
|
125
|
-
'powderblue': '#b0e0e6',
|
|
126
|
-
'purple': '#800080',
|
|
127
|
-
'red': '#ff0000',
|
|
128
|
-
'rosybrown': '#bc8f8f',
|
|
129
|
-
'royalblue': '#4169e1',
|
|
130
|
-
'saddlebrown': '#8b4513',
|
|
131
|
-
'salmon': '#fa8072',
|
|
132
|
-
'sandybrown': '#f4a460',
|
|
133
|
-
'seagreen': '#2e8b57',
|
|
134
|
-
'seashell': '#fff5ee',
|
|
135
|
-
'sienna': '#a0522d',
|
|
136
|
-
'silver': '#c0c0c0',
|
|
137
|
-
'skyblue': '#87ceeb',
|
|
138
|
-
'slateblue': '#6a5acd',
|
|
139
|
-
'slategray': '#708090',
|
|
140
|
-
'slategrey': '#708090',
|
|
141
|
-
'snow': '#fffafa',
|
|
142
|
-
'springgreen': '#00ff7f',
|
|
143
|
-
'steelblue': '#4682b4',
|
|
144
|
-
'tan': '#d2b48c',
|
|
145
|
-
'teal': '#008080',
|
|
146
|
-
'thistle': '#d8bfd8',
|
|
147
|
-
'tomato': '#ff6347',
|
|
148
|
-
'turquoise': '#40e0d0',
|
|
149
|
-
'violet': '#ee82ee',
|
|
150
|
-
'wheat': '#f5deb3',
|
|
151
|
-
'white': '#ffffff',
|
|
152
|
-
'whitesmoke': '#f5f5f5',
|
|
153
|
-
'yellow': '#ffff00',
|
|
154
|
-
'yellowgreen': '#9acd32',
|
|
155
|
-
'rebeccapurple': '#663399',
|
|
156
|
-
'transparent': '#00000000'
|
|
157
|
-
});
|
|
158
|
-
// color to name
|
|
159
|
-
const NAMES_COLORS = Object.seal({
|
|
160
|
-
'#f0f8ff': 'aliceblue',
|
|
161
|
-
'#faebd7': 'antiquewhite',
|
|
162
|
-
// '#00ffff': 'aqua',
|
|
163
|
-
'#7fffd4': 'aquamarine',
|
|
164
|
-
'#f0ffff': 'azure',
|
|
165
|
-
'#f5f5dc': 'beige',
|
|
166
|
-
'#ffe4c4': 'bisque',
|
|
167
|
-
'#000000': 'black',
|
|
168
|
-
'#ffebcd': 'blanchedalmond',
|
|
169
|
-
'#0000ff': 'blue',
|
|
170
|
-
'#8a2be2': 'blueviolet',
|
|
171
|
-
'#a52a2a': 'brown',
|
|
172
|
-
'#deb887': 'burlywood',
|
|
173
|
-
'#5f9ea0': 'cadetblue',
|
|
174
|
-
'#7fff00': 'chartreuse',
|
|
175
|
-
'#d2691e': 'chocolate',
|
|
176
|
-
'#ff7f50': 'coral',
|
|
177
|
-
'#6495ed': 'cornflowerblue',
|
|
178
|
-
'#fff8dc': 'cornsilk',
|
|
179
|
-
'#dc143c': 'crimson',
|
|
180
|
-
'#00ffff': 'cyan',
|
|
181
|
-
'#00008b': 'darkblue',
|
|
182
|
-
'#008b8b': 'darkcyan',
|
|
183
|
-
'#b8860b': 'darkgoldenrod',
|
|
184
|
-
// '#a9a9a9': 'darkgray',
|
|
185
|
-
'#a9a9a9': 'darkgrey',
|
|
186
|
-
'#006400': 'darkgreen',
|
|
187
|
-
'#bdb76b': 'darkkhaki',
|
|
188
|
-
'#8b008b': 'darkmagenta',
|
|
189
|
-
'#556b2f': 'darkolivegreen',
|
|
190
|
-
'#ff8c00': 'darkorange',
|
|
191
|
-
'#9932cc': 'darkorchid',
|
|
192
|
-
'#8b0000': 'darkred',
|
|
193
|
-
'#e9967a': 'darksalmon',
|
|
194
|
-
'#8fbc8f': 'darkseagreen',
|
|
195
|
-
'#483d8b': 'darkslateblue',
|
|
196
|
-
// '#2f4f4f': 'darkslategray',
|
|
197
|
-
'#2f4f4f': 'darkslategrey',
|
|
198
|
-
'#00ced1': 'darkturquoise',
|
|
199
|
-
'#9400d3': 'darkviolet',
|
|
200
|
-
'#ff1493': 'deeppink',
|
|
201
|
-
'#00bfff': 'deepskyblue',
|
|
202
|
-
// '#696969': 'dimgray',
|
|
203
|
-
'#696969': 'dimgrey',
|
|
204
|
-
'#1e90ff': 'dodgerblue',
|
|
205
|
-
'#b22222': 'firebrick',
|
|
206
|
-
'#fffaf0': 'floralwhite',
|
|
207
|
-
'#228b22': 'forestgreen',
|
|
208
|
-
// '#ff00ff': 'fuchsia',
|
|
209
|
-
'#dcdcdc': 'gainsboro',
|
|
210
|
-
'#f8f8ff': 'ghostwhite',
|
|
211
|
-
'#ffd700': 'gold',
|
|
212
|
-
'#daa520': 'goldenrod',
|
|
213
|
-
// '#808080': 'gray',
|
|
214
|
-
'#808080': 'grey',
|
|
215
|
-
'#008000': 'green',
|
|
216
|
-
'#adff2f': 'greenyellow',
|
|
217
|
-
'#f0fff0': 'honeydew',
|
|
218
|
-
'#ff69b4': 'hotpink',
|
|
219
|
-
'#cd5c5c': 'indianred',
|
|
220
|
-
'#4b0082': 'indigo',
|
|
221
|
-
'#fffff0': 'ivory',
|
|
222
|
-
'#f0e68c': 'khaki',
|
|
223
|
-
'#e6e6fa': 'lavender',
|
|
224
|
-
'#fff0f5': 'lavenderblush',
|
|
225
|
-
'#7cfc00': 'lawngreen',
|
|
226
|
-
'#fffacd': 'lemonchiffon',
|
|
227
|
-
'#add8e6': 'lightblue',
|
|
228
|
-
'#f08080': 'lightcoral',
|
|
229
|
-
'#e0ffff': 'lightcyan',
|
|
230
|
-
'#fafad2': 'lightgoldenrodyellow',
|
|
231
|
-
// '#d3d3d3': 'lightgray',
|
|
232
|
-
'#d3d3d3': 'lightgrey',
|
|
233
|
-
'#90ee90': 'lightgreen',
|
|
234
|
-
'#ffb6c1': 'lightpink',
|
|
235
|
-
'#ffa07a': 'lightsalmon',
|
|
236
|
-
'#20b2aa': 'lightseagreen',
|
|
237
|
-
'#87cefa': 'lightskyblue',
|
|
238
|
-
// '#778899': 'lightslategray',
|
|
239
|
-
'#778899': 'lightslategrey',
|
|
240
|
-
'#b0c4de': 'lightsteelblue',
|
|
241
|
-
'#ffffe0': 'lightyellow',
|
|
242
|
-
'#00ff00': 'lime',
|
|
243
|
-
'#32cd32': 'limegreen',
|
|
244
|
-
'#faf0e6': 'linen',
|
|
245
|
-
'#ff00ff': 'magenta',
|
|
246
|
-
'#800000': 'maroon',
|
|
247
|
-
'#66cdaa': 'mediumaquamarine',
|
|
248
|
-
'#0000cd': 'mediumblue',
|
|
249
|
-
'#ba55d3': 'mediumorchid',
|
|
250
|
-
'#9370d8': 'mediumpurple',
|
|
251
|
-
'#3cb371': 'mediumseagreen',
|
|
252
|
-
'#7b68ee': 'mediumslateblue',
|
|
253
|
-
'#00fa9a': 'mediumspringgreen',
|
|
254
|
-
'#48d1cc': 'mediumturquoise',
|
|
255
|
-
'#c71585': 'mediumvioletred',
|
|
256
|
-
'#191970': 'midnightblue',
|
|
257
|
-
'#f5fffa': 'mintcream',
|
|
258
|
-
'#ffe4e1': 'mistyrose',
|
|
259
|
-
'#ffe4b5': 'moccasin',
|
|
260
|
-
'#ffdead': 'navajowhite',
|
|
261
|
-
'#000080': 'navy',
|
|
262
|
-
'#fdf5e6': 'oldlace',
|
|
263
|
-
'#808000': 'olive',
|
|
264
|
-
'#6b8e23': 'olivedrab',
|
|
265
|
-
'#ffa500': 'orange',
|
|
266
|
-
'#ff4500': 'orangered',
|
|
267
|
-
'#da70d6': 'orchid',
|
|
268
|
-
'#eee8aa': 'palegoldenrod',
|
|
269
|
-
'#98fb98': 'palegreen',
|
|
270
|
-
'#afeeee': 'paleturquoise',
|
|
271
|
-
'#d87093': 'palevioletred',
|
|
272
|
-
'#ffefd5': 'papayawhip',
|
|
273
|
-
'#ffdab9': 'peachpuff',
|
|
274
|
-
'#cd853f': 'peru',
|
|
275
|
-
'#ffc0cb': 'pink',
|
|
276
|
-
'#dda0dd': 'plum',
|
|
277
|
-
'#b0e0e6': 'powderblue',
|
|
278
|
-
'#800080': 'purple',
|
|
279
|
-
'#ff0000': 'red',
|
|
280
|
-
'#bc8f8f': 'rosybrown',
|
|
281
|
-
'#4169e1': 'royalblue',
|
|
282
|
-
'#8b4513': 'saddlebrown',
|
|
283
|
-
'#fa8072': 'salmon',
|
|
284
|
-
'#f4a460': 'sandybrown',
|
|
285
|
-
'#2e8b57': 'seagreen',
|
|
286
|
-
'#fff5ee': 'seashell',
|
|
287
|
-
'#a0522d': 'sienna',
|
|
288
|
-
'#c0c0c0': 'silver',
|
|
289
|
-
'#87ceeb': 'skyblue',
|
|
290
|
-
'#6a5acd': 'slateblue',
|
|
291
|
-
// '#708090': 'slategray',
|
|
292
|
-
'#708090': 'slategrey',
|
|
293
|
-
'#fffafa': 'snow',
|
|
294
|
-
'#00ff7f': 'springgreen',
|
|
295
|
-
'#4682b4': 'steelblue',
|
|
296
|
-
'#d2b48c': 'tan',
|
|
297
|
-
'#008080': 'teal',
|
|
298
|
-
'#d8bfd8': 'thistle',
|
|
299
|
-
'#ff6347': 'tomato',
|
|
300
|
-
'#40e0d0': 'turquoise',
|
|
301
|
-
'#ee82ee': 'violet',
|
|
302
|
-
'#f5deb3': 'wheat',
|
|
303
|
-
'#ffffff': 'white',
|
|
304
|
-
'#f5f5f5': 'whitesmoke',
|
|
305
|
-
'#ffff00': 'yellow',
|
|
306
|
-
'#9acd32': 'yellowgreen',
|
|
307
|
-
'#663399': 'rebeccapurple',
|
|
308
|
-
'#00000000': 'transparent'
|
|
309
|
-
});
|
|
310
|
-
/**
|
|
311
|
-
* clamp color values
|
|
312
|
-
* @param token
|
|
313
|
-
*/
|
|
314
|
-
function clamp(token) {
|
|
315
|
-
if (token.kin == 'rgb' || token.kin == 'rgba') {
|
|
316
|
-
token.chi.filter((token) => ![EnumToken.LiteralTokenType, EnumToken.CommaTokenType, EnumToken.WhitespaceTokenType].includes(token.typ)).
|
|
317
|
-
forEach((token, index) => {
|
|
318
|
-
if (index <= 2) {
|
|
319
|
-
if (token.typ == EnumToken.NumberTokenType) {
|
|
320
|
-
token.val = String(Math.min(255, Math.max(0, +token.val)));
|
|
321
|
-
}
|
|
322
|
-
else if (token.typ == EnumToken.PercentageTokenType) {
|
|
323
|
-
token.val = String(Math.min(100, Math.max(0, +token.val)));
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
if (token.typ == EnumToken.NumberTokenType) {
|
|
328
|
-
token.val = String(Math.min(1, Math.max(0, +token.val)));
|
|
329
|
-
}
|
|
330
|
-
else if (token.typ == EnumToken.PercentageTokenType) {
|
|
331
|
-
token.val = String(Math.min(100, Math.max(0, +token.val)));
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
return token;
|
|
337
|
-
}
|
|
338
|
-
function getNumber(token) {
|
|
339
|
-
if (token.typ == EnumToken.IdenTokenType && token.val == 'none') {
|
|
340
|
-
return 0;
|
|
341
|
-
}
|
|
342
|
-
// @ts-ignore
|
|
343
|
-
return token.typ == EnumToken.PercentageTokenType ? token.val / 100 : +token.val;
|
|
344
|
-
}
|
|
345
|
-
function getAngle(token) {
|
|
346
|
-
if (token.typ == EnumToken.IdenTokenType) {
|
|
347
|
-
if (token.val == 'none') {
|
|
348
|
-
return 0;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
if (token.typ == EnumToken.AngleTokenType) {
|
|
352
|
-
switch (token.unit) {
|
|
353
|
-
case 'deg':
|
|
354
|
-
// @ts-ignore
|
|
355
|
-
return token.val / 360;
|
|
356
|
-
case 'rad':
|
|
357
|
-
// @ts-ignore
|
|
358
|
-
return token.val / (2 * Math.PI);
|
|
359
|
-
case 'grad':
|
|
360
|
-
// @ts-ignore
|
|
361
|
-
return token.val / 400;
|
|
362
|
-
case 'turn':
|
|
363
|
-
// @ts-ignore
|
|
364
|
-
return +token.val;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
// @ts-ignore
|
|
368
|
-
return token.val / 360;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
export { COLORS_NAMES, NAMES_COLORS, clamp, getAngle, getNumber };
|