@@ -31,9 +31,10 @@ $ deno add @tbela99/css-parser
31
31
relative color
32
32
- generate nested css rules
33
33
- convert nested css rules to legacy syntax
34
+ - convert colors to any supported color format
34
35
- generate sourcemap
35
36
- compute css shorthands. see supported properties list below
36
- - css transform functions minification
37
+ - minify css transform functions
37
38
- evaluate math functions: calc(), clamp(), min(), max(), etc.
38
39
- inline css variables
39
40
- remove duplicate properties
@@ -96,7 +97,7 @@ Javascript module from cdn
96
97
97
98
<script type =" module" >
98
99
99
- import {transform } from ' https://esm.sh/@tbela99/css-parser@1.1.1 /web' ;
100
+ import {transform } from ' https://esm.sh/@tbela99/css-parser@1.1.2 /web' ;
100
101
101
102
102
103
const css = `
@@ -210,7 +211,26 @@ Include ParseOptions and RenderOptions
210
211
- expandNestingRules: boolean, optional. expand nesting rules.
211
212
- preserveLicense: boolean, force preserving comments starting with '/\* !' when minify is enabled.
212
213
- removeComments: boolean, remove comments in generated css.
213
- - convertColor: boolean, convert colors to hex.
214
+ - convertColor: boolean | ColorType, convert colors to the specified color. default to ColorType.HEX. supported values are:
215
+ - true: same as ColorType.HEX
216
+ - false: no color conversion
217
+ - ColorType.HEX
218
+ - ColorType.RGB/ColorType.RGBA
219
+ - ColorType.HSL
220
+ - ColorType.HWB
221
+ - ColorType.CMYK/ColorType.DEVICE_CMYK
222
+ - ColorType.SRGB
223
+ - ColorType.SRGB_LINEAR
224
+ - ColorType.DISPLAY_P3
225
+ - ColorType.PROPHOTO_RGB
226
+ - ColorType.A98_RGB
227
+ - ColorType.REC2020
228
+ - ColorType.XYZ/ColorType.XYZ_D65
229
+ - ColorType.XYZ_D50
230
+ - ColorType.LAB
231
+ - ColorType.LCH
232
+ - ColorType.OKLAB
233
+ - ColorType.OKLCH
214
234
215
235
> Sourcemap Options
216
236
@@ -279,6 +299,32 @@ console.debug(render(result.ast.chi[0].chi[1].chi[1], {withParents: true}));
279
299
280
300
```
281
301
302
+ ### Convert colors
303
+
304
+ ``` javascript
305
+ import {transform } from ' @tbela99/css-parser' ;
306
+
307
+
308
+ const css = `
309
+ .hsl { color: #b3222280; }
310
+ ` ;
311
+ const result: TransformResult = await transform (css, {
312
+ beautify: true ,
313
+ convertColor: ColorType .SRGB
314
+ });
315
+
316
+ console .log (result .css );
317
+
318
+ ```
319
+
320
+ result
321
+
322
+ ``` css
323
+ .hsl {
324
+ color : color (srgb .7019607843137254 .13333333333333333 .13333333333333333 /50% )
325
+ }
326
+ ```
327
+
282
328
### Merge similar rules
283
329
284
330
CSS
@@ -716,15 +762,15 @@ for (const {node, parent, root} of walk(ast)) {
716
762
## Minification
717
763
718
764
- [x] minify keyframes
719
- - [x] minify transform
765
+ - [x] minify transform functions
720
766
- [x] evaluate math functions calc(), clamp(), min(), max(), round(), mod(), rem(), sin(), cos(), tan(), asin(),
721
767
acos(), atan(), atan2(), pow(), sqrt(), hypot(), log(), exp(), abs(), sign()
768
+ - [x] minify colors
769
+ - [x] minify numbers and Dimensions tokens
722
770
- [x] multi-pass minification
723
771
- [x] inline css variables
724
772
- [x] merge identical rules
725
773
- [x] merge adjacent rules
726
- - [x] minify colors
727
- - [x] minify numbers and Dimensions tokens
728
774
- [x] compute shorthand: see the list below
729
775
- [x] remove redundant declarations
730
776
- [x] conditionally unwrap : is ()
@@ -733,6 +779,7 @@ for (const {node, parent, root} of walk(ast)) {
733
779
- [x] avoid reparsing (declarations, selectors, at-rule)
734
780
- [x] node and browser versions
735
781
- [x] decode and replace utf-8 escape sequence
782
+ - [x] experimental CSS prefix removal
736
783
737
784
## Computed shorthands properties
738
785
0 commit comments