@tbela99/css-parser 2.1.0 → 2.2.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 +42 -1
- package/README.md +14 -7
- package/architecture.png +0 -0
- package/dist/{src/data → data}/properties.json.js +86 -2
- package/dist/{src/data → data}/validation.json.js +5 -2
- package/dist/index-umd-web.js +10738 -4359
- package/dist/index.d.ts +734 -100
- package/dist/{src/lib → lib}/ast/arena-node.js +10 -10
- package/dist/{src/lib → lib}/ast/arena.js +304 -139
- package/dist/{src/lib → lib}/ast/cache.js +2 -2
- package/dist/{src/lib → lib}/ast/features/calc.js +11 -9
- package/dist/{src/lib → lib}/ast/features/if.js +6 -6
- package/dist/{src/lib → lib}/ast/features/index.js +3 -2
- package/dist/{src/lib → lib}/ast/features/inlinecssvariables.js +12 -10
- package/dist/lib/ast/features/mixin.js +953 -0
- package/dist/{src/lib → lib}/ast/features/prefix.js +39 -39
- package/dist/lib/ast/features/shorthand.js +129 -0
- package/dist/lib/ast/features/transform.js +188 -0
- package/dist/{src/lib → lib}/ast/features/type.js +2 -2
- package/dist/{src/lib → lib}/ast/math/expression.js +24 -24
- package/dist/{src/lib → lib}/ast/math/math.js +2 -2
- package/dist/{src/lib → lib}/ast/minify.js +745 -201
- package/dist/lib/ast/mixins/custom-function.js +393 -0
- package/dist/lib/ast/mixins/utils.js +53 -0
- package/dist/lib/ast/mixins/variables.js +678 -0
- package/dist/lib/ast/strings.js +906 -0
- package/dist/lib/ast/transform/compute.js +560 -0
- package/dist/lib/ast/transform/matrix.js +67 -0
- package/dist/lib/ast/transform/minify.js +325 -0
- package/dist/lib/ast/transform/perspective.js +24 -0
- package/dist/{src/lib → lib}/ast/transform/rotate.js +16 -7
- package/dist/lib/ast/transform/scale.js +43 -0
- package/dist/lib/ast/transform/skew.js +38 -0
- package/dist/lib/ast/transform/translate.js +56 -0
- package/dist/lib/ast/transform/utils.js +390 -0
- package/dist/{src/lib → lib}/ast/types.js +2 -2
- package/dist/{src/lib → lib}/ast/walk.js +2 -2
- package/dist/{src/lib → lib}/fs/resolve.js +2 -2
- package/dist/{src/lib → lib}/parser/declaration/list.js +25 -8
- package/dist/{src/lib → lib}/parser/declaration/map.js +15 -15
- package/dist/{src/lib → lib}/parser/declaration/set.js +5 -5
- package/dist/{src/lib → lib}/parser/input.js +18 -3
- package/dist/{src/lib → lib}/parser/linesmap.js +2 -2
- package/dist/{src/lib → lib}/parser/parse.js +425 -258
- package/dist/{src/lib → lib}/parser/source.js +2 -2
- package/dist/{src/lib → lib}/parser/tokenize.js +480 -312
- package/dist/{src/lib → lib}/parser/utils/angle.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-container.js +12 -12
- package/dist/{src/lib → lib}/parser/utils/at-rule-font-feature-values.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-generic.js +7 -7
- package/dist/{src/lib → lib}/parser/utils/at-rule-import.js +10 -10
- package/dist/{src/lib → lib}/parser/utils/at-rule-media.js +14 -14
- package/dist/{src/lib → lib}/parser/utils/at-rule-support.js +9 -14
- package/dist/{src/lib → lib}/parser/utils/at-rule-when-else.js +6 -6
- package/dist/{src/lib → lib}/parser/utils/at-rule.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/base64.js +2 -2
- package/dist/lib/parser/utils/cache.js +53 -0
- package/dist/lib/parser/utils/canonical.js +78 -0
- package/dist/lib/parser/utils/codes.js +93 -0
- package/dist/{src/lib → lib}/parser/utils/config.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/declaration.js +31 -26
- package/dist/{src/lib → lib}/parser/utils/eq.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/hash.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/selector.js +305 -63
- package/dist/{src/lib → lib}/parser/utils/text.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/token.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/type.js +9 -7
- package/dist/{src/lib → lib}/printer/render.js +420 -152
- package/dist/lib/printer/result.js +148 -0
- package/dist/{src/lib → lib}/printer/sourcemap/lib/codec.js +2 -2
- package/dist/{src/lib → lib}/printer/sourcemap/sourcemap.js +2 -2
- package/dist/lib/printer/writer.js +252 -0
- package/dist/{src/lib → lib}/syntax/color/a98rgb.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/alpha.js +10 -10
- package/dist/{src/lib → lib}/syntax/color/cmyk.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/color-mix.js +18 -18
- package/dist/{src/lib → lib}/syntax/color/color.js +18 -18
- package/dist/{src/lib → lib}/syntax/color/hex.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/hsl.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/hwb.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/lab.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/lch.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/oklab.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/oklch.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/p3.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/prophotorgb.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/rec2020.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/relative-color.js +14 -14
- package/dist/{src/lib → lib}/syntax/color/rgb.js +4 -4
- package/dist/{src/lib → lib}/syntax/color/srgb.js +5 -5
- package/dist/{src/lib → lib}/syntax/color/utils/color-type.js +4 -4
- package/dist/{src/lib → lib}/syntax/color/utils/colorspace.js +10 -10
- package/dist/{src/lib → lib}/syntax/color/utils/components.js +5 -5
- package/dist/{src/lib → lib}/syntax/color/utils/distance.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/utils/make-color.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/utils/matrix.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/xyz.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/xyzd50.js +2 -2
- package/dist/{src/lib → lib}/syntax/constants.js +26 -3
- package/dist/{src/lib → lib}/syntax/syntax.js +37 -29
- package/dist/{src/lib → lib}/validation/config.js +23 -10
- package/dist/lib/validation/first.js +571 -0
- package/dist/{src/lib → lib}/validation/match.js +292 -150
- package/dist/{src/lib → lib}/validation/parser/parse.js +2 -2
- package/dist/{src/lib → lib}/validation/parser/typedef.js +2 -2
- package/dist/{src/lib → lib}/validation/utils/list.js +3 -19
- package/dist/{src/node.js → node.js} +52 -34
- package/dist/{src/types.js → types.js} +2 -2
- package/dist/{src/utils → utils}/sync.js +10 -5
- package/dist/version.d.ts +4 -0
- package/dist/version.js +13 -0
- package/dist/{src/web.js → web.js} +47 -34
- package/package.json +12 -12
- package/dist/package.json.js +0 -10
- package/dist/src/lib/ast/features/shorthand.js +0 -95
- package/dist/src/lib/ast/features/transform.js +0 -90
- package/dist/src/lib/ast/transform/compute.js +0 -362
- package/dist/src/lib/ast/transform/matrix.js +0 -88
- package/dist/src/lib/ast/transform/minify.js +0 -267
- package/dist/src/lib/ast/transform/perspective.js +0 -16
- package/dist/src/lib/ast/transform/scale.js +0 -39
- package/dist/src/lib/ast/transform/skew.js +0 -30
- package/dist/src/lib/ast/transform/translate.js +0 -39
- package/dist/src/lib/ast/transform/utils.js +0 -287
- package/dist/src/lib/parser/utils/cache.js +0 -54
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { TokenField } from '../ast/arena.js';
|
|
@@ -568,7 +568,7 @@ function isFlexUnit(unit) {
|
|
|
568
568
|
return flexUnitSet.has(unit.toLowerCase());
|
|
569
569
|
}
|
|
570
570
|
function isLength(arena, dimension) {
|
|
571
|
-
return arena.unit[dimension] !== 0 && isLengthUnit(arena.
|
|
571
|
+
return arena.unit[dimension] !== 0 && isLengthUnit(arena.resolveString(arena.unit[dimension]));
|
|
572
572
|
}
|
|
573
573
|
/**
|
|
574
574
|
* Reduce color stops
|
|
@@ -754,7 +754,7 @@ function reduceConicColorStops(arena, stops) {
|
|
|
754
754
|
*/
|
|
755
755
|
function isRectangularOrthogonalColorspace(arena, token) {
|
|
756
756
|
return (arena.dataTypes[token] === EnumToken.IdenTokenType &&
|
|
757
|
-
colorFuncColorSpace.some((t) => equalsIgnoreCase(t, arena.
|
|
757
|
+
colorFuncColorSpace.some((t) => equalsIgnoreCase(t, arena.resolveString(arena.stringValue[token]))));
|
|
758
758
|
}
|
|
759
759
|
/**
|
|
760
760
|
* Is polar colorspace
|
|
@@ -764,7 +764,7 @@ function isRectangularOrthogonalColorspace(arena, token) {
|
|
|
764
764
|
*/
|
|
765
765
|
function isPolarColorspace(arena, token) {
|
|
766
766
|
return (arena.dataTypes[token] === EnumToken.IdenTokenType &&
|
|
767
|
-
["hsl", "hwb", "lch", "oklch"].some((t) => equalsIgnoreCase(t, arena.
|
|
767
|
+
["hsl", "hwb", "lch", "oklch"].some((t) => equalsIgnoreCase(t, arena.resolveString(arena.stringValue[token]))));
|
|
768
768
|
}
|
|
769
769
|
/**
|
|
770
770
|
* Is ident color
|
|
@@ -776,7 +776,19 @@ function isIdentColor(arena, token) {
|
|
|
776
776
|
return (arena.dataTypes[token] === EnumToken.ColorTokenType &&
|
|
777
777
|
arena.colorType[token] !== ColorType.NONE &&
|
|
778
778
|
[ColorType.SYS, ColorType.DPSYS, ColorType.LIT].includes(arena.colorType[token]) &&
|
|
779
|
-
isIdent(arena.
|
|
779
|
+
isIdent(arena.resolveString(arena.stringValue[token])));
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* true if the identifier is a color: a system color, a named color, `currentcolor` or `transparent`, ignoring the case
|
|
783
|
+
* @param str
|
|
784
|
+
*/
|
|
785
|
+
function isColorName(str) {
|
|
786
|
+
const val = lowercase(str);
|
|
787
|
+
if (systemColors.has(val) || deprecatedSystemColors.has(val) || nonStandardColors.has(val)) {
|
|
788
|
+
return true;
|
|
789
|
+
}
|
|
790
|
+
// named color
|
|
791
|
+
return val in COLORS_NAMES || "currentcolor" === val || "transparent" === val;
|
|
780
792
|
}
|
|
781
793
|
/**
|
|
782
794
|
* color function arguments without whitespace and comments
|
|
@@ -815,16 +827,12 @@ function isColor(arena, token, errors) {
|
|
|
815
827
|
}
|
|
816
828
|
}
|
|
817
829
|
if (typ === EnumToken.IdenTokenType) {
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
return true;
|
|
821
|
-
}
|
|
822
|
-
// named color
|
|
823
|
-
return val in COLORS_NAMES || "currentcolor" === val || "transparent" === val;
|
|
830
|
+
// computed once per string id
|
|
831
|
+
return arena.stringFlag(arena.stringValue[token], 0 /* StringFlag.Color */, isColorName);
|
|
824
832
|
}
|
|
825
833
|
if (typ === EnumToken.FunctionTokenType || typ === EnumToken.ColorTokenType) {
|
|
826
834
|
if (arena.firstToken[token] !== 0) {
|
|
827
|
-
const name = arena.
|
|
835
|
+
const name = arena.resolveString(arena.stringValue[token]);
|
|
828
836
|
if (name === "light-dark") {
|
|
829
837
|
const children = filterChildren(arena, token, [
|
|
830
838
|
EnumToken.IdenTokenType,
|
|
@@ -855,7 +863,7 @@ function isColor(arena, token, errors) {
|
|
|
855
863
|
if (colorSpace != null) {
|
|
856
864
|
for (const value of components) {
|
|
857
865
|
if (arena.dataTypes[value] === EnumToken.IdenTokenType) {
|
|
858
|
-
const val = arena.
|
|
866
|
+
const val = arena.resolveString(arena.stringValue[value]).toLowerCase();
|
|
859
867
|
if (
|
|
860
868
|
// @ts-expect-error
|
|
861
869
|
typeof Math[val.toUpperCase()] !== "number" &&
|
|
@@ -872,12 +880,12 @@ function isColor(arena, token, errors) {
|
|
|
872
880
|
}
|
|
873
881
|
}
|
|
874
882
|
else if (arena.dataTypes[value] === EnumToken.MathFunctionTokenType &&
|
|
875
|
-
equalsIgnoreCase("calc", arena.
|
|
883
|
+
equalsIgnoreCase("calc", arena.resolveString(arena.stringValue[value]))) {
|
|
876
884
|
let val;
|
|
877
885
|
// inlined: arena.walkValues(arena.tokens(value))
|
|
878
886
|
for (const v of new ValueWalker(arena, arena.tokens(value))) {
|
|
879
887
|
if (arena.dataTypes[v] === EnumToken.IdenTokenType) {
|
|
880
|
-
val = arena.
|
|
888
|
+
val = arena.resolveString(arena.stringValue[v]).toLowerCase();
|
|
881
889
|
if (
|
|
882
890
|
// @ts-expect-error
|
|
883
891
|
typeof Math[val.toUpperCase()] !== "number" &&
|
|
@@ -915,7 +923,7 @@ function isColor(arena, token, errors) {
|
|
|
915
923
|
else if (parent != null &&
|
|
916
924
|
parent !== token &&
|
|
917
925
|
arena.dataTypes[parent] === EnumToken.MathFunctionTokenType &&
|
|
918
|
-
arena.
|
|
926
|
+
arena.resolveString(arena.stringValue[parent]) === "calc") {
|
|
919
927
|
const children = arena.tokens(parent);
|
|
920
928
|
l = k + 1;
|
|
921
929
|
while (l + 1 < children.length) {
|
|
@@ -959,7 +967,7 @@ function isColor(arena, token, errors) {
|
|
|
959
967
|
EnumToken.PercentageTokenType,
|
|
960
968
|
]);
|
|
961
969
|
const isRelative = arena.dataTypes[children[0]] === EnumToken.IdenTokenType &&
|
|
962
|
-
arena.
|
|
970
|
+
arena.resolveString(arena.stringValue[children[0]]) === "from";
|
|
963
971
|
let offset = 0;
|
|
964
972
|
if (isRelative) {
|
|
965
973
|
offset = 2;
|
|
@@ -983,7 +991,7 @@ function isColor(arena, token, errors) {
|
|
|
983
991
|
childType === EnumToken.PercentageTokenType ||
|
|
984
992
|
isColor(arena, children[i]) ||
|
|
985
993
|
(childType === EnumToken.IdenTokenType &&
|
|
986
|
-
equalsIgnoreCase("none", arena.
|
|
994
|
+
equalsIgnoreCase("none", arena.resolveString(arena.stringValue[children[i]])))) {
|
|
987
995
|
continue;
|
|
988
996
|
}
|
|
989
997
|
return false;
|
|
@@ -1009,7 +1017,7 @@ function isColor(arena, token, errors) {
|
|
|
1009
1017
|
let k = 0;
|
|
1010
1018
|
if (children[j].length > 0 &&
|
|
1011
1019
|
arena.dataTypes[children[j][0]] === EnumToken.IdenTokenType &&
|
|
1012
|
-
equalsIgnoreCase("in", arena.
|
|
1020
|
+
equalsIgnoreCase("in", arena.resolveString(arena.stringValue[children[j][k]]))) {
|
|
1013
1021
|
k++;
|
|
1014
1022
|
if (k < children[j].length && arena.dataTypes[children[j][k]] === EnumToken.IdenTokenType) {
|
|
1015
1023
|
if (!isRectangularOrthogonalColorspace(arena, children[j][k])) {
|
|
@@ -1018,11 +1026,11 @@ function isColor(arena, token, errors) {
|
|
|
1018
1026
|
else if (arena.dataTypes[children[j][k]] !== EnumToken.IdenTokenType) {
|
|
1019
1027
|
return false;
|
|
1020
1028
|
}
|
|
1021
|
-
else if (equalsIgnoreCase("hue", arena.
|
|
1029
|
+
else if (equalsIgnoreCase("hue", arena.resolveString(arena.stringValue[children[j][k]]))) {
|
|
1022
1030
|
k++;
|
|
1023
1031
|
}
|
|
1024
1032
|
else {
|
|
1025
|
-
switch (arena.
|
|
1033
|
+
switch (arena.resolveString(arena.stringValue[children[j][k]])) {
|
|
1026
1034
|
case "increasing":
|
|
1027
1035
|
case "decreasing":
|
|
1028
1036
|
case "longer":
|
|
@@ -1034,7 +1042,7 @@ function isColor(arena, token, errors) {
|
|
|
1034
1042
|
}
|
|
1035
1043
|
if (k >= children[j].length ||
|
|
1036
1044
|
arena.dataTypes[children[j][k]] !== EnumToken.IdenTokenType ||
|
|
1037
|
-
!equalsIgnoreCase("hue", arena.
|
|
1045
|
+
!equalsIgnoreCase("hue", arena.resolveString(arena.stringValue[children[j][k]]))) {
|
|
1038
1046
|
return false;
|
|
1039
1047
|
}
|
|
1040
1048
|
k++;
|
|
@@ -1062,7 +1070,7 @@ function isColor(arena, token, errors) {
|
|
|
1062
1070
|
function parseColor(arena, token) {
|
|
1063
1071
|
const typ = arena.dataTypes[token];
|
|
1064
1072
|
if (typ === EnumToken.IdenTokenType) {
|
|
1065
|
-
const val = arena.
|
|
1073
|
+
const val = arena.resolveString(arena.stringValue[token]).toLowerCase();
|
|
1066
1074
|
if (nonStandardColors.has(val)) {
|
|
1067
1075
|
arena.dataTypes[token] = EnumToken.ColorTokenType;
|
|
1068
1076
|
// inlined: arena.setColorType(token, ColorType.NON_STD)
|
|
@@ -1091,7 +1099,7 @@ function parseColor(arena, token) {
|
|
|
1091
1099
|
}
|
|
1092
1100
|
}
|
|
1093
1101
|
if (typ === EnumToken.ColorTokenType) {
|
|
1094
|
-
const val = arena.
|
|
1102
|
+
const val = arena.resolveString(arena.stringValue[token]);
|
|
1095
1103
|
if (arena.colorType[token] === ColorType.NONE && arena.stringValue[token] !== 0) {
|
|
1096
1104
|
// inlined: arena.setColorType(token, ColorType[val.replaceAll("-", "_").toUpperCase()] ?? 0)
|
|
1097
1105
|
// @ts-expect-error
|
|
@@ -1102,11 +1110,11 @@ function parseColor(arena, token) {
|
|
|
1102
1110
|
arena.dataTypes[t] !== EnumToken.CommentTokenType);
|
|
1103
1111
|
if (tk != null &&
|
|
1104
1112
|
arena.dataTypes[tk] === EnumToken.IdenTokenType &&
|
|
1105
|
-
arena.
|
|
1113
|
+
arena.resolveString(arena.stringValue[tk]) === "from") {
|
|
1106
1114
|
// inlined: arena.setUnitString(token, "rel")
|
|
1107
1115
|
arena.unit[token] = arena.internString("rel");
|
|
1108
1116
|
}
|
|
1109
|
-
else if (val === "color-mix" && tk != null && arena.
|
|
1117
|
+
else if (val === "color-mix" && tk != null && arena.resolveString(arena.stringValue[tk]) === "in") {
|
|
1110
1118
|
// inlined: arena.setUnitString(token, "mix")
|
|
1111
1119
|
arena.unit[token] = arena.internString("mix");
|
|
1112
1120
|
}
|
|
@@ -1377,7 +1385,7 @@ function length2Px(arena, value) {
|
|
|
1377
1385
|
}
|
|
1378
1386
|
else {
|
|
1379
1387
|
// the absolute length units: 1in = 2.54cm = 96px. the units are case-insensitive
|
|
1380
|
-
switch (arena.
|
|
1388
|
+
switch (arena.resolveString(arena.unit[value])?.toLowerCase()) {
|
|
1381
1389
|
case "cm":
|
|
1382
1390
|
result = (val * 96) / 2.54;
|
|
1383
1391
|
break;
|
|
@@ -1476,4 +1484,4 @@ function toPrecisionAngle(angle, precision = anglePrecision, correctValue = true
|
|
|
1476
1484
|
return angle;
|
|
1477
1485
|
}
|
|
1478
1486
|
|
|
1479
|
-
export { angleUnits, dimensionUnits, flexUnits, frequencyUnits, isAngleUnit, isColor, isDigit, isFlexUnit, isFrequencyUnit, isFunction, isHash, isIdent, isIdentCodepoint, isIdentColor, isIdentStart, isLength, isLengthUnit, isLetter, isNewLine, isNonPrintable, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolutionUnit, isTimeUnit, isWhiteSpace, length2Px, minifyNumber, parseColor, parseDimension, pseudoAliasMap, reduceColorStops, reduceConicColorStops, reducegradientBackgroundPosition, renamedStandardProperties, resolutionUnits, timeUnits, toPrecisionAngle, toPrecisionValue };
|
|
1487
|
+
export { angleUnits, dimensionUnits, flexUnits, frequencyUnits, isAngleUnit, isColor, isColorName, isDigit, isFlexUnit, isFrequencyUnit, isFunction, isHash, isIdent, isIdentCodepoint, isIdentColor, isIdentStart, isLength, isLengthUnit, isLetter, isNewLine, isNonPrintable, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolutionUnit, isTimeUnit, isWhiteSpace, length2Px, minifyNumber, parseColor, parseDimension, pseudoAliasMap, reduceColorStops, reduceConicColorStops, reducegradientBackgroundPosition, renamedStandardProperties, resolutionUnits, timeUnits, toPrecisionAngle, toPrecisionValue };
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import config from '../../data/validation.json.js';
|
|
9
9
|
import { trimSyntaxArray, parseSyntax } from './parser/parse.js';
|
|
10
|
-
import {
|
|
10
|
+
import { ValidationTokenEnum, ValidationSyntaxGroupEnum } from './parser/typedef.js';
|
|
11
11
|
import { memoize } from '../parser/utils/cache.js';
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* parsed syntaxes, by syntax node: the names that share a definition (`-webkit-transform` and `transform`, the aliases)
|
|
15
|
+
* share the parsed syntax, and the validations cached by syntax (see `matchDeclarationSyntax()`)
|
|
16
|
+
*/
|
|
17
|
+
const parsedSyntaxes = new WeakMap();
|
|
14
18
|
Object.freeze(config);
|
|
15
19
|
function getSyntaxConfig() {
|
|
16
20
|
// @ts-expect-error
|
|
@@ -51,8 +55,17 @@ function lookupNode(group, key) {
|
|
|
51
55
|
* @param key the type name without the angle brackets, or the function name followed by `()`
|
|
52
56
|
*/
|
|
53
57
|
function hasSyntax(key) {
|
|
54
|
-
|
|
58
|
+
let defined = definedSyntaxes.get(key);
|
|
59
|
+
if (defined === undefined) {
|
|
60
|
+
defined = lookupNode(ValidationSyntaxGroupEnum.Syntaxes, key) != null;
|
|
61
|
+
definedSyntaxes.set(key, defined);
|
|
62
|
+
}
|
|
63
|
+
return defined;
|
|
55
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* the types and the functions that are defined, by name, see {@link hasSyntax}
|
|
67
|
+
*/
|
|
68
|
+
const definedSyntaxes = new Map();
|
|
56
69
|
/**
|
|
57
70
|
* return the raw syntax of a type or a function
|
|
58
71
|
* @param key the type name without the angle brackets, or the function name followed by `()`
|
|
@@ -82,12 +95,12 @@ const getParsedSyntax = memoize((group, key) => {
|
|
|
82
95
|
if (obj == null) {
|
|
83
96
|
return null;
|
|
84
97
|
}
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
parsedSyntaxes.set(
|
|
98
|
+
let syntax = parsedSyntaxes.get(obj);
|
|
99
|
+
if (syntax === undefined) {
|
|
100
|
+
syntax = Object.freeze(trimSyntaxArray(parseSyntax(obj.syntax)));
|
|
101
|
+
parsedSyntaxes.set(obj, syntax);
|
|
89
102
|
}
|
|
90
|
-
return
|
|
103
|
+
return syntax;
|
|
91
104
|
});
|
|
92
105
|
const getSyntaxRule = memoize((group, key) => {
|
|
93
106
|
const node = findNode(group, key);
|