@tbela99/css-parser 2.3.0 → 2.3.2
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 +43 -0
- package/README.md +66 -21
- package/architecture.png +0 -0
- package/dist/ast/arena-node.js +32 -3
- package/dist/ast/arena.js +88 -10
- package/dist/ast/cache.js +1 -1
- package/dist/ast/features/calc.js +1 -1
- package/dist/ast/features/if.js +1 -1
- package/dist/ast/features/index.js +1 -1
- package/dist/ast/features/inlinecssvariables.js +1 -1
- package/dist/ast/features/mixin.js +1 -1
- package/dist/ast/features/prefix.js +1 -1
- package/dist/ast/features/shorthand.js +1 -1
- package/dist/ast/features/transform.js +1 -1
- package/dist/ast/features/type.js +1 -1
- package/dist/ast/math/expression.js +1 -1
- package/dist/ast/math/math.js +1 -1
- package/dist/ast/minify.js +131 -36
- package/dist/ast/mixins/custom-function.js +1 -1
- package/dist/ast/mixins/utils.js +1 -1
- package/dist/ast/mixins/variables.js +1 -1
- package/dist/ast/strings.js +26 -1
- package/dist/ast/transform/compute.js +6 -2
- package/dist/ast/transform/matrix.js +1 -1
- package/dist/ast/transform/minify.js +1 -1
- package/dist/ast/transform/perspective.js +1 -1
- package/dist/ast/transform/rotate.js +1 -1
- package/dist/ast/transform/scale.js +1 -1
- package/dist/ast/transform/skew.js +1 -1
- package/dist/ast/transform/translate.js +1 -1
- package/dist/ast/transform/utils.js +1 -1
- package/dist/ast/types.js +22 -2
- package/dist/ast/walk.js +1 -1
- package/dist/data/properties.json.js +1 -1
- package/dist/data/validation.json.js +1 -1
- package/dist/fs/resolve.js +1 -1
- package/dist/index-umd-web.js +1099 -295
- package/dist/index.d.ts +612 -688
- package/dist/node.js +14 -8
- package/dist/parser/declaration/list.js +8 -5
- package/dist/parser/declaration/map.js +1 -1
- package/dist/parser/declaration/set.js +1 -1
- package/dist/parser/input.js +62 -4
- package/dist/parser/linesmap.js +1 -1
- package/dist/parser/parse.js +121 -13
- package/dist/parser/source.js +1 -1
- package/dist/parser/tokenize.js +161 -19
- package/dist/parser/utils/angle.js +1 -1
- package/dist/parser/utils/at-rule-container.js +1 -1
- package/dist/parser/utils/at-rule-font-feature-values.js +1 -1
- package/dist/parser/utils/at-rule-generic.js +1 -1
- package/dist/parser/utils/at-rule-import.js +1 -1
- package/dist/parser/utils/at-rule-media.js +42 -2
- package/dist/parser/utils/at-rule-support.js +1 -1
- package/dist/parser/utils/at-rule-when-else.js +1 -1
- package/dist/parser/utils/at-rule.js +1 -1
- package/dist/parser/utils/base64.js +1 -1
- package/dist/parser/utils/cache.js +1 -1
- package/dist/parser/utils/canonical.js +1 -1
- package/dist/parser/utils/codes.js +1 -1
- package/dist/parser/utils/config.js +1 -1
- package/dist/parser/utils/declaration.js +1 -1
- package/dist/parser/utils/eq.js +1 -1
- package/dist/parser/utils/hash.js +1 -1
- package/dist/parser/utils/selector.js +98 -6
- package/dist/parser/utils/text.js +1 -1
- package/dist/parser/utils/token.js +1 -1
- package/dist/parser/utils/type.js +1 -1
- package/dist/printer/lib/codec.js +1 -1
- package/dist/printer/render.js +5 -7
- package/dist/printer/result.js +18 -3
- package/dist/printer/sourcemap.js +1 -1
- package/dist/printer/writer.js +1 -1
- package/dist/syntax/color/a98rgb.js +1 -1
- package/dist/syntax/color/alpha.js +1 -1
- package/dist/syntax/color/cmyk.js +1 -1
- package/dist/syntax/color/color-mix.js +1 -1
- package/dist/syntax/color/color.js +1 -1
- package/dist/syntax/color/hex.js +1 -1
- package/dist/syntax/color/hsl.js +12 -4
- package/dist/syntax/color/hwb.js +9 -3
- package/dist/syntax/color/lab.js +1 -1
- package/dist/syntax/color/lch.js +1 -1
- package/dist/syntax/color/oklab.js +1 -1
- package/dist/syntax/color/oklch.js +2 -2
- package/dist/syntax/color/p3.js +1 -1
- package/dist/syntax/color/prophotorgb.js +1 -1
- package/dist/syntax/color/rec2020.js +1 -1
- package/dist/syntax/color/relative-color.js +1 -1
- package/dist/syntax/color/rgb.js +1 -1
- package/dist/syntax/color/srgb.js +3 -2
- package/dist/syntax/color/utils/color-type.js +1 -1
- package/dist/syntax/color/utils/colorspace.js +1 -1
- package/dist/syntax/color/utils/components.js +1 -1
- package/dist/syntax/color/utils/distance.js +1 -1
- package/dist/syntax/color/utils/make-color.js +1 -1
- package/dist/syntax/color/utils/matrix.js +1 -1
- package/dist/syntax/color/xyz.js +1 -1
- package/dist/syntax/color/xyzd50.js +1 -1
- package/dist/syntax/constants.js +2 -2
- package/dist/syntax/syntax.js +1 -1
- package/dist/types.js +1 -1
- package/dist/utils/sync.js +1 -1
- package/dist/validation/compiled/builtins.js +1 -1
- package/dist/validation/compiled/runtime.js +1 -1
- package/dist/validation/compiled/syntaxes.js +1 -1
- package/dist/validation/config.js +1 -1
- package/dist/validation/first.js +1 -1
- package/dist/validation/match.js +77 -4
- package/dist/validation/parser/parse.js +1 -1
- package/dist/validation/parser/typedef.js +4 -1
- package/dist/validation/utils/list.js +1 -1
- package/dist/version.js +2 -2
- package/dist/web.js +13 -6
- package/package.json +15 -6
package/dist/printer/render.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { getAngle, convertColor } from '../syntax/color/color.js';
|
|
@@ -1734,7 +1734,8 @@ function renderToken(arena, token, options, cache, reducer, errors) {
|
|
|
1734
1734
|
key === "0 0" ||
|
|
1735
1735
|
key === "top left" ||
|
|
1736
1736
|
key === "left top") {
|
|
1737
|
-
|
|
1737
|
+
// a single value is centered vertically: both values are kept
|
|
1738
|
+
positions.splice(0, positions.length, arena.createToken(EnumToken.PercentageTokenType, 0), arena.createToken(EnumToken.WhitespaceTokenType), arena.createToken(EnumToken.PercentageTokenType, 0));
|
|
1738
1739
|
}
|
|
1739
1740
|
else if (key === "50% 0%" ||
|
|
1740
1741
|
key === "50% 0" ||
|
|
@@ -1758,7 +1759,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
|
|
|
1758
1759
|
key === "0% 100%" ||
|
|
1759
1760
|
key === "left bottom" ||
|
|
1760
1761
|
key === "bottom left") {
|
|
1761
|
-
positions.splice(0, positions.length, arena.createToken(EnumToken.
|
|
1762
|
+
positions.splice(0, positions.length, arena.createToken(EnumToken.PercentageTokenType, 0), arena.createToken(EnumToken.WhitespaceTokenType), arena.createToken(EnumToken.PercentageTokenType, 100));
|
|
1762
1763
|
}
|
|
1763
1764
|
else if (key === "50% 100%" ||
|
|
1764
1765
|
key === "center bottom" ||
|
|
@@ -1768,10 +1769,7 @@ function renderToken(arena, token, options, cache, reducer, errors) {
|
|
|
1768
1769
|
else if (key === "100% 100%" ||
|
|
1769
1770
|
key === "right bottom" ||
|
|
1770
1771
|
key === "bottom right") {
|
|
1771
|
-
positions.splice(0, positions.length, arena.createToken(EnumToken.PercentageTokenType, 100));
|
|
1772
|
-
}
|
|
1773
|
-
else if (position1 === position2) {
|
|
1774
|
-
positions.splice(0, positions.length, positions[k]);
|
|
1772
|
+
positions.splice(0, positions.length, arena.createToken(EnumToken.PercentageTokenType, 100), arena.createToken(EnumToken.WhitespaceTokenType), arena.createToken(EnumToken.PercentageTokenType, 100));
|
|
1775
1773
|
}
|
|
1776
1774
|
}
|
|
1777
1775
|
}
|
package/dist/printer/result.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
@@ -37,7 +37,16 @@ class RenderResult {
|
|
|
37
37
|
*/
|
|
38
38
|
static shape = new RenderResult(new Uint8Array(0), [], { total: "0ms" });
|
|
39
39
|
/**
|
|
40
|
-
* Rendered CSS, encoded as UTF-8
|
|
40
|
+
* Rendered CSS, encoded as UTF-8: the output of the render, no conversion. Use it to write the css to a file or to
|
|
41
|
+
* the network, or to send it to another thread without a copy:
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* self.postMessage(result.write, [result.write.buffer]);
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* It is a view of the first bytes of a larger buffer (`write.buffer`): without a transfer, `postMessage()` copies
|
|
48
|
+
* the whole buffer, send `write.slice()` to copy only the css. See
|
|
49
|
+
* [Zero copy between threads](../../files/usage.md#zero-copy-between-threads).
|
|
41
50
|
*/
|
|
42
51
|
write;
|
|
43
52
|
/**
|
|
@@ -61,6 +70,7 @@ class RenderResult {
|
|
|
61
70
|
*/
|
|
62
71
|
#codeLength;
|
|
63
72
|
/**
|
|
73
|
+
* create a render result
|
|
64
74
|
* @param write rendered css, encoded as UTF-8
|
|
65
75
|
* @param errors
|
|
66
76
|
* @param stats
|
|
@@ -84,7 +94,11 @@ class RenderResult {
|
|
|
84
94
|
return result.#codeLength >= 0 ? result.#codeLength : result.code.length;
|
|
85
95
|
}
|
|
86
96
|
/**
|
|
87
|
-
* Rendered CSS. The bytes of {@link RenderResult.write} are decoded the first time the property is read
|
|
97
|
+
* Rendered CSS. The bytes of {@link RenderResult.write} are decoded the first time the property is read, the
|
|
98
|
+
* string is kept for the next reads: no string is created when it is not read.
|
|
99
|
+
*
|
|
100
|
+
* It is a getter, not a property of the object: `postMessage()` and `structuredClone()` do not send it, and it is
|
|
101
|
+
* an empty string when it is read for the first time after {@link RenderResult.write} was transferred.
|
|
88
102
|
*/
|
|
89
103
|
get code() {
|
|
90
104
|
if (this.#code === null) {
|
|
@@ -121,6 +135,7 @@ class TransformResult extends RenderResult {
|
|
|
121
135
|
*/
|
|
122
136
|
arena;
|
|
123
137
|
/**
|
|
138
|
+
* create a transform result from the parse result and the render result
|
|
124
139
|
* @param parseResult
|
|
125
140
|
* @param renderResult
|
|
126
141
|
* @param stats
|
package/dist/printer/writer.js
CHANGED
package/dist/syntax/color/hex.js
CHANGED
package/dist/syntax/color/hsl.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { color2srgbvalues, getNumber } from './color.js';
|
|
@@ -93,6 +93,14 @@ function hslToken(arena, values) {
|
|
|
93
93
|
}
|
|
94
94
|
return arena.createColor("hsl", ColorType.HSL, chi);
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* value of a red, green or blue component of an `rgb()` color, from 0 to 255: `100%` is 255
|
|
98
|
+
* @param arena
|
|
99
|
+
* @param token
|
|
100
|
+
*/
|
|
101
|
+
function rgbChannel(arena, token) {
|
|
102
|
+
return (arena.dataTypes[token] === EnumToken.PercentageTokenType ? 255 : 1) * getNumber(arena, token);
|
|
103
|
+
}
|
|
96
104
|
function rgb2hslvalues(arena, token) {
|
|
97
105
|
const chi = getColorComponents(arena, token);
|
|
98
106
|
if (chi == null || chi.length < 3) {
|
|
@@ -101,15 +109,15 @@ function rgb2hslvalues(arena, token) {
|
|
|
101
109
|
// @ts-ignore
|
|
102
110
|
let t = chi[0];
|
|
103
111
|
// @ts-ignore
|
|
104
|
-
let r =
|
|
112
|
+
let r = rgbChannel(arena, t);
|
|
105
113
|
// @ts-ignore
|
|
106
114
|
t = chi[1];
|
|
107
115
|
// @ts-ignore
|
|
108
|
-
let g =
|
|
116
|
+
let g = rgbChannel(arena, t);
|
|
109
117
|
// @ts-ignore
|
|
110
118
|
t = chi[2];
|
|
111
119
|
// @ts-ignore
|
|
112
|
-
let b =
|
|
120
|
+
let b = rgbChannel(arena, t);
|
|
113
121
|
// @ts-ignore
|
|
114
122
|
let a = null;
|
|
115
123
|
if (chi.length === 4) {
|
package/dist/syntax/color/hwb.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { getColorComponents } from './utils/components.js';
|
|
@@ -78,11 +78,17 @@ function hwbToken(arena, values) {
|
|
|
78
78
|
return arena.createColor("hwb", ColorType.HWB, chi);
|
|
79
79
|
}
|
|
80
80
|
function rgb2hwbvalues(arena, token) {
|
|
81
|
-
const
|
|
81
|
+
const components = getColorComponents(arena, token);
|
|
82
|
+
// the components cannot be computed: var(), ...
|
|
83
|
+
if (components == null) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const values = components.map((t, index) => {
|
|
82
87
|
if (index === 3) {
|
|
83
88
|
return getNumber(arena, t);
|
|
84
89
|
}
|
|
85
|
-
|
|
90
|
+
// the components are from 0 to 255: 100% is 255
|
|
91
|
+
return ((arena.dataTypes[t] === EnumToken.PercentageTokenType ? 255 : 1) * getNumber(arena, t)) / 255;
|
|
86
92
|
});
|
|
87
93
|
// @ts-ignore
|
|
88
94
|
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
package/dist/syntax/color/lab.js
CHANGED
package/dist/syntax/color/lch.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { getColorComponents } from './utils/components.js';
|
|
@@ -100,7 +100,7 @@ function hsl2oklchvalues(arena, token) {
|
|
|
100
100
|
}
|
|
101
101
|
function hwb2oklchvalues(arena, token) {
|
|
102
102
|
const values = hwb2oklabvalues(arena, token);
|
|
103
|
-
return labvalues2lchvalues(values[0], values[1], values[2], values[3]);
|
|
103
|
+
return values == null ? null : labvalues2lchvalues(values[0], values[1], values[2], values[3]);
|
|
104
104
|
}
|
|
105
105
|
function cmyk2oklchvalues(arena, token) {
|
|
106
106
|
const values = cmyk2srgbvalues(arena, token);
|
package/dist/syntax/color/p3.js
CHANGED
package/dist/syntax/color/rgb.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { getColorComponents } from './utils/components.js';
|
|
@@ -94,8 +94,9 @@ function xyz2srgb(x, y, z, alpha = null) {
|
|
|
94
94
|
}
|
|
95
95
|
function hwb2srgbvalues(arena, token) {
|
|
96
96
|
const { h, w, b, a } = hwbvalues(arena, token) ?? {};
|
|
97
|
+
// the components cannot be computed: var(), ...
|
|
97
98
|
if (h == null || w == null || b == null) {
|
|
98
|
-
return
|
|
99
|
+
return null;
|
|
99
100
|
}
|
|
100
101
|
const rgb = hwb2srgb(h, w, b);
|
|
101
102
|
if (a != null && a !== 1) {
|
package/dist/syntax/color/xyz.js
CHANGED
package/dist/syntax/constants.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken } from '../ast/types.js';
|
|
9
9
|
import config from '../data/validation.json.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* key of the position of a validation token in the syntax, see {@link ValidationToken}
|
|
13
13
|
*/
|
|
14
14
|
const LOC = Symbol.for("loc");
|
|
15
15
|
/**
|
package/dist/syntax/syntax.js
CHANGED
package/dist/types.js
CHANGED
package/dist/utils/sync.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { interpreted, seq, kws, alt, leaf, kw, rep, list, unordered, fn, comma, occ, opt, rng, ref, slash, fndef, num, optGroup, closeParens, str, colon, openParens, optList, empty } from './runtime.js';
|