@tbela99/css-parser 1.4.6 → 1.4.8
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 +23 -0
- package/README.md +1 -0
- package/dist/index-umd-web.js +6578 -6969
- package/dist/index.cjs +7808 -8197
- package/dist/index.d.ts +923 -51
- package/dist/lib/ast/clone.js +16 -23
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/if.js +88 -87
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +26 -22
- package/dist/lib/ast/features/transform.js +3 -3
- package/dist/lib/ast/find.js +17 -14
- package/dist/lib/ast/minify.js +97 -94
- package/dist/lib/ast/types.js +10 -2
- package/dist/lib/ast/walk.js +1 -1
- package/dist/lib/fs/resolve.js +47 -45
- package/dist/lib/parser/arena.js +206 -0
- package/dist/lib/parser/declaration/list.js +9 -10
- package/dist/lib/parser/declaration/map.js +13 -18
- package/dist/lib/parser/linemap.js +62 -0
- package/dist/lib/parser/parse.js +331 -504
- package/dist/lib/parser/source.js +72 -0
- package/dist/lib/parser/tokenize.js +39 -33
- package/dist/lib/parser/utils/at-rule-container.js +244 -247
- package/dist/lib/parser/utils/at-rule-generic.js +25 -25
- package/dist/lib/parser/utils/at-rule-import.js +194 -234
- package/dist/lib/parser/utils/at-rule-media.js +284 -283
- package/dist/lib/parser/utils/at-rule-support.js +279 -251
- package/dist/lib/parser/utils/at-rule-when-else.js +256 -259
- package/dist/lib/parser/utils/at-rule.js +19 -16
- package/dist/lib/parser/utils/cache.js +33 -5
- package/dist/lib/parser/utils/declaration.js +260 -298
- package/dist/lib/parser/utils/hash.js +15 -15
- package/dist/lib/parser/utils/selector.js +182 -222
- package/dist/lib/parser/utils/token.js +4 -7
- package/dist/lib/renderer/render.js +152 -121
- package/dist/lib/syntax/color/alpha.js +1 -4
- package/dist/lib/syntax/color/color-mix.js +8 -1
- package/dist/lib/syntax/color/color.js +17 -9
- package/dist/lib/syntax/color/hex.js +1 -1
- package/dist/lib/syntax/color/p3.js +9 -1
- package/dist/lib/syntax/color/utils/colorspace.js +3 -3
- package/dist/lib/syntax/color/utils/components.js +21 -22
- package/dist/lib/syntax/color/utils/distance.js +6 -1
- package/dist/lib/syntax/color/utils/matrix.js +12 -11
- package/dist/lib/syntax/constants.js +25 -3
- package/dist/lib/syntax/syntax.js +240 -311
- package/dist/lib/validation/config.js +16 -17
- package/dist/lib/validation/match.js +1118 -1131
- package/dist/lib/validation/parser/parse.js +130 -286
- package/dist/node.js +18 -14
- package/dist/web.js +12 -10
- package/package.json +4 -4
- package/dist/lib/validation/utils/whitespace.js +0 -17
- /package/dist/lib/syntax/color/{relativecolor.js → relative-color.js} +0 -0
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { walkValues } from '../../../ast/walk.js';
|
|
1
|
+
import { ColorType, EnumToken } from '../../../ast/types.js';
|
|
3
2
|
import { COLORS_NAMES } from '../../constants.js';
|
|
4
3
|
import { expandHexValue } from '../hex.js';
|
|
5
|
-
import { isColor, parseColor } from '../../syntax.js';
|
|
6
4
|
import { equalsIgnoreCase } from '../../../parser/utils/text.js';
|
|
7
5
|
|
|
8
6
|
function getColorComponents(token) {
|
|
9
|
-
if (token.typ === EnumToken.IdenTokenType) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
7
|
+
// if (token.typ === EnumToken.IdenTokenType) {
|
|
8
|
+
// if (isColor(token)) {
|
|
9
|
+
// parseColor(token);
|
|
10
|
+
// } else {
|
|
11
|
+
// return null;
|
|
12
|
+
// }
|
|
13
|
+
// }
|
|
17
14
|
if (token.kin == ColorType.HEX || token.kin == ColorType.LIT) {
|
|
18
15
|
if (equalsIgnoreCase('currentcolor', token.val)) {
|
|
19
16
|
return null;
|
|
@@ -37,23 +34,25 @@ function getColorComponents(token) {
|
|
|
37
34
|
].includes(child.typ)) {
|
|
38
35
|
continue;
|
|
39
36
|
}
|
|
40
|
-
if (child.typ === EnumToken.IdenTokenType && isColor(child)) {
|
|
41
|
-
|
|
42
|
-
}
|
|
37
|
+
// if (child.typ === EnumToken.IdenTokenType && isColor(child)) {
|
|
38
|
+
// parseColor(child);
|
|
39
|
+
// }
|
|
43
40
|
if (child.typ === EnumToken.FunctionTokenType ||
|
|
44
41
|
child.typ === EnumToken.WildCardFunctionTokenType ||
|
|
45
42
|
child.typ === EnumToken.MathFunctionTokenType) {
|
|
46
43
|
if ("var" == child.val.toLowerCase()) {
|
|
47
44
|
return null;
|
|
48
45
|
}
|
|
49
|
-
else {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
46
|
+
// else {
|
|
47
|
+
// for (const { value } of walkValues((child as FunctionToken).chi)) {
|
|
48
|
+
// if (
|
|
49
|
+
// value.typ == EnumToken.WildCardFunctionTokenDefType &&
|
|
50
|
+
// "var" === (value as FunctionToken).val.toLowerCase()
|
|
51
|
+
// ) {
|
|
52
|
+
// return null;
|
|
53
|
+
// }
|
|
54
|
+
// }
|
|
55
|
+
// }
|
|
57
56
|
}
|
|
58
57
|
if (child.typ == EnumToken.ColorTokenType && equalsIgnoreCase("currentcolor", child.val)) {
|
|
59
58
|
return null;
|
|
@@ -22,7 +22,12 @@ function okLabDistance(color1, color2) {
|
|
|
22
22
|
if (okLab1 == null || okLab2 == null) {
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
const diff = [okLab1[0] - okLab2[0], okLab1[1] - okLab2[1], okLab1[2] - okLab2[2]];
|
|
26
|
+
// include alpha
|
|
27
|
+
if (okLab1[3] != null || okLab2[3] != null) {
|
|
28
|
+
diff.push((okLab1[3] ?? 1) - (okLab2[3] ?? 1));
|
|
29
|
+
}
|
|
30
|
+
return Math.hypot(...diff);
|
|
26
31
|
}
|
|
27
32
|
/**
|
|
28
33
|
* Check if two colors are close in okLab space.
|
|
@@ -6,27 +6,28 @@
|
|
|
6
6
|
*/
|
|
7
7
|
// A is m x n. B is n x p. product is m x p.
|
|
8
8
|
function multiplyMatrices(A, B) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
9
|
+
// if (!Array.isArray(A[0])) {
|
|
10
|
+
// // A is vector, convert to [[a, b, c, ...]]
|
|
11
|
+
// A = <number[][]>[A];
|
|
12
|
+
// }
|
|
14
13
|
if (!Array.isArray(B[0])) {
|
|
15
14
|
// B is vector, convert to [[a], [b], [c], ...]]
|
|
16
15
|
B = B.map((x) => [x]);
|
|
17
16
|
}
|
|
18
17
|
let p = B[0].length;
|
|
19
18
|
let B_cols = B[0].map((_, i) => B.map((x) => x[i])); // transpose B
|
|
19
|
+
// @ts-expect-error
|
|
20
20
|
let product = A.map((row) => B_cols.map((col) => {
|
|
21
|
-
if (!Array.isArray(row)) {
|
|
22
|
-
|
|
23
|
-
}
|
|
21
|
+
// if (!Array.isArray(row)) {
|
|
22
|
+
// return col.reduce((a: number, c: number) => a + c * row, 0);
|
|
23
|
+
// }
|
|
24
24
|
return row.reduce((a, c, i) => a + c * (col[i] || 0), 0);
|
|
25
25
|
}));
|
|
26
|
-
if (m === 1) {
|
|
27
|
-
|
|
28
|
-
}
|
|
26
|
+
// if (m === 1) {
|
|
27
|
+
// product = <number[]>product[0]; // Avoid [[a, b, c, ...]]
|
|
28
|
+
// }
|
|
29
29
|
if (p === 1) {
|
|
30
|
+
// @ts-expect-error
|
|
30
31
|
return product.map((x) => x[0]); // Avoid [[a], [b], [c], ...]]
|
|
31
32
|
}
|
|
32
33
|
return product;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { EnumToken } from '../ast/types.js';
|
|
2
2
|
import config from '../validation/config.json.js';
|
|
3
3
|
|
|
4
|
+
const LOC = Symbol.for("loc");
|
|
5
|
+
const RAW = Symbol.for("raw");
|
|
6
|
+
const STATE = Symbol.for("state");
|
|
7
|
+
const ROOT = Symbol.for("root");
|
|
8
|
+
const ERRORS = Symbol.for("errors");
|
|
9
|
+
const TOKENS = Symbol.for("tokens");
|
|
10
|
+
const PARENT = Symbol.for("parent");
|
|
11
|
+
const OPTIMIZED = Symbol.for("optimized");
|
|
12
|
+
const PROPERTYNAME = Symbol.for("propertyName");
|
|
4
13
|
const regMatchLinearGradient = /^-((webkit)|o|moz)(-repeating)?-linear-gradient$/i;
|
|
5
14
|
const regMatchRadialGradient = /^-((webkit)|o|moz)(-repeating)?-radial-gradient$/i;
|
|
6
15
|
const mFLT = new Set([EnumToken.LtTokenType, EnumToken.LteTokenType]);
|
|
@@ -70,6 +79,17 @@ const colorRange = {
|
|
|
70
79
|
b: [0, 0.4],
|
|
71
80
|
},
|
|
72
81
|
};
|
|
82
|
+
// https://www.w3.org/TR/css-values-4/#math-function
|
|
83
|
+
const pseudoElements = [
|
|
84
|
+
":before",
|
|
85
|
+
":after",
|
|
86
|
+
":first-line",
|
|
87
|
+
":first-letter",
|
|
88
|
+
"::before",
|
|
89
|
+
"::after",
|
|
90
|
+
"::first-line",
|
|
91
|
+
"::first-letter",
|
|
92
|
+
];
|
|
73
93
|
const wildCardFuncs = ["var", "env", "if"];
|
|
74
94
|
const mathFuncs = [
|
|
75
95
|
"minmax",
|
|
@@ -137,7 +157,7 @@ const pageMarginBoxType = new Set([
|
|
|
137
157
|
const urlFunc = ["url"];
|
|
138
158
|
const timelineFunc = ["view", "scroll"];
|
|
139
159
|
const gridTemplateFunc = ["minmax", "fit-content", "repeat"];
|
|
140
|
-
const generalEnclosedFunc = [];
|
|
160
|
+
// export const generalEnclosedFunc: string[] = [];
|
|
141
161
|
const supportFunc = ["selector", "font-tech", "font-format", "at-rule", "named-feature"];
|
|
142
162
|
const whenElseFunc = ["media", "supports"];
|
|
143
163
|
const containerFunc = ["style", "scroll-state"];
|
|
@@ -227,9 +247,12 @@ const colorFuncColorSpace = [
|
|
|
227
247
|
"srgb",
|
|
228
248
|
"srgb-linear",
|
|
229
249
|
"display-p3",
|
|
250
|
+
"display-p3-linear",
|
|
230
251
|
"prophoto-rgb",
|
|
231
252
|
"a98-rgb",
|
|
232
253
|
"rec2020",
|
|
254
|
+
"lab",
|
|
255
|
+
"oklab",
|
|
233
256
|
"xyz",
|
|
234
257
|
"xyz-d65",
|
|
235
258
|
"xyz-d50",
|
|
@@ -458,7 +481,6 @@ const trimTokenSpace = new Set([
|
|
|
458
481
|
EnumToken.SupportsQueryConditionTokenType,
|
|
459
482
|
EnumToken.SupportsQueryUnaryConditionTokenType,
|
|
460
483
|
]);
|
|
461
|
-
const definedPropertySettings = { configurable: true, enumerable: false, writable: true };
|
|
462
484
|
const combinators = ["+", ">", "~", "||", "|"];
|
|
463
485
|
|
|
464
|
-
export { COLORS_NAMES, D50, NAMES_COLORS, anglePrecision, colorDistancePrecision, colorFuncColorSpace, colorPrecision, colorRange, colorsFunc, combinators, containerFunc,
|
|
486
|
+
export { COLORS_NAMES, D50, ERRORS, LOC, NAMES_COLORS, OPTIMIZED, PARENT, PROPERTYNAME, RAW, ROOT, STATE, TOKENS, anglePrecision, colorDistancePrecision, colorFuncColorSpace, colorPrecision, colorRange, colorsFunc, combinators, containerFunc, deprecatedSystemColors, e, epsilon, funcLike, gridTemplateFunc, imageFunc, k, mFGT, mFLT, mathFuncs, mediaTypes, nonStandardColors, pageMarginBoxType, pseudoElements, regMatchLinearGradient, regMatchRadialGradient, supportFunc, systemColors, timelineFunc, timingFunc, tokensMap, tokensfuncDefMap, tokensfuncSet, transformFunctions, trimTokenSpace, urlFunc, urlTokenMatcher, whenElseFunc, wildCardFuncs };
|