@tbela99/css-parser 1.3.2 → 1.3.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 (59) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +59 -20
  3. package/dist/index-umd-web.js +1846 -1075
  4. package/dist/index.cjs +1941 -1202
  5. package/dist/index.d.ts +914 -181
  6. package/dist/lib/ast/expand.js +5 -10
  7. package/dist/lib/ast/features/calc.js +8 -8
  8. package/dist/lib/ast/features/inlinecssvariables.js +9 -8
  9. package/dist/lib/ast/features/prefix.js +5 -15
  10. package/dist/lib/ast/features/shorthand.js +5 -6
  11. package/dist/lib/ast/features/transform.js +18 -25
  12. package/dist/lib/ast/features/type.js +4 -2
  13. package/dist/lib/ast/minify.js +56 -112
  14. package/dist/lib/ast/transform/compute.js +2 -4
  15. package/dist/lib/ast/transform/matrix.js +20 -20
  16. package/dist/lib/ast/transform/minify.js +105 -12
  17. package/dist/lib/ast/transform/rotate.js +11 -11
  18. package/dist/lib/ast/transform/scale.js +6 -6
  19. package/dist/lib/ast/transform/skew.js +4 -4
  20. package/dist/lib/ast/transform/translate.js +3 -3
  21. package/dist/lib/ast/transform/utils.js +30 -37
  22. package/dist/lib/ast/types.js +16 -4
  23. package/dist/lib/ast/walk.js +172 -70
  24. package/dist/lib/fs/resolve.js +12 -7
  25. package/dist/lib/parser/declaration/list.js +3 -1
  26. package/dist/lib/parser/parse.js +441 -161
  27. package/dist/lib/parser/tokenize.js +12 -14
  28. package/dist/lib/renderer/render.js +7 -7
  29. package/dist/lib/syntax/color/cmyk.js +6 -3
  30. package/dist/lib/syntax/color/color-mix.js +2 -3
  31. package/dist/lib/syntax/color/color.js +28 -6
  32. package/dist/lib/syntax/color/hex.js +3 -0
  33. package/dist/lib/syntax/color/hsl.js +18 -7
  34. package/dist/lib/syntax/color/hwb.js +3 -3
  35. package/dist/lib/syntax/color/lab.js +4 -4
  36. package/dist/lib/syntax/color/lch.js +7 -4
  37. package/dist/lib/syntax/color/oklab.js +4 -4
  38. package/dist/lib/syntax/color/oklch.js +18 -6
  39. package/dist/lib/syntax/color/relativecolor.js +9 -56
  40. package/dist/lib/syntax/color/srgb.js +1 -1
  41. package/dist/lib/syntax/syntax.js +36 -18
  42. package/dist/lib/validation/at-rules/container.js +11 -0
  43. package/dist/lib/validation/at-rules/counter-style.js +11 -0
  44. package/dist/lib/validation/at-rules/font-feature-values.js +11 -0
  45. package/dist/lib/validation/at-rules/keyframes.js +11 -0
  46. package/dist/lib/validation/at-rules/layer.js +11 -0
  47. package/dist/lib/validation/at-rules/media.js +11 -0
  48. package/dist/lib/validation/at-rules/page-margin-box.js +11 -0
  49. package/dist/lib/validation/at-rules/page.js +11 -0
  50. package/dist/lib/validation/at-rules/supports.js +11 -0
  51. package/dist/lib/validation/at-rules/when.js +11 -0
  52. package/dist/lib/validation/config.js +0 -2
  53. package/dist/lib/validation/config.json.js +21 -9
  54. package/dist/lib/validation/parser/parse.js +53 -2
  55. package/dist/lib/validation/syntax.js +199 -36
  56. package/dist/node.js +63 -36
  57. package/dist/web.js +84 -25
  58. package/package.json +7 -5
  59. package/dist/lib/validation/parser/types.js +0 -54
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.3.4
4
+
5
+ - [x] make streaming optional #109
6
+ - [x] patch at-rule syntax for @font-feature-value #110
7
+ - [x] support percentage in transform() and scale() #111
8
+ - [x] allow arrays in visitor definition #112
9
+
10
+ ## v1.3.3
11
+
12
+ - [x] relative color computation bug #105
13
+ - [x] allow duplicated declarations of whitelisted properties #106
14
+
3
15
  ## v1.3.2
4
16
 
5
17
  - [x] add missing return type
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # css-parser
6
6
 
7
- CSS parser and minifier for node and the browser
7
+ CSS parser, minifier and validator for node and the browser
8
8
 
9
9
  ## Installation
10
10
 
@@ -41,6 +41,10 @@ $ deno add @tbela99/css-parser
41
41
  - flatten @import rules
42
42
  - experimental CSS prefix removal
43
43
 
