@tbela99/css-parser 2.0.1 → 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 +86 -1
- package/README.md +15 -7
- package/architecture.png +0 -0
- package/dist/{src/data → data}/properties.json.js +86 -2
- package/dist/{src/data → data}/validation.json.js +4848 -3750
- package/dist/index-umd-web.js +18234 -9498
- package/dist/index.d.ts +1251 -373
- package/dist/{src/lib → lib}/ast/arena-node.js +119 -57
- package/dist/{src/lib → lib}/ast/arena.js +1034 -655
- package/dist/{src/lib → lib}/ast/cache.js +36 -31
- package/dist/{src/lib → lib}/ast/features/calc.js +37 -27
- package/dist/{src/lib → lib}/ast/features/if.js +24 -19
- package/dist/{src/lib → lib}/ast/features/index.js +3 -2
- package/dist/{src/lib → lib}/ast/features/inlinecssvariables.js +42 -23
- package/dist/lib/ast/features/mixin.js +953 -0
- package/dist/{src/lib → lib}/ast/features/prefix.js +82 -69
- 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 +150 -150
- package/dist/{src/lib → lib}/ast/math/math.js +8 -8
- package/dist/{src/lib → lib}/ast/minify.js +932 -354
- 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 +7 -15
- package/dist/{src/lib → lib}/ast/walk.js +19 -19
- package/dist/{src/lib → lib}/fs/resolve.js +15 -15
- package/dist/{src/lib → lib}/parser/declaration/list.js +55 -26
- package/dist/{src/lib → lib}/parser/declaration/map.js +85 -72
- package/dist/{src/lib → lib}/parser/declaration/set.js +32 -27
- package/dist/lib/parser/input.js +85 -0
- package/dist/{src/lib → lib}/parser/linesmap.js +3 -16
- package/dist/{src/lib → lib}/parser/parse.js +852 -619
- package/dist/lib/parser/source.js +71 -0
- package/dist/{src/lib → lib}/parser/tokenize.js +886 -722
- package/dist/{src/lib → lib}/parser/utils/angle.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-container.js +68 -35
- 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 +31 -13
- package/dist/{src/lib → lib}/parser/utils/at-rule-import.js +29 -16
- package/dist/{src/lib → lib}/parser/utils/at-rule-media.js +77 -58
- package/dist/{src/lib → lib}/parser/utils/at-rule-support.js +18 -20
- package/dist/{src/lib → lib}/parser/utils/at-rule-when-else.js +9 -8
- 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 +67 -49
- package/dist/{src/lib → lib}/parser/utils/eq.js +14 -14
- package/dist/{src/lib → lib}/parser/utils/hash.js +4 -4
- package/dist/lib/parser/utils/selector.js +720 -0
- 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 +11 -9
- package/dist/{src/lib → lib}/printer/render.js +536 -243
- package/dist/lib/printer/result.js +148 -0
- package/dist/{src/lib → lib}/printer/sourcemap/lib/codec.js +5 -8
- package/dist/{src/lib → lib}/printer/sourcemap/sourcemap.js +13 -13
- package/dist/lib/printer/writer.js +252 -0
- package/dist/{src/lib → lib}/syntax/color/a98rgb.js +6 -6
- package/dist/{src/lib → lib}/syntax/color/alpha.js +12 -11
- package/dist/{src/lib → lib}/syntax/color/cmyk.js +11 -6
- package/dist/{src/lib → lib}/syntax/color/color-mix.js +78 -67
- package/dist/{src/lib → lib}/syntax/color/color.js +52 -47
- package/dist/{src/lib → lib}/syntax/color/hex.js +17 -17
- package/dist/{src/lib → lib}/syntax/color/hsl.js +8 -8
- package/dist/{src/lib → lib}/syntax/color/hwb.js +6 -7
- package/dist/{src/lib → lib}/syntax/color/lab.js +8 -8
- package/dist/{src/lib → lib}/syntax/color/lch.js +12 -11
- package/dist/{src/lib → lib}/syntax/color/oklab.js +9 -9
- package/dist/{src/lib → lib}/syntax/color/oklch.js +5 -5
- package/dist/{src/lib → lib}/syntax/color/p3.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/prophotorgb.js +4 -4
- package/dist/{src/lib → lib}/syntax/color/rec2020.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/relative-color.js +41 -34
- package/dist/{src/lib → lib}/syntax/color/rgb.js +17 -17
- package/dist/{src/lib → lib}/syntax/color/srgb.js +20 -20
- package/dist/{src/lib → lib}/syntax/color/utils/color-type.js +6 -4
- package/dist/{src/lib → lib}/syntax/color/utils/colorspace.js +12 -14
- package/dist/{src/lib → lib}/syntax/color/utils/components.js +13 -13
- package/dist/{src/lib → lib}/syntax/color/utils/distance.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/utils/make-color.js +6 -4
- package/dist/{src/lib → lib}/syntax/color/utils/matrix.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/xyz.js +5 -10
- package/dist/{src/lib → lib}/syntax/color/xyzd50.js +3 -3
- package/dist/{src/lib → lib}/syntax/constants.js +30 -3
- package/dist/{src/lib → lib}/syntax/syntax.js +151 -116
- package/dist/lib/validation/config.js +173 -0
- package/dist/lib/validation/first.js +571 -0
- package/dist/{src/lib → lib}/validation/match.js +1256 -579
- package/dist/{src/lib → lib}/validation/parser/parse.js +85 -59
- package/dist/{src/lib → lib}/validation/parser/typedef.js +6 -2
- package/dist/{src/lib → lib}/validation/utils/list.js +3 -19
- package/dist/{src/node.js → node.js} +92 -80
- package/dist/{src/types.js → types.js} +2 -2
- package/dist/{src/utils → utils}/sync.js +13 -8
- package/dist/version.d.ts +4 -0
- package/dist/version.js +13 -0
- package/dist/{src/web.js → web.js} +80 -75
- package/package.json +13 -13
- package/dist/package.json.js +0 -10
- package/dist/src/lib/ast/features/shorthand.js +0 -87
- package/dist/src/lib/ast/features/transform.js +0 -85
- package/dist/src/lib/ast/transform/compute.js +0 -358
- 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/source.js +0 -127
- package/dist/src/lib/parser/utils/cache.js +0 -54
- package/dist/src/lib/parser/utils/selector.js +0 -440
- package/dist/src/lib/validation/config.js +0 -120
|
@@ -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.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { convertColor } from '../color.js';
|
|
@@ -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.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken, ColorType } from '../../../ast/types.js';
|
|
@@ -11,6 +11,7 @@ import { minmax, getNumber } from '../color.js';
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Create a color token
|
|
14
|
+
* @param arena
|
|
14
15
|
* @param kind
|
|
15
16
|
* @param components
|
|
16
17
|
* @param alpha
|
|
@@ -22,14 +23,15 @@ function makeColor(arena, kind, components, alpha) {
|
|
|
22
23
|
}
|
|
23
24
|
const alphaValue = alpha == null
|
|
24
25
|
? 1
|
|
25
|
-
: arena.dataTypes[alpha] === EnumToken.IdenTokenType &&
|
|
26
|
+
: arena.dataTypes[alpha] === EnumToken.IdenTokenType &&
|
|
27
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[alpha]), "none")
|
|
26
28
|
? 0
|
|
27
29
|
: minmax(getNumber(arena, alpha), 0, 1);
|
|
28
30
|
components.length = 3;
|
|
29
31
|
// the components may belong to another color token: a token belongs to one token list
|
|
30
32
|
for (let i = 0; i < components.length; i++) {
|
|
31
33
|
// inlined: arena.take(components[i])
|
|
32
|
-
components[i] = arena.parents[components[i]]
|
|
34
|
+
components[i] = arena.parents[components[i]] === 0 ? components[i] : arena.clone(components[i], true);
|
|
33
35
|
}
|
|
34
36
|
if (alphaValue !== 1) {
|
|
35
37
|
components.push(arena.createToken(EnumToken.NumberTokenType, alphaValue));
|
|
@@ -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.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
// from https://www.w3.org/TR/css-color-4/multiply-matrices.js
|
|
@@ -1,19 +1,14 @@
|
|
|
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.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { multiplyMatrices } from './utils/matrix.js';
|
|
9
9
|
import { srgb2lsrgbvalues } from './srgb.js';
|
|
10
10
|
import { XYZ_D65_to_D50 } from './xyzd50.js';
|
|
11
11
|
|
|
12
|
-
// export function lab2xyz(l: number, a: number, b: number, alpha?: number): number[] {
|
|
13
|
-
// const [x, y, z] = Lab_to_XYZ(l, a, b);
|
|
14
|
-
//
|
|
15
|
-
// return alpha == null || alpha == 1 ? [x, y, z] : [x, y, z, alpha];
|
|
16
|
-
// }
|
|
17
12
|
function XYZ_to_lin_sRGB(x, y, z, alpha = null) {
|
|
18
13
|
// convert XYZ to linear-light sRGB
|
|
19
14
|
const M = [
|
|
@@ -24,7 +19,7 @@ function XYZ_to_lin_sRGB(x, y, z, alpha = null) {
|
|
|
24
19
|
const XYZ = [x, y, z]; // convert to XYZ
|
|
25
20
|
return multiplyMatrices(M, XYZ)
|
|
26
21
|
.map((v) => v)
|
|
27
|
-
.concat(alpha == null || alpha
|
|
22
|
+
.concat(alpha == null || alpha === 1 ? [] : [alpha]);
|
|
28
23
|
}
|
|
29
24
|
function XYZ_D50_to_D65(x, y, z) {
|
|
30
25
|
// Bradford chromatic adaptation from D50 to D65
|
|
@@ -45,7 +40,7 @@ function srgb2xyz(r, g, b, alpha) {
|
|
|
45
40
|
0.21263900587151036 * r + 0.7151686787677559 * g + 0.07219231536073371 * b,
|
|
46
41
|
0.01933081871559185 * r + 0.11919477979462599 * g + 0.9505321522496606 * b,
|
|
47
42
|
];
|
|
48
|
-
if (alpha != null && alpha
|
|
43
|
+
if (alpha != null && alpha !== 1) {
|
|
49
44
|
rgb.push(alpha);
|
|
50
45
|
}
|
|
51
46
|
return rgb;
|
|
@@ -55,7 +50,7 @@ function srgb2xyz_d65(r, g, b, alpha) {
|
|
|
55
50
|
// xyx d65
|
|
56
51
|
let values = srgb2xyz(r, g, b);
|
|
57
52
|
let rgb = XYZ_D65_to_D50(values[0], values[1], values[2]);
|
|
58
|
-
if (alpha != null && alpha
|
|
53
|
+
if (alpha != null && alpha !== 1) {
|
|
59
54
|
rgb.push(alpha);
|
|
60
55
|
}
|
|
61
56
|
return rgb;
|
|
@@ -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.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { lsrgb2srgbvalues } from './srgb.js';
|
|
@@ -31,7 +31,7 @@ function XYZ_D65_to_D50(x, y, z, alpha = null) {
|
|
|
31
31
|
[0.02962780877005599, 0.9904344267538799, -0.017073799063418826],
|
|
32
32
|
[-0.009243040646204504, 0.015055191490298152, 0.7518742814281371],
|
|
33
33
|
];
|
|
34
|
-
return multiplyMatrices(M, [x, y, z]).concat(alpha == null || alpha
|
|
34
|
+
return multiplyMatrices(M, [x, y, z]).concat(alpha == null || alpha === 1 ? [] : [alpha]);
|
|
35
35
|
}
|
|
36
36
|
function xyzd502srgb(x, y, z, alpha = null) {
|
|
37
37
|
// @ts-ignore
|
|
@@ -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.0
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken } from '../ast/types.js';
|
|
@@ -12,6 +12,10 @@ import config from '../../data/validation.json.js';
|
|
|
12
12
|
* Used by the validation parser
|
|
13
13
|
*/
|
|
14
14
|
const LOC = Symbol.for("loc");
|
|
15
|
+
/**
|
|
16
|
+
* the units of the validation data, in their canonical spelling (`Hz`, `Q`, `dB`)
|
|
17
|
+
*/
|
|
18
|
+
const validationUnits = config.units;
|
|
15
19
|
const regMatchLinearGradient = /^-((webkit)|o|moz)(-repeating)?-linear-gradient$/i;
|
|
16
20
|
const regMatchRadialGradient = /^-((webkit)|o|moz)(-repeating)?-radial-gradient$/i;
|
|
17
21
|
const mFLT = new Set([EnumToken.LtTokenType, EnumToken.LteTokenType]);
|
|
@@ -40,6 +44,29 @@ const tokensfuncDefMap = new Map([
|
|
|
40
44
|
[EnumToken.GeneralEnclosedFunctionTokenDefType, EnumToken.GeneralEnclosedFunctionTokenType],
|
|
41
45
|
]);
|
|
42
46
|
const tokensfuncSet = new Set(tokensfuncDefMap.values());
|
|
47
|
+
/**
|
|
48
|
+
* function definition token types (the keys of {@link tokensfuncDefMap}) and function token types (the values), by
|
|
49
|
+
* token type: a typed array lookup is faster than a Map lookup
|
|
50
|
+
*/
|
|
51
|
+
const functionTypes = new Uint8Array(256);
|
|
52
|
+
for (const [def, type] of tokensfuncDefMap) {
|
|
53
|
+
functionTypes[def] |= 1;
|
|
54
|
+
functionTypes[type] |= 2;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* true if the token type is a function definition (`name(`), like `tokensfuncDefMap.has(type)`
|
|
58
|
+
* @param type
|
|
59
|
+
*/
|
|
60
|
+
function isFunctionDefType(type) {
|
|
61
|
+
return (functionTypes[type] & 1) === 1;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* true if the token type is a function, like `tokensfuncSet.has(type)`
|
|
65
|
+
* @param type
|
|
66
|
+
*/
|
|
67
|
+
function isFunctionType(type) {
|
|
68
|
+
return (functionTypes[type] & 2) === 2;
|
|
69
|
+
}
|
|
43
70
|
/**
|
|
44
71
|
* Epsilon
|
|
45
72
|
*/
|
|
@@ -492,4 +519,4 @@ const trimTokenSpace = new Set([
|
|
|
492
519
|
]);
|
|
493
520
|
const combinators = ["+", ">", "~", "||", "|"];
|
|
494
521
|
|
|
495
|
-
export { COLORS_NAMES, D50, LOC, NAMES_COLORS, 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 };
|
|
522
|
+
export { COLORS_NAMES, D50, LOC, NAMES_COLORS, anglePrecision, colorDistancePrecision, colorFuncColorSpace, colorPrecision, colorRange, colorsFunc, combinators, containerFunc, deprecatedSystemColors, e, epsilon, funcLike, gridTemplateFunc, imageFunc, isFunctionDefType, isFunctionType, k, mFGT, mFLT, mathFuncs, mediaTypes, nonStandardColors, pageMarginBoxType, pseudoElements, regMatchLinearGradient, regMatchRadialGradient, supportFunc, systemColors, timelineFunc, timingFunc, tokensMap, tokensfuncDefMap, tokensfuncSet, transformFunctions, trimTokenSpace, urlFunc, urlTokenMatcher, validationUnits, whenElseFunc, wildCardFuncs };
|