@tbela99/css-parser 1.8.2 → 2.0.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 +62 -0
- package/README.md +129 -31
- package/dist/index-umd-web.js +27383 -24083
- package/dist/index.d.ts +2737 -2200
- package/dist/package.json.js +2 -2
- package/dist/src/data/properties.json.js +1 -1
- package/dist/src/data/validation.json.js +1 -1
- package/dist/src/lib/ast/arena-node.js +548 -0
- package/dist/src/lib/ast/arena.js +3198 -0
- package/dist/src/lib/ast/features/calc.js +85 -76
- package/dist/src/lib/ast/features/if.js +155 -115
- package/dist/src/lib/ast/features/index.js +1 -1
- package/dist/src/lib/ast/features/inlinecssvariables.js +77 -84
- package/dist/src/lib/ast/features/prefix.js +184 -183
- package/dist/src/lib/ast/features/shorthand.js +40 -46
- package/dist/src/lib/ast/features/transform.js +24 -24
- package/dist/src/lib/ast/features/type.js +1 -1
- package/dist/src/lib/ast/fingerprint.js +333 -0
- package/dist/src/lib/ast/math/expression.js +458 -543
- package/dist/src/lib/ast/math/math.js +19 -41
- package/dist/src/lib/ast/minify.js +590 -647
- package/dist/src/lib/ast/transform/compute.js +82 -85
- package/dist/src/lib/ast/transform/matrix.js +21 -38
- package/dist/src/lib/ast/transform/minify.js +82 -193
- package/dist/src/lib/ast/transform/perspective.js +2 -3
- package/dist/src/lib/ast/transform/rotate.js +1 -1
- package/dist/src/lib/ast/transform/scale.js +1 -1
- package/dist/src/lib/ast/transform/skew.js +1 -1
- package/dist/src/lib/ast/transform/translate.js +1 -1
- package/dist/src/lib/ast/transform/utils.js +2 -2
- package/dist/src/lib/ast/types.js +263 -258
- package/dist/src/lib/ast/walk.js +246 -610
- package/dist/src/lib/fs/resolve.js +1 -1
- package/dist/src/lib/parser/declaration/list.js +223 -139
- package/dist/src/lib/parser/declaration/map.js +251 -238
- package/dist/src/lib/parser/declaration/set.js +74 -66
- package/dist/src/lib/parser/linesmap.js +1 -1
- package/dist/src/lib/parser/parse.js +1379 -1658
- package/dist/src/lib/parser/source.js +7 -4
- package/dist/src/lib/parser/tokenize.js +406 -199
- package/dist/src/lib/parser/utils/angle.js +11 -13
- package/dist/src/lib/parser/utils/at-rule-container.js +183 -168
- package/dist/src/lib/parser/utils/at-rule-font-feature-values.js +5 -5
- package/dist/src/lib/parser/utils/at-rule-generic.js +31 -24
- package/dist/src/lib/parser/utils/at-rule-import.js +44 -44
- package/dist/src/lib/parser/utils/at-rule-media.js +216 -205
- package/dist/src/lib/parser/utils/at-rule-support.js +83 -88
- package/dist/src/lib/parser/utils/at-rule-when-else.js +47 -47
- package/dist/src/lib/parser/utils/at-rule.js +5 -5
- package/dist/src/lib/parser/utils/base64.js +2 -2
- package/dist/src/lib/parser/utils/cache.js +1 -1
- package/dist/src/lib/parser/utils/config.js +1 -1
- package/dist/src/lib/parser/utils/declaration.js +233 -234
- package/dist/src/lib/parser/utils/eq.js +50 -3
- package/dist/src/lib/parser/utils/hash.js +2 -35
- package/dist/src/lib/parser/utils/selector.js +309 -387
- package/dist/src/lib/parser/utils/text.js +18 -4
- package/dist/src/lib/parser/utils/token.js +16 -69
- package/dist/src/lib/parser/utils/type.js +37 -24
- package/dist/src/lib/printer/render.js +965 -511
- package/dist/src/lib/printer/sourcemap/lib/codec.js +1 -1
- package/dist/src/lib/printer/sourcemap/sourcemap.js +1 -1
- package/dist/src/lib/syntax/color/a98rgb.js +1 -1
- package/dist/src/lib/syntax/color/alpha.js +36 -37
- package/dist/src/lib/syntax/color/cmyk.js +35 -52
- package/dist/src/lib/syntax/color/color-mix.js +96 -132
- package/dist/src/lib/syntax/color/color.js +222 -231
- package/dist/src/lib/syntax/color/hex.js +45 -55
- package/dist/src/lib/syntax/color/hsl.js +54 -62
- package/dist/src/lib/syntax/color/hwb.js +60 -68
- package/dist/src/lib/syntax/color/lab.js +59 -67
- package/dist/src/lib/syntax/color/lch.js +59 -67
- package/dist/src/lib/syntax/color/oklab.js +60 -68
- package/dist/src/lib/syntax/color/oklch.js +60 -67
- package/dist/src/lib/syntax/color/p3.js +1 -1
- package/dist/src/lib/syntax/color/prophotorgb.js +1 -1
- package/dist/src/lib/syntax/color/rec2020.js +1 -1
- package/dist/src/lib/syntax/color/relative-color.js +94 -144
- package/dist/src/lib/syntax/color/rgb.js +54 -57
- package/dist/src/lib/syntax/color/srgb.js +55 -53
- package/dist/src/lib/syntax/color/utils/color-type.js +13 -10
- package/dist/src/lib/syntax/color/utils/colorspace.js +11 -11
- package/dist/src/lib/syntax/color/utils/components.js +19 -20
- package/dist/src/lib/syntax/color/utils/distance.js +15 -13
- package/dist/src/lib/syntax/color/utils/make-color.js +15 -19
- package/dist/src/lib/syntax/color/utils/matrix.js +2 -2
- package/dist/src/lib/syntax/color/xyz.js +1 -1
- package/dist/src/lib/syntax/color/xyzd50.js +1 -1
- package/dist/src/lib/syntax/constants.js +2 -16
- package/dist/src/lib/syntax/syntax.js +301 -407
- package/dist/src/lib/validation/config.js +1 -1
- package/dist/src/lib/validation/match.js +959 -723
- package/dist/src/lib/validation/parser/parse.js +230 -112
- package/dist/src/lib/validation/parser/typedef.js +1 -1
- package/dist/src/lib/validation/utils/list.js +27 -12
- package/dist/src/node.js +12 -72
- package/dist/src/types.js +1 -1
- package/dist/src/utils/sync.js +9 -6
- package/dist/src/web.js +11 -73
- package/package.json +9 -10
- package/dist/index.cjs +0 -35870
- package/dist/src/lib/ast/clone.js +0 -51
- package/dist/src/lib/ast/expand.js +0 -311
- package/dist/src/lib/ast/find.js +0 -192
- package/dist/src/lib/ast/node.js +0 -59
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version:
|
|
5
|
+
Version: 2.0.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { ColorType, EnumToken } from '../../ast/types.js';
|
|
@@ -11,9 +11,8 @@ import { getColorComponents } from './utils/components.js';
|
|
|
11
11
|
import { makeColor } from './utils/make-color.js';
|
|
12
12
|
import { getColorType } from './utils/color-type.js';
|
|
13
13
|
import { equalsIgnoreCase } from '../../parser/utils/text.js';
|
|
14
|
-
import { cloneNode } from '../../ast/clone.js';
|
|
15
|
-
import { walkValues } from '../../ast/walk.js';
|
|
16
14
|
import { evaluate } from '../../ast/math/expression.js';
|
|
15
|
+
import { ValueWalker } from '../../ast/walk.js';
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
* Compute alpha color
|
|
@@ -21,28 +20,30 @@ import { evaluate } from '../../ast/math/expression.js';
|
|
|
21
20
|
* @param alpha
|
|
22
21
|
* @returns
|
|
23
22
|
*/
|
|
24
|
-
function alpha(color, alpha) {
|
|
23
|
+
function alpha(arena, color, alpha) {
|
|
25
24
|
if (alpha == null) {
|
|
26
25
|
return color;
|
|
27
26
|
}
|
|
28
27
|
// https://www.w3.org/TR/css-color-5/#:~:text=There%20is%20no%20relative%20device%2Dcmyk%28%29%20syntax
|
|
29
|
-
if (color
|
|
28
|
+
if (arena.colorType[color] === ColorType.DEVICE_CMYK) {
|
|
30
29
|
return null;
|
|
31
30
|
}
|
|
32
|
-
let components = getColorComponents(color);
|
|
33
|
-
if (alpha
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
let components = getColorComponents(arena, color);
|
|
32
|
+
if (arena.dataTypes[alpha] === EnumToken.MathFunctionTokenType) {
|
|
33
|
+
// inlined: arena.walkValues(arena.tokens(alpha))
|
|
34
|
+
for (const value of new ValueWalker(arena, arena.tokens(alpha))) {
|
|
35
|
+
if (arena.dataTypes[value] === EnumToken.IdenTokenType) {
|
|
36
|
+
if (equalsIgnoreCase(arena.strings[arena.stringValue[value]], "alpha")) {
|
|
37
|
+
// replace the identifier with the alpha value
|
|
38
|
+
if (components?.[3]) {
|
|
39
|
+
arena.copyToken(value, components[3]);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
arena.resetToken(value, EnumToken.NumberTokenType, 1);
|
|
43
|
+
}
|
|
43
44
|
// continue;
|
|
44
45
|
}
|
|
45
|
-
// else if (equalsIgnoreCase(
|
|
46
|
+
// else if (equalsIgnoreCase(arena.strings[arena.stringValue[value]], "none")) {
|
|
46
47
|
// Object.assign(value, {
|
|
47
48
|
// typ: EnumToken.NumberTokenType,
|
|
48
49
|
// val: 0,
|
|
@@ -50,7 +51,7 @@ function alpha(color, alpha) {
|
|
|
50
51
|
// }
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
|
-
const result = evaluate([alpha]);
|
|
54
|
+
const result = evaluate(arena, [alpha]);
|
|
54
55
|
if (result.length == 1) {
|
|
55
56
|
alpha = result[0];
|
|
56
57
|
}
|
|
@@ -60,43 +61,41 @@ function alpha(color, alpha) {
|
|
|
60
61
|
// }
|
|
61
62
|
}
|
|
62
63
|
// console.error({ alpha });
|
|
63
|
-
if (alpha
|
|
64
|
-
alpha
|
|
65
|
-
alpha
|
|
64
|
+
if (arena.dataTypes[alpha] !== EnumToken.IdenTokenType &&
|
|
65
|
+
arena.dataTypes[alpha] !== EnumToken.NumberTokenType &&
|
|
66
|
+
arena.dataTypes[alpha] !== EnumToken.PercentageTokenType) {
|
|
66
67
|
return null;
|
|
67
68
|
}
|
|
68
|
-
if (alpha
|
|
69
|
-
if (equalsIgnoreCase(alpha
|
|
70
|
-
equalsIgnoreCase(alpha
|
|
71
|
-
equalsIgnoreCase(alpha
|
|
69
|
+
if (arena.dataTypes[alpha] === EnumToken.IdenTokenType) {
|
|
70
|
+
if (equalsIgnoreCase(arena.strings[arena.stringValue[alpha]], "NaN") ||
|
|
71
|
+
equalsIgnoreCase(arena.strings[arena.stringValue[alpha]], "Infinity") ||
|
|
72
|
+
equalsIgnoreCase(arena.strings[arena.stringValue[alpha]], "-Infinity")) {
|
|
72
73
|
return null;
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
|
-
if (color
|
|
76
|
-
|
|
77
|
-
if (
|
|
76
|
+
if (arena.colorType[color] === ColorType.COLOR_MIX || arena.strings[arena.unit[color]] === "rel") {
|
|
77
|
+
const converted = convertColor(arena, color, getColorType(arena, color));
|
|
78
|
+
if (converted == null) {
|
|
78
79
|
return null;
|
|
79
80
|
}
|
|
80
|
-
|
|
81
|
+
color = converted;
|
|
82
|
+
components = getColorComponents(arena, color);
|
|
81
83
|
}
|
|
82
84
|
if (components == null) {
|
|
83
85
|
return null;
|
|
84
86
|
}
|
|
85
|
-
if (alpha
|
|
86
|
-
// if (equalsIgnoreCase(
|
|
87
|
+
if (arena.dataTypes[alpha] === EnumToken.IdenTokenType) {
|
|
88
|
+
// if (equalsIgnoreCase(arena.strings[arena.stringValue[alpha]], "alpha")) {
|
|
87
89
|
// alpha = components[3] ?? {
|
|
88
90
|
// typ: EnumToken.NumberTokenType,
|
|
89
91
|
// val: 1,
|
|
90
92
|
// };
|
|
91
93
|
// } else
|
|
92
|
-
if (equalsIgnoreCase(alpha
|
|
93
|
-
|
|
94
|
-
typ: EnumToken.NumberTokenType,
|
|
95
|
-
val: 0,
|
|
96
|
-
});
|
|
94
|
+
if (equalsIgnoreCase(arena.strings[arena.stringValue[alpha]], "none")) {
|
|
95
|
+
arena.resetToken(alpha, EnumToken.NumberTokenType, 0);
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
|
-
return makeColor(color
|
|
98
|
+
return makeColor(arena, arena.colorType[color], components, alpha);
|
|
100
99
|
}
|
|
101
100
|
|
|
102
101
|
export { alpha };
|
|
@@ -2,69 +2,69 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version:
|
|
5
|
+
Version: 2.0.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { EnumToken, ColorType } from '../../ast/types.js';
|
|
9
9
|
import { color2srgbvalues } from './color.js';
|
|
10
10
|
import { lch2srgbvalues, lab2srgbvalues, oklch2srgbvalues, oklab2srgbvalues, hwb2srgbvalues, rgb2srgbvalues } from './srgb.js';
|
|
11
11
|
import { hsl2srgbvalues } from './rgb.js';
|
|
12
12
|
|
|
13
|
-
function rgb2cmykToken(token) {
|
|
14
|
-
let components = rgb2srgbvalues(token);
|
|
13
|
+
function rgb2cmykToken(arena, token) {
|
|
14
|
+
let components = rgb2srgbvalues(arena, token);
|
|
15
15
|
if (components == null || components.length < 3) {
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
|
-
return cmyktoken(srgb2cmykvalues(components[0], components[1], components[2], components[3]));
|
|
18
|
+
return cmyktoken(arena, srgb2cmykvalues(components[0], components[1], components[2], components[3]));
|
|
19
19
|
}
|
|
20
|
-
function hsl2cmykToken(token) {
|
|
21
|
-
let values = hsl2srgbvalues(token);
|
|
20
|
+
function hsl2cmykToken(arena, token) {
|
|
21
|
+
let values = hsl2srgbvalues(arena, token);
|
|
22
22
|
if (values == null) {
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
25
|
-
return cmyktoken(srgb2cmykvalues(values[0], values[1], values[2], values[3]));
|
|
25
|
+
return cmyktoken(arena, srgb2cmykvalues(values[0], values[1], values[2], values[3]));
|
|
26
26
|
}
|
|
27
|
-
function hwb2cmykToken(token) {
|
|
28
|
-
const values = hwb2srgbvalues(token);
|
|
27
|
+
function hwb2cmykToken(arena, token) {
|
|
28
|
+
const values = hwb2srgbvalues(arena, token);
|
|
29
29
|
if (values == null) {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
|
-
return cmyktoken(srgb2cmykvalues(values[0], values[1], values[2], values[3]));
|
|
32
|
+
return cmyktoken(arena, srgb2cmykvalues(values[0], values[1], values[2], values[3]));
|
|
33
33
|
}
|
|
34
|
-
function lab2cmykToken(token) {
|
|
35
|
-
const components = lab2srgbvalues(token);
|
|
34
|
+
function lab2cmykToken(arena, token) {
|
|
35
|
+
const components = lab2srgbvalues(arena, token);
|
|
36
36
|
if (components == null || components.length < 3) {
|
|
37
37
|
return null;
|
|
38
38
|
}
|
|
39
|
-
return cmyktoken(srgb2cmykvalues(components[0], components[1], components[2], components[3]));
|
|
39
|
+
return cmyktoken(arena, srgb2cmykvalues(components[0], components[1], components[2], components[3]));
|
|
40
40
|
}
|
|
41
|
-
function lch2cmykToken(token) {
|
|
42
|
-
const components = lch2srgbvalues(token);
|
|
41
|
+
function lch2cmykToken(arena, token) {
|
|
42
|
+
const components = lch2srgbvalues(arena, token);
|
|
43
43
|
if (components == null || components.length < 3) {
|
|
44
44
|
return null;
|
|
45
45
|
}
|
|
46
|
-
return cmyktoken(srgb2cmykvalues(components[0], components[1], components[2], components[3]));
|
|
46
|
+
return cmyktoken(arena, srgb2cmykvalues(components[0], components[1], components[2], components[3]));
|
|
47
47
|
}
|
|
48
|
-
function oklab2cmyk(token) {
|
|
49
|
-
const components = oklab2srgbvalues(token);
|
|
48
|
+
function oklab2cmyk(arena, token) {
|
|
49
|
+
const components = oklab2srgbvalues(arena, token);
|
|
50
50
|
if (components == null || components.length < 3) {
|
|
51
51
|
return null;
|
|
52
52
|
}
|
|
53
|
-
return cmyktoken(srgb2cmykvalues(components[0], components[1], components[2], components[3]));
|
|
53
|
+
return cmyktoken(arena, srgb2cmykvalues(components[0], components[1], components[2], components[3]));
|
|
54
54
|
}
|
|
55
|
-
function oklch2cmykToken(token) {
|
|
56
|
-
const components = oklch2srgbvalues(token);
|
|
55
|
+
function oklch2cmykToken(arena, token) {
|
|
56
|
+
const components = oklch2srgbvalues(arena, token);
|
|
57
57
|
if (components == null || components.length < 3) {
|
|
58
58
|
return null;
|
|
59
59
|
}
|
|
60
|
-
return cmyktoken(srgb2cmykvalues(components[0], components[1], components[2], components[3]));
|
|
60
|
+
return cmyktoken(arena, srgb2cmykvalues(components[0], components[1], components[2], components[3]));
|
|
61
61
|
}
|
|
62
|
-
function color2cmykToken(token) {
|
|
63
|
-
const values = color2srgbvalues(token);
|
|
62
|
+
function color2cmykToken(arena, token) {
|
|
63
|
+
const values = color2srgbvalues(arena, token);
|
|
64
64
|
if (values == null) {
|
|
65
65
|
return null;
|
|
66
66
|
}
|
|
67
|
-
return cmyktoken(srgb2cmykvalues(values[0], values[1], values[2], values[3]));
|
|
67
|
+
return cmyktoken(arena, srgb2cmykvalues(values[0], values[1], values[2], values[3]));
|
|
68
68
|
}
|
|
69
69
|
function srgb2cmykvalues(r, g, b, a = null) {
|
|
70
70
|
const k = 1 - Math.max(r, g, b);
|
|
@@ -78,32 +78,15 @@ function srgb2cmykvalues(r, g, b, a = null) {
|
|
|
78
78
|
}
|
|
79
79
|
return result;
|
|
80
80
|
}
|
|
81
|
-
function cmyktoken(values) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
val: curr * 100,
|
|
92
|
-
},
|
|
93
|
-
]
|
|
94
|
-
: [
|
|
95
|
-
...acc,
|
|
96
|
-
{
|
|
97
|
-
typ: EnumToken.LiteralTokenType,
|
|
98
|
-
val: "/",
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
typ: EnumToken.PercentageTokenType,
|
|
102
|
-
val: curr * 100,
|
|
103
|
-
},
|
|
104
|
-
], []),
|
|
105
|
-
kin: ColorType.DEVICE_CMYK,
|
|
106
|
-
};
|
|
81
|
+
function cmyktoken(arena, values) {
|
|
82
|
+
const chi = [];
|
|
83
|
+
for (let index = 0; index < values.length; index++) {
|
|
84
|
+
if (index == 4) {
|
|
85
|
+
chi.push(arena.createToken(EnumToken.LiteralTokenType, "/"));
|
|
86
|
+
}
|
|
87
|
+
chi.push(arena.createToken(EnumToken.PercentageTokenType, values[index] * 100));
|
|
88
|
+
}
|
|
89
|
+
return arena.createColor("device-cmyk", ColorType.DEVICE_CMYK, chi);
|
|
107
90
|
}
|
|
108
91
|
|
|
109
92
|
export { color2cmykToken, hsl2cmykToken, hwb2cmykToken, lab2cmykToken, lch2cmykToken, oklab2cmyk, oklch2cmykToken, rgb2cmykToken, srgb2cmykvalues };
|