@tbela99/css-parser 1.4.2 → 1.4.4
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 +354 -4
- package/README.md +69 -1077
- package/dist/config.json.js +76 -3
- package/dist/index-umd-web.js +26838 -18743
- package/dist/index.cjs +26819 -18731
- package/dist/index.d.ts +2471 -1884
- package/dist/lib/ast/clone.js +46 -0
- package/dist/lib/ast/expand.js +90 -65
- package/dist/lib/ast/features/calc.js +86 -43
- package/dist/lib/ast/features/if.js +221 -0
- package/dist/lib/ast/features/index.js +1 -0
- package/dist/lib/ast/features/inlinecssvariables.js +33 -28
- package/dist/lib/ast/features/prefix.js +406 -44
- package/dist/lib/ast/features/shorthand.js +6 -9
- package/dist/lib/ast/features/transform.js +14 -15
- package/dist/lib/ast/find.js +175 -0
- package/dist/lib/ast/math/expression.js +145 -99
- package/dist/lib/ast/math/math.js +30 -41
- package/dist/lib/ast/minify.js +551 -232
- package/dist/lib/ast/transform/compute.js +82 -69
- package/dist/lib/ast/transform/matrix.js +12 -26
- package/dist/lib/ast/transform/minify.js +154 -150
- 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 +3 -2
- package/dist/lib/ast/types.js +345 -30
- package/dist/lib/ast/walk.js +119 -64
- package/dist/lib/fs/resolve.js +94 -88
- package/dist/lib/parser/declaration/list.js +117 -26
- package/dist/lib/parser/declaration/map.js +141 -96
- package/dist/lib/parser/declaration/set.js +30 -25
- package/dist/lib/parser/parse.js +1810 -1739
- package/dist/lib/parser/tokenize.js +662 -403
- package/dist/lib/parser/utils/angle.js +29 -0
- package/dist/lib/parser/utils/at-rule-container.js +486 -0
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
- package/dist/lib/parser/utils/at-rule-generic.js +118 -0
- package/dist/lib/parser/utils/at-rule-import.js +393 -0
- package/dist/lib/parser/utils/at-rule-media.js +603 -0
- package/dist/lib/parser/utils/at-rule-support.js +431 -0
- package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
- package/dist/lib/parser/utils/at-rule.js +31 -0
- package/dist/lib/parser/utils/cache.js +19 -0
- package/dist/lib/parser/utils/config.js +1 -0
- package/dist/lib/parser/utils/declaration.js +672 -91
- package/dist/lib/parser/utils/hash.js +1 -1
- package/dist/lib/parser/utils/selector.js +518 -0
- package/dist/lib/parser/utils/text.js +17 -1
- package/dist/lib/parser/utils/token.js +104 -0
- package/dist/lib/parser/utils/type.js +29 -18
- package/dist/lib/renderer/render.js +870 -269
- package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
- package/dist/lib/syntax/color/a98rgb.js +8 -12
- package/dist/lib/syntax/color/alpha.js +64 -0
- package/dist/lib/syntax/color/cmyk.js +23 -21
- package/dist/lib/syntax/color/color-mix.js +311 -237
- package/dist/lib/syntax/color/color.js +98 -92
- package/dist/lib/syntax/color/hex.js +29 -33
- package/dist/lib/syntax/color/hsl.js +7 -14
- package/dist/lib/syntax/color/hwb.js +14 -27
- package/dist/lib/syntax/color/lab.js +23 -24
- package/dist/lib/syntax/color/lch.js +16 -18
- package/dist/lib/syntax/color/oklab.js +21 -40
- package/dist/lib/syntax/color/oklch.js +16 -18
- package/dist/lib/syntax/color/p3.js +0 -8
- package/dist/lib/syntax/color/rec2020.js +9 -13
- package/dist/lib/syntax/color/relativecolor.js +160 -48
- package/dist/lib/syntax/color/rgb.js +14 -18
- package/dist/lib/syntax/color/srgb.js +30 -29
- package/dist/lib/syntax/color/utils/color-type.js +18 -0
- package/dist/lib/syntax/color/utils/colorspace.js +46 -0
- package/dist/lib/syntax/color/utils/components.js +36 -16
- package/dist/lib/syntax/color/utils/distance.js +21 -11
- package/dist/lib/syntax/color/utils/make-color.js +56 -0
- package/dist/lib/syntax/color/xyz.js +10 -22
- package/dist/lib/syntax/color/xyzd50.js +6 -20
- package/dist/lib/syntax/constants.js +464 -0
- package/dist/lib/syntax/syntax.js +825 -592
- package/dist/lib/validation/config.js +72 -33
- package/dist/lib/validation/config.json.js +1185 -85
- package/dist/lib/validation/match.js +3120 -0
- package/dist/lib/validation/parser/parse.js +683 -935
- package/dist/lib/validation/parser/typedef.js +106 -0
- package/dist/lib/validation/utils/list.js +4 -11
- package/dist/lib/validation/utils/whitespace.js +2 -8
- package/dist/node.js +102 -57
- package/dist/web.js +100 -48
- package/package.json +31 -17
- package/dist/lib/syntax/color/utils/constants.js +0 -214
- package/dist/lib/syntax/utils.js +0 -70
- package/dist/lib/validation/at-rules/container.js +0 -342
- package/dist/lib/validation/at-rules/counter-style.js +0 -90
- package/dist/lib/validation/at-rules/custom-media.js +0 -50
- package/dist/lib/validation/at-rules/document.js +0 -89
- package/dist/lib/validation/at-rules/else.js +0 -5
- package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
- package/dist/lib/validation/at-rules/import.js +0 -150
- package/dist/lib/validation/at-rules/keyframes.js +0 -67
- package/dist/lib/validation/at-rules/layer.js +0 -41
- package/dist/lib/validation/at-rules/media.js +0 -255
- package/dist/lib/validation/at-rules/namespace.js +0 -81
- package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
- package/dist/lib/validation/at-rules/page.js +0 -100
- package/dist/lib/validation/at-rules/supports.js +0 -295
- package/dist/lib/validation/at-rules/when.js +0 -185
- package/dist/lib/validation/atrule.js +0 -184
- package/dist/lib/validation/selector.js +0 -36
- package/dist/lib/validation/syntax.js +0 -1073
- package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
- package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
- package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
- package/dist/lib/validation/syntaxes/family-name.js +0 -57
- package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
- package/dist/lib/validation/syntaxes/layer-name.js +0 -57
- package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
- package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
- package/dist/lib/validation/syntaxes/selector-list.js +0 -5
- package/dist/lib/validation/syntaxes/selector.js +0 -5
- package/dist/lib/validation/syntaxes/url.js +0 -40
|
@@ -23,7 +23,7 @@ class SourceMap {
|
|
|
23
23
|
* Map
|
|
24
24
|
* @private
|
|
25
25
|
*/
|
|
26
|
-
#map = new Map;
|
|
26
|
+
#map = new Map();
|
|
27
27
|
/**
|
|
28
28
|
* Line
|
|
29
29
|
* @private
|
|
@@ -35,7 +35,7 @@ class SourceMap {
|
|
|
35
35
|
* @param original
|
|
36
36
|
*/
|
|
37
37
|
add(source, original) {
|
|
38
|
-
if (original.src !==
|
|
38
|
+
if (original.src !== "") {
|
|
39
39
|
if (!this.#sources.includes(original.src)) {
|
|
40
40
|
this.#sources.push(original.src);
|
|
41
41
|
}
|
|
@@ -45,12 +45,22 @@ class SourceMap {
|
|
|
45
45
|
this.#line = line;
|
|
46
46
|
}
|
|
47
47
|
if (!this.#map.has(line)) {
|
|
48
|
-
record = [
|
|
48
|
+
record = [
|
|
49
|
+
Math.max(0, source.sta.col - 1),
|
|
50
|
+
this.#sources.indexOf(original.src),
|
|
51
|
+
original.sta.lin - 1,
|
|
52
|
+
original.sta.col - 1,
|
|
53
|
+
];
|
|
49
54
|
this.#map.set(line, [record]);
|
|
50
55
|
}
|
|
51
56
|
else {
|
|
52
57
|
const arr = this.#map.get(line);
|
|
53
|
-
record = [
|
|
58
|
+
record = [
|
|
59
|
+
Math.max(0, source.sta.col - 1 - arr[0][0]),
|
|
60
|
+
this.#sources.indexOf(original.src) - arr[0][1],
|
|
61
|
+
original.sta.lin - 1,
|
|
62
|
+
original.sta.col - 1,
|
|
63
|
+
];
|
|
54
64
|
arr.push(record);
|
|
55
65
|
}
|
|
56
66
|
if (this.lastLocation != null) {
|
|
@@ -75,16 +85,16 @@ class SourceMap {
|
|
|
75
85
|
let i = 0;
|
|
76
86
|
for (; i <= this.#line; i++) {
|
|
77
87
|
if (!this.#map.has(i)) {
|
|
78
|
-
mappings.push(
|
|
88
|
+
mappings.push("");
|
|
79
89
|
}
|
|
80
90
|
else {
|
|
81
|
-
mappings.push(this.#map.get(i).reduce((acc, curr) => acc + (acc ===
|
|
91
|
+
mappings.push(this.#map.get(i).reduce((acc, curr) => acc + (acc === "" ? "" : ",") + encode(curr), ""));
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
return {
|
|
85
95
|
version: this.#version,
|
|
86
96
|
sources: this.#sources.slice(),
|
|
87
|
-
mappings: mappings.join(
|
|
97
|
+
mappings: mappings.join(";"),
|
|
88
98
|
};
|
|
89
99
|
}
|
|
90
100
|
}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { xyz2srgb } from './srgb.js';
|
|
2
2
|
import { multiplyMatrices } from './utils/matrix.js';
|
|
3
|
-
import './utils/constants.js';
|
|
4
|
-
import '../../ast/types.js';
|
|
5
|
-
import '../../ast/minify.js';
|
|
6
|
-
import '../../ast/walk.js';
|
|
7
|
-
import '../../parser/parse.js';
|
|
8
|
-
import '../../parser/tokenize.js';
|
|
9
|
-
import '../../parser/utils/config.js';
|
|
10
3
|
import { srgb2xyz } from './xyz.js';
|
|
11
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
12
4
|
|
|
13
5
|
function a98rgb2srgbvalues(r, g, b, a = null) {
|
|
14
6
|
// @ts-ignore
|
|
@@ -23,21 +15,25 @@ function a98rgb2la98(r, g, b, a = null) {
|
|
|
23
15
|
// convert an array of a98-rgb values in the range 0.0 - 1.0
|
|
24
16
|
// to linear light (un-companded) form.
|
|
25
17
|
// negative values are also now accepted
|
|
26
|
-
return [r, g, b]
|
|
18
|
+
return [r, g, b]
|
|
19
|
+
.map(function (val) {
|
|
27
20
|
let sign = val < 0 ? -1 : 1;
|
|
28
21
|
let abs = Math.abs(val);
|
|
29
22
|
return sign * Math.pow(abs, 563 / 256);
|
|
30
|
-
})
|
|
23
|
+
})
|
|
24
|
+
.concat(a == null || a == 1 ? [] : [a]);
|
|
31
25
|
}
|
|
32
26
|
function la98rgb2a98rgb(r, g, b, a = null) {
|
|
33
27
|
// convert an array of linear-light a98-rgb in the range 0.0-1.0
|
|
34
28
|
// to gamma corrected form
|
|
35
29
|
// negative values are also now accepted
|
|
36
|
-
return [r, b, g]
|
|
30
|
+
return [r, b, g]
|
|
31
|
+
.map(function (val) {
|
|
37
32
|
let sign = val < 0 ? -1 : 1;
|
|
38
33
|
let abs = Math.abs(val);
|
|
39
34
|
return sign * Math.pow(abs, 256 / 563);
|
|
40
|
-
})
|
|
35
|
+
})
|
|
36
|
+
.concat(a == null || a == 1 ? [] : [a]);
|
|
41
37
|
}
|
|
42
38
|
function la98rgb2xyz(r, g, b, a = null) {
|
|
43
39
|
// convert an array of linear-light a98-rgb values to CIE XYZ
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ColorType, EnumToken } from '../../ast/types.js';
|
|
2
|
+
import { convertColor } from './color.js';
|
|
3
|
+
import { getColorComponents } from './utils/components.js';
|
|
4
|
+
import { makeColor } from './utils/make-color.js';
|
|
5
|
+
import { getColorType } from './utils/color-type.js';
|
|
6
|
+
import { equalsIgnoreCase } from '../../parser/utils/text.js';
|
|
7
|
+
import { cloneNode } from '../../ast/clone.js';
|
|
8
|
+
import { walkValues } from '../../ast/walk.js';
|
|
9
|
+
import { replaceNodeOrValue } from '../../parser/utils/token.js';
|
|
10
|
+
import { evaluate } from '../../ast/math/expression.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Compute alpha color
|
|
14
|
+
* @param color
|
|
15
|
+
* @param alpha
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
function alpha(color, alpha) {
|
|
19
|
+
if (alpha == null) {
|
|
20
|
+
return color;
|
|
21
|
+
}
|
|
22
|
+
if (color.kin === ColorType.DEVICE_CMYK) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (alpha == null) {
|
|
26
|
+
return color;
|
|
27
|
+
}
|
|
28
|
+
if (color.kin === ColorType.COLOR_MIX || color.cal === "rel") {
|
|
29
|
+
color = convertColor(color, getColorType(color));
|
|
30
|
+
if (color == null) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const components = getColorComponents(color);
|
|
35
|
+
if (components == null) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
if (alpha.typ === EnumToken.IdenTokenType && equalsIgnoreCase(alpha.val, "alpha")) {
|
|
39
|
+
alpha = components[3] ?? {
|
|
40
|
+
typ: EnumToken.NumberTokenType,
|
|
41
|
+
val: 1,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
else if (alpha.typ === EnumToken.MathFunctionTokenType &&
|
|
45
|
+
equalsIgnoreCase(alpha.val, "calc")) {
|
|
46
|
+
alpha = cloneNode(alpha, true);
|
|
47
|
+
const alphaValue = components[3] ?? {
|
|
48
|
+
typ: EnumToken.NumberTokenType,
|
|
49
|
+
val: 1,
|
|
50
|
+
};
|
|
51
|
+
for (const { value, parent } of walkValues(alpha.chi, alpha)) {
|
|
52
|
+
if (value.typ === EnumToken.IdenTokenType && equalsIgnoreCase(value.val, "alpha")) {
|
|
53
|
+
replaceNodeOrValue(parent, value, alphaValue);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const result = evaluate([alpha]);
|
|
57
|
+
if (result.length == 1) {
|
|
58
|
+
alpha = result[0];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return makeColor(color.kin, components, alpha);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { alpha };
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { ColorType, EnumToken } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
2
|
import { color2srgbvalues, toPrecisionValue } from './color.js';
|
|
8
|
-
import { hsl2srgbvalues } from './rgb.js';
|
|
9
|
-
import './utils/constants.js';
|
|
10
3
|
import { lch2srgbvalues, lab2srgbvalues, oklch2srgbvalues, oklab2srgbvalues, hwb2srgbvalues, rgb2srgbvalues } from './srgb.js';
|
|
11
|
-
import '
|
|
4
|
+
import { hsl2srgbvalues } from './rgb.js';
|
|
12
5
|
|
|
13
6
|
function rgb2cmykToken(token) {
|
|
14
7
|
const components = rgb2srgbvalues(token);
|
|
@@ -88,19 +81,28 @@ function srgb2cmykvalues(r, g, b, a = null) {
|
|
|
88
81
|
function cmyktoken(values) {
|
|
89
82
|
return {
|
|
90
83
|
typ: EnumToken.ColorTokenType,
|
|
91
|
-
val:
|
|
92
|
-
chi: values.reduce((acc, curr, index) => index < 4
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
84
|
+
val: "device-cmyk",
|
|
85
|
+
chi: values.reduce((acc, curr, index) => index < 4
|
|
86
|
+
? [
|
|
87
|
+
...acc,
|
|
88
|
+
{
|
|
89
|
+
typ: EnumToken.PercentageTokenType,
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
val: toPrecisionValue(curr * 100),
|
|
92
|
+
},
|
|
93
|
+
]
|
|
94
|
+
: [
|
|
95
|
+
...acc,
|
|
96
|
+
{
|
|
97
|
+
typ: EnumToken.LiteralTokenType,
|
|
98
|
+
val: "/",
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
typ: EnumToken.PercentageTokenType,
|
|
102
|
+
val: toPrecisionValue(curr, 2) * 100,
|
|
103
|
+
},
|
|
104
|
+
], []),
|
|
105
|
+
kin: ColorType.DEVICE_CMYK,
|
|
104
106
|
};
|
|
105
107
|
}
|
|
106
108
|
|