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