@tbela99/css-parser 0.9.0 → 1.0.0

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 (70) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +22 -12
  3. package/dist/index-umd-web.js +2678 -2838
  4. package/dist/index.cjs +2468 -2628
  5. package/dist/index.d.ts +71 -26
  6. package/dist/lib/ast/expand.js +15 -2
  7. package/dist/lib/ast/features/calc.js +7 -10
  8. package/dist/lib/ast/features/index.js +1 -0
  9. package/dist/lib/ast/features/inlinecssvariables.js +0 -5
  10. package/dist/lib/ast/features/prefix.js +2 -7
  11. package/dist/lib/ast/features/shorthand.js +6 -9
  12. package/dist/lib/ast/features/transform.js +60 -0
  13. package/dist/lib/ast/math/expression.js +14 -10
  14. package/dist/lib/ast/math/math.js +14 -2
  15. package/dist/lib/ast/minify.js +47 -6
  16. package/dist/lib/ast/transform/compute.js +336 -0
  17. package/dist/lib/ast/transform/convert.js +33 -0
  18. package/dist/lib/ast/transform/matrix.js +111 -0
  19. package/dist/lib/ast/transform/minify.js +296 -0
  20. package/dist/lib/ast/transform/perspective.js +10 -0
  21. package/dist/lib/ast/transform/rotate.js +40 -0
  22. package/dist/lib/ast/transform/scale.js +32 -0
  23. package/dist/lib/ast/transform/skew.js +23 -0
  24. package/dist/lib/ast/transform/translate.js +32 -0
  25. package/dist/lib/ast/transform/utils.js +198 -0
  26. package/dist/lib/ast/types.js +2 -0
  27. package/dist/lib/ast/walk.js +23 -17
  28. package/dist/lib/parser/parse.js +174 -127
  29. package/dist/lib/parser/utils/declaration.js +1 -1
  30. package/dist/lib/renderer/color/{colormix.js → color-mix.js} +6 -0
  31. package/dist/lib/renderer/color/color.js +96 -20
  32. package/dist/lib/renderer/color/hex.js +17 -7
  33. package/dist/lib/renderer/color/hsl.js +7 -2
  34. package/dist/lib/renderer/color/lab.js +10 -1
  35. package/dist/lib/renderer/color/lch.js +8 -0
  36. package/dist/lib/renderer/color/oklab.js +8 -0
  37. package/dist/lib/renderer/color/oklch.js +8 -0
  38. package/dist/lib/renderer/color/prophotorgb.js +2 -2
  39. package/dist/lib/renderer/color/relativecolor.js +10 -21
  40. package/dist/lib/renderer/color/rgb.js +10 -7
  41. package/dist/lib/renderer/color/srgb.js +30 -6
  42. package/dist/lib/renderer/color/utils/components.js +13 -2
  43. package/dist/lib/renderer/color/xyz.js +2 -18
  44. package/dist/lib/renderer/color/xyzd50.js +20 -2
  45. package/dist/lib/renderer/render.js +70 -32
  46. package/dist/lib/renderer/sourcemap/sourcemap.js +1 -1
  47. package/dist/lib/syntax/syntax.js +75 -56
  48. package/dist/lib/validation/at-rules/container.js +6 -6
  49. package/dist/lib/validation/at-rules/document.js +40 -60
  50. package/dist/lib/validation/at-rules/import.js +61 -59
  51. package/dist/lib/validation/at-rules/keyframes.js +1 -1
  52. package/dist/lib/validation/at-rules/media.js +1 -1
  53. package/dist/lib/validation/at-rules/supports.js +40 -9
  54. package/dist/lib/validation/atrule.js +0 -4
  55. package/dist/lib/validation/config.json.js +83 -35
  56. package/dist/lib/validation/parser/parse.js +1 -95
  57. package/dist/lib/validation/parser/types.js +1 -2
  58. package/dist/lib/validation/selector.js +5 -2
  59. package/dist/lib/validation/syntaxes/compound-selector.js +2 -2
  60. package/dist/lib/validation/syntaxes/keyframe-block-list.js +2 -2
  61. package/dist/lib/validation/syntaxes/keyframe-selector.js +11 -90
  62. package/dist/lib/validation/syntaxes/layer-name.js +5 -16
  63. package/dist/lib/validation/syntaxes/relative-selector.js +15 -14
  64. package/dist/lib/validation/utils/list.js +18 -1
  65. package/dist/node/load.js +1 -1
  66. package/package.json +13 -12
  67. package/dist/lib/renderer/color/prophotoRgb.js +0 -56
  68. package/dist/lib/validation/declaration.js +0 -102
  69. package/dist/lib/validation/syntax.js +0 -1475
  70. package/dist/lib/validation/syntaxes/image.js +0 -29
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Thierry Bela
3
+ Copyright (c) 2023-present Thierry Bela
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![playground](https://img.shields.io/badge/playground-try%20it%20now-%230a7398
2
2
  )](https://tbela99.github.io/css-parser/playground/) [![npm](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Ftbela99%2Fcss-parser%2Fmaster%2Fpackage.json&query=version&logo=npm&label=npm&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40tbela99%2Fcss-parser)](https://www.npmjs.com/package/@tbela99/css-parser) [![npm](https://img.shields.io/jsr/v/%40tbela99/css-parser?link=https%3A%2F%2Fjsr.io%2F%40tbela99%2Fcss-parser
3
- )](https://jsr.io/@tbela99/css-parser) [![cov](https://tbela99.github.io/css-parser/badges/coverage.svg)](https://github.com/tbela99/css-parser/actions) [![NPM Downloads](https://img.shields.io/npm/dm/%40tbela99%2Fcss-parser)](https://www.npmjs.com/package/@tbela99/css-parser)
3
+ )](https://jsr.io/@tbela99/css-parser) [![cov](https://tbela99.github.io/css-parser/badges/coverage.svg)](https://github.com/tbela99/css-parser/actions) [![NPM Downloads](https://img.shields.io/npm/dm/%40tbela99%2Fcss-parser)](https://www.npmjs.com/package/@tbela99/css-parser) [![bundle size](https://img.shields.io/bundlejs/size/%40tbela99/css-parser%400.9.0?exports=cjs)](https://www.npmjs.com/package/@tbela99/css-parser)
4
4
 
5
5
  # css-parser
6
6
 
@@ -27,15 +27,14 @@ $ deno add @tbela99/css-parser
27
27
  - fault-tolerant parser, will try to fix invalid tokens according to the CSS syntax module 3 recommendations.
28
28
  - fast and efficient minification without unsafe transforms,
29
29
  see [benchmark](https://tbela99.github.io/css-parser/benchmark/index.html)
30
- - minify colors.
31
- - support css color level 4 & 5: color(), lab(), lch(), oklab(), oklch(), color-mix(), light-dark(), system colors and
30
+ - minify colors: color(), lab(), lch(), oklab(), oklch(), color-mix(), light-dark(), system colors and
32
31
  relative color
33
32
  - generate nested css rules
34
33
  - convert nested css rules to legacy syntax
35
34
  - generate sourcemap
36
35
  - compute css shorthands. see supported properties list below
37
- - evaluate math functions: calc(), clamp(), min(), max(), round(), mod(), rem(), sin(), cos(), tan(), asin(), acos(),
38
- atan(), atan2(), pow(), sqrt(), hypot(), log(), exp(), abs(), sign()
36
+ - css transform functions minification
37
+ - evaluate math functions: calc(), clamp(), min(), max(), etc.
39
38
  - inline css variables
40
39
  - remove duplicate properties
41
40
  - flatten @import rules
@@ -65,7 +64,7 @@ import as a module
65
64
 
66
65
  ```javascript
67
66
 
68
- import {transform} from 'npm:@tbela99/css-parser';
67
+ import {transform} from '@tbela99/css-parser';
69
68
 
70
69
  // ...
71
70
  ```
@@ -96,7 +95,7 @@ Javascript module from cdn
96
95
 
97
96
  <script type="module">
98
97
 
99
- import {transform} from 'https://esm.sh/@tbela99/css-parser@0.4.0/web';
98
+ import {transform} from 'https://esm.sh/@tbela99/css-parser@1.0.0/web';
100
99
 
101
100
 
102
101
  const css = `
@@ -154,10 +153,12 @@ Include ParseOptions and RenderOptions
154
153
  > Minify Options
155
154
 
156
155
  - minify: boolean, optional. default to _true_. optimize ast.
156
+ - pass: number, optional. minification pass. default to 1
157
157
  - nestingRules: boolean, optional. automatically generated nested rules.
158
158
  - expandNestingRules: boolean, optional. convert nesting rules into separate rules. will automatically set nestingRules
159
159
  to false.
160
160
  - removeDuplicateDeclarations: boolean, optional. remove duplicate declarations.
161
+ - computeTransform: boolean, optional. compute css transform functions.
161
162
  - computeShorthand: boolean, optional. compute shorthand properties.
162
163
  - computeCalcExpression: boolean, optional. evaluate calc() expression
163
164
  - inlineCssVariables: boolean, optional. replace some css variables with their actual value. they must be declared once
@@ -175,13 +176,18 @@ Include ParseOptions and RenderOptions
175
176
  - src: string, optional. original css file location to be used with sourcemap, also used to resolve url().
176
177
  - sourcemap: boolean, optional. preserve node location data.
177
178
 
178
- > Misc Options
179
+ > Ast Traversal Options
180
+
181
+ - visitor: VisitorNodeMap, optional. node visitor used to transform the ast.
179
182
 
183
+ > Urls and \@import Options
184
+
185
+ - resolveImport: boolean, optional. replace @import rule by the content of the referenced stylesheet.
180
186
  - resolveUrls: boolean, optional. resolve css 'url()' according to the parameters 'src' and 'cwd'
181
- - resolveImport: boolean, optional. replace @import rule by the content of its referenced stylesheet.
187
+
188
+ > Misc Options
182
189
  - removeCharset: boolean, optional. remove @charset.
183
190
  - cwd: string, optional. destination directory used to resolve url().
184
- - visitor: VisitorNodeMap, optional. node visitor used to transform the ast.
185
191
  - signal: AbortSignal, optional. abort parsing.
186
192
 
187
193
  #### RenderOptions
@@ -700,7 +706,11 @@ for (const {node, parent, root} of walk(ast)) {
700
706
 
701
707
  ## Minification
702
708
 
703
- - [x] reduce calc()
709
+ - [x] minify keyframs
710
+ - [x] minify transform
711
+ - [x] evaluate math functions calc(), clamp(), min(), max(), round(), mod(), rem(), sin(), cos(), tan(), asin(),
712
+ acos(), atan(), atan2(), pow(), sqrt(), hypot(), log(), exp(), abs(), sign()
713
+ - [x] multi-pass minification
704
714
  - [x] inline css variables
705
715
  - [x] merge identical rules
706
716
  - [x] merge adjacent rules
@@ -816,7 +826,7 @@ the visitor is called only on 'height' declarations
816
826
  ```typescript
817
827
 
818
828
  import {AstDeclaration, LengthToken, ParserOptions} from "../src/@types";
819
- import {EnumToken, EnumToken} from "../src/lib";
829
+ import {EnumToken} from "../src/lib";
820
830
  import {transform} from "../src/node";
821
831
 
822
832
  const options: ParserOptions = {