@tbela99/css-parser 1.2.0 → 1.3.1

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/CHANGELOG.md +11 -0
  2. package/README.md +29 -11
  3. package/dist/index-umd-web.js +2041 -1967
  4. package/dist/index.cjs +2129 -1964
  5. package/dist/index.d.ts +1936 -77
  6. package/dist/lib/ast/expand.js +4 -65
  7. package/dist/lib/ast/features/calc.js +3 -27
  8. package/dist/lib/ast/features/inlinecssvariables.js +2 -21
  9. package/dist/lib/ast/features/prefix.js +2 -1
  10. package/dist/lib/ast/features/transform.js +4 -3
  11. package/dist/lib/ast/features/type.js +9 -0
  12. package/dist/lib/ast/math/expression.js +26 -149
  13. package/dist/lib/ast/math/math.js +9 -9
  14. package/dist/lib/ast/minify.js +82 -171
  15. package/dist/lib/ast/transform/compute.js +4 -37
  16. package/dist/lib/ast/transform/matrix.js +33 -34
  17. package/dist/lib/ast/transform/minify.js +32 -51
  18. package/dist/lib/ast/transform/perspective.js +1 -1
  19. package/dist/lib/ast/transform/rotate.js +13 -13
  20. package/dist/lib/ast/transform/scale.js +8 -8
  21. package/dist/lib/ast/transform/skew.js +4 -4
  22. package/dist/lib/ast/transform/translate.js +8 -8
  23. package/dist/lib/ast/transform/utils.js +31 -39
  24. package/dist/lib/ast/types.js +459 -5
  25. package/dist/lib/ast/walk.js +18 -0
  26. package/dist/lib/fs/resolve.js +11 -3
  27. package/dist/lib/parser/declaration/map.js +1 -0
  28. package/dist/lib/parser/declaration/set.js +2 -2
  29. package/dist/lib/parser/parse.js +139 -32
  30. package/dist/lib/parser/tokenize.js +41 -93
  31. package/dist/lib/parser/utils/type.js +1 -1
  32. package/dist/lib/renderer/render.js +61 -30
  33. package/dist/lib/renderer/sourcemap/sourcemap.js +34 -0
  34. package/dist/lib/syntax/color/cmyk.js +2 -2
  35. package/dist/lib/syntax/color/color-mix.js +11 -12
  36. package/dist/lib/syntax/color/color.js +14 -7
  37. package/dist/lib/syntax/color/hsl.js +4 -4
  38. package/dist/lib/syntax/color/hwb.js +27 -8
  39. package/dist/lib/syntax/color/lab.js +4 -4
  40. package/dist/lib/syntax/color/lch.js +4 -4
  41. package/dist/lib/syntax/color/oklab.js +4 -4
  42. package/dist/lib/syntax/color/oklch.js +4 -4
  43. package/dist/lib/syntax/color/relativecolor.js +1 -1
  44. package/dist/lib/syntax/color/rgb.js +4 -4
  45. package/dist/lib/syntax/color/utils/components.js +15 -3
  46. package/dist/lib/syntax/color/utils/distance.js +15 -1
  47. package/dist/lib/syntax/syntax.js +18 -17
  48. package/dist/lib/syntax/utils.js +1 -1
  49. package/dist/lib/validation/at-rules/document.js +1 -1
  50. package/dist/lib/validation/at-rules/import.js +4 -4
  51. package/dist/lib/validation/at-rules/keyframes.js +0 -11
  52. package/dist/lib/validation/at-rules/supports.js +6 -6
  53. package/dist/lib/validation/config.js +0 -4
  54. package/dist/lib/validation/config.json.js +33 -30
  55. package/dist/lib/validation/parser/parse.js +0 -8
  56. package/dist/lib/validation/selector.js +0 -9
  57. package/dist/lib/validation/syntax.js +17 -135
  58. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -11
  59. package/dist/lib/validation/syntaxes/family-name.js +0 -32
  60. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -11
  61. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -26
  62. package/dist/lib/validation/syntaxes/url.js +0 -33
  63. package/dist/lib/validation/utils/list.js +0 -8
  64. package/dist/node.js +229 -0
  65. package/dist/web.js +158 -0
  66. package/package.json +14 -11
  67. package/dist/node/index.js +0 -57
  68. package/dist/node/load.js +0 -20
  69. package/dist/web/index.js +0 -66
  70. package/dist/web/load.js +0 -31
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.3.1
4
+
5
+ - [x] generate documentation
6
+ - [x] parse input from readable stream
7
+ - [x] add parseFile() and transformFile()
8
+ -
9
+ ## v1.3.0
10
+
11
+ - [x] numerical and dimension tokens use numbers instead of string
12
+ - [x] fix bug when inlineCssVariables is disabled and computeCalcExpression is enabled
13
+
3
14
  ## V1.2.0
