@tbela99/css-parser 1.4.11 → 1.6.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 (80) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +18 -11
  3. package/dist/index-umd-web.js +6558 -5310
  4. package/dist/index.cjs +6576 -5313
  5. package/dist/index.d.ts +805 -279
  6. package/dist/lib/ast/clone.js +13 -8
  7. package/dist/lib/ast/expand.js +65 -15
  8. package/dist/lib/ast/features/calc.js +19 -56
  9. package/dist/lib/ast/features/if.js +28 -4
  10. package/dist/lib/ast/features/inlinecssvariables.js +6 -5
  11. package/dist/lib/ast/features/prefix.js +52 -73
  12. package/dist/lib/ast/features/shorthand.js +11 -6
  13. package/dist/lib/ast/features/transform.js +6 -3
  14. package/dist/lib/ast/find.js +7 -5
  15. package/dist/lib/ast/math/expression.js +190 -32
  16. package/dist/lib/ast/minify.js +117 -49
  17. package/dist/lib/ast/node.js +52 -0
  18. package/dist/lib/ast/transform/compute.js +63 -4
  19. package/dist/lib/ast/transform/minify.js +6 -6
  20. package/dist/lib/ast/transform/perspective.js +1 -1
  21. package/dist/lib/ast/transform/rotate.js +1 -1
  22. package/dist/lib/ast/transform/scale.js +1 -1
  23. package/dist/lib/ast/transform/skew.js +1 -1
  24. package/dist/lib/ast/transform/translate.js +1 -1
  25. package/dist/lib/ast/transform/utils.js +46 -18
  26. package/dist/lib/ast/types.js +1 -1
  27. package/dist/lib/ast/walk.js +55 -11
  28. package/dist/lib/fs/resolve.js +68 -27
  29. package/dist/lib/parser/declaration/list.js +22 -7
  30. package/dist/lib/parser/declaration/map.js +40 -13
  31. package/dist/lib/parser/declaration/set.js +3 -1
  32. package/dist/lib/parser/linesmap.js +2 -12
  33. package/dist/lib/parser/parse.js +843 -912
  34. package/dist/lib/parser/source.js +16 -2
  35. package/dist/lib/parser/tokenize.js +1489 -725
  36. package/dist/lib/parser/utils/at-rule-container.js +29 -196
  37. package/dist/lib/parser/utils/at-rule-generic.js +6 -7
  38. package/dist/lib/parser/utils/at-rule-import.js +17 -13
  39. package/dist/lib/parser/utils/at-rule-media.js +36 -19
  40. package/dist/lib/parser/utils/at-rule-support.js +19 -9
  41. package/dist/lib/parser/utils/at-rule-when-else.js +11 -38
  42. package/dist/lib/parser/utils/at-rule.js +0 -18
  43. package/dist/lib/parser/utils/declaration.js +30 -95
  44. package/dist/lib/parser/utils/hash.js +4 -4
  45. package/dist/lib/parser/utils/selector.js +164 -141
  46. package/dist/lib/parser/utils/text.js +4 -2
  47. package/dist/lib/renderer/render.js +230 -125
  48. package/dist/lib/renderer/sourcemap/lib/codec.js +78 -0
  49. package/dist/lib/renderer/sourcemap/sourcemap.js +187 -34
  50. package/dist/lib/syntax/color/a98rgb.js +14 -4
  51. package/dist/lib/syntax/color/cmyk.js +10 -18
  52. package/dist/lib/syntax/color/color-mix.js +21 -34
  53. package/dist/lib/syntax/color/color.js +32 -49
  54. package/dist/lib/syntax/color/hsl.js +15 -15
  55. package/dist/lib/syntax/color/hwb.js +18 -17
  56. package/dist/lib/syntax/color/lab.js +17 -17
  57. package/dist/lib/syntax/color/lch.js +13 -13
  58. package/dist/lib/syntax/color/oklab.js +10 -11
  59. package/dist/lib/syntax/color/oklch.js +15 -18
  60. package/dist/lib/syntax/color/p3.js +18 -12
  61. package/dist/lib/syntax/color/prophotorgb.js +26 -28
  62. package/dist/lib/syntax/color/rec2020.js +8 -4
  63. package/dist/lib/syntax/color/relative-color.js +26 -10
  64. package/dist/lib/syntax/color/srgb.js +5 -4
  65. package/dist/lib/syntax/color/utils/distance.js +1 -1
  66. package/dist/lib/syntax/color/xyz.js +2 -2
  67. package/dist/lib/syntax/color/xyzd50.js +2 -2
  68. package/dist/lib/syntax/constants.js +12 -2
  69. package/dist/lib/syntax/syntax.js +45 -258
  70. package/dist/lib/validation/config.json.js +3 -0
  71. package/dist/lib/validation/match.js +110 -27
  72. package/dist/node.js +55 -33
  73. package/dist/types.d.ts +5 -1
  74. package/dist/types.js +4 -0
  75. package/dist/utils/sync.d.ts +16 -0
  76. package/dist/utils/sync.js +73 -0
  77. package/dist/web.js +37 -30
  78. package/package.json +1 -1
  79. package/dist/lib/renderer/sourcemap/lib/encode.js +0 -37
  80. package/llms.txt +0 -73
package/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # Changelog
2
2
 
3
+ # v1.6.0
4
+
5
+ - [x] added support for math function `tan()`.
6
+
7
+ ## Improvements
8
+ - [x] faster tokenizer
9
+ - [x] ensure transform: rotate(360deg) is not minified to transform: none
10
+ - [x] support input sourcemap from inline sourcemap file. This is only supported by the async parser.
11
+
12
+ ```css
13
+
14
+ table.colortable {
15
+ width: 100%;
16
+ text-shadow: none;
17
+ border-collapse: collapse
18
+ }
19
+ table.colortable td {
20
+ text-align: center
21
+ }
22
+ table.colortable td.c {
23
+ text-transform: uppercase;
24
+ background: #ff0
25
+ }
26
+ table.colortable th {
27
+ text-align: center;
28
+ color: green;
29
+ font-weight: 400;
30
+ padding: 2px 3px
31
+ }
32
+
33
+ /*# sourceMappingURL=sourcemap.css.map */
34
+ ```
35
+
36
+ # v1.5.0
37
+
38
+ ## Improvements
39
+
40
+ - [x] Add support for input sourcemap
41
+
3
42
  # v1.4.11
4
43
 
5
44
  - fix bug in url resolution
package/README.md CHANGED
@@ -4,7 +4,9 @@
4
4
 
5
5
  # css-parser
6
6
 
7
- CSS parser, transformer, minifier and validator for node and the browser
7
+ An all-in-one CSS parsing solution for Node.js and the browser, covering parsing, validation, transformation, minification, and AST-based tooling.
8
+
9
+ The library always fully parses the stylesheet into a structured AST, and token values are exposed as typed data so custom transforms, plugins, and analysis can work with reliable, semantic input instead of raw strings.
8
10
 
9
11
  ## Installation
10
12
 
@@ -23,9 +25,11 @@ $ deno add @tbela99/css-parser
23
25
  ## Features
24
26
 
25
27
  * **Zero dependencies** — lightweight and easy to integrate into any project.
28
+ * **All-in-one CSS parsing solution** covering parsing, validation, transformation, minification, and AST manipulation.
26
29
  * **Standards-based CSS validation** powered by MDN data.
27
30
  * **Full CSS Modules support** for modern component-based workflows.
28
- * **Fault-tolerant parsing** that follows the CSS Syntax Module Level 3 specification.
31
+ * **Fault-tolerant parsing** that follows the CSS Syntax Module Level 3 specification and always produces a complete, structured parse result.
32
+ * **Typed tokens and AST** — parsed CSS is exposed as strongly typed tokens and nodes so plugins and transforms can operate on semantic structures.
29
33
  * **High-performance minification** with safe optimizations and no unsafe transforms.
30
34
  * **Advanced color processing** with support for modern color spaces and functions, including `color()`, `lab()`, `lch()`, `oklab()`, `oklch()`, `color-mix()`, `light-dark()`, system colors, and relative colors.
31
35
  * **Color conversion engine** capable of transforming colors between all supported formats.
@@ -39,7 +43,7 @@ $ deno add @tbela99/css-parser
39
43
  * **`@import` flattening** to produce self-contained stylesheets.
40
44
 
41
45
  ## Vendor prefix removal
42
- **Experimental vendor prefix cleanup** to modernize generated CSS.
46
+ **Vendor prefix cleanup** to modernize generated CSS.
43
47
 
44
48
  ## Syntax lowering
45
49
  CSS-Parser can transform these modern CSS features into lower-level CSS syntax:
@@ -81,10 +85,13 @@ Try it [online](https://tbela99.github.io/css-parser/playground/)
81
85
  - [CSS Modules](https://tbela99.github.io/css-parser/docs/documents/Guide.CSS_Modules.html)
82
86
  - [Minification](https://tbela99.github.io/css-parser/docs/documents/Guide.Minification.html)
83
87
  - [Custom Transform](https://tbela99.github.io/css-parser/docs/documents/Guide.Custom_Transform.html)
88
+ - [Sourcemap](https://tbela99.github.io/css-parser/docs/documents/Guide.Sourcemap.html)
89
+ - [Plugins API](https://tbela99.github.io/css-parser/docs/documents/Guide.Plugins_API.html)
84
90
  - [Syntax Lowering](https://tbela99.github.io/css-parser/docs/documents/Guide.Syntax_Lowering.html)
91
+ - [Prefix Removal](https://tbela99.github.io/css-parser/docs/documents/Guide.Prefix_Removal.html)
85
92
  - [Ast Manipulation](https://tbela99.github.io/css-parser/docs/documents/Guide.Ast_Manipulation.html)
86
93
  - [Utility Functions](https://tbela99.github.io/css-parser/docs/documents/Guide.Utility_Functions.html)
87
- -
94
+
88
95
  ## AST
89
96
 
90
97
  ### Comment
@@ -92,6 +99,11 @@ Try it [online](https://tbela99.github.io/css-parser/playground/)
92
99
  - typ: number
93
100
  - val: string, the comment
94
101
 
102
+ ### AtRuleStyleSheet
103
+
104
+ - typ: number
105
+ - chi: array of children
106
+
95
107
  ### Declaration
96
108
 
97
109
  - typ: number
@@ -108,7 +120,7 @@ Try it [online](https://tbela99.github.io/css-parser/playground/)
108
120
  - state: EnumAstNodeStatus, validation state
109
121
  - errors: ErrorDescription[], validation errors
110
122
 
111
- ### AtRule
123
+ ### AtRule and KeyframesAtRule
112
124
 
113
125
  - typ: number
114
126
  - nam: string. AtRule name
@@ -116,12 +128,7 @@ Try it [online](https://tbela99.github.io/css-parser/playground/)
116
128
  - state: EnumAstNodeStatus, validation state
117
129
  - errors: ErrorDescription[], validation errors
118
130
 
119
- ### AtRuleStyleSheet
120
-
121
- - typ: number
122
- - chi: array of children
123
-
124
- ### KeyFrameRule
131
+ ### KeyframesRule
125
132
 
126
133
  - typ: number
127
134
  - sel: string, css selector