@tbela99/css-parser 1.4.3 → 1.4.5
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 +196 -2
- package/README.md +68 -1120
- package/dist/config.json.js +43 -2
- package/dist/index-umd-web.js +18118 -15886
- package/dist/index.cjs +16838 -14611
- package/dist/index.d.ts +1804 -1684
- package/dist/lib/ast/clone.js +4 -3
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/calc.js +59 -54
- package/dist/lib/ast/features/if.js +64 -17
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +343 -6
- package/dist/lib/ast/features/transform.js +7 -4
- package/dist/lib/ast/find.js +5 -5
- package/dist/lib/ast/math/expression.js +12 -8
- package/dist/lib/ast/minify.js +28 -33
- package/dist/lib/ast/transform/minify.js +135 -131
- package/dist/lib/ast/transform/utils.js +3 -2
- package/dist/lib/ast/types.js +69 -8
- package/dist/lib/ast/walk.js +4 -5
- package/dist/lib/fs/resolve.js +71 -57
- package/dist/lib/parser/declaration/list.js +92 -3
- package/dist/lib/parser/declaration/map.js +5 -5
- package/dist/lib/parser/parse.js +530 -466
- package/dist/lib/parser/tokenize.js +110 -4
- package/dist/lib/parser/utils/angle.js +29 -0
- package/dist/lib/parser/utils/at-rule-container.js +2 -2
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +2 -2
- package/dist/lib/parser/utils/at-rule-generic.js +1 -1
- package/dist/lib/parser/utils/at-rule-media.js +2 -2
- package/dist/lib/parser/utils/at-rule-support.js +73 -8
- package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
- package/dist/lib/parser/utils/at-rule.js +2 -8
- package/dist/lib/parser/utils/declaration.js +179 -76
- package/dist/lib/parser/utils/selector.js +53 -11
- package/dist/lib/parser/utils/token.js +13 -11
- package/dist/lib/renderer/render.js +501 -59
- package/dist/lib/syntax/color/alpha.js +64 -0
- package/dist/lib/syntax/color/cmyk.js +2 -2
- package/dist/lib/syntax/color/color-mix.js +283 -220
- package/dist/lib/syntax/color/color.js +37 -28
- package/dist/lib/syntax/color/hex.js +2 -2
- package/dist/lib/syntax/color/hsl.js +3 -3
- package/dist/lib/syntax/color/hwb.js +7 -7
- package/dist/lib/syntax/color/lab.js +5 -5
- package/dist/lib/syntax/color/lch.js +4 -4
- package/dist/lib/syntax/color/oklab.js +3 -3
- package/dist/lib/syntax/color/oklch.js +3 -3
- package/dist/lib/syntax/color/relativecolor.js +97 -12
- package/dist/lib/syntax/color/srgb.js +5 -5
- 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 +7 -3
- package/dist/lib/syntax/color/utils/distance.js +21 -4
- package/dist/lib/syntax/color/utils/make-color.js +56 -0
- package/dist/lib/syntax/color/xyz.js +2 -2
- package/dist/lib/syntax/constants.js +29 -1
- package/dist/lib/syntax/syntax.js +307 -39
- package/dist/lib/validation/config.js +2 -2
- package/dist/lib/validation/config.json.js +32 -17
- package/dist/lib/validation/match.js +239 -104
- package/dist/lib/validation/parser/parse.js +0 -1
- package/dist/lib/validation/parser/typedef.js +6 -0
- package/dist/node.js +64 -22
- package/dist/web.js +65 -18
- package/package.json +26 -15
- package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.repl_history +0 -4
- package/badges/coverage.svg +0 -20
- package/deno.lock +0 -2861
- package/dist/lib/ast/clone.d.ts +0 -10
- package/dist/lib/ast/expand.d.ts +0 -14
- package/dist/lib/ast/features/calc.d.ts +0 -10
- package/dist/lib/ast/features/if.d.ts +0 -10
- package/dist/lib/ast/features/index.d.ts +0 -6
- package/dist/lib/ast/features/inlinecssvariables.d.ts +0 -15
- package/dist/lib/ast/features/prefix.d.ts +0 -8
- package/dist/lib/ast/features/shorthand.d.ts +0 -12
- package/dist/lib/ast/features/transform.d.ts +0 -10
- package/dist/lib/ast/features/type.d.ts +0 -15
- package/dist/lib/ast/find.d.ts +0 -165
- package/dist/lib/ast/math/expression.d.ts +0 -18
- package/dist/lib/ast/math/math.d.ts +0 -6
- package/dist/lib/ast/minify.d.ts +0 -19
- package/dist/lib/ast/transform/compute.d.ts +0 -8
- package/dist/lib/ast/transform/matrix.d.ts +0 -22
- package/dist/lib/ast/transform/minify.d.ts +0 -5
- package/dist/lib/ast/transform/perspective.d.ts +0 -3
- package/dist/lib/ast/transform/rotate.d.ts +0 -12
- package/dist/lib/ast/transform/scale.d.ts +0 -6
- package/dist/lib/ast/transform/skew.d.ts +0 -4
- package/dist/lib/ast/transform/translate.d.ts +0 -6
- package/dist/lib/ast/transform/utils.d.ts +0 -9
- package/dist/lib/ast/types.d.ts +0 -903
- package/dist/lib/ast/walk.d.ts +0 -162
- package/dist/lib/fs/resolve.d.ts +0 -20
- package/dist/lib/parser/declaration/list.d.ts +0 -16
- package/dist/lib/parser/declaration/map.d.ts +0 -15
- package/dist/lib/parser/declaration/set.d.ts +0 -9
- package/dist/lib/parser/node.d.ts +0 -7
- package/dist/lib/parser/parse.d.ts +0 -107
- package/dist/lib/parser/tokenize.d.ts +0 -57
- package/dist/lib/parser/utils/at-rule-container.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-generic.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-import.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-media.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.js +0 -28
- package/dist/lib/parser/utils/at-rule-support.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-token.d.ts +0 -1
- package/dist/lib/parser/utils/at-rule-when-else.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule.d.ts +0 -13
- package/dist/lib/parser/utils/cache.d.ts +0 -6
- package/dist/lib/parser/utils/config.d.ts +0 -2
- package/dist/lib/parser/utils/declaration-list.d.ts +0 -5
- package/dist/lib/parser/utils/declaration.d.ts +0 -18
- package/dist/lib/parser/utils/eq.d.ts +0 -1
- package/dist/lib/parser/utils/hash.d.ts +0 -21
- package/dist/lib/parser/utils/selector.d.ts +0 -5
- package/dist/lib/parser/utils/text.d.ts +0 -3
- package/dist/lib/parser/utils/token.d.ts +0 -14
- package/dist/lib/parser/utils/type.d.ts +0 -2
- package/dist/lib/renderer/render.d.ts +0 -28
- package/dist/lib/renderer/sourcemap/lib/encode.d.ts +0 -1
- package/dist/lib/renderer/sourcemap/sourcemap.d.ts +0 -26
- package/dist/lib/syntax/color/a98rgb.d.ts +0 -2
- package/dist/lib/syntax/color/cmyk.d.ts +0 -10
- package/dist/lib/syntax/color/color-mix.d.ts +0 -2
- package/dist/lib/syntax/color/color.d.ts +0 -42
- package/dist/lib/syntax/color/hex.d.ts +0 -16
- package/dist/lib/syntax/color/hsl.d.ts +0 -20
- package/dist/lib/syntax/color/hsv.d.ts +0 -2
- package/dist/lib/syntax/color/hwb.d.ts +0 -21
- package/dist/lib/syntax/color/lab.d.ts +0 -25
- package/dist/lib/syntax/color/lch.d.ts +0 -23
- package/dist/lib/syntax/color/oklab.d.ts +0 -22
- package/dist/lib/syntax/color/oklch.d.ts +0 -20
- package/dist/lib/syntax/color/p3.d.ts +0 -6
- package/dist/lib/syntax/color/prophotorgb.d.ts +0 -2
- package/dist/lib/syntax/color/rec2020.d.ts +0 -2
- package/dist/lib/syntax/color/relativecolor.d.ts +0 -13
- package/dist/lib/syntax/color/rgb.d.ts +0 -20
- package/dist/lib/syntax/color/srgb.d.ts +0 -23
- package/dist/lib/syntax/color/utils/components.d.ts +0 -2
- package/dist/lib/syntax/color/utils/distance.d.ts +0 -18
- package/dist/lib/syntax/color/utils/matrix.d.ts +0 -6
- package/dist/lib/syntax/color/xyz.d.ts +0 -5
- package/dist/lib/syntax/color/xyzd50.d.ts +0 -4
- package/dist/lib/syntax/constants.d.ts +0 -67
- package/dist/lib/syntax/syntax.d.ts +0 -38
- package/dist/lib/validation/config.d.ts +0 -14
- package/dist/lib/validation/json.d.ts +0 -2
- package/dist/lib/validation/match.d.ts +0 -38
- package/dist/lib/validation/parser/parse.d.ts +0 -8
- package/dist/lib/validation/parser/typedef.d.ts +0 -95
- package/dist/lib/validation/utils/list.d.ts +0 -4
- package/dist/lib/validation/utils/whitespace.d.ts +0 -2
- package/dist/node.d.ts +0 -207
- package/dist/web.d.ts +0 -169
- package/playground/index.html +0 -1328
- package/playground/sw.js +0 -55
- package/playground/tree.js +0 -176
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,202 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## v1.4.
|
|
3
|
+
## v1.4.5
|
|
4
|
+
|
|
5
|
+
- [x] Temporarily disable if syntax expansion
|
|
6
|
+
|
|
7
|
+
## v1.4.4
|
|
8
|
+
|
|
9
|
+
### Validation changes
|
|
10
|
+
|
|
11
|
+
- [x] Added the `state` and `errors` properties to nodes to expose their validation status and any associated validation errors.
|
|
12
|
+
- [x] Nodes that fail validation are no longer discarded. Nodes are discarded only if they are invalid, unparsed, or malformed. Unknown nodes are discarded when lenient parsing is disabled.
|
|
13
|
+
|
|
14
|
+
### Color
|
|
15
|
+
|
|
16
|
+
- [x] `alpha()`: Added support for minifying the CSS Color 5 `alpha()` color function.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
|
|
20
|
+
import {transform} from '@tbela99/css-parser';
|
|
21
|
+
|
|
22
|
+
const css = `
|
|
23
|
+
|
|
24
|
+
:root {
|
|
25
|
+
--mycolor: oklch(60% 0.25 315 / 0.8);
|
|
26
|
+
}
|
|
27
|
+
.s {
|
|
28
|
+
|
|
29
|
+
color:
|
|
30
|
+
alpha(from var(--mycolor) / calc(alpha * 0.5));
|
|
31
|
+
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
const result = await transform(css, {
|
|
35
|
+
beautify: true,
|
|
36
|
+
inlineCssVariables: true,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
console.debug(result.code);
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
result:
|
|
44
|
+
|
|
45
|
+
```css
|
|
46
|
+
.s {
|
|
47
|
+
color: #b538e366
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- [x] `color-mix()`: Implemented support for the updated `color-mix()` syntax defined in https://www.w3.org/TR/css-values-5/#color-mix
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
|
|
56
|
+
import {transform} from '@tbela99/css-parser';
|
|
57
|
+
|
|
58
|
+
const css = `
|
|
59
|
+
.hsl { color: color-mix(firebrick, goldenrod); }
|
|
60
|
+
`;
|
|
61
|
+
|
|
62
|
+
const result = await transform(css, {
|
|
63
|
+
beautify: true,
|
|
64
|
+
convertColor: ColorType.OKLAB
|
|
65
|
+
});
|
|
4
66
|
|
|
67
|
+
console.debug(result.code);
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
result:
|
|
72
|
+
|
|
73
|
+
```css
|
|
74
|
+
.hsl {
|
|
75
|
+
color: oklab(.624172 .087878 .113592)
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Webkit gradient prefix removal
|
|
80
|
+
|
|
81
|
+
- [x] Convert -webkit-* gradient functions
|
|
82
|
+
- [x] -webkit-gradient() to:
|
|
83
|
+
- [x] linear-gradient()
|
|
84
|
+
- [ ] radial-gradient() - not supported ⚠️
|
|
85
|
+
- [x] -webkit-linear-gradient()
|
|
86
|
+
- [x] -webkit-repeating-linear-gradient()
|
|
87
|
+
- [x] -webkit-radial-gradient()
|
|
88
|
+
- [x] -webkit-repeating-radial-gradient()
|
|
89
|
+
|
|
90
|
+
### CSS gradient minification
|
|
91
|
+
|
|
92
|
+
- [x] Minify gradient functions
|
|
93
|
+
- [x] linear-gradient()
|
|
94
|
+
- [x] radial-gradient()
|
|
95
|
+
- [x] conic-gradient()
|
|
96
|
+
- [x] repeating-linear-gradient()
|
|
97
|
+
- [x] repeating-radial-gradient()
|
|
98
|
+
- [x] repeating-conic-gradient()
|
|
99
|
+
|
|
100
|
+
### Other changes
|
|
101
|
+
|
|
102
|
+
- [x] Minify transform-origin property
|
|
103
|
+
- [x] Changing oklab distance threshold to `0.00001` according to https://drafts.csswg.org/css-color-4/#comparing-color-values
|
|
104
|
+
|
|
105
|
+
### Bug fixes
|
|
106
|
+
- [x] Fix path resolution on Windows
|
|
107
|
+
- [x] Do not minify supports() arguments
|
|
108
|
+
|
|
109
|
+
CSS incorrectly parsed:
|
|
110
|
+
|
|
111
|
+
```css
|
|
112
|
+
body {
|
|
113
|
+
background-color: if(
|
|
114
|
+
supports(color: oklch(0.7 0.185 232)): oklch(0.7 0.185 232);
|
|
115
|
+
else: #00adf3;
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
&::after {
|
|
119
|
+
content: if(
|
|
120
|
+
supports(color: oklch(0.7 0.185 232)): "Your browser supports OKLCH";
|
|
121
|
+
else: "Your browser does not support OKLCH";
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
result:
|
|
128
|
+
|
|
129
|
+
```css
|
|
130
|
+
body {
|
|
131
|
+
background-color: if(supports(color:#00aefc):#00aefc;else:#00adf3);
|
|
132
|
+
&:after {
|
|
133
|
+
content: if(supports(color:#00aefc):"Your browser supports OKLCH";else:"Your browser does not support OKLCH")
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
instead of:
|
|
139
|
+
|
|
140
|
+
```css
|
|
141
|
+
body {
|
|
142
|
+
background-color: #00adf3;
|
|
143
|
+
@supports (color:oklch(.7 .185 232)) {
|
|
144
|
+
background-color: #00aefc
|
|
145
|
+
}
|
|
146
|
+
&:after {
|
|
147
|
+
content: "Your browser does not support OKLCH";
|
|
148
|
+
@supports (color:oklch(.7 .185 232)) {
|
|
149
|
+
content: "Your browser supports OKLCH"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
- [x] Incorrectly parse selector when removePrefix and css module settings are enabled
|
|
156
|
+
|
|
157
|
+
```css
|
|
158
|
+
*,:before,:after {
|
|
159
|
+
box-sizing: border-box
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
is parsed and rendered as:
|
|
163
|
+
|
|
164
|
+
```css
|
|
165
|
+
,,*:before:after {
|
|
166
|
+
box-sizing: border-box
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
instead of:
|
|
171
|
+
|
|
172
|
+
```css
|
|
173
|
+
*,:before,:after {
|
|
174
|
+
box-sizing: border-box
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Deprecation
|
|
179
|
+
|
|
180
|
+
#### Loading as commonjs module
|
|
181
|
+
- [x] Deprecate commonjs entry point. It will be removed in a future release.
|
|
182
|
+
|
|
183
|
+
#### Functions
|
|
184
|
+
- [x] Deprecate `parseFile()`. Use `parse({file, asStream, ...options})` instead.
|
|
185
|
+
- [x] Deprecate `transformFile()`. Use `transform({file, asStream, ...options})` instead
|
|
186
|
+
|
|
187
|
+
#### Enums
|
|
188
|
+
- [x] Deprecate using `ValidationLevel` to configure parsing validation settings. Use `boolean` values instead.
|
|
189
|
+
- [x] Deprecate invalid `EnumToken` node types. There are no longer used.
|
|
190
|
+
- [x] `EnumToken.InvalidRuleNodeType`
|
|
191
|
+
- [x] `EnumToken.InvalidAtRuleNodeType`
|
|
192
|
+
- [x] `EnumToken.InvalidDeclarationNodeType`
|
|
193
|
+
|
|
194
|
+
#### Interfaces
|
|
195
|
+
- [x] `AstInvalidRule`
|
|
196
|
+
- [x] `AstInvalidDeclaration`
|
|
197
|
+
- [x] `AstInvalidAtRule`
|
|
198
|
+
|
|
199
|
+
## v1.4.3
|
|
5
200
|
|
|
6
201
|
### CSS Modules
|
|
7
202
|
|
|
@@ -14,7 +209,6 @@ result = await transform(css, {
|
|
|
14
209
|
beautify: true,
|
|
15
210
|
module: {scoped: ModuleScopeEnumOptions.Shortest
|
|
16
211
|
}
|
|
17
|
-
|
|
18
212
|
});
|
|
19
213
|
|
|
20
214
|
console.log(result.code);
|