44
+ ## Online documentation
45
+
46
+ See the full documentation at the [CSS Parser](https://tbela99.github.io/css-parser/docs) documentation site
47
+
44
48
  ## Playground
45
49
 
46
50
  Try it [online](https://tbela99.github.io/css-parser/playground/)
@@ -97,8 +101,7 @@ Javascript module from cdn
97
101
 
98
102
  <script type="module">
99
103
 
100
- import {transform} from 'https://esm.sh/@tbela99/css-parser@1.3.1/web';
101
-
104
+ import {transform} from 'https://esm.sh/@tbela99/css-parser@1.3.4/web';
102
105
 
103
106
  const css = `
104
107
  .s {
@@ -119,11 +122,44 @@ Javascript module
119
122
  <script src="dist/web.js" type="module"></script>
120
123
  ```
121
124
 
122
- Single Javascript file
125
+ Javascript umd module from cdn
123
126
 
124
- ```javascript
127
+ ```html
128
+
129
+ <script src="https://unpkg.com/@tbela99/css-parser@1.3.4/dist/index-umd-web.js"></script>
130
+ <script>
131
+
132
+ (async () => {
133
+
134
+ const css = `
135
+
136
+ .table {
137
+ border-collapse: collapse;
138
+ width: 100%;
139
+ }
140
+
141
+ .table td, .table th {
142
+ border: 1px solid #ddd;
143
+ padding: 8px;
144
+ }
125
145
 
126
- <script src="dist/index-umd-web.js"></script>
146
+ .table tr:nth-child(even){background-color: #f2f2f2;}
147
+
148
+ .table tr:hover {background-color: #ddd;}
149
+
150
+ .table th {
151
+ padding-top: 12px;
152
+ padding-bottom: 12px;
153
+ text-align: left;
154
+ background-color: #4CAF50;
155
+ color: white;
156
+ }
157
+ `;
158
+
159
+ console.debug(await CSSParser.transform(css, {beautify: true, convertColor: CSSParser.ColorType.OKLCH}).then(r => r.code));
160
+ })();
161
+
162
+ </script>
127
163
  ```
128
164
 
129
165
  ## Transform
@@ -728,6 +764,7 @@ result
728
764
  # Node Walker
729
765
 
730
766
  ```javascript
767
+
731
768
  import {walk} from '@tbela99/css-parser';
732
769
 
733
770
  for (const {node, parent, root} of walk(ast)) {
@@ -887,7 +924,8 @@ const css = `
887
924
  }
888
925
  `;
889
926
 
890
- console.debug(await transform(css, options));
927
+ const result = await transform(css, options);
928
+ console.debug(result.code);
891
929
 
892
930
  // .foo{transform:scale(calc(40/3))}
893
931
  ```
@@ -898,9 +936,7 @@ the visitor is called only on 'height' declarations
898
936
 
899
937
  ```typescript
900
938
 
901
- import {AstDeclaration, LengthToken, ParserOptions} from "../src/@types";
902
- import {EnumToken} from "../src/lib";
903
- import {transform} from "../src/node";
939
+ import {AstDeclaration, EnumToken, LengthToken, ParserOptions, transform} from '@tbela99/css-parser';
904
940
 
905
941
  const options: ParserOptions = {
906
942
 
@@ -942,7 +978,8 @@ color: lch(from peru calc(l * 0.8) calc(c * 0.7) calc(h + 180))
942
978
  }
943
979
  `;
944
980
 
945
- console.debug(await transform(css, options));
981
+ const result = await transform(css, options);
982
+ console.debug(result.code);
946
983
 
947
984
  // .foo{height:calc(40px/3);width:3px}.selector{color:#0880b0}
948
985
 
@@ -983,7 +1020,8 @@ const css = `
983
1020
  }
984
1021
  `;
985
1022
 
986
- console.debug(await transform(css, options));
1023
+ const result = await transform(css, options);
1024
+ console.debug(result.code);
987
1025
 
988
1026
  // .foo{height:calc(40px/3)}
989
1027
 
@@ -1024,7 +1062,8 @@ const css = `
1024
1062
  }
1025
1063
  `;
1026
1064
 
1027
- console.debug(await transform(css, options));
1065
+ const result = await transform(css, options);
1066
+ console.debug(result.code);
1028
1067
 
1029
1068
  // .foo{height:calc(40px/3)}
1030
1069
 
@@ -1043,10 +1082,10 @@ const options: ParserOptions = {
1043
1082
 
1044
1083
  visitor: {
1045
1084
 
1046
-
1047
1085
  Rule(node: AstRule): AstRule {
1048
1086
 
1049
- return {...node, sel: '.foo,.bar,.fubar'};
1087
+ node.sel = '.foo,.bar,.fubar'
1088
+ return node;
1050
1089
  }
1051
1090
  }
1052
1091
  };
@@ -1059,7 +1098,8 @@ const css = `
1059
1098
  }
1060
1099
  `;
1061
1100
 
1062
- console.debug(await transform(css, options));
1101
+ const result = await transform(css, options);
1102
+ console.debug(result.code);
1063
1103
 
1064
1104
  // .foo,.bar,.fubar{height:calc(40px/3)}
1065
1105
 
@@ -1071,9 +1111,7 @@ Adding declarations to any rule
1071
1111
 
1072
1112
  ```typescript
1073
1113
 
1074
- import {transform} from "../src/node";
1075
- import {AstRule, ParserOptions} from "../src/@types";
1076
- import {parseDeclarations} from "../src/lib";
1114
+ import {AstRule, parseDeclarations, ParserOptions, transform} from '@tbela99/css-parser';
1077
1115
 
1078
1116
  const options: ParserOptions = {
1079
1117
 
@@ -1099,7 +1137,8 @@ const css = `
1099
1137
  }
1100
1138
  `;
1101
1139
 
1102
- console.debug(await transform(css, options));
1140
+ const result = await transform(css, options);
1141
+ console.debug(result.code);
1103
1142
 
1104
1143
  // .foo{width:3px}
1105
1144