@tbela99/css-parser 1.1.1 → 1.2.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 (101) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +53 -6
  3. package/dist/index-umd-web.js +4195 -3363
  4. package/dist/index.cjs +4199 -3367
  5. package/dist/index.d.ts +42 -31
  6. package/dist/lib/ast/expand.js +81 -65
  7. package/dist/lib/ast/features/calc.js +37 -35
  8. package/dist/lib/ast/features/inlinecssvariables.js +25 -17
  9. package/dist/lib/ast/features/prefix.js +22 -19
  10. package/dist/lib/ast/features/shorthand.js +1 -1
  11. package/dist/lib/ast/features/transform.js +17 -2
  12. package/dist/lib/ast/math/expression.js +184 -159
  13. package/dist/lib/ast/math/math.js +22 -20
  14. package/dist/lib/ast/minify.js +249 -199
  15. package/dist/lib/ast/transform/compute.js +48 -38
  16. package/dist/lib/ast/transform/matrix.js +6 -5
  17. package/dist/lib/ast/transform/minify.js +31 -34
  18. package/dist/lib/ast/transform/utils.js +76 -16
  19. package/dist/lib/ast/types.js +32 -1
  20. package/dist/lib/fs/resolve.js +1 -14
  21. package/dist/lib/parser/declaration/list.js +1 -1
  22. package/dist/lib/parser/declaration/map.js +1 -1
  23. package/dist/lib/parser/declaration/set.js +1 -1
  24. package/dist/lib/parser/parse.js +19 -95
  25. package/dist/lib/parser/tokenize.js +1 -13
  26. package/dist/lib/parser/utils/declaration.js +1 -1
  27. package/dist/lib/parser/utils/type.js +1 -1
  28. package/dist/lib/renderer/render.js +44 -168
  29. package/dist/lib/{renderer → syntax}/color/a98rgb.js +2 -2
  30. package/dist/lib/syntax/color/cmyk.js +104 -0
  31. package/dist/lib/{renderer → syntax}/color/color-mix.js +20 -21
  32. package/dist/lib/syntax/color/color.js +581 -0
  33. package/dist/lib/syntax/color/hex.js +179 -0
  34. package/dist/lib/syntax/color/hsl.js +201 -0
  35. package/dist/lib/syntax/color/hwb.js +185 -0
  36. package/dist/lib/syntax/color/lab.js +262 -0
  37. package/dist/lib/syntax/color/lch.js +194 -0
  38. package/dist/lib/syntax/color/oklab.js +237 -0
  39. package/dist/lib/syntax/color/oklch.js +166 -0
  40. package/dist/lib/{renderer → syntax}/color/p3.js +3 -3
  41. package/dist/lib/{renderer → syntax}/color/rec2020.js +11 -11
  42. package/dist/lib/{renderer → syntax}/color/relativecolor.js +53 -40
  43. package/dist/lib/syntax/color/rgb.js +140 -0
  44. package/dist/lib/{renderer → syntax}/color/srgb.js +58 -46
  45. package/dist/lib/{renderer → syntax}/color/utils/components.js +7 -7
  46. package/dist/lib/{renderer → syntax}/color/utils/constants.js +6 -33
  47. package/dist/lib/syntax/color/utils/distance.js +30 -0
  48. package/dist/lib/{renderer → syntax}/color/xyz.js +27 -14
  49. package/dist/lib/{renderer → syntax}/color/xyzd50.js +8 -8
  50. package/dist/lib/syntax/syntax.js +77 -67
  51. package/dist/lib/syntax/utils.js +70 -0
  52. package/dist/lib/validation/at-rules/container.js +1 -1
  53. package/dist/lib/validation/at-rules/counter-style.js +1 -1
  54. package/dist/lib/validation/at-rules/custom-media.js +1 -1
  55. package/dist/lib/validation/at-rules/document.js +1 -1
  56. package/dist/lib/validation/at-rules/font-feature-values.js +2 -2
  57. package/dist/lib/validation/at-rules/import.js +1 -1
  58. package/dist/lib/validation/at-rules/keyframes.js +14 -13
  59. package/dist/lib/validation/at-rules/layer.js +1 -1
  60. package/dist/lib/validation/at-rules/media.js +1 -1
  61. package/dist/lib/validation/at-rules/namespace.js +1 -1
  62. package/dist/lib/validation/at-rules/page-margin-box.js +1 -1
  63. package/dist/lib/validation/at-rules/page.js +1 -1
  64. package/dist/lib/validation/at-rules/supports.js +1 -1
  65. package/dist/lib/validation/at-rules/when.js +1 -1
  66. package/dist/lib/validation/atrule.js +2 -2
  67. package/dist/lib/validation/config.js +4 -3
  68. package/dist/lib/validation/config.json.js +1 -1
  69. package/dist/lib/validation/parser/parse.js +12 -7
  70. package/dist/lib/validation/selector.js +9 -8
  71. package/dist/lib/validation/syntax.js +170 -120
  72. package/dist/lib/validation/syntaxes/complex-selector-list.js +13 -19
  73. package/dist/lib/validation/syntaxes/complex-selector.js +1 -1
  74. package/dist/lib/validation/syntaxes/compound-selector.js +5 -24
  75. package/dist/lib/validation/syntaxes/family-name.js +36 -39
  76. package/dist/lib/validation/syntaxes/keyframe-selector.js +14 -22
  77. package/dist/lib/validation/syntaxes/layer-name.js +1 -1
  78. package/dist/lib/validation/syntaxes/relative-selector-list.js +27 -25
  79. package/dist/lib/validation/syntaxes/relative-selector.js +1 -1
  80. package/dist/lib/validation/syntaxes/url.js +35 -33
  81. package/dist/lib/validation/utils/list.js +10 -9
  82. package/dist/lib/validation/utils/whitespace.js +1 -1
  83. package/dist/node/index.js +4 -2
  84. package/dist/web/index.js +4 -2
  85. package/package.json +4 -4
  86. package/.editorconfig +0 -484
  87. package/dist/lib/ast/transform/convert.js +0 -33
  88. package/dist/lib/ast/utils/utils.js +0 -104
  89. package/dist/lib/renderer/color/color.js +0 -654
  90. package/dist/lib/renderer/color/hex.js +0 -105
  91. package/dist/lib/renderer/color/hsl.js +0 -125
  92. package/dist/lib/renderer/color/hwb.js +0 -103
  93. package/dist/lib/renderer/color/lab.js +0 -148
  94. package/dist/lib/renderer/color/lch.js +0 -90
  95. package/dist/lib/renderer/color/oklab.js +0 -131
  96. package/dist/lib/renderer/color/oklch.js +0 -75
  97. package/dist/lib/renderer/color/rgb.js +0 -50
  98. package/dist/lib/validation/syntaxes/keyframe-block-list.js +0 -28
  99. package/dist/lib/{renderer → syntax}/color/hsv.js +0 -0
  100. package/dist/lib/{renderer → syntax}/color/prophotorgb.js +1 -1
  101. /package/dist/lib/{renderer → syntax}/color/utils/matrix.js +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
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
+
3
9
  ## v1.1.1
4
10
 
5
11
  - [x] fix bug when css nesting is disabled #89
package/README.md CHANGED
@@ -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