@tbela99/css-parser 1.2.0 → 1.3.0
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/CHANGELOG.md +5 -0
- package/README.md +2 -2
- package/dist/index-umd-web.js +483 -849
- package/dist/index.cjs +483 -849
- package/dist/index.d.ts +107 -11
- package/dist/lib/ast/features/calc.js +1 -25
- package/dist/lib/ast/features/inlinecssvariables.js +0 -19
- package/dist/lib/ast/features/transform.js +2 -2
- package/dist/lib/ast/math/expression.js +26 -149
- package/dist/lib/ast/math/math.js +8 -8
- package/dist/lib/ast/transform/compute.js +4 -37
- package/dist/lib/ast/transform/matrix.js +33 -34
- package/dist/lib/ast/transform/minify.js +32 -51
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.js +13 -13
- package/dist/lib/ast/transform/scale.js +8 -8
- package/dist/lib/ast/transform/skew.js +4 -4
- package/dist/lib/ast/transform/translate.js +8 -8
- package/dist/lib/ast/transform/utils.js +31 -39
- package/dist/lib/ast/types.js +91 -2
- package/dist/lib/parser/declaration/set.js +2 -2
- package/dist/lib/parser/parse.js +34 -12
- package/dist/lib/parser/tokenize.js +28 -40
- package/dist/lib/parser/utils/type.js +1 -1
- package/dist/lib/renderer/render.js +36 -27
- package/dist/lib/syntax/color/cmyk.js +2 -2
- package/dist/lib/syntax/color/color-mix.js +11 -12
- package/dist/lib/syntax/color/color.js +7 -7
- package/dist/lib/syntax/color/hsl.js +4 -4
- package/dist/lib/syntax/color/hwb.js +27 -8
- package/dist/lib/syntax/color/lab.js +4 -4
- package/dist/lib/syntax/color/lch.js +4 -4
- package/dist/lib/syntax/color/oklab.js +4 -4
- package/dist/lib/syntax/color/oklch.js +4 -4
- package/dist/lib/syntax/color/relativecolor.js +1 -1
- package/dist/lib/syntax/color/rgb.js +4 -4
- package/dist/lib/syntax/color/utils/components.js +15 -3
- package/dist/lib/syntax/color/utils/distance.js +11 -1
- package/dist/lib/syntax/syntax.js +8 -17
- package/dist/lib/syntax/utils.js +1 -1
- package/dist/lib/validation/at-rules/document.js +1 -1
- package/dist/lib/validation/at-rules/import.js +4 -4
- package/dist/lib/validation/at-rules/keyframes.js +0 -11
- package/dist/lib/validation/at-rules/supports.js +6 -6
- package/dist/lib/validation/config.js +0 -4
- package/dist/lib/validation/parser/parse.js +0 -8
- package/dist/lib/validation/selector.js +0 -9
- package/dist/lib/validation/syntax.js +14 -134
- package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -11
- package/dist/lib/validation/syntaxes/family-name.js +0 -32
- package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -11
- package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -26
- package/dist/lib/validation/syntaxes/url.js +0 -33
- package/dist/lib/validation/utils/list.js +0 -8
- package/package.json +1 -1
package/dist/lib/parser/parse.js
CHANGED
|
@@ -122,6 +122,18 @@ async function doParse(iterator, options = {}) {
|
|
|
122
122
|
stats.bytesIn = item.bytesIn;
|
|
123
123
|
rawTokens.push(item);
|
|
124
124
|
if (item.hint != null && BadTokensTypes.includes(item.hint)) {
|
|
125
|
+
const node = getTokenType(item.token, item.hint);
|
|
126
|
+
errors.push({
|
|
127
|
+
action: 'drop',
|
|
128
|
+
message: 'Bad token',
|
|
129
|
+
syntax: null,
|
|
130
|
+
node,
|
|
131
|
+
location: {
|
|
132
|
+
src,
|
|
133
|
+
sta: item.sta,
|
|
134
|
+
end: item.end
|
|
135
|
+
}
|
|
136
|
+
});
|
|
125
137
|
// bad token
|
|
126
138
|
continue;
|
|
127
139
|
}
|
|
@@ -166,7 +178,12 @@ async function doParse(iterator, options = {}) {
|
|
|
166
178
|
errors.push({
|
|
167
179
|
action: 'drop',
|
|
168
180
|
message: 'invalid block',
|
|
169
|
-
rawTokens: tokens.slice()
|
|
181
|
+
rawTokens: tokens.slice(),
|
|
182
|
+
location: {
|
|
183
|
+
src,
|
|
184
|
+
sta: tokens[0].sta,
|
|
185
|
+
end: tokens[tokens.length - 1].end
|
|
186
|
+
}
|
|
170
187
|
});
|
|
171
188
|
}
|
|
172
189
|
}
|
|
@@ -334,6 +351,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
334
351
|
errors.push({
|
|
335
352
|
action: 'drop',
|
|
336
353
|
message: `CDOCOMM not allowed here ${JSON.stringify(tokens[i], null, 1)}`,
|
|
354
|
+
node: tokens[i],
|
|
337
355
|
location
|
|
338
356
|
});
|
|
339
357
|
continue;
|
|
@@ -388,7 +406,8 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
388
406
|
if (!(type == EnumToken.InvalidAtRuleTokenType &&
|
|
389
407
|
// @ts-ignore
|
|
390
408
|
['charset', 'layer', 'import'].includes(context.chi[i].nam))) {
|
|
391
|
-
|
|
409
|
+
// @ts-ignore
|
|
410
|
+
errors.push({ action: 'drop', message: 'invalid @import', location, rawTokens: [atRule, ...tokens] });
|
|
392
411
|
return null;
|
|
393
412
|
}
|
|
394
413
|
}
|
|
@@ -464,7 +483,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
464
483
|
action: 'drop',
|
|
465
484
|
message: '@charset must have only one space',
|
|
466
485
|
// @ts-ignore
|
|
467
|
-
location
|
|
486
|
+
location, rawTokens: [atRule, ...tokens]
|
|
468
487
|
});
|
|
469
488
|
return null;
|
|
470
489
|
}
|
|
@@ -533,6 +552,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
533
552
|
errors.push({
|
|
534
553
|
action: 'drop',
|
|
535
554
|
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), '') + '"',
|
|
555
|
+
node,
|
|
536
556
|
// @ts-ignore
|
|
537
557
|
location: { src, ...(map.get(valid.node) ?? location) }
|
|
538
558
|
});
|
|
@@ -581,7 +601,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
581
601
|
if (curr.typ == EnumToken.IdenTokenType && curr.val == 'from') {
|
|
582
602
|
Object.assign(curr, { typ: EnumToken.PercentageTokenType, val: '0' });
|
|
583
603
|
}
|
|
584
|
-
else if (curr.typ == EnumToken.PercentageTokenType && curr.val ==
|
|
604
|
+
else if (curr.typ == EnumToken.PercentageTokenType && curr.val == 100) {
|
|
585
605
|
Object.assign(curr, { typ: EnumToken.IdenTokenType, val: 'to' });
|
|
586
606
|
}
|
|
587
607
|
}
|
|
@@ -634,6 +654,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
634
654
|
errors.push({
|
|
635
655
|
action: 'drop',
|
|
636
656
|
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), '') + '"',
|
|
657
|
+
node,
|
|
637
658
|
// @ts-ignore
|
|
638
659
|
location
|
|
639
660
|
});
|
|
@@ -658,7 +679,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
658
679
|
val: tokens[i].val.charAt(0)
|
|
659
680
|
}, {
|
|
660
681
|
typ: EnumToken.NumberTokenType,
|
|
661
|
-
val: tokens[i].val.slice(1)
|
|
682
|
+
val: +tokens[i].val.slice(1)
|
|
662
683
|
});
|
|
663
684
|
}
|
|
664
685
|
else if (start == '/' && isFunction(val)) {
|
|
@@ -859,9 +880,10 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
859
880
|
}
|
|
860
881
|
}
|
|
861
882
|
}
|
|
883
|
+
const val = value.typ == EnumToken.IdenTokenType ? value.val.toLowerCase() : null;
|
|
862
884
|
if (value.typ == EnumToken.IdenTokenType) {
|
|
863
885
|
if (parent == null && mediaTypes.some((t) => {
|
|
864
|
-
if (
|
|
886
|
+
if (val === t) {
|
|
865
887
|
// @ts-ignore
|
|
866
888
|
value.typ = EnumToken.MediaFeatureTokenType;
|
|
867
889
|
return true;
|
|
@@ -870,18 +892,18 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
870
892
|
})) {
|
|
871
893
|
continue;
|
|
872
894
|
}
|
|
873
|
-
if (value.typ == EnumToken.IdenTokenType && 'and'
|
|
895
|
+
if (value.typ == EnumToken.IdenTokenType && 'and' === val) {
|
|
874
896
|
// @ts-ignore
|
|
875
897
|
value.typ = EnumToken.MediaFeatureAndTokenType;
|
|
876
898
|
continue;
|
|
877
899
|
}
|
|
878
|
-
if (value.typ == EnumToken.IdenTokenType && 'or'
|
|
900
|
+
if (value.typ == EnumToken.IdenTokenType && 'or' === val) {
|
|
879
901
|
// @ts-ignore
|
|
880
902
|
value.typ = EnumToken.MediaFeatureOrTokenType;
|
|
881
903
|
continue;
|
|
882
904
|
}
|
|
883
905
|
if (value.typ == EnumToken.IdenTokenType &&
|
|
884
|
-
['not', 'only'].some((t) =>
|
|
906
|
+
['not', 'only'].some((t) => val === t)) {
|
|
885
907
|
// @ts-ignore
|
|
886
908
|
const array = parent?.chi ?? tokens;
|
|
887
909
|
const startIndex = array.indexOf(value);
|
|
@@ -1194,19 +1216,19 @@ function getTokenType(val, hint) {
|
|
|
1194
1216
|
if (isNumber(val)) {
|
|
1195
1217
|
return {
|
|
1196
1218
|
typ: EnumToken.NumberTokenType,
|
|
1197
|
-
val
|
|
1219
|
+
val: +val
|
|
1198
1220
|
};
|
|
1199
1221
|
}
|
|
1200
1222
|
if (isPercentage(val)) {
|
|
1201
1223
|
return {
|
|
1202
1224
|
typ: EnumToken.PercentageTokenType,
|
|
1203
|
-
val: val.slice(0, -1)
|
|
1225
|
+
val: +val.slice(0, -1)
|
|
1204
1226
|
};
|
|
1205
1227
|
}
|
|
1206
1228
|
if (isFlex(val)) {
|
|
1207
1229
|
return {
|
|
1208
1230
|
typ: EnumToken.FlexTokenType,
|
|
1209
|
-
val: val.slice(0, -2)
|
|
1231
|
+
val: +val.slice(0, -2)
|
|
1210
1232
|
};
|
|
1211
1233
|
}
|
|
1212
1234
|
if (isDimension(val)) {
|
|
@@ -3,7 +3,7 @@ import '../ast/minify.js';
|
|
|
3
3
|
import '../ast/walk.js';
|
|
4
4
|
import './parse.js';
|
|
5
5
|
import './utils/config.js';
|
|
6
|
-
import { isWhiteSpace, isIdentStart, isIdent, isNewLine, isDigit
|
|
6
|
+
import { isWhiteSpace, isIdentStart, isIdent, isNewLine, isDigit } from '../syntax/syntax.js';
|
|
7
7
|
import '../syntax/color/utils/constants.js';
|
|
8
8
|
import '../renderer/sourcemap/lib/encode.js';
|
|
9
9
|
|
|
@@ -424,8 +424,6 @@ function* tokenize(stream) {
|
|
|
424
424
|
value = peek(parseInfo);
|
|
425
425
|
// let cp: number;
|
|
426
426
|
let whitespace = '';
|
|
427
|
-
let hasWhiteSpace = false;
|
|
428
|
-
let errorState = false;
|
|
429
427
|
if (value == '"' || value == "'") {
|
|
430
428
|
const quote = value;
|
|
431
429
|
let inquote = true;
|
|
@@ -465,7 +463,6 @@ function* tokenize(stream) {
|
|
|
465
463
|
if (isWhiteSpace(charCode)) {
|
|
466
464
|
whitespace += value;
|
|
467
465
|
while (value = peek(parseInfo)) {
|
|
468
|
-
hasWhiteSpace = true;
|
|
469
466
|
if (isWhiteSpace(value?.charCodeAt(0))) {
|
|
470
467
|
whitespace += next(parseInfo);
|
|
471
468
|
continue;
|
|
@@ -521,42 +518,33 @@ function* tokenize(stream) {
|
|
|
521
518
|
buffer = '';
|
|
522
519
|
break;
|
|
523
520
|
}
|
|
524
|
-
if (
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
if (
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
if (charCode == 0x29) {
|
|
552
|
-
break;
|
|
553
|
-
}
|
|
554
|
-
buffer += next(parseInfo);
|
|
555
|
-
}
|
|
556
|
-
yield pushToken(buffer, parseInfo, EnumToken.BadUrlTokenType);
|
|
557
|
-
buffer = '';
|
|
558
|
-
break;
|
|
559
|
-
}
|
|
521
|
+
// if (errorState) {
|
|
522
|
+
//
|
|
523
|
+
// buffer += whitespace + value;
|
|
524
|
+
//
|
|
525
|
+
// while (value = peek(parseInfo)) {
|
|
526
|
+
//
|
|
527
|
+
// charCode = value.charCodeAt(0);
|
|
528
|
+
//
|
|
529
|
+
// if (charCode == 0x5c) {
|
|
530
|
+
//
|
|
531
|
+
// buffer += next(parseInfo, 2);
|
|
532
|
+
// continue;
|
|
533
|
+
// }
|
|
534
|
+
//
|
|
535
|
+
// // ')'
|
|
536
|
+
// if (charCode == 0x29) {
|
|
537
|
+
//
|
|
538
|
+
// break;
|
|
539
|
+
// }
|
|
540
|
+
//
|
|
541
|
+
// buffer += next(parseInfo);
|
|
542
|
+
// }
|
|
543
|
+
//
|
|
544
|
+
// yield pushToken(buffer, parseInfo, EnumToken.BadUrlTokenType);
|
|
545
|
+
// buffer = '';
|
|
546
|
+
// break;
|
|
547
|
+
// }
|
|
560
548
|
buffer += value;
|
|
561
549
|
}
|
|
562
550
|
}
|
|
@@ -14,7 +14,7 @@ function matchType(val, properties) {
|
|
|
14
14
|
(properties.types.some((t) => EnumToken[t] == val.typ))) {
|
|
15
15
|
return true;
|
|
16
16
|
}
|
|
17
|
-
if (val.typ == EnumToken.NumberTokenType && val.val ==
|
|
17
|
+
if (val.typ == EnumToken.NumberTokenType && val.val == 0) {
|
|
18
18
|
// @ts-ignore
|
|
19
19
|
return properties.types.some((type) => {
|
|
20
20
|
// @ts-ignore
|
|
@@ -325,7 +325,7 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
325
325
|
if (Array.isArray(token.chi)) {
|
|
326
326
|
const isLegacy = ['rgb', 'rgba', 'hsl', 'hsla'].includes(token.val.toLowerCase());
|
|
327
327
|
const useAlpha = (['rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'oklab', 'oklch', 'lab', 'lch'].includes(token.val.toLowerCase()) && token.chi.length == 4) ||
|
|
328
|
-
('color'
|
|
328
|
+
('color' == token.val.toLowerCase() && token.chi.length == 5);
|
|
329
329
|
return (token.val.endsWith('a') ? token.val.slice(0, -1) : token.val) + '(' + token.chi.reduce((acc, curr, index, array) => {
|
|
330
330
|
if (/[,/]\s*$/.test(acc)) {
|
|
331
331
|
if (curr.typ == EnumToken.WhitespaceTokenType) {
|
|
@@ -522,32 +522,41 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
522
522
|
return token.val.slice(1);
|
|
523
523
|
}
|
|
524
524
|
case EnumToken.UrlTokenTokenType:
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
525
|
+
// if (token.typ == EnumToken.UrlTokenTokenType) {
|
|
526
|
+
//
|
|
527
|
+
// if (options.output != null) {
|
|
528
|
+
//
|
|
529
|
+
// if (!('original' in token)) {
|
|
530
|
+
//
|
|
531
|
+
// // do not modify original token
|
|
532
|
+
// token = {...token};
|
|
533
|
+
// Object.defineProperty(token, 'original', {
|
|
534
|
+
// enumerable: false,
|
|
535
|
+
// writable: false,
|
|
536
|
+
// value: (token as UrlToken).val
|
|
537
|
+
// })
|
|
538
|
+
// }
|
|
539
|
+
//
|
|
540
|
+
// // @ts-ignore
|
|
541
|
+
// if (!(token.original in cache)) {
|
|
542
|
+
//
|
|
543
|
+
// let output: string = <string>options.output ?? '';
|
|
544
|
+
// const key = output + 'abs';
|
|
545
|
+
//
|
|
546
|
+
// if (!(key in cache)) {
|
|
547
|
+
//
|
|
548
|
+
// // @ts-ignore
|
|
549
|
+
// cache[key] = options.dirname(options.resolve(output, options.cwd).absolute);
|
|
550
|
+
// }
|
|
551
|
+
//
|
|
552
|
+
// // @ts-ignore
|
|
553
|
+
// cache[token.original] = options.resolve(token.original, cache[key]).relative;
|
|
554
|
+
// }
|
|
555
|
+
//
|
|
556
|
+
// // @ts-ignore
|
|
557
|
+
// token.val = cache[token.original];
|
|
558
|
+
// }
|
|
559
|
+
// }
|
|
551
560
|
case EnumToken.HashTokenType:
|
|
552
561
|
case EnumToken.IdenTokenType:
|
|
553
562
|
case EnumToken.AtRuleTokenType:
|
|
@@ -92,11 +92,11 @@ function cmyktoken(values) {
|
|
|
92
92
|
chi: values.reduce((acc, curr, index) => index < 4 ? [...acc, {
|
|
93
93
|
typ: EnumToken.PercentageTokenType,
|
|
94
94
|
// @ts-ignore
|
|
95
|
-
val:
|
|
95
|
+
val: curr * 100
|
|
96
96
|
}] : [...acc, {
|
|
97
97
|
typ: EnumToken.LiteralTokenType,
|
|
98
98
|
val: '/'
|
|
99
|
-
}, { typ: EnumToken.PercentageTokenType, val:
|
|
99
|
+
}, { typ: EnumToken.PercentageTokenType, val: curr * 100 }], []),
|
|
100
100
|
kin: ColorType.DEVICE_CMYK
|
|
101
101
|
};
|
|
102
102
|
}
|
|
@@ -57,7 +57,7 @@ function interpolateHue(interpolationMethod, h1, h2) {
|
|
|
57
57
|
return [h1, h2];
|
|
58
58
|
}
|
|
59
59
|
function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color2, percentage2) {
|
|
60
|
-
if (color1.val == 'currentcolor' || color2.val == 'currentcolor') {
|
|
60
|
+
if (color1.val.toLowerCase() == 'currentcolor' || color2.val == 'currentcolor'.toLowerCase()) {
|
|
61
61
|
return null;
|
|
62
62
|
}
|
|
63
63
|
if (hueInterpolationMethod != null && isRectangularOrthogonalColorspace(colorSpace)) {
|
|
@@ -69,20 +69,19 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
|
|
|
69
69
|
if (percentage1 == null) {
|
|
70
70
|
if (percentage2 == null) {
|
|
71
71
|
// @ts-ignore
|
|
72
|
-
percentage1 = { typ: EnumToken.NumberTokenType, val:
|
|
72
|
+
percentage1 = { typ: EnumToken.NumberTokenType, val: .5 };
|
|
73
73
|
// @ts-ignore
|
|
74
|
-
percentage2 = { typ: EnumToken.NumberTokenType, val:
|
|
74
|
+
percentage2 = { typ: EnumToken.NumberTokenType, val: .5 };
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
77
|
if (+percentage2.val <= 0) {
|
|
78
78
|
return null;
|
|
79
79
|
}
|
|
80
80
|
if (+percentage2.val >= 100) {
|
|
81
|
-
|
|
82
|
-
percentage2 = { typ: EnumToken.NumberTokenType, val: '1' };
|
|
81
|
+
percentage2 = { typ: EnumToken.NumberTokenType, val: 1 };
|
|
83
82
|
}
|
|
84
83
|
// @ts-ignore
|
|
85
|
-
percentage1 = { typ: EnumToken.NumberTokenType, val:
|
|
84
|
+
percentage1 = { typ: EnumToken.NumberTokenType, val: 1 - percentage2.val / 100 };
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
87
|
else {
|
|
@@ -94,10 +93,10 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
|
|
|
94
93
|
// @ts-ignore
|
|
95
94
|
if (percentage1.val >= 100) {
|
|
96
95
|
// @ts-ignore
|
|
97
|
-
percentage1 = { typ: EnumToken.NumberTokenType, val:
|
|
96
|
+
percentage1 = { typ: EnumToken.NumberTokenType, val: 1 };
|
|
98
97
|
}
|
|
99
98
|
// @ts-ignore
|
|
100
|
-
percentage2 = { typ: EnumToken.NumberTokenType, val:
|
|
99
|
+
percentage2 = { typ: EnumToken.NumberTokenType, val: 1 - percentage1.val / 100 };
|
|
101
100
|
}
|
|
102
101
|
else {
|
|
103
102
|
// @ts-ignore
|
|
@@ -275,7 +274,7 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
|
|
|
275
274
|
chi: values.map(v => {
|
|
276
275
|
return {
|
|
277
276
|
typ: EnumToken.NumberTokenType,
|
|
278
|
-
val:
|
|
277
|
+
val: v
|
|
279
278
|
};
|
|
280
279
|
}),
|
|
281
280
|
kin: ColorType.LCH
|
|
@@ -332,11 +331,11 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
|
|
|
332
331
|
};
|
|
333
332
|
if (colorSpace.val == 'hsl' || colorSpace.val == 'hwb') {
|
|
334
333
|
// @ts-ignore
|
|
335
|
-
result.chi[0] = { typ: EnumToken.AngleTokenType, val:
|
|
334
|
+
result.chi[0] = { typ: EnumToken.AngleTokenType, val: result.chi[0].val * 360 };
|
|
336
335
|
// @ts-ignore
|
|
337
|
-
result.chi[1] = { typ: EnumToken.PercentageTokenType, val:
|
|
336
|
+
result.chi[1] = { typ: EnumToken.PercentageTokenType, val: result.chi[1].val * 100 };
|
|
338
337
|
// @ts-ignore
|
|
339
|
-
result.chi[2] = { typ: EnumToken.PercentageTokenType, val:
|
|
338
|
+
result.chi[2] = { typ: EnumToken.PercentageTokenType, val: result.chi[2].val * 100 };
|
|
340
339
|
}
|
|
341
340
|
return result;
|
|
342
341
|
}
|
|
@@ -28,7 +28,7 @@ import { a98rgb2srgbvalues, srgb2a98values } from './a98rgb.js';
|
|
|
28
28
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* Converts a color
|
|
31
|
+
* Converts a color to another color space
|
|
32
32
|
* @param token
|
|
33
33
|
* @param to
|
|
34
34
|
*/
|
|
@@ -36,7 +36,7 @@ function convertColor(token, to) {
|
|
|
36
36
|
if (token.kin == ColorType.SYS ||
|
|
37
37
|
token.kin == ColorType.DPSYS ||
|
|
38
38
|
(isIdentColor(token) &&
|
|
39
|
-
|
|
39
|
+
'currentcolor' == token.val.toLowerCase())) {
|
|
40
40
|
return token;
|
|
41
41
|
}
|
|
42
42
|
if (token.kin == ColorType.COLOR_MIX && to != ColorType.COLOR_MIX) {
|
|
@@ -505,14 +505,14 @@ function color2srgbvalues(token) {
|
|
|
505
505
|
function values2colortoken(values, to) {
|
|
506
506
|
values = srgb2srgbcolorspace(values, to);
|
|
507
507
|
const chi = [
|
|
508
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
509
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
510
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
508
|
+
{ typ: EnumToken.NumberTokenType, val: values[0] },
|
|
509
|
+
{ typ: EnumToken.NumberTokenType, val: values[1] },
|
|
510
|
+
{ typ: EnumToken.NumberTokenType, val: values[2] },
|
|
511
511
|
];
|
|
512
512
|
if (values.length == 4) {
|
|
513
513
|
chi.push({ typ: EnumToken.LiteralTokenType, val: "/" }, {
|
|
514
514
|
typ: EnumToken.PercentageTokenType,
|
|
515
|
-
val:
|
|
515
|
+
val: values[3] * 100
|
|
516
516
|
});
|
|
517
517
|
}
|
|
518
518
|
const colorSpace = ColorType[to].toLowerCase().replaceAll('_', '-');
|
|
@@ -533,7 +533,7 @@ function getNumber(token) {
|
|
|
533
533
|
return 0;
|
|
534
534
|
}
|
|
535
535
|
// @ts-ignore
|
|
536
|
-
return token.typ == EnumToken.PercentageTokenType ? token.val / 100 :
|
|
536
|
+
return token.typ == EnumToken.PercentageTokenType ? token.val / 100 : token.val;
|
|
537
537
|
}
|
|
538
538
|
/**
|
|
539
539
|
* convert angle to turn
|
|
@@ -76,12 +76,12 @@ function color2HslToken(token) {
|
|
|
76
76
|
function hslToken(values) {
|
|
77
77
|
values[0] = toPrecisionAngle(values[0] * 360);
|
|
78
78
|
const chi = [
|
|
79
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
80
|
-
{ typ: EnumToken.PercentageTokenType, val:
|
|
81
|
-
{ typ: EnumToken.PercentageTokenType, val:
|
|
79
|
+
{ typ: EnumToken.NumberTokenType, val: values[0] },
|
|
80
|
+
{ typ: EnumToken.PercentageTokenType, val: values[1] * 100 },
|
|
81
|
+
{ typ: EnumToken.PercentageTokenType, val: values[2] * 100 },
|
|
82
82
|
];
|
|
83
83
|
if (values.length == 4 && values[3] != 1) {
|
|
84
|
-
chi.push({ typ: EnumToken.LiteralTokenType, val: '/' }, { typ: EnumToken.PercentageTokenType, val:
|
|
84
|
+
chi.push({ typ: EnumToken.LiteralTokenType, val: '/' }, { typ: EnumToken.PercentageTokenType, val: values[3] * 100 });
|
|
85
85
|
}
|
|
86
86
|
return {
|
|
87
87
|
typ: EnumToken.ColorTokenType,
|
|
@@ -70,12 +70,15 @@ function color2hwbToken(token) {
|
|
|
70
70
|
function hwbToken(values) {
|
|
71
71
|
values[0] = toPrecisionAngle(values[0] * 360);
|
|
72
72
|
const chi = [
|
|
73
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
74
|
-
{ typ: EnumToken.PercentageTokenType, val:
|
|
75
|
-
{ typ: EnumToken.PercentageTokenType, val:
|
|
73
|
+
{ typ: EnumToken.NumberTokenType, val: values[0] },
|
|
74
|
+
{ typ: EnumToken.PercentageTokenType, val: values[1] * 100 },
|
|
75
|
+
{ typ: EnumToken.PercentageTokenType, val: values[2] * 100 },
|
|
76
76
|
];
|
|
77
77
|
if (values.length == 4) {
|
|
78
|
-
chi.push({ typ: EnumToken.LiteralTokenType, val: '/' }, {
|
|
78
|
+
chi.push({ typ: EnumToken.LiteralTokenType, val: '/' }, {
|
|
79
|
+
typ: EnumToken.PercentageTokenType,
|
|
80
|
+
val: values[3] * 100
|
|
81
|
+
});
|
|
79
82
|
}
|
|
80
83
|
return {
|
|
81
84
|
typ: EnumToken.ColorTokenType,
|
|
@@ -110,16 +113,28 @@ function hsl2hwbvalues(token) {
|
|
|
110
113
|
}));
|
|
111
114
|
}
|
|
112
115
|
function lab2hwbvalues(token) {
|
|
116
|
+
const values = lab2srgbvalues(token);
|
|
117
|
+
if (values == null) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
113
120
|
// @ts-ignore
|
|
114
|
-
return srgb2hwb(...
|
|
121
|
+
return srgb2hwb(...values);
|
|
115
122
|
}
|
|
116
123
|
function lch2hwbvalues(token) {
|
|
124
|
+
const values = lch2srgbvalues(token);
|
|
125
|
+
if (values == null) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
117
128
|
// @ts-ignore
|
|
118
|
-
return srgb2hwb(...
|
|
129
|
+
return srgb2hwb(...values);
|
|
119
130
|
}
|
|
120
131
|
function oklab2hwbvalues(token) {
|
|
132
|
+
const values = oklab2srgbvalues(token);
|
|
133
|
+
if (values == null) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
121
136
|
// @ts-ignore
|
|
122
|
-
return srgb2hwb(...
|
|
137
|
+
return srgb2hwb(...values);
|
|
123
138
|
}
|
|
124
139
|
function oklch2hwbvalues(token) {
|
|
125
140
|
const values = oklch2srgbvalues(token);
|
|
@@ -153,8 +168,12 @@ function rgb2whiteness(r, g, b) {
|
|
|
153
168
|
return Math.min(r, g, b);
|
|
154
169
|
}
|
|
155
170
|
function color2hwbvalues(token) {
|
|
171
|
+
const values = color2srgbvalues(token);
|
|
172
|
+
if (values == null) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
156
175
|
// @ts-ignore
|
|
157
|
-
return srgb2hwb(...
|
|
176
|
+
return srgb2hwb(...values);
|
|
158
177
|
}
|
|
159
178
|
function srgb2hwb(r, g, b, a = null, fallback = 0) {
|
|
160
179
|
r *= 100;
|
|
@@ -76,14 +76,14 @@ function color2labToken(token) {
|
|
|
76
76
|
}
|
|
77
77
|
function labToken(values) {
|
|
78
78
|
const chi = [
|
|
79
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
80
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
81
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
79
|
+
{ typ: EnumToken.NumberTokenType, val: values[0] },
|
|
80
|
+
{ typ: EnumToken.NumberTokenType, val: values[1] },
|
|
81
|
+
{ typ: EnumToken.NumberTokenType, val: values[2] },
|
|
82
82
|
];
|
|
83
83
|
if (values.length == 4) {
|
|
84
84
|
chi.push({ typ: EnumToken.LiteralTokenType, val: '/' }, {
|
|
85
85
|
typ: EnumToken.PercentageTokenType,
|
|
86
|
-
val:
|
|
86
|
+
val: values[3] * 100
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
return {
|
|
@@ -77,12 +77,12 @@ function color2lchToken(token) {
|
|
|
77
77
|
function lchToken(values) {
|
|
78
78
|
values[2] = toPrecisionAngle(values[2]);
|
|
79
79
|
const chi = [
|
|
80
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
81
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
82
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
80
|
+
{ typ: EnumToken.NumberTokenType, val: values[0] },
|
|
81
|
+
{ typ: EnumToken.NumberTokenType, val: values[1] },
|
|
82
|
+
{ typ: EnumToken.NumberTokenType, val: values[2] },
|
|
83
83
|
];
|
|
84
84
|
if (values.length == 4) {
|
|
85
|
-
chi.push({ typ: EnumToken.LiteralTokenType, val: '/' }, { typ: EnumToken.PercentageTokenType, val:
|
|
85
|
+
chi.push({ typ: EnumToken.LiteralTokenType, val: '/' }, { typ: EnumToken.PercentageTokenType, val: values[3] * 100 });
|
|
86
86
|
}
|
|
87
87
|
return {
|
|
88
88
|
typ: EnumToken.ColorTokenType,
|
|
@@ -78,14 +78,14 @@ function color2oklabToken(token) {
|
|
|
78
78
|
}
|
|
79
79
|
function oklabToken(values) {
|
|
80
80
|
const chi = [
|
|
81
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
82
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
83
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
81
|
+
{ typ: EnumToken.NumberTokenType, val: values[0] },
|
|
82
|
+
{ typ: EnumToken.NumberTokenType, val: values[1] },
|
|
83
|
+
{ typ: EnumToken.NumberTokenType, val: values[2] },
|
|
84
84
|
];
|
|
85
85
|
if (values.length == 4) {
|
|
86
86
|
chi.push({ typ: EnumToken.LiteralTokenType, val: '/' }, {
|
|
87
87
|
typ: EnumToken.PercentageTokenType,
|
|
88
|
-
val:
|
|
88
|
+
val: values[3] * 100
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
return {
|
|
@@ -76,14 +76,14 @@ function color2oklchToken(token) {
|
|
|
76
76
|
function oklchToken(values) {
|
|
77
77
|
values[2] = toPrecisionAngle(values[2]);
|
|
78
78
|
const chi = [
|
|
79
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
80
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
81
|
-
{ typ: EnumToken.NumberTokenType, val:
|
|
79
|
+
{ typ: EnumToken.NumberTokenType, val: values[0] },
|
|
80
|
+
{ typ: EnumToken.NumberTokenType, val: values[1] },
|
|
81
|
+
{ typ: EnumToken.NumberTokenType, val: values[2] },
|
|
82
82
|
];
|
|
83
83
|
if (values.length == 4) {
|
|
84
84
|
chi.push({ typ: EnumToken.LiteralTokenType, val: '/' }, {
|
|
85
85
|
typ: EnumToken.PercentageTokenType,
|
|
86
|
-
val:
|
|
86
|
+
val: values[3] * 100
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
return {
|