Skip to content

Commit 3186b6f

Browse files
authored
Merge pull request #95 from tbela99/feature/color-conversion
- [x] color conversion #94 - [x] dead code removal #93 - [x] validation syntax update #92
2 parents 21ff83b + be48721 commit 3186b6f

File tree

235 files changed

+198686
-13883
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

235 files changed

+198686
-13883
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
/Writerside
1919
/validator
2020
/sw.js
21-
/jsr.json
21+
/jsr.json
22+
/.editorconfig

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## V1.2.0
4+
5+
- [x] convert color to any supported color space #94
6+
- [x] dead code removal #93
7+
- [x] validation syntax update #92
8+
39
## v1.1.1
410

511
- [x] fix bug when css nesting is disabled #89

README.md

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ $ deno add @tbela99/css-parser
3131
relative color
3232
- generate nested css rules
3333
- convert nested css rules to legacy syntax
34+
- convert colors to any supported color format
3435
- generate sourcemap
3536
- compute css shorthands. see supported properties list below
36-
- css transform functions minification
37+
- minify css transform functions
3738
- evaluate math functions: calc(), clamp(), min(), max(), etc.
3839
- inline css variables
3940
- remove duplicate properties
@@ -96,7 +97,7 @@ Javascript module from cdn
9697

9798
<script type="module">
9899
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';
100101
101102
102103
const css = `
@@ -210,7 +211,26 @@ Include ParseOptions and RenderOptions
210211
- expandNestingRules: boolean, optional. expand nesting rules.
211212
- preserveLicense: boolean, force preserving comments starting with '/\*!' when minify is enabled.
212213
- 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
214234

215235
> Sourcemap Options
216236
@@ -279,6 +299,32 @@ console.debug(render(result.ast.chi[0].chi[1].chi[1], {withParents: true}));
279299

280300
```
281301

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+
282328
### Merge similar rules
283329

284330
CSS
@@ -716,15 +762,15 @@ for (const {node, parent, root} of walk(ast)) {
716762
## Minification
717763

718764
- [x] minify keyframes
719-
- [x] minify transform
765+
- [x] minify transform functions
720766
- [x] evaluate math functions calc(), clamp(), min(), max(), round(), mod(), rem(), sin(), cos(), tan(), asin(),
721767
acos(), atan(), atan2(), pow(), sqrt(), hypot(), log(), exp(), abs(), sign()
768+
- [x] minify colors
769+
- [x] minify numbers and Dimensions tokens
722770
- [x] multi-pass minification
723771
- [x] inline css variables
724772
- [x] merge identical rules
725773
- [x] merge adjacent rules
726-
- [x] minify colors
727-
- [x] minify numbers and Dimensions tokens
728774
- [x] compute shorthand: see the list below
729775
- [x] remove redundant declarations
730776
- [x] conditionally unwrap :is()
@@ -733,6 +779,7 @@ for (const {node, parent, root} of walk(ast)) {
733779
- [x] avoid reparsing (declarations, selectors, at-rule)
734780
- [x] node and browser versions
735781
- [x] decode and replace utf-8 escape sequence
782+
- [x] experimental CSS prefix removal
736783

737784
## Computed shorthands properties
738785

0 commit comments

Comments
 (0)