4
15
 
5
16
  - [x] convert color to any supported color space #94
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) [![bundle size](https://img.shields.io/bundlejs/size/%40tbela99/css-parser%400.9.0?exports=cjs)](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) [![Doc](https://img.shields.io/badge/online-documentation-blue)](https://tbela99.github.io/css-parser/docs) [![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
 
@@ -97,7 +97,7 @@ Javascript module from cdn
97
97
 
98
98
  <script type="module">
99
99
 
100
- import {transform} from 'https://esm.sh/@tbela99/css-parser@1.1.2/web';
100
+ import {transform} from 'https://esm.sh/@tbela99/css-parser@1.3.1/web';
101
101
 
102
102
 
103
103
  const css = `
@@ -116,7 +116,7 @@ Javascript module
116
116
 
117
117
  ```javascript
118
118
 
119
- <script src="dist/web/index.js" type="module"></script>
119
+ <script src="dist/web.js" type="module"></script>
120
120
  ```
121
121
 
122
122
  Single Javascript file
@@ -134,7 +134,9 @@ Parse and render css in a single pass.
134
134
 
135
135
  ```typescript
136
136
 
137
- transform(css, transformOptions: TransformOptions = {}): TransformResult
137
+ transform(css: string | ReadableStream<string>, transformOptions: TransformOptions = {}): TransformResult
138
+ parse(css: string | ReadableStream<string>, parseOptions: ParseOptions = {}): ParseResult;
139
+ render(ast: AstNode, renderOptions: RenderOptions = {}): RenderResult;
138
140
  ```
139
141
 
140
142
  ### Example
@@ -146,6 +148,21 @@ import {transform} from '@tbela99/css-parser';
146
148
  const {ast, code, map, errors, stats} = await transform(css, {minify: true, resolveImport: true, cwd: 'files/css'});
147
149
  ```
148
150
 
151
+ ### Example
152
+
153
+ Read from stdin with node using readable stream
154
+
155
+ ```typescript
156
+ import {transform} from "../src/node";
157
+ import {Readable} from "node:stream";
158
+ import type {TransformResult} from '../src/@types/index.d.ts';
159
+
160
+ const readableStream: ReadableStream<string> = Readable.toWeb(process.stdin) as ReadableStream<string>;
161
+ const result: TransformResult = await transform(readableStream, {beautify: true});
162
+
163
+ console.log(result.code);
164
+ ```
165
+
149
166
  ### TransformOptions
150
167
 
151
168
  Include ParseOptions and RenderOptions
@@ -215,17 +232,17 @@ Include ParseOptions and RenderOptions
215
232
  - true: same as ColorType.HEX
216
233
  - false: no color conversion
217
234
  - ColorType.HEX
218
- - ColorType.RGB/ColorType.RGBA
235
+ - ColorType.RGB or ColorType.RGBA
219
236
  - ColorType.HSL
220
237
  - ColorType.HWB
221
- - ColorType.CMYK/ColorType.DEVICE_CMYK
238
+ - ColorType.CMYK or ColorType.DEVICE_CMYK
222
239
  - ColorType.SRGB
223
240
  - ColorType.SRGB_LINEAR
224
241
  - ColorType.DISPLAY_P3
225
242
  - ColorType.PROPHOTO_RGB
226
243
  - ColorType.A98_RGB
227
244
  - ColorType.REC2020
228
- - ColorType.XYZ/ColorType.XYZ_D65
245
+ - ColorType.XYZ or ColorType.XYZ_D65
229
246
  - ColorType.XYZ_D50
230
247
  - ColorType.LAB
231
248
  - ColorType.LCH
@@ -302,7 +319,7 @@ console.debug(render(result.ast.chi[0].chi[1].chi[1], {withParents: true}));
302
319
  ### Convert colors
303
320
 
304
321
  ```javascript
305
- import {transform} from '@tbela99/css-parser';
322
+ import {transform, ColorType} from '@tbela99/css-parser';
306
323
 
307
324
 
308
325
  const css = `
@@ -903,8 +920,8 @@ const options: ParserOptions = {
903
920
  nam: 'width',
904
921
  val: [
905
922
  <LengthToken>{
906
- typ: EnumToken.Length,
907
- val: '3',
923
+ typ: EnumToken.LengthTokenType,
924
+ val: 3,
908
925
  unit: 'px'
909
926
  }
910
927
  ]
@@ -989,7 +1006,8 @@ const options: ParserOptions = {
989
1006
 
990
1007
  media: (node: AstAtRule): AstAtRule => {
991
1008
 
992
- return {...node, val: 'all'}
1009
+ node.val = 'all';
1010
+ return node
993
1011
  }
994
1012
  }
995
1013
  }