@tbela99/css-parser 1.6.5 → 1.6.7
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 +153 -0
- package/CONTRIBUTING.md +119 -0
- package/README.md +1 -58
- package/architecture.png +0 -0
- package/dist/data/validation.json.js +4 -1
- package/dist/index-umd-web.js +730 -463
- package/dist/index.cjs +730 -463
- package/dist/index.d.ts +16 -8
- package/dist/lib/ast/expand.js +12 -10
- package/dist/lib/ast/features/calc.js +3 -10
- package/dist/lib/ast/features/prefix.js +1 -3
- package/dist/lib/ast/features/transform.js +1 -1
- package/dist/lib/ast/math/expression.js +46 -35
- package/dist/lib/ast/types.js +16 -8
- package/dist/lib/ast/walk.js +9 -0
- package/dist/lib/parser/declaration/list.js +17 -8
- package/dist/lib/parser/declaration/map.js +2 -1
- package/dist/lib/parser/parse.js +32 -29
- 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/parser/utils/declaration.js +10 -0
- package/dist/lib/printer/render.js +11 -8
- package/dist/lib/syntax/color/color-mix.js +132 -48
- package/dist/lib/syntax/color/color.js +0 -1
- package/dist/lib/syntax/color/hsl.js +45 -38
- package/dist/lib/syntax/color/hsv.js +1 -15
- package/dist/lib/syntax/color/hwb.js +83 -53
- package/dist/lib/syntax/color/oklab.js +1 -1
- package/dist/lib/syntax/color/relative-color.js +29 -0
- package/dist/lib/syntax/color/srgb.js +81 -58
- package/dist/lib/validation/match.js +3 -3
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,158 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# v1.6.7
|
|
4
|
+
|
|
5
|
+
## Improvement
|
|
6
|
+
|
|
7
|
+
- limit the amount of memory used when parsing large files
|
|
8
|
+
- use node flags as bitmasks
|
|
9
|
+
|
|
10
|
+
## Fixes
|
|
11
|
+
|
|
12
|
+
- [x] fix powerless and missing components handling with color-mix(). missing and powerless colors are now [carried forwarded](https://drafts.csswg.org/css-color-5/#rcs-intro)
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
const css = `
|
|
16
|
+
|
|
17
|
+
button {
|
|
18
|
+
|
|
19
|
+
color: color-mix(in hsl, hwb(none none none), hsl(11 33 44));
|
|
20
|
+
color: color-mix(in hsl, lch(none none 180), hsl(11 33 44));
|
|
21
|
+
color: color-mix(in srgb, white, black);
|
|
22
|
+
color: color-mix(in oklch, oklch(0.783 0.108 326.5 / 0.5), oklch(0.392 0.4 0 / none));
|
|
23
|
+
|
|
24
|
+
color: color-mix(in srgb, color(display-p3 none none none), color(srgb 0.11 0.33 0.44));
|
|
25
|
+
color: color-mix(in oklch, oklch(78.3% 0.108 326.5), oklch(39.2% 0.4 none)) ;
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
const result = transformSync({input: css,
|
|
31
|
+
beautify: true,
|
|
32
|
+
inlineCssVariables: true,
|
|
33
|
+
removeDuplicateDeclarations: false,
|
|
34
|
+
convertColor: ColorType.SRGB
|
|
35
|
+
});
|
|
36
|
+
// console.debug(result);
|
|
37
|
+
console.debug(result.code);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
result
|
|
41
|
+
|
|
42
|
+
```css
|
|
43
|
+
button {
|
|
44
|
+
color: color(srgb .78255 .272052 .15745);
|
|
45
|
+
color: color(srgb .5852 .32384 .2948);
|
|
46
|
+
color: color(srgb .5 .5 .5);
|
|
47
|
+
color: color(srgb .843871 -.026576 .636173/50%);
|
|
48
|
+
color: color(srgb .11 .33 .44);
|
|
49
|
+
color: color(srgb .764947 .131643 .788822)
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
# v1.6.6
|
|
54
|
+
|
|
55
|
+
## Fixes
|
|
56
|
+
|
|
57
|
+
- [x] parsing aspect ratio using a single number
|
|
58
|
+
- [x] bugs in calc()
|
|
59
|
+
- [x] computing media range in container at-rule
|
|
60
|
+
|
|
61
|
+
```css
|
|
62
|
+
|
|
63
|
+
@media (aspect-ratio: 1.77) {
|
|
64
|
+
html {
|
|
65
|
+
background-color: cyan;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
body {
|
|
70
|
+
left: sin(45deg);
|
|
71
|
+
left: cos(45deg);
|
|
72
|
+
left: tan(45deg);
|
|
73
|
+
left: asin(0.5);
|
|
74
|
+
left: acos(0.5);
|
|
75
|
+
left: atan(10);
|
|
76
|
+
left: atan2(-1, 1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
p {
|
|
80
|
+
font-size: calc(pow(10, 12) * 1rem);
|
|
81
|
+
font-size: calc(sqrt(100) * 1rem);
|
|
82
|
+
font-size: calc(hypot(3, 4) * 1rem);
|
|
83
|
+
font-size: calc(log(10) * 1rem);
|
|
84
|
+
font-size: calc(exp(10) * 1rem);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
p {
|
|
89
|
+
color: alpha(from red / calc(alpha * 0.5));
|
|
90
|
+
}
|
|
91
|
+
p {
|
|
92
|
+
font-size: calc(pow(e, pi) * 1rem);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@container (min-width: 700px) {
|
|
96
|
+
.container {
|
|
97
|
+
|
|
98
|
+
display: grid;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@container (max-width: 1400px) {
|
|
103
|
+
.container {
|
|
104
|
+
|
|
105
|
+
display: grid;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@container (min-width: 700px) and (max-width: 1400px) {
|
|
110
|
+
.container {
|
|
111
|
+
|
|
112
|
+
display: grid;
|
|
113
|
+
/* styles applied when a container is at least 700px */
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
is now computed as
|
|
119
|
+
|
|
120
|
+
```css
|
|
121
|
+
@media (aspect-ratio:1.77) {
|
|
122
|
+
html {
|
|
123
|
+
background-color: cyan
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
body {
|
|
127
|
+
left: .707107;
|
|
128
|
+
left: .707107;
|
|
129
|
+
left: 1;
|
|
130
|
+
left: 30deg;
|
|
131
|
+
left: 60deg;
|
|
132
|
+
left: .234turn;
|
|
133
|
+
left: -45deg
|
|
134
|
+
}
|
|
135
|
+
p {
|
|
136
|
+
font-size: 23.140693rem;
|
|
137
|
+
color: #ff000080
|
|
138
|
+
}
|
|
139
|
+
@container (width>=700px) {
|
|
140
|
+
.container {
|
|
141
|
+
display: grid
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
@container (width<=1400px) {
|
|
145
|
+
.container {
|
|
146
|
+
display: grid
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
@container (700px<=width<=1400px) {
|
|
150
|
+
.container {
|
|
151
|
+
display: grid
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
3
156
|
# v1.6.5
|
|
4
157
|
|
|
5
158
|
## 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
|
@@ -242,61 +242,4 @@ Try it [online](https://tbela99.github.io/css-parser/playground/)
|
|
|
242
242
|
|
|
243
243
|
# Architecture
|
|
244
244
|
|
|
245
|
-
|
|
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
|
-
```
|
|
245
|
+

|
package/architecture.png
ADDED
|
Binary file
|
|
@@ -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
|
},
|