@tbela99/css-parser 1.4.11 → 1.6.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 +39 -0
- package/README.md +18 -11
- package/dist/index-umd-web.js +6558 -5310
- package/dist/index.cjs +6576 -5313
- package/dist/index.d.ts +805 -279
- package/dist/lib/ast/clone.js +13 -8
- package/dist/lib/ast/expand.js +65 -15
- package/dist/lib/ast/features/calc.js +19 -56
- package/dist/lib/ast/features/if.js +28 -4
- package/dist/lib/ast/features/inlinecssvariables.js +6 -5
- package/dist/lib/ast/features/prefix.js +52 -73
- package/dist/lib/ast/features/shorthand.js +11 -6
- package/dist/lib/ast/features/transform.js +6 -3
- package/dist/lib/ast/find.js +7 -5
- package/dist/lib/ast/math/expression.js +190 -32
- package/dist/lib/ast/minify.js +117 -49
- package/dist/lib/ast/node.js +52 -0
- package/dist/lib/ast/transform/compute.js +63 -4
- package/dist/lib/ast/transform/minify.js +6 -6
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.js +1 -1
- package/dist/lib/ast/transform/scale.js +1 -1
- package/dist/lib/ast/transform/skew.js +1 -1
- package/dist/lib/ast/transform/translate.js +1 -1
- package/dist/lib/ast/transform/utils.js +46 -18
- package/dist/lib/ast/types.js +1 -1
- package/dist/lib/ast/walk.js +55 -11
- package/dist/lib/fs/resolve.js +68 -27
- package/dist/lib/parser/declaration/list.js +22 -7
- package/dist/lib/parser/declaration/map.js +40 -13
- package/dist/lib/parser/declaration/set.js +3 -1
- package/dist/lib/parser/linesmap.js +2 -12
- package/dist/lib/parser/parse.js +843 -912
- package/dist/lib/parser/source.js +16 -2
- package/dist/lib/parser/tokenize.js +1489 -725
- package/dist/lib/parser/utils/at-rule-container.js +29 -196
- package/dist/lib/parser/utils/at-rule-generic.js +6 -7
- package/dist/lib/parser/utils/at-rule-import.js +17 -13
- package/dist/lib/parser/utils/at-rule-media.js +36 -19
- package/dist/lib/parser/utils/at-rule-support.js +19 -9
- package/dist/lib/parser/utils/at-rule-when-else.js +11 -38
- package/dist/lib/parser/utils/at-rule.js +0 -18
- package/dist/lib/parser/utils/declaration.js +30 -95
- package/dist/lib/parser/utils/hash.js +4 -4
- package/dist/lib/parser/utils/selector.js +164 -141
- package/dist/lib/parser/utils/text.js +4 -2
- package/dist/lib/renderer/render.js +230 -125
- package/dist/lib/renderer/sourcemap/lib/codec.js +78 -0
- package/dist/lib/renderer/sourcemap/sourcemap.js +187 -34
- package/dist/lib/syntax/color/a98rgb.js +14 -4
- package/dist/lib/syntax/color/cmyk.js +10 -18
- package/dist/lib/syntax/color/color-mix.js +21 -34
- package/dist/lib/syntax/color/color.js +32 -49
- package/dist/lib/syntax/color/hsl.js +15 -15
- package/dist/lib/syntax/color/hwb.js +18 -17
- package/dist/lib/syntax/color/lab.js +17 -17
- package/dist/lib/syntax/color/lch.js +13 -13
- package/dist/lib/syntax/color/oklab.js +10 -11
- package/dist/lib/syntax/color/oklch.js +15 -18
- package/dist/lib/syntax/color/p3.js +18 -12
- package/dist/lib/syntax/color/prophotorgb.js +26 -28
- package/dist/lib/syntax/color/rec2020.js +8 -4
- package/dist/lib/syntax/color/relative-color.js +26 -10
- package/dist/lib/syntax/color/srgb.js +5 -4
- package/dist/lib/syntax/color/utils/distance.js +1 -1
- package/dist/lib/syntax/color/xyz.js +2 -2
- package/dist/lib/syntax/color/xyzd50.js +2 -2
- package/dist/lib/syntax/constants.js +12 -2
- package/dist/lib/syntax/syntax.js +45 -258
- package/dist/lib/validation/config.json.js +3 -0
- package/dist/lib/validation/match.js +110 -27
- package/dist/node.js +55 -33
- package/dist/types.d.ts +5 -1
- package/dist/types.js +4 -0
- package/dist/utils/sync.d.ts +16 -0
- package/dist/utils/sync.js +73 -0
- package/dist/web.js +37 -30
- package/package.json +1 -1
- package/dist/lib/renderer/sourcemap/lib/encode.js +0 -37
- package/llms.txt +0 -73
|
@@ -3,12 +3,16 @@ import { multiplyMatrices } from './utils/matrix.js';
|
|
|
3
3
|
import { srgb2xyz } from './xyz.js';
|
|
4
4
|
|
|
5
5
|
function rec20202srgb(r, g, b, a) {
|
|
6
|
+
let values = rec20202lrec2020(r, g, b);
|
|
7
|
+
values = lrec20202xyz(values[0], values[1], values[2]);
|
|
6
8
|
// @ts-ignore
|
|
7
|
-
return xyz2srgb(
|
|
9
|
+
return xyz2srgb(values[0], values[1], values[2], a);
|
|
8
10
|
}
|
|
9
11
|
function srgb2rec2020values(r, g, b, a) {
|
|
12
|
+
let values = srgb2xyz(r, g, b);
|
|
13
|
+
values = xyz2lrec2020(values[0], values[1], values[2]);
|
|
10
14
|
// @ts-ignore
|
|
11
|
-
return lrec20202rec2020(
|
|
15
|
+
return lrec20202rec2020(values[0], values[1], values[2], a);
|
|
12
16
|
}
|
|
13
17
|
function rec20202lrec2020(r, g, b, a) {
|
|
14
18
|
// convert an array of rec2020 RGB values in the range 0.0 - 1.0
|
|
@@ -54,7 +58,7 @@ function lrec20202xyz(r, g, b, a) {
|
|
|
54
58
|
[0, 19567812 / 697040785, 295819943 / 278816314],
|
|
55
59
|
];
|
|
56
60
|
// 0 is actually calculated as 4.994106574466076e-17
|
|
57
|
-
return multiplyMatrices(M, [r, g, b]).concat(
|
|
61
|
+
return multiplyMatrices(M, [r, g, b]).concat([] );
|
|
58
62
|
}
|
|
59
63
|
function xyz2lrec2020(x, y, z, a) {
|
|
60
64
|
// convert XYZ to linear-light rec2020
|
|
@@ -63,7 +67,7 @@ function xyz2lrec2020(x, y, z, a) {
|
|
|
63
67
|
[-19765991 / 29648200, 47925759 / 29648200, 467509 / 29648200],
|
|
64
68
|
[792561 / 44930125, -1921689 / 44930125, 42328811 / 44930125],
|
|
65
69
|
];
|
|
66
|
-
return multiplyMatrices(M, [x, y, z]).concat(
|
|
70
|
+
return multiplyMatrices(M, [x, y, z]).concat([] );
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
export { rec20202srgb, srgb2rec2020values };
|
|
@@ -2,7 +2,7 @@ import { convertColor, getNumber } from './color.js';
|
|
|
2
2
|
import { EnumToken, ColorType } from '../../ast/types.js';
|
|
3
3
|
import { walkValues } from '../../ast/walk.js';
|
|
4
4
|
import { evaluateFunc, evaluate } from '../../ast/math/expression.js';
|
|
5
|
-
import { colorsFunc, colorFuncColorSpace,
|
|
5
|
+
import { colorsFunc, colorFuncColorSpace, LOCEND, LOCSTA, LOCSRCID, colorRange, mathFuncs } from '../constants.js';
|
|
6
6
|
import { equalsIgnoreCase } from '../../parser/utils/text.js';
|
|
7
7
|
import { getColorComponents } from './utils/components.js';
|
|
8
8
|
|
|
@@ -34,7 +34,9 @@ function parseRelativeColorComponents(relativeKeys, original, rExp, gExp, bExp,
|
|
|
34
34
|
const validKeys = names.split("");
|
|
35
35
|
let val = "";
|
|
36
36
|
if (components != null) {
|
|
37
|
-
|
|
37
|
+
for (const component of components) {
|
|
38
|
+
allComponents.push(component);
|
|
39
|
+
}
|
|
38
40
|
}
|
|
39
41
|
// ensure all components are valid for the color space
|
|
40
42
|
for (const component of allComponents) {
|
|
@@ -103,19 +105,25 @@ function parseRelativeColorComponents(relativeKeys, original, rExp, gExp, bExp,
|
|
|
103
105
|
? {
|
|
104
106
|
typ: EnumToken.NumberTokenType,
|
|
105
107
|
val: 1,
|
|
106
|
-
[
|
|
108
|
+
[LOCSRCID]: b[LOCSRCID],
|
|
109
|
+
[LOCSTA]: b[LOCSTA],
|
|
110
|
+
[LOCEND]: b[LOCEND],
|
|
107
111
|
}
|
|
108
112
|
: alpha.typ == EnumToken.IdenTokenType && alpha.val == "none"
|
|
109
113
|
? {
|
|
110
114
|
typ: EnumToken.NumberTokenType,
|
|
111
115
|
val: 0,
|
|
112
|
-
[
|
|
116
|
+
[LOCSRCID]: alpha[LOCSRCID],
|
|
117
|
+
[LOCSTA]: alpha[LOCSTA],
|
|
118
|
+
[LOCEND]: alpha[LOCEND],
|
|
113
119
|
}
|
|
114
120
|
: alpha.typ == EnumToken.PercentageTokenType
|
|
115
121
|
? {
|
|
116
122
|
typ: EnumToken.NumberTokenType,
|
|
117
123
|
val: getNumber(alpha),
|
|
118
|
-
[
|
|
124
|
+
[LOCSRCID]: alpha[LOCSRCID],
|
|
125
|
+
[LOCSTA]: alpha[LOCSTA],
|
|
126
|
+
[LOCEND]: alpha[LOCEND],
|
|
119
127
|
}
|
|
120
128
|
: alpha,
|
|
121
129
|
};
|
|
@@ -128,13 +136,17 @@ function parseRelativeColorComponents(relativeKeys, original, rExp, gExp, bExp,
|
|
|
128
136
|
? {
|
|
129
137
|
typ: EnumToken.NumberTokenType,
|
|
130
138
|
val: 1,
|
|
131
|
-
[
|
|
139
|
+
[LOCSRCID]: bExp[LOCSRCID],
|
|
140
|
+
[LOCSTA]: bExp[LOCSTA],
|
|
141
|
+
[LOCEND]: bExp[LOCEND],
|
|
132
142
|
}
|
|
133
143
|
: aExp.typ == EnumToken.IdenTokenType && aExp.val == "none"
|
|
134
144
|
? {
|
|
135
145
|
typ: EnumToken.NumberTokenType,
|
|
136
146
|
val: 0,
|
|
137
|
-
[
|
|
147
|
+
[LOCSRCID]: aExp[LOCSRCID],
|
|
148
|
+
[LOCSTA]: aExp[LOCSTA],
|
|
149
|
+
[LOCEND]: aExp[LOCEND],
|
|
138
150
|
}
|
|
139
151
|
: aExp),
|
|
140
152
|
};
|
|
@@ -165,7 +177,9 @@ function getValue(t, converted, component) {
|
|
|
165
177
|
return {
|
|
166
178
|
typ: EnumToken.NumberTokenType,
|
|
167
179
|
val: value,
|
|
168
|
-
[
|
|
180
|
+
[LOCSRCID]: t[LOCSRCID],
|
|
181
|
+
[LOCSTA]: t[LOCSTA],
|
|
182
|
+
[LOCEND]: t[LOCEND],
|
|
169
183
|
};
|
|
170
184
|
}
|
|
171
185
|
return t;
|
|
@@ -208,8 +222,10 @@ function computeComponentValue(expr, values) {
|
|
|
208
222
|
{
|
|
209
223
|
typ: EnumToken.NumberTokenType,
|
|
210
224
|
// @ts-ignore
|
|
211
|
-
val:
|
|
212
|
-
[
|
|
225
|
+
val: Math[value.val.toUpperCase()],
|
|
226
|
+
[LOCSRCID]: value[LOCSRCID],
|
|
227
|
+
[LOCSTA]: value[LOCSTA],
|
|
228
|
+
[LOCEND]: value[LOCEND],
|
|
213
229
|
// @ts-ignore
|
|
214
230
|
});
|
|
215
231
|
}
|
|
@@ -69,8 +69,9 @@ function hex2srgbvalues(token) {
|
|
|
69
69
|
}
|
|
70
70
|
// xyz d65 input
|
|
71
71
|
function xyz2srgb(x, y, z, alpha = null) {
|
|
72
|
+
let values = XYZ_to_lin_sRGB(x, y, z);
|
|
72
73
|
// @ts-ignore
|
|
73
|
-
return lsrgb2srgbvalues(
|
|
74
|
+
return lsrgb2srgbvalues(values[0], values[1], values[2], alpha);
|
|
74
75
|
}
|
|
75
76
|
function hwb2srgbvalues(token) {
|
|
76
77
|
const { h: hue, s: white, l: black, a: alpha } = hslvalues(token) ?? {};
|
|
@@ -141,8 +142,8 @@ function oklch2srgbvalues(token) {
|
|
|
141
142
|
if (l == null || c == null || h == null) {
|
|
142
143
|
return null;
|
|
143
144
|
}
|
|
144
|
-
|
|
145
|
-
const rgb = OKLab_to_sRGB(
|
|
145
|
+
const values = lchvalues2labvalues(l, c, h);
|
|
146
|
+
const rgb = OKLab_to_sRGB(values[0], values[1], values[2]);
|
|
146
147
|
if (alpha != 1) {
|
|
147
148
|
rgb.push(alpha);
|
|
148
149
|
}
|
|
@@ -243,7 +244,7 @@ function lch2srgbvalues(token) {
|
|
|
243
244
|
return null;
|
|
244
245
|
}
|
|
245
246
|
// @ts-ignore
|
|
246
|
-
const [l, a, b, alpha] = lchvalues2labvalues(
|
|
247
|
+
const [l, a, b, alpha] = lchvalues2labvalues(components[0], components[1], components[2], components[3]);
|
|
247
248
|
if (l == null || a == null || b == null) {
|
|
248
249
|
return null;
|
|
249
250
|
}
|
|
@@ -28,7 +28,7 @@ function okLabDistance(color1, color2) {
|
|
|
28
28
|
if (okLab1[3] != null || okLab2[3] != null) {
|
|
29
29
|
diff.push((okLab1[3] ?? 1) - (okLab2[3] ?? 1));
|
|
30
30
|
}
|
|
31
|
-
return toPrecisionValue(Math.hypot(
|
|
31
|
+
return toPrecisionValue(Math.hypot(diff[0], diff[1], diff[2], diff[3] ?? 0));
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Check if two colors are close in okLab space.
|
|
@@ -41,8 +41,8 @@ function srgb2xyz(r, g, b, alpha) {
|
|
|
41
41
|
// xyz d50
|
|
42
42
|
function srgb2xyz_d65(r, g, b, alpha) {
|
|
43
43
|
// xyx d65
|
|
44
|
-
|
|
45
|
-
let rgb = XYZ_D65_to_D50(
|
|
44
|
+
let values = srgb2xyz(r, g, b);
|
|
45
|
+
let rgb = XYZ_D65_to_D50(values[0], values[1], values[2]);
|
|
46
46
|
if (alpha != null && alpha != 1) {
|
|
47
47
|
rgb.push(alpha);
|
|
48
48
|
}
|
|
@@ -7,8 +7,8 @@ import { labvalues2lchvalues } from './lch.js';
|
|
|
7
7
|
/*
|
|
8
8
|
*/
|
|
9
9
|
function xyzd502lch(x, y, z, alpha) {
|
|
10
|
-
|
|
11
|
-
const [l, a, b] = xyz2lab(
|
|
10
|
+
const values = XYZ_D50_to_D65(x, y, z);
|
|
11
|
+
const [l, a, b] = xyz2lab(values[0], values[1], values[2]);
|
|
12
12
|
// L in range [0,100]. For use in CSS, add a percent
|
|
13
13
|
return labvalues2lchvalues(l, a, b, alpha);
|
|
14
14
|
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { EnumToken } from '../ast/types.js';
|
|
2
2
|
import config from '../validation/config.json.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Location source id
|
|
6
|
+
*/
|
|
7
|
+
const LOCSRCID = Symbol.for("locSrcId");
|
|
8
|
+
const LOCSTA = Symbol.for("locSta");
|
|
9
|
+
const LOCEND = Symbol.for("locEnd");
|
|
10
|
+
/**
|
|
11
|
+
* Used by the validation parser
|
|
12
|
+
*/
|
|
4
13
|
const LOC = Symbol.for("loc");
|
|
5
14
|
const RAW = Symbol.for("raw");
|
|
6
15
|
const STATE = Symbol.for("state");
|
|
@@ -53,7 +62,7 @@ const colorPrecision = 6;
|
|
|
53
62
|
/**
|
|
54
63
|
* Angle precision
|
|
55
64
|
*/
|
|
56
|
-
const anglePrecision =
|
|
65
|
+
const anglePrecision = 3;
|
|
57
66
|
/**
|
|
58
67
|
* Color range definitions
|
|
59
68
|
*/
|
|
@@ -109,6 +118,7 @@ const mathFuncs = [
|
|
|
109
118
|
"acos",
|
|
110
119
|
"atan",
|
|
111
120
|
"atan2",
|
|
121
|
+
"tan",
|
|
112
122
|
"pow",
|
|
113
123
|
"sqrt",
|
|
114
124
|
"hypot",
|
|
@@ -484,4 +494,4 @@ const trimTokenSpace = new Set([
|
|
|
484
494
|
]);
|
|
485
495
|
const combinators = ["+", ">", "~", "||", "|"];
|
|
486
496
|
|
|
487
|
-
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 };
|
|
497
|
+
export { COLORS_NAMES, D50, ERRORS, LOC, LOCEND, LOCSRCID, LOCSTA, 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 };
|