@tbela99/css-parser 1.1.1 → 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 +11 -0
- package/README.md +53 -6
- package/dist/index-umd-web.js +5503 -5037
- package/dist/index.cjs +5510 -5044
- package/dist/index.d.ts +148 -41
- package/dist/lib/ast/expand.js +81 -65
- package/dist/lib/ast/features/calc.js +14 -36
- package/dist/lib/ast/features/inlinecssvariables.js +6 -17
- package/dist/lib/ast/features/prefix.js +22 -19
- package/dist/lib/ast/features/shorthand.js +1 -1
- package/dist/lib/ast/features/transform.js +17 -2
- package/dist/lib/ast/math/expression.js +74 -172
- package/dist/lib/ast/math/math.js +24 -22
- package/dist/lib/ast/minify.js +249 -199
- package/dist/lib/ast/transform/compute.js +18 -41
- package/dist/lib/ast/transform/matrix.js +36 -36
- package/dist/lib/ast/transform/minify.js +37 -59
- 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 +80 -28
- package/dist/lib/ast/types.js +122 -2
- package/dist/lib/fs/resolve.js +1 -14
- package/dist/lib/parser/declaration/list.js +1 -1
- package/dist/lib/parser/declaration/map.js +1 -1
- package/dist/lib/parser/declaration/set.js +3 -3
- package/dist/lib/parser/parse.js +53 -107
- package/dist/lib/parser/tokenize.js +29 -53
- package/dist/lib/parser/utils/declaration.js +1 -1
- package/dist/lib/parser/utils/type.js +2 -2
- package/dist/lib/renderer/render.js +79 -194
- package/dist/lib/{renderer → syntax}/color/a98rgb.js +2 -2
- package/dist/lib/syntax/color/cmyk.js +104 -0
- package/dist/lib/{renderer → syntax}/color/color-mix.js +31 -33
- package/dist/lib/syntax/color/color.js +581 -0
- package/dist/lib/syntax/color/hex.js +179 -0
- package/dist/lib/syntax/color/hsl.js +201 -0
- package/dist/lib/syntax/color/hwb.js +204 -0
- package/dist/lib/syntax/color/lab.js +262 -0
- package/dist/lib/syntax/color/lch.js +194 -0
- package/dist/lib/syntax/color/oklab.js +237 -0
- package/dist/lib/syntax/color/oklch.js +166 -0
- package/dist/lib/{renderer → syntax}/color/p3.js +3 -3
- package/dist/lib/{renderer → syntax}/color/rec2020.js +11 -11
- package/dist/lib/{renderer → syntax}/color/relativecolor.js +54 -41
- package/dist/lib/syntax/color/rgb.js +140 -0
- package/dist/lib/{renderer → syntax}/color/srgb.js +58 -46
- package/dist/lib/syntax/color/utils/components.js +46 -0
- package/dist/lib/{renderer → syntax}/color/utils/constants.js +6 -33
- package/dist/lib/syntax/color/utils/distance.js +40 -0
- package/dist/lib/{renderer → syntax}/color/xyz.js +27 -14
- package/dist/lib/{renderer → syntax}/color/xyzd50.js +8 -8
- package/dist/lib/syntax/syntax.js +78 -77
- package/dist/lib/syntax/utils.js +70 -0
- package/dist/lib/validation/at-rules/container.js +1 -1
- package/dist/lib/validation/at-rules/counter-style.js +1 -1
- package/dist/lib/validation/at-rules/custom-media.js +1 -1
- package/dist/lib/validation/at-rules/document.js +2 -2
- package/dist/lib/validation/at-rules/font-feature-values.js +2 -2
- package/dist/lib/validation/at-rules/import.js +5 -5
- package/dist/lib/validation/at-rules/keyframes.js +3 -13
- package/dist/lib/validation/at-rules/layer.js +1 -1
- package/dist/lib/validation/at-rules/media.js +1 -1
- package/dist/lib/validation/at-rules/namespace.js +1 -1
- package/dist/lib/validation/at-rules/page-margin-box.js +1 -1
- package/dist/lib/validation/at-rules/page.js +1 -1
- package/dist/lib/validation/at-rules/supports.js +7 -7
- package/dist/lib/validation/at-rules/when.js +1 -1
- package/dist/lib/validation/atrule.js +2 -2
- package/dist/lib/validation/config.js +0 -3
- package/dist/lib/validation/config.json.js +1 -1
- package/dist/lib/validation/parser/parse.js +8 -11
- package/dist/lib/validation/selector.js +1 -9
- package/dist/lib/validation/syntax.js +67 -137
- package/dist/lib/validation/syntaxes/complex-selector-list.js +2 -19
- package/dist/lib/validation/syntaxes/complex-selector.js +1 -1
- package/dist/lib/validation/syntaxes/compound-selector.js +5 -24
- package/dist/lib/validation/syntaxes/family-name.js +5 -40
- package/dist/lib/validation/syntaxes/keyframe-selector.js +3 -22
- package/dist/lib/validation/syntaxes/layer-name.js +1 -1
- package/dist/lib/validation/syntaxes/relative-selector-list.js +1 -25
- package/dist/lib/validation/syntaxes/relative-selector.js +1 -1
- package/dist/lib/validation/syntaxes/url.js +3 -34
- package/dist/lib/validation/utils/list.js +2 -9
- package/dist/lib/validation/utils/whitespace.js +1 -1
- package/dist/node/index.js +4 -2
- package/dist/web/index.js +4 -2
- package/package.json +4 -4
- package/.editorconfig +0 -484
- package/dist/lib/ast/transform/convert.js +0 -33
- package/dist/lib/ast/utils/utils.js +0 -104
- package/dist/lib/renderer/color/color.js +0 -654
- package/dist/lib/renderer/color/hex.js +0 -105
- package/dist/lib/renderer/color/hsl.js +0 -125
- package/dist/lib/renderer/color/hwb.js +0 -103
- package/dist/lib/renderer/color/lab.js +0 -148
- package/dist/lib/renderer/color/lch.js +0 -90
- package/dist/lib/renderer/color/oklab.js +0 -131
- package/dist/lib/renderer/color/oklch.js +0 -75
- package/dist/lib/renderer/color/rgb.js +0 -50
- package/dist/lib/renderer/color/utils/components.js +0 -34
- package/dist/lib/validation/syntaxes/keyframe-block-list.js +0 -28
- package/dist/lib/{renderer → syntax}/color/hsv.js +0 -0
- package/dist/lib/{renderer → syntax}/color/prophotorgb.js +1 -1
- /package/dist/lib/{renderer → syntax}/color/utils/matrix.js +0 -0
package/dist/lib/parser/parse.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '
|
|
3
|
-
import { EnumToken, ValidationLevel, SyntaxValidationResult } from '../ast/types.js';
|
|
1
|
+
import { isIdentStart, isIdent, isIdentColor, mathFuncs, isColor, parseColor, isPseudo, pseudoElements, isAtKeyword, isFunction, isNumber, isPercentage, isFlex, isDimension, parseDimension, isHexColor, isHash, mediaTypes } from '../syntax/syntax.js';
|
|
2
|
+
import { EnumToken, ColorType, ValidationLevel, SyntaxValidationResult } from '../ast/types.js';
|
|
4
3
|
import { minify, definedPropertySettings, combinators } from '../ast/minify.js';
|
|
5
4
|
import { walkValues, walk, WalkerOptionEnum } from '../ast/walk.js';
|
|
6
5
|
import { expand } from '../ast/expand.js';
|
|
6
|
+
import './utils/config.js';
|
|
7
7
|
import { parseDeclarationNode } from './utils/declaration.js';
|
|
8
8
|
import { renderToken } from '../renderer/render.js';
|
|
9
|
-
import { funcLike,
|
|
9
|
+
import { funcLike, timingFunc, timelineFunc, COLORS_NAMES, systemColors, deprecatedSystemColors, colorsFunc } from '../syntax/color/utils/constants.js';
|
|
10
10
|
import { buildExpression } from '../ast/math/expression.js';
|
|
11
11
|
import { tokenize } from './tokenize.js';
|
|
12
12
|
import '../validation/config.js';
|
|
@@ -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
|
}
|
|
@@ -234,7 +251,6 @@ async function doParse(iterator, options = {}) {
|
|
|
234
251
|
}
|
|
235
252
|
}
|
|
236
253
|
catch (error) {
|
|
237
|
-
// console.error(error);
|
|
238
254
|
// @ts-ignore
|
|
239
255
|
errors.push({ action: 'ignore', message: 'doParse: ' + error.message, error });
|
|
240
256
|
}
|
|
@@ -335,6 +351,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
335
351
|
errors.push({
|
|
336
352
|
action: 'drop',
|
|
337
353
|
message: `CDOCOMM not allowed here ${JSON.stringify(tokens[i], null, 1)}`,
|
|
354
|
+
node: tokens[i],
|
|
338
355
|
location
|
|
339
356
|
});
|
|
340
357
|
continue;
|
|
@@ -389,7 +406,8 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
389
406
|
if (!(type == EnumToken.InvalidAtRuleTokenType &&
|
|
390
407
|
// @ts-ignore
|
|
391
408
|
['charset', 'layer', 'import'].includes(context.chi[i].nam))) {
|
|
392
|
-
|
|
409
|
+
// @ts-ignore
|
|
410
|
+
errors.push({ action: 'drop', message: 'invalid @import', location, rawTokens: [atRule, ...tokens] });
|
|
393
411
|
return null;
|
|
394
412
|
}
|
|
395
413
|
}
|
|
@@ -465,7 +483,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
465
483
|
action: 'drop',
|
|
466
484
|
message: '@charset must have only one space',
|
|
467
485
|
// @ts-ignore
|
|
468
|
-
location
|
|
486
|
+
location, rawTokens: [atRule, ...tokens]
|
|
469
487
|
});
|
|
470
488
|
return null;
|
|
471
489
|
}
|
|
@@ -485,7 +503,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
485
503
|
}
|
|
486
504
|
const t = parseAtRulePrelude(parseTokens(tokens, { minify: options.minify }), atRule);
|
|
487
505
|
const raw = t.reduce((acc, curr) => {
|
|
488
|
-
acc.push(renderToken(curr, { removeComments: true }));
|
|
506
|
+
acc.push(renderToken(curr, { removeComments: true, convertColor: false }));
|
|
489
507
|
return acc;
|
|
490
508
|
}, []);
|
|
491
509
|
const nam = renderToken(atRule, { removeComments: true });
|
|
@@ -507,7 +525,6 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
507
525
|
node.loc = loc;
|
|
508
526
|
node.loc.end = { ...map.get(delim).end };
|
|
509
527
|
}
|
|
510
|
-
// if (options.validation) {
|
|
511
528
|
let isValid = true;
|
|
512
529
|
if (node.nam == 'else') {
|
|
513
530
|
const prev = getLastNode(context);
|
|
@@ -535,6 +552,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
535
552
|
errors.push({
|
|
536
553
|
action: 'drop',
|
|
537
554
|
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), '') + '"',
|
|
555
|
+
node,
|
|
538
556
|
// @ts-ignore
|
|
539
557
|
location: { src, ...(map.get(valid.node) ?? location) }
|
|
540
558
|
});
|
|
@@ -544,6 +562,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
544
562
|
else {
|
|
545
563
|
node.val = node.tokens.reduce((acc, curr) => acc + renderToken(curr, {
|
|
546
564
|
minify: false,
|
|
565
|
+
convertColor: false,
|
|
547
566
|
removeComments: true
|
|
548
567
|
}), '');
|
|
549
568
|
}
|
|
@@ -582,7 +601,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
582
601
|
if (curr.typ == EnumToken.IdenTokenType && curr.val == 'from') {
|
|
583
602
|
Object.assign(curr, { typ: EnumToken.PercentageTokenType, val: '0' });
|
|
584
603
|
}
|
|
585
|
-
else if (curr.typ == EnumToken.PercentageTokenType && curr.val ==
|
|
604
|
+
else if (curr.typ == EnumToken.PercentageTokenType && curr.val == 100) {
|
|
586
605
|
Object.assign(curr, { typ: EnumToken.IdenTokenType, val: 'to' });
|
|
587
606
|
}
|
|
588
607
|
}
|
|
@@ -635,6 +654,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
635
654
|
errors.push({
|
|
636
655
|
action: 'drop',
|
|
637
656
|
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), '') + '"',
|
|
657
|
+
node,
|
|
638
658
|
// @ts-ignore
|
|
639
659
|
location
|
|
640
660
|
});
|
|
@@ -659,7 +679,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
659
679
|
val: tokens[i].val.charAt(0)
|
|
660
680
|
}, {
|
|
661
681
|
typ: EnumToken.NumberTokenType,
|
|
662
|
-
val: tokens[i].val.slice(1)
|
|
682
|
+
val: +tokens[i].val.slice(1)
|
|
663
683
|
});
|
|
664
684
|
}
|
|
665
685
|
else if (start == '/' && isFunction(val)) {
|
|
@@ -675,7 +695,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
675
695
|
if (name == null && [EnumToken.IdenTokenType, EnumToken.DashedIdenTokenType].includes(tokens[i].typ)) {
|
|
676
696
|
name = tokens.slice(0, i + 1);
|
|
677
697
|
}
|
|
678
|
-
else if (name == null && tokens[i].typ == EnumToken.ColorTokenType && [
|
|
698
|
+
else if (name == null && tokens[i].typ == EnumToken.ColorTokenType && [ColorType.SYS, ColorType.DPSYS].includes(tokens[i].kin)) {
|
|
679
699
|
name = tokens.slice(0, i + 1);
|
|
680
700
|
tokens[i].typ = EnumToken.IdenTokenType;
|
|
681
701
|
}
|
|
@@ -784,12 +804,11 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
784
804
|
value: valid.valid == SyntaxValidationResult.Valid
|
|
785
805
|
});
|
|
786
806
|
if (valid.valid == SyntaxValidationResult.Drop) {
|
|
787
|
-
// console.error({result, valid});
|
|
788
|
-
// console.error(JSON.stringify({result, options, valid}, null, 1));
|
|
789
807
|
errors.push({
|
|
790
808
|
action: 'drop',
|
|
791
809
|
message: valid.error,
|
|
792
810
|
syntax: valid.syntax,
|
|
811
|
+
node: valid.node,
|
|
793
812
|
location: map.get(valid.node) ?? valid.node?.loc ?? result.loc ?? location
|
|
794
813
|
});
|
|
795
814
|
if (!options.lenient) {
|
|
@@ -861,9 +880,10 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
861
880
|
}
|
|
862
881
|
}
|
|
863
882
|
}
|
|
883
|
+
const val = value.typ == EnumToken.IdenTokenType ? value.val.toLowerCase() : null;
|
|
864
884
|
if (value.typ == EnumToken.IdenTokenType) {
|
|
865
885
|
if (parent == null && mediaTypes.some((t) => {
|
|
866
|
-
if (
|
|
886
|
+
if (val === t) {
|
|
867
887
|
// @ts-ignore
|
|
868
888
|
value.typ = EnumToken.MediaFeatureTokenType;
|
|
869
889
|
return true;
|
|
@@ -872,18 +892,18 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
872
892
|
})) {
|
|
873
893
|
continue;
|
|
874
894
|
}
|
|
875
|
-
if (value.typ == EnumToken.IdenTokenType && 'and'
|
|
895
|
+
if (value.typ == EnumToken.IdenTokenType && 'and' === val) {
|
|
876
896
|
// @ts-ignore
|
|
877
897
|
value.typ = EnumToken.MediaFeatureAndTokenType;
|
|
878
898
|
continue;
|
|
879
899
|
}
|
|
880
|
-
if (value.typ == EnumToken.IdenTokenType && 'or'
|
|
900
|
+
if (value.typ == EnumToken.IdenTokenType && 'or' === val) {
|
|
881
901
|
// @ts-ignore
|
|
882
902
|
value.typ = EnumToken.MediaFeatureOrTokenType;
|
|
883
903
|
continue;
|
|
884
904
|
}
|
|
885
905
|
if (value.typ == EnumToken.IdenTokenType &&
|
|
886
|
-
['not', 'only'].some((t) =>
|
|
906
|
+
['not', 'only'].some((t) => val === t)) {
|
|
887
907
|
// @ts-ignore
|
|
888
908
|
const array = parent?.chi ?? tokens;
|
|
889
909
|
const startIndex = array.indexOf(value);
|
|
@@ -950,10 +970,7 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
950
970
|
break;
|
|
951
971
|
}
|
|
952
972
|
if (valueIndex == -1) {
|
|
953
|
-
// @ts-ignore
|
|
954
|
-
// value.chi[nameIndex].typ = EnumToken.MediaFeatureTokenType;
|
|
955
973
|
continue;
|
|
956
|
-
// return tokens;
|
|
957
974
|
}
|
|
958
975
|
for (i = nameIndex + 1; i < value.chi.length; i++) {
|
|
959
976
|
if ([
|
|
@@ -965,7 +982,7 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
965
982
|
const node = value.chi.splice(nameIndex, 1)[0];
|
|
966
983
|
// 'background'
|
|
967
984
|
// @ts-ignore
|
|
968
|
-
if (node.typ == EnumToken.ColorTokenType && node.kin ==
|
|
985
|
+
if (node.typ == EnumToken.ColorTokenType && node.kin == ColorType.DPSYS) {
|
|
969
986
|
// @ts-ignore
|
|
970
987
|
delete node.kin;
|
|
971
988
|
node.typ = EnumToken.IdenTokenType;
|
|
@@ -992,7 +1009,7 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
992
1009
|
* @param tokens
|
|
993
1010
|
*/
|
|
994
1011
|
function parseSelector(tokens) {
|
|
995
|
-
for (const { value,
|
|
1012
|
+
for (const { value, parent } of walkValues(tokens)) {
|
|
996
1013
|
if (value.typ == EnumToken.CommentTokenType ||
|
|
997
1014
|
value.typ == EnumToken.WhitespaceTokenType ||
|
|
998
1015
|
value.typ == EnumToken.CommaTokenType ||
|
|
@@ -1005,43 +1022,6 @@ function parseSelector(tokens) {
|
|
|
1005
1022
|
// @ts-ignore
|
|
1006
1023
|
value.typ = EnumToken.ChildCombinatorTokenType;
|
|
1007
1024
|
}
|
|
1008
|
-
// @ts-ignore
|
|
1009
|
-
else if (value.typ == EnumToken.WhitespaceTokenType) {
|
|
1010
|
-
if (nextValue != null && nextValue.typ == EnumToken.LiteralTokenType) {
|
|
1011
|
-
if (['>', '+', '~'].includes(nextValue.val)) {
|
|
1012
|
-
switch (value.val) {
|
|
1013
|
-
case '>':
|
|
1014
|
-
// @ts-ignore
|
|
1015
|
-
nextValue.typ = EnumToken.ChildCombinatorTokenType;
|
|
1016
|
-
break;
|
|
1017
|
-
case '+':
|
|
1018
|
-
// @ts-ignore
|
|
1019
|
-
nextValue.typ = EnumToken.NextSiblingCombinatorTokenType;
|
|
1020
|
-
break;
|
|
1021
|
-
case '~':
|
|
1022
|
-
// @ts-ignore
|
|
1023
|
-
nextValue.typ = EnumToken.SubsequentSiblingCombinatorTokenType;
|
|
1024
|
-
break;
|
|
1025
|
-
}
|
|
1026
|
-
// @ts-ignore
|
|
1027
|
-
delete nextValue.val;
|
|
1028
|
-
continue;
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
if (previousValue != null && [
|
|
1032
|
-
EnumToken.ChildCombinatorTokenType,
|
|
1033
|
-
EnumToken.DescendantCombinatorTokenType,
|
|
1034
|
-
EnumToken.NextSiblingCombinatorTokenType,
|
|
1035
|
-
EnumToken.SubsequentSiblingCombinatorTokenType,
|
|
1036
|
-
EnumToken.ColumnCombinatorTokenType,
|
|
1037
|
-
EnumToken.NameSpaceAttributeTokenType,
|
|
1038
|
-
EnumToken.CommaTokenType
|
|
1039
|
-
].includes(previousValue.typ)) {
|
|
1040
|
-
continue;
|
|
1041
|
-
}
|
|
1042
|
-
// @ts-ignore
|
|
1043
|
-
value.typ = EnumToken.DescendantCombinatorTokenType;
|
|
1044
|
-
}
|
|
1045
1025
|
else if (value.typ == EnumToken.LiteralTokenType) {
|
|
1046
1026
|
if (value.val.charAt(0) == '&') {
|
|
1047
1027
|
// @ts-ignore
|
|
@@ -1059,12 +1039,7 @@ function parseSelector(tokens) {
|
|
|
1059
1039
|
value.typ = EnumToken.ClassSelectorTokenType;
|
|
1060
1040
|
}
|
|
1061
1041
|
}
|
|
1062
|
-
|
|
1063
|
-
if (value.typ == EnumToken.DelimTokenType) {
|
|
1064
|
-
// @ts-ignore
|
|
1065
|
-
value.typ = EnumToken.NextSiblingCombinatorTokenType;
|
|
1066
|
-
}
|
|
1067
|
-
else if (['*', '>', '+', '~'].includes(value.val)) {
|
|
1042
|
+
if (['*', '>', '+', '~'].includes(value.val)) {
|
|
1068
1043
|
switch (value.val) {
|
|
1069
1044
|
case '*':
|
|
1070
1045
|
// @ts-ignore
|
|
@@ -1084,13 +1059,12 @@ function parseSelector(tokens) {
|
|
|
1084
1059
|
break;
|
|
1085
1060
|
}
|
|
1086
1061
|
// @ts-ignore
|
|
1087
|
-
// @ts-ignore
|
|
1088
1062
|
delete value.val;
|
|
1089
1063
|
}
|
|
1090
1064
|
}
|
|
1091
1065
|
else if (value.typ == EnumToken.ColorTokenType) {
|
|
1092
|
-
if (value.kin ==
|
|
1093
|
-
if (value.kin ==
|
|
1066
|
+
if (value.kin == ColorType.LIT || value.kin == ColorType.HEX || value.kin == ColorType.SYS || value.kin == ColorType.DPSYS) {
|
|
1067
|
+
if (value.kin == ColorType.HEX) {
|
|
1094
1068
|
if (!isIdent(value.val.slice(1))) {
|
|
1095
1069
|
continue;
|
|
1096
1070
|
}
|
|
@@ -1130,10 +1104,6 @@ function parseSelector(tokens) {
|
|
|
1130
1104
|
}
|
|
1131
1105
|
return tokens;
|
|
1132
1106
|
}
|
|
1133
|
-
// export async function parseDeclarations(src: string, options: ParserOptions = {}): Promise<AstDeclaration[]> {
|
|
1134
|
-
//
|
|
1135
|
-
// return doParse(`.x{${src}`, options).then((result: ParseResult) => <AstDeclaration[]>(<AstRule>result.ast.chi[0]).chi.filter(t => t.typ == EnumToken.DeclarationNodeType));
|
|
1136
|
-
// }
|
|
1137
1107
|
/**
|
|
1138
1108
|
* parse css string
|
|
1139
1109
|
* @param src
|
|
@@ -1223,14 +1193,14 @@ function getTokenType(val, hint) {
|
|
|
1223
1193
|
chi: []
|
|
1224
1194
|
};
|
|
1225
1195
|
}
|
|
1226
|
-
if (
|
|
1196
|
+
if (timingFunc.includes(val.toLowerCase())) {
|
|
1227
1197
|
return {
|
|
1228
1198
|
typ: EnumToken.TimingFunctionTokenType,
|
|
1229
1199
|
val,
|
|
1230
1200
|
chi: []
|
|
1231
1201
|
};
|
|
1232
1202
|
}
|
|
1233
|
-
if (
|
|
1203
|
+
if (timelineFunc.includes(val)) {
|
|
1234
1204
|
return {
|
|
1235
1205
|
typ: EnumToken.TimelineFunctionTokenType,
|
|
1236
1206
|
val,
|
|
@@ -1246,19 +1216,19 @@ function getTokenType(val, hint) {
|
|
|
1246
1216
|
if (isNumber(val)) {
|
|
1247
1217
|
return {
|
|
1248
1218
|
typ: EnumToken.NumberTokenType,
|
|
1249
|
-
val
|
|
1219
|
+
val: +val
|
|
1250
1220
|
};
|
|
1251
1221
|
}
|
|
1252
1222
|
if (isPercentage(val)) {
|
|
1253
1223
|
return {
|
|
1254
1224
|
typ: EnumToken.PercentageTokenType,
|
|
1255
|
-
val: val.slice(0, -1)
|
|
1225
|
+
val: +val.slice(0, -1)
|
|
1256
1226
|
};
|
|
1257
1227
|
}
|
|
1258
1228
|
if (isFlex(val)) {
|
|
1259
1229
|
return {
|
|
1260
1230
|
typ: EnumToken.FlexTokenType,
|
|
1261
|
-
val: val.slice(0, -2)
|
|
1231
|
+
val: +val.slice(0, -2)
|
|
1262
1232
|
};
|
|
1263
1233
|
}
|
|
1264
1234
|
if (isDimension(val)) {
|
|
@@ -1269,7 +1239,7 @@ function getTokenType(val, hint) {
|
|
|
1269
1239
|
return {
|
|
1270
1240
|
typ: EnumToken.ColorTokenType,
|
|
1271
1241
|
val: v,
|
|
1272
|
-
kin:
|
|
1242
|
+
kin: ColorType.LIT
|
|
1273
1243
|
};
|
|
1274
1244
|
}
|
|
1275
1245
|
if (isIdent(val)) {
|
|
@@ -1277,14 +1247,14 @@ function getTokenType(val, hint) {
|
|
|
1277
1247
|
return {
|
|
1278
1248
|
typ: EnumToken.ColorTokenType,
|
|
1279
1249
|
val,
|
|
1280
|
-
kin:
|
|
1250
|
+
kin: ColorType.SYS
|
|
1281
1251
|
};
|
|
1282
1252
|
}
|
|
1283
1253
|
if (deprecatedSystemColors.has(v)) {
|
|
1284
1254
|
return {
|
|
1285
1255
|
typ: EnumToken.ColorTokenType,
|
|
1286
1256
|
val,
|
|
1287
|
-
kin:
|
|
1257
|
+
kin: ColorType.DPSYS
|
|
1288
1258
|
};
|
|
1289
1259
|
}
|
|
1290
1260
|
return {
|
|
@@ -1296,7 +1266,7 @@ function getTokenType(val, hint) {
|
|
|
1296
1266
|
return {
|
|
1297
1267
|
typ: EnumToken.ColorTokenType,
|
|
1298
1268
|
val,
|
|
1299
|
-
kin:
|
|
1269
|
+
kin: ColorType.HEX
|
|
1300
1270
|
};
|
|
1301
1271
|
}
|
|
1302
1272
|
if (val.charAt(0) == '#' && isHash(val)) {
|
|
@@ -1373,7 +1343,6 @@ function parseTokens(tokens, options = {}) {
|
|
|
1373
1343
|
}
|
|
1374
1344
|
// @ts-ignore
|
|
1375
1345
|
if (attr.chi.length > 1) {
|
|
1376
|
-
/*(<AttrToken>t).chi =*/
|
|
1377
1346
|
// @ts-ignore
|
|
1378
1347
|
parseTokens(attr.chi, t.typ);
|
|
1379
1348
|
}
|
|
@@ -1593,7 +1562,6 @@ function parseTokens(tokens, options = {}) {
|
|
|
1593
1562
|
// @ts-ignore
|
|
1594
1563
|
if (t.chi.length > 0) {
|
|
1595
1564
|
if (t.typ == EnumToken.PseudoClassFuncTokenType && t.val == ':is' && options.minify) {
|
|
1596
|
-
//
|
|
1597
1565
|
const count = t.chi.filter((t) => t.typ != EnumToken.CommentTokenType).length;
|
|
1598
1566
|
if (count == 1 ||
|
|
1599
1567
|
(i == 0 &&
|
|
@@ -1604,28 +1572,6 @@ function parseTokens(tokens, options = {}) {
|
|
|
1604
1572
|
}
|
|
1605
1573
|
}
|
|
1606
1574
|
}
|
|
1607
|
-
continue;
|
|
1608
|
-
}
|
|
1609
|
-
if (options.parseColor) {
|
|
1610
|
-
if (t.typ == EnumToken.IdenTokenType) {
|
|
1611
|
-
// named color
|
|
1612
|
-
const value = t.val.toLowerCase();
|
|
1613
|
-
if (value in COLORS_NAMES) {
|
|
1614
|
-
Object.assign(t, {
|
|
1615
|
-
typ: EnumToken.ColorTokenType,
|
|
1616
|
-
val: COLORS_NAMES[value].length < value.length ? COLORS_NAMES[value] : value,
|
|
1617
|
-
kin: ColorKind.HEX
|
|
1618
|
-
});
|
|
1619
|
-
}
|
|
1620
|
-
continue;
|
|
1621
|
-
}
|
|
1622
|
-
if (t.typ == EnumToken.HashTokenType && isHexColor(t.val)) {
|
|
1623
|
-
// hex color
|
|
1624
|
-
// @ts-ignore
|
|
1625
|
-
t.typ = EnumToken.ColorTokenType;
|
|
1626
|
-
// @ts-ignore
|
|
1627
|
-
t.kin = ColorKind.HEX;
|
|
1628
|
-
}
|
|
1629
1575
|
}
|
|
1630
1576
|
}
|
|
1631
1577
|
return tokens;
|
|
@@ -3,8 +3,8 @@ 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
|
|
7
|
-
import '../
|
|
6
|
+
import { isWhiteSpace, isIdentStart, isIdent, isNewLine, isDigit } from '../syntax/syntax.js';
|
|
7
|
+
import '../syntax/color/utils/constants.js';
|
|
8
8
|
import '../renderer/sourcemap/lib/encode.js';
|
|
9
9
|
|
|
10
10
|
var TokenMap;
|
|
@@ -92,11 +92,6 @@ function* consumeString(quoteStr, buffer, parseInfo) {
|
|
|
92
92
|
}
|
|
93
93
|
break;
|
|
94
94
|
}
|
|
95
|
-
if (i == 1) {
|
|
96
|
-
buffer += value + sequence[i];
|
|
97
|
-
next(parseInfo, 2);
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
95
|
if (escapeSequence.trimEnd().length > 0) {
|
|
101
96
|
const codepoint = parseInt(escapeSequence, 16);
|
|
102
97
|
if (codepoint == 0 ||
|
|
@@ -119,7 +114,6 @@ function* consumeString(quoteStr, buffer, parseInfo) {
|
|
|
119
114
|
buffer += value;
|
|
120
115
|
yield pushToken(buffer, parseInfo, hasNewLine ? EnumToken.BadStringTokenType : EnumToken.StringTokenType);
|
|
121
116
|
next(parseInfo);
|
|
122
|
-
// i += value.length;
|
|
123
117
|
buffer = '';
|
|
124
118
|
return;
|
|
125
119
|
}
|
|
@@ -161,15 +155,9 @@ function prev(parseInfo, count = 1) {
|
|
|
161
155
|
function next(parseInfo, count = 1) {
|
|
162
156
|
let char = '';
|
|
163
157
|
let chr = '';
|
|
164
|
-
if (count < 0) {
|
|
165
|
-
return '';
|
|
166
|
-
}
|
|
167
158
|
while (count-- && (chr = parseInfo.stream.charAt(parseInfo.currentPosition.ind + 1))) {
|
|
168
159
|
char += chr;
|
|
169
160
|
const codepoint = parseInfo.stream.charCodeAt(++parseInfo.currentPosition.ind);
|
|
170
|
-
if (isNaN(codepoint)) {
|
|
171
|
-
return char;
|
|
172
|
-
}
|
|
173
161
|
if (isNewLine(codepoint)) {
|
|
174
162
|
parseInfo.currentPosition.lin++;
|
|
175
163
|
parseInfo.currentPosition.col = 0;
|
|
@@ -436,8 +424,6 @@ function* tokenize(stream) {
|
|
|
436
424
|
value = peek(parseInfo);
|
|
437
425
|
// let cp: number;
|
|
438
426
|
let whitespace = '';
|
|
439
|
-
let hasWhiteSpace = false;
|
|
440
|
-
let errorState = false;
|
|
441
427
|
if (value == '"' || value == "'") {
|
|
442
428
|
const quote = value;
|
|
443
429
|
let inquote = true;
|
|
@@ -477,7 +463,6 @@ function* tokenize(stream) {
|
|
|
477
463
|
if (isWhiteSpace(charCode)) {
|
|
478
464
|
whitespace += value;
|
|
479
465
|
while (value = peek(parseInfo)) {
|
|
480
|
-
hasWhiteSpace = true;
|
|
481
466
|
if (isWhiteSpace(value?.charCodeAt(0))) {
|
|
482
467
|
whitespace += next(parseInfo);
|
|
483
468
|
continue;
|
|
@@ -533,42 +518,33 @@ function* tokenize(stream) {
|
|
|
533
518
|
buffer = '';
|
|
534
519
|
break;
|
|
535
520
|
}
|
|
536
|
-
if (
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
if (
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
if (charCode == 0x29) {
|
|
564
|
-
break;
|
|
565
|
-
}
|
|
566
|
-
buffer += next(parseInfo);
|
|
567
|
-
}
|
|
568
|
-
yield pushToken(buffer, parseInfo, EnumToken.BadUrlTokenType);
|
|
569
|
-
buffer = '';
|
|
570
|
-
break;
|
|
571
|
-
}
|
|
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
|
+
// }
|
|
572
548
|
buffer += value;
|
|
573
549
|
}
|
|
574
550
|
}
|
|
@@ -5,7 +5,7 @@ import '../parse.js';
|
|
|
5
5
|
import '../tokenize.js';
|
|
6
6
|
import './config.js';
|
|
7
7
|
import { isWhiteSpace } from '../../syntax/syntax.js';
|
|
8
|
-
import '../../
|
|
8
|
+
import '../../syntax/color/utils/constants.js';
|
|
9
9
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
10
10
|
|
|
11
11
|
function parseDeclarationNode(node, errors, location) {
|
|
@@ -5,7 +5,7 @@ import '../parse.js';
|
|
|
5
5
|
import '../tokenize.js';
|
|
6
6
|
import './config.js';
|
|
7
7
|
import { mathFuncs } from '../../syntax/syntax.js';
|
|
8
|
-
import '../../
|
|
8
|
+
import '../../syntax/color/utils/constants.js';
|
|
9
9
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
10
10
|
|
|
11
11
|
function matchType(val, properties) {
|
|
@@ -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
|