@tbela99/css-parser 1.6.4 → 1.6.6
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 +146 -0
- package/CONTRIBUTING.md +119 -0
- package/README.md +104 -0
- package/dist/data/validation.json.js +4 -1
- package/dist/index-umd-web.js +399 -326
- package/dist/index.cjs +398 -326
- package/dist/index.d.ts +15 -2
- package/dist/lib/ast/features/calc.js +10 -5
- package/dist/lib/ast/features/if.js +1 -1
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +1 -1
- package/dist/lib/ast/features/shorthand.js +1 -4
- package/dist/lib/ast/features/transform.js +1 -1
- package/dist/lib/ast/math/expression.js +70 -36
- package/dist/lib/ast/minify.js +2 -1
- package/dist/lib/parser/declaration/list.js +20 -10
- package/dist/lib/parser/declaration/map.js +39 -26
- package/dist/lib/parser/parse.js +4 -3
- package/dist/lib/parser/tokenize.js +99 -124
- package/dist/lib/parser/utils/at-rule-container.js +70 -1
- package/dist/lib/parser/utils/at-rule-media.js +0 -2
- package/dist/lib/printer/render.js +14 -38
- package/dist/lib/syntax/color/a98rgb.js +1 -1
- package/dist/lib/syntax/color/alpha.js +19 -20
- package/dist/lib/syntax/color/color-mix.js +15 -14
- package/dist/lib/syntax/color/hex.js +4 -1
- package/dist/lib/syntax/color/relative-color.js +11 -11
- package/dist/lib/syntax/color/utils/components.js +0 -20
- package/dist/lib/syntax/constants.js +5 -0
- package/dist/lib/syntax/syntax.js +2 -2
- package/dist/lib/validation/match.js +5 -4
- package/dist/web.js +1 -0
- package/package.json +12 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,151 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# v1.6.6
|
|
4
|
+
|
|
5
|
+
## Fixes
|
|
6
|
+
|
|
7
|
+
- [x] parsing aspect ratio using a single number
|
|
8
|
+
- [x] bugs in calc()
|
|
9
|
+
- [x] computing media range in container at-rule
|
|
10
|
+
|
|
11
|
+
```css
|
|
12
|
+
|
|
13
|
+
@media (aspect-ratio: 1.77) {
|
|
14
|
+
html {
|
|
15
|
+
background-color: cyan;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
body {
|
|
20
|
+
left: sin(45deg);
|
|
21
|
+
left: cos(45deg);
|
|
22
|
+
left: tan(45deg);
|
|
23
|
+
left: asin(0.5);
|
|
24
|
+
left: acos(0.5);
|
|
25
|
+
left: atan(10);
|
|
26
|
+
left: atan2(-1, 1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
p {
|
|
30
|
+
font-size: calc(pow(10, 12) * 1rem);
|
|
31
|
+
font-size: calc(sqrt(100) * 1rem);
|
|
32
|
+
font-size: calc(hypot(3, 4) * 1rem);
|
|
33
|
+
font-size: calc(log(10) * 1rem);
|
|
34
|
+
font-size: calc(exp(10) * 1rem);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
p {
|
|
39
|
+
color: alpha(from red / calc(alpha * 0.5));
|
|
40
|
+
}
|
|
41
|
+
p {
|
|
42
|
+
font-size: calc(pow(e, pi) * 1rem);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@container (min-width: 700px) {
|
|
46
|
+
.container {
|
|
47
|
+
|
|
48
|
+
display: grid;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@container (max-width: 1400px) {
|
|
53
|
+
.container {
|
|
54
|
+
|
|
55
|
+
display: grid;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@container (min-width: 700px) and (max-width: 1400px) {
|
|
60
|
+
.container {
|
|
61
|
+
|
|
62
|
+
display: grid;
|
|
63
|
+
/* styles applied when a container is at least 700px */
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
is now computed as
|
|
69
|
+
|
|
70
|
+
```css
|
|
71
|
+
@media (aspect-ratio:1.77) {
|
|
72
|
+
html {
|
|
73
|
+
background-color: cyan
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
body {
|
|
77
|
+
left: .707107;
|
|
78
|
+
left: .707107;
|
|
79
|
+
left: 1;
|
|
80
|
+
left: 30deg;
|
|
81
|
+
left: 60deg;
|
|
82
|
+
left: .234turn;
|
|
83
|
+
left: -45deg
|
|
84
|
+
}
|
|
85
|
+
p {
|
|
86
|
+
font-size: 23.140693rem;
|
|
87
|
+
color: #ff000080
|
|
88
|
+
}
|
|
89
|
+
@container (width>=700px) {
|
|
90
|
+
.container {
|
|
91
|
+
display: grid
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
@container (width<=1400px) {
|
|
95
|
+
.container {
|
|
96
|
+
display: grid
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
@container (700px<=width<=1400px) {
|
|
100
|
+
.container {
|
|
101
|
+
display: grid
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
# v1.6.5
|
|
107
|
+
|
|
108
|
+
## New
|
|
109
|
+
|
|
110
|
+
- [x] Added fine-grained minification parameters:
|
|
111
|
+
- [x] RenderOptions#minifyValues: minify CSS values such as numbers and dimension tokens
|
|
112
|
+
- [x] ParseOptions#minifyAST: minify the AST.
|
|
113
|
+
|
|
114
|
+
## Improvement
|
|
115
|
+
|
|
116
|
+
```css
|
|
117
|
+
.footer{
|
|
118
|
+
grid-row:4;
|
|
119
|
+
grid-column:1;
|
|
120
|
+
grid-column-end:2;
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
is now computed as
|
|
125
|
+
|
|
126
|
+
```css
|
|
127
|
+
.footer {
|
|
128
|
+
grid-area: 4/1/auto/2
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Fixes
|
|
133
|
+
|
|
134
|
+
- [x] fix a98-rgb, hwb color color space handling in color-mix()
|
|
135
|
+
- [x] fix percentage handling in relative rgb color
|
|
136
|
+
|
|
137
|
+
```css
|
|
138
|
+
.c {
|
|
139
|
+
color: rgb(from rgb(20% 40% 60% / 80%) r g b / calc(alpha / 2));
|
|
140
|
+
```
|
|
141
|
+
is now computed as
|
|
142
|
+
|
|
143
|
+
```css
|
|
144
|
+
.c {
|
|
145
|
+
color: #3696
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
3
149
|
# v1.6.4
|
|
4
150
|
|
|
5
151
|
## New
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in contributing to CSS Parser. This guide explains how to get the project running locally, update its generated configuration data, run the checks, and submit a change. It is intended to help new contributors get started and make contributions easier to review.
|
|
4
|
+
|
|
5
|
+
## Get the source
|
|
6
|
+
|
|
7
|
+
1. Fork the repository on GitHub.
|
|
8
|
+
2. Clone your fork and enter the project directory:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
git clone https://github.com/<your-user-name>/css-parser.git
|
|
12
|
+
cd css-parser
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
3. Add the upstream repository and install the root project dependencies:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
git remote add upstream https://github.com/tbela99/css-parser.git
|
|
19
|
+
npm install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
4. Create a branch for your change:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
git switch -c descriptive-branch-name
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Use a current Node.js release compatible with the project dependencies.
|
|
29
|
+
|
|
30
|
+
## Update generated configuration
|
|
31
|
+
|
|
32
|
+
The repository includes scripts for refreshing generated CSS property and syntax data. Run them from the project root:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
npm run config-update
|
|
36
|
+
npm run syntax-update
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`config-update` regenerates `src/data/properties.json`. `syntax-update` regenerates `src/data/validation.json` from upstream CSS data and therefore requires an internet connection. Review the generated changes and include them when they are relevant to your contribution.
|
|
40
|
+
|
|
41
|
+
## Building
|
|
42
|
+
|
|
43
|
+
Run the build command:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npm run build
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Validate your changes before committing using deno:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
deno publish --dry-run
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Run tests
|
|
56
|
+
|
|
57
|
+
Run the complete Node.js and browser test suites before submitting a change:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
npm test
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
For a quicker, focused check, run either suite:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
npm run test:node
|
|
67
|
+
npm run test:web
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The browser tests use Playwright with Chromium, Firefox, and WebKit. Install the required browsers if Playwright reports that they are missing.
|
|
71
|
+
|
|
72
|
+
For debugging, run either suite:
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
npm run debug:node
|
|
76
|
+
npm run debug:web
|
|
77
|
+
```
|
|
78
|
+
## Check code coverage
|
|
79
|
+
|
|
80
|
+
Generate Node.js coverage reports with:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
npm run test:cov
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The command prints a text summary and writes an HTML report under `coverage/`. Browser coverage can be collected separately with:
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
npm run test:web-cov
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
When changing behavior, add or update tests that exercise it and use the coverage reports to spot untested paths.
|
|
93
|
+
|
|
94
|
+
## Run the benchmark
|
|
95
|
+
|
|
96
|
+
The benchmark has its own dependencies and must be run from the `benchmark/` directory:
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
cd benchmark
|
|
100
|
+
npm install
|
|
101
|
+
npm run all
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
This computes output sizes, runs the timing benchmarks, and generates `benchmark/results/benchmark.html`. Open that report to inspect the results. To run individual stages, use `npm run sizes`, `npm run bench`, or `npm run report` from `benchmark/`.
|
|
105
|
+
|
|
106
|
+
## Open a pull request
|
|
107
|
+
|
|
108
|
+
1. Review your changes and make sure no unrelated generated files or benchmark results are included.
|
|
109
|
+
2. Run the relevant tests; include coverage or benchmark results when they help explain the change.
|
|
110
|
+
3. Push your branch to your fork:
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
git push -u origin descriptive-branch-name
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
4. Open a pull request on GitHub against `tbela99/css-parser`'s `master` branch.
|
|
117
|
+
5. In the pull request description, explain the problem and the proposed change, link any related issue, and list the checks you ran. Include before-and-after benchmark results for performance-related changes.
|
|
118
|
+
|
|
119
|
+
Keep each pull request focused, and be ready to discuss or revise the change during review.
|
package/README.md
CHANGED
|
@@ -68,6 +68,49 @@ A sample result:
|
|
|
68
68
|
On the [complete benchmark suite](https://tbela99.github.io/css-parser/benchmark/index.html), css-parser generated a total output size of 2,158,698 bytes, compared to 2,494,113 bytes for Lightning CSS and larger outputs for all other tested minifiers.
|
|
69
69
|
While some tools prioritize raw execution speed, css-parser focuses on maximizing compression while preserving stylesheet semantics, resulting in consistently smaller production bundles.
|
|
70
70
|
|
|
71
|
+
## Minification performance vs execution speed
|
|
72
|
+
|
|
73
|
+
`css-parser` is designed for maximum minification performance, but the optimal configuration depends on what matters most for your workload.
|
|
74
|
+
|
|
75
|
+
The parser provides settings that let you choose the balance between minification performance and execution speed:
|
|
76
|
+
|
|
77
|
+
- Minification performance: prioritize the quality and efficiency of the minification process, allowing the parser to perform additional work when generating the minimized output.
|
|
78
|
+
|
|
79
|
+
- Execution speed: minimize the amount of work performed during parsing and minification to achieve the fastest possible execution time.
|
|
80
|
+
|
|
81
|
+
However, the available settings allow you to shift the balance toward execution speed when minimizing runtime is more important than performing every available minification optimization.
|
|
82
|
+
|
|
83
|
+
The example below demonstrates a balanced configuration that improves execution speed by disabling advanced minification features.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
|
|
87
|
+
import {transformSync} from "@tbela99/css-parser";
|
|
88
|
+
|
|
89
|
+
const css = `...`;
|
|
90
|
+
|
|
91
|
+
const result = transformSync({
|
|
92
|
+
input: css,
|
|
93
|
+
minify: false,
|
|
94
|
+
beautify: false,
|
|
95
|
+
removeEmpty: true,
|
|
96
|
+
removeComments: true,
|
|
97
|
+
convertColor: true,
|
|
98
|
+
minifyValues: true,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
console.debug(result.code);
|
|
102
|
+
console.debug(result.stats);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Performance vs execution speed comparison
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
| File: tailwind.css | Speed optimization | Minification optimization |
|
|
109
|
+
| --------------------- | ------------------ | ------------------------- |
|
|
110
|
+
| Size: 2,380,419 bytes | 1,890,728 bytes | 1,633,188 bytes |
|
|
111
|
+
| Time | 205.91 ms | 471.89 ms |
|
|
112
|
+
| Size reduction | -20.6% | -31.4% |
|
|
113
|
+
|
|
71
114
|
## Playground
|
|
72
115
|
|
|
73
116
|
Try it [online](https://tbela99.github.io/css-parser/playground/)
|
|
@@ -196,3 +239,64 @@ Try it [online](https://tbela99.github.io/css-parser/playground/)
|
|
|
196
239
|
## Performance
|
|
197
240
|
|
|
198
241
|
- [x] Bundle file referenced by the @import statement.
|
|
242
|
+
|
|
243
|
+
# Architecture
|
|
244
|
+
|
|
245
|
+
```mermaid
|
|
246
|
+
flowchart TD
|
|
247
|
+
%% --- Transform ---
|
|
248
|
+
Input(["CSS input"])
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
%% The Grouped Container
|
|
252
|
+
subgraph Group10["Transform step"]
|
|
253
|
+
|
|
254
|
+
transform["transform()/transformSync()"]
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
%% The Grouped Container
|
|
258
|
+
subgraph Group1 ["Parse step"]
|
|
259
|
+
|
|
260
|
+
%% --- Parse step ---
|
|
261
|
+
parse["parse()/parseSync()"]
|
|
262
|
+
tokenize(["tokenize()"])
|
|
263
|
+
parseNode(["parse and validate token stream"])
|
|
264
|
+
visitors(["visitors"])
|
|
265
|
+
minify(["minify AST"])
|
|
266
|
+
cssModules(["generate CSS module"])
|
|
267
|
+
parseResult["Parse result"]
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
%% The Grouped Container
|
|
271
|
+
subgraph Group2 ["Render step"]
|
|
272
|
+
|
|
273
|
+
%% --- Render step ---
|
|
274
|
+
renderAst(["Render AST"])
|
|
275
|
+
sourcemap([Sourcemap generation])
|
|
276
|
+
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
%% --- Result step ---
|
|
280
|
+
transformResult["Transform result"]
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
%% --- Routing step ---
|
|
284
|
+
Input --> transform
|
|
285
|
+
transform --> parse
|
|
286
|
+
parse --> tokenize
|
|
287
|
+
tokenize --> parseNode
|
|
288
|
+
parseNode -- "Visitors set?" --> visitors
|
|
289
|
+
visitors -- "Minify AST?" --> minify
|
|
290
|
+
minify -- "CSS module?" --> cssModules
|
|
291
|
+
visitors -- "CSS module?" --> cssModules
|
|
292
|
+
cssModules --> parseResult
|
|
293
|
+
parseNode -- "CSS module?" --> cssModules
|
|
294
|
+
parseNode -- "Minify AST?" --> minify
|
|
295
|
+
parseNode --> parseResult
|
|
296
|
+
visitors --> parseResult
|
|
297
|
+
minify --> parseResult
|
|
298
|
+
parseResult --> renderAst
|
|
299
|
+
renderAst -- "Sourcemap?" --> sourcemap
|
|
300
|
+
renderAst --> transformResult
|
|
301
|
+
sourcemap --> transformResult
|
|
302
|
+
```
|
|
@@ -2518,7 +2518,7 @@ var syntaxes = {
|
|
|
2518
2518
|
syntax: "<number> | <percentage> | none"
|
|
2519
2519
|
},
|
|
2520
2520
|
"an+b": {
|
|
2521
|
-
syntax: "odd | even | <integer> | <n-dimension> | '+'
|
|
2521
|
+
syntax: "odd | even | <integer> | <n-dimension> | '+'? n | -n | <ndashdigit-dimension> | '+'? <ndashdigit-ident> | <dashndashdigit-ident> | <n-dimension> <signed-integer> | '+'? n <signed-integer> | -n <signed-integer> | <ndash-dimension> <signless-integer> | '+'? n- <signless-integer> | -n- <signless-integer> | <n-dimension> ['+' | '-'] <signless-integer> | '+'? n ['+' | '-'] <signless-integer> | -n ['+' | '-'] <signless-integer>"
|
|
2522
2522
|
},
|
|
2523
2523
|
"anchor()": {
|
|
2524
2524
|
syntax: "anchor( <anchor-name>? && <anchor-side>, <length-percentage>? )"
|
|
@@ -4551,6 +4551,9 @@ var atRules = {
|
|
|
4551
4551
|
marks: {
|
|
4552
4552
|
syntax: "none | [ crop || cross ]"
|
|
4553
4553
|
},
|
|
4554
|
+
"page-margin-safety": {
|
|
4555
|
+
syntax: "none | clamp | add"
|
|
4556
|
+
},
|
|
4554
4557
|
"page-orientation": {
|
|
4555
4558
|
syntax: "upright | rotate-left | rotate-right"
|
|
4556
4559
|
},
|