@tbela99/css-parser 1.4.1 → 1.4.3

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 (216) hide show
  1. package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
  2. package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
  3. package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
  4. package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
  5. package/.repl_history +4 -0
  6. package/CHANGELOG.md +168 -4
  7. package/README.md +82 -0
  8. package/badges/coverage.svg +20 -0
  9. package/deno.lock +2861 -0
  10. package/dist/config.json.js +33 -1
  11. package/dist/index-umd-web.js +24393 -18479
  12. package/dist/index.cjs +27430 -21519
  13. package/dist/index.d.ts +1403 -933
  14. package/dist/lib/ast/clone.d.ts +10 -0
  15. package/dist/lib/ast/clone.js +45 -0
  16. package/dist/lib/ast/expand.d.ts +14 -0
  17. package/dist/lib/ast/expand.js +89 -64
  18. package/dist/lib/ast/features/calc.d.ts +10 -0
  19. package/dist/lib/ast/features/calc.js +62 -24
  20. package/dist/lib/ast/features/if.d.ts +10 -0
  21. package/dist/lib/ast/features/if.js +215 -0
  22. package/dist/lib/ast/features/index.d.ts +6 -0
  23. package/dist/lib/ast/features/index.js +1 -0
  24. package/dist/lib/ast/features/inlinecssvariables.d.ts +15 -0
  25. package/dist/lib/ast/features/inlinecssvariables.js +32 -27
  26. package/dist/lib/ast/features/prefix.d.ts +8 -0
  27. package/dist/lib/ast/features/prefix.js +68 -43
  28. package/dist/lib/ast/features/shorthand.d.ts +12 -0
  29. package/dist/lib/ast/features/shorthand.js +6 -9
  30. package/dist/lib/ast/features/transform.d.ts +10 -0
  31. package/dist/lib/ast/features/transform.js +9 -13
  32. package/dist/lib/ast/features/type.d.ts +15 -0
  33. package/dist/lib/ast/find.d.ts +165 -0
  34. package/dist/lib/ast/find.js +175 -0
  35. package/dist/lib/ast/math/expression.d.ts +18 -0
  36. package/dist/lib/ast/math/expression.js +140 -98
  37. package/dist/lib/ast/math/math.d.ts +6 -0
  38. package/dist/lib/ast/math/math.js +30 -41
  39. package/dist/lib/ast/minify.d.ts +19 -0
  40. package/dist/lib/ast/minify.js +543 -215
  41. package/dist/lib/ast/transform/compute.d.ts +8 -0
  42. package/dist/lib/ast/transform/compute.js +82 -69
  43. package/dist/lib/ast/transform/matrix.d.ts +22 -0
  44. package/dist/lib/ast/transform/matrix.js +12 -26
  45. package/dist/lib/ast/transform/minify.d.ts +5 -0
  46. package/dist/lib/ast/transform/minify.js +20 -20
  47. package/dist/lib/ast/transform/perspective.d.ts +3 -0
  48. package/dist/lib/ast/transform/perspective.js +1 -1
  49. package/dist/lib/ast/transform/rotate.d.ts +12 -0
  50. package/dist/lib/ast/transform/rotate.js +1 -1
  51. package/dist/lib/ast/transform/scale.d.ts +6 -0
  52. package/dist/lib/ast/transform/scale.js +1 -1
  53. package/dist/lib/ast/transform/skew.d.ts +4 -0
  54. package/dist/lib/ast/transform/skew.js +1 -1
  55. package/dist/lib/ast/transform/translate.d.ts +6 -0
  56. package/dist/lib/ast/transform/translate.js +1 -1
  57. package/dist/lib/ast/transform/utils.d.ts +9 -0
  58. package/dist/lib/ast/types.d.ts +903 -0
  59. package/dist/lib/ast/types.js +277 -23
  60. package/dist/lib/ast/walk.d.ts +162 -0
  61. package/dist/lib/ast/walk.js +116 -60
  62. package/dist/lib/fs/resolve.d.ts +20 -0
  63. package/dist/lib/fs/resolve.js +37 -45
  64. package/dist/lib/parser/declaration/list.d.ts +16 -0
  65. package/dist/lib/parser/declaration/list.js +26 -24
  66. package/dist/lib/parser/declaration/map.d.ts +15 -0
  67. package/dist/lib/parser/declaration/map.js +140 -95
  68. package/dist/lib/parser/declaration/set.d.ts +9 -0
  69. package/dist/lib/parser/declaration/set.js +30 -25
  70. package/dist/lib/parser/node.d.ts +7 -0
  71. package/dist/lib/parser/parse.d.ts +107 -0
  72. package/dist/lib/parser/parse.js +1454 -1445
  73. package/dist/lib/parser/tokenize.d.ts +57 -0
  74. package/dist/lib/parser/tokenize.js +557 -404
  75. package/dist/lib/parser/utils/at-rule-container.d.ts +5 -0
  76. package/dist/lib/parser/utils/at-rule-container.js +486 -0
  77. package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +5 -0
  78. package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
  79. package/dist/lib/parser/utils/at-rule-generic.d.ts +5 -0
  80. package/dist/lib/parser/utils/at-rule-generic.js +118 -0
  81. package/dist/lib/parser/utils/at-rule-import.d.ts +5 -0
  82. package/dist/lib/parser/utils/at-rule-import.js +393 -0
  83. package/dist/lib/parser/utils/at-rule-media.d.ts +5 -0
  84. package/dist/lib/parser/utils/at-rule-media.js +603 -0
  85. package/dist/lib/parser/utils/at-rule-page.d.ts +5 -0
  86. package/dist/lib/parser/utils/at-rule-page.js +28 -0
  87. package/dist/lib/parser/utils/at-rule-support.d.ts +5 -0
  88. package/dist/lib/parser/utils/at-rule-support.js +366 -0
  89. package/dist/lib/parser/utils/at-rule-token.d.ts +1 -0
  90. package/dist/lib/parser/utils/at-rule-when-else.d.ts +5 -0
  91. package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
  92. package/dist/lib/parser/utils/at-rule.d.ts +13 -0
  93. package/dist/lib/parser/utils/at-rule.js +37 -0
  94. package/dist/lib/parser/utils/cache.d.ts +6 -0
  95. package/dist/lib/parser/utils/cache.js +19 -0
  96. package/dist/lib/parser/utils/config.d.ts +2 -0
  97. package/dist/lib/parser/utils/config.js +1 -0
  98. package/dist/lib/parser/utils/declaration-list.d.ts +5 -0
  99. package/dist/lib/parser/utils/declaration.d.ts +18 -0
  100. package/dist/lib/parser/utils/declaration.js +569 -91
  101. package/dist/lib/parser/utils/eq.d.ts +1 -0
  102. package/dist/lib/parser/utils/hash.d.ts +21 -0
  103. package/dist/lib/parser/utils/hash.js +1 -1
  104. package/dist/lib/parser/utils/selector.d.ts +5 -0
  105. package/dist/lib/parser/utils/selector.js +476 -0
  106. package/dist/lib/parser/utils/text.d.ts +3 -0
  107. package/dist/lib/parser/utils/text.js +17 -1
  108. package/dist/lib/parser/utils/token.d.ts +14 -0
  109. package/dist/lib/parser/utils/token.js +102 -0
  110. package/dist/lib/parser/utils/type.d.ts +2 -0
  111. package/dist/lib/parser/utils/type.js +29 -18
  112. package/dist/lib/renderer/render.d.ts +28 -0
  113. package/dist/lib/renderer/render.js +421 -262
  114. package/dist/lib/renderer/sourcemap/lib/encode.d.ts +1 -0
  115. package/dist/lib/renderer/sourcemap/sourcemap.d.ts +26 -0
  116. package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
  117. package/dist/lib/syntax/color/a98rgb.d.ts +2 -0
  118. package/dist/lib/syntax/color/a98rgb.js +8 -12
  119. package/dist/lib/syntax/color/cmyk.d.ts +10 -0
  120. package/dist/lib/syntax/color/cmyk.js +23 -21
  121. package/dist/lib/syntax/color/color-mix.d.ts +2 -0
  122. package/dist/lib/syntax/color/color-mix.js +88 -77
  123. package/dist/lib/syntax/color/color.d.ts +42 -0
  124. package/dist/lib/syntax/color/color.js +65 -68
  125. package/dist/lib/syntax/color/hex.d.ts +16 -0
  126. package/dist/lib/syntax/color/hex.js +27 -31
  127. package/dist/lib/syntax/color/hsl.d.ts +20 -0
  128. package/dist/lib/syntax/color/hsl.js +5 -12
  129. package/dist/lib/syntax/color/hsv.d.ts +2 -0
  130. package/dist/lib/syntax/color/hwb.d.ts +21 -0
  131. package/dist/lib/syntax/color/hwb.js +8 -21
  132. package/dist/lib/syntax/color/lab.d.ts +25 -0
  133. package/dist/lib/syntax/color/lab.js +20 -21
  134. package/dist/lib/syntax/color/lch.d.ts +23 -0
  135. package/dist/lib/syntax/color/lch.js +13 -15
  136. package/dist/lib/syntax/color/oklab.d.ts +22 -0
  137. package/dist/lib/syntax/color/oklab.js +20 -39
  138. package/dist/lib/syntax/color/oklch.d.ts +20 -0
  139. package/dist/lib/syntax/color/oklch.js +14 -16
  140. package/dist/lib/syntax/color/p3.d.ts +6 -0
  141. package/dist/lib/syntax/color/p3.js +0 -8
  142. package/dist/lib/syntax/color/prophotorgb.d.ts +2 -0
  143. package/dist/lib/syntax/color/rec2020.d.ts +2 -0
  144. package/dist/lib/syntax/color/rec2020.js +9 -13
  145. package/dist/lib/syntax/color/relativecolor.d.ts +13 -0
  146. package/dist/lib/syntax/color/relativecolor.js +68 -41
  147. package/dist/lib/syntax/color/rgb.d.ts +20 -0
  148. package/dist/lib/syntax/color/rgb.js +14 -18
  149. package/dist/lib/syntax/color/srgb.d.ts +23 -0
  150. package/dist/lib/syntax/color/srgb.js +27 -26
  151. package/dist/lib/syntax/color/utils/components.d.ts +2 -0
  152. package/dist/lib/syntax/color/utils/components.js +30 -14
  153. package/dist/lib/syntax/color/utils/distance.d.ts +18 -0
  154. package/dist/lib/syntax/color/utils/distance.js +1 -8
  155. package/dist/lib/syntax/color/utils/matrix.d.ts +6 -0
  156. package/dist/lib/syntax/color/xyz.d.ts +5 -0
  157. package/dist/lib/syntax/color/xyz.js +8 -20
  158. package/dist/lib/syntax/color/xyzd50.d.ts +4 -0
  159. package/dist/lib/syntax/color/xyzd50.js +6 -20
  160. package/dist/lib/syntax/constants.d.ts +67 -0
  161. package/dist/lib/syntax/constants.js +436 -0
  162. package/dist/lib/syntax/syntax.d.ts +38 -0
  163. package/dist/lib/syntax/syntax.js +533 -568
  164. package/dist/lib/validation/config.d.ts +14 -0
  165. package/dist/lib/validation/config.js +72 -33
  166. package/dist/lib/validation/config.json.js +1159 -74
  167. package/dist/lib/validation/json.d.ts +2 -0
  168. package/dist/lib/validation/match.d.ts +38 -0
  169. package/dist/lib/validation/match.js +2985 -0
  170. package/dist/lib/validation/parser/parse.d.ts +8 -0
  171. package/dist/lib/validation/parser/parse.js +684 -935
  172. package/dist/lib/validation/parser/typedef.d.ts +95 -0
  173. package/dist/lib/validation/parser/typedef.js +100 -0
  174. package/dist/lib/validation/utils/list.d.ts +4 -0
  175. package/dist/lib/validation/utils/list.js +4 -11
  176. package/dist/lib/validation/utils/whitespace.d.ts +2 -0
  177. package/dist/lib/validation/utils/whitespace.js +2 -8
  178. package/dist/node.d.ts +207 -0
  179. package/dist/node.js +53 -47
  180. package/dist/web.d.ts +169 -0
  181. package/dist/web.js +50 -41
  182. package/package.json +18 -13
  183. package/playground/index.html +1328 -0
  184. package/playground/sw.js +55 -0
  185. package/playground/tree.js +176 -0
  186. package/dist/lib/syntax/color/utils/constants.js +0 -214
  187. package/dist/lib/syntax/utils.js +0 -70
  188. package/dist/lib/validation/at-rules/container.js +0 -342
  189. package/dist/lib/validation/at-rules/counter-style.js +0 -90
  190. package/dist/lib/validation/at-rules/custom-media.js +0 -50
  191. package/dist/lib/validation/at-rules/document.js +0 -89
  192. package/dist/lib/validation/at-rules/else.js +0 -5
  193. package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
  194. package/dist/lib/validation/at-rules/import.js +0 -150
  195. package/dist/lib/validation/at-rules/keyframes.js +0 -67
  196. package/dist/lib/validation/at-rules/layer.js +0 -41
  197. package/dist/lib/validation/at-rules/media.js +0 -255
  198. package/dist/lib/validation/at-rules/namespace.js +0 -81
  199. package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
  200. package/dist/lib/validation/at-rules/page.js +0 -100
  201. package/dist/lib/validation/at-rules/supports.js +0 -295
  202. package/dist/lib/validation/at-rules/when.js +0 -185
  203. package/dist/lib/validation/atrule.js +0 -184
  204. package/dist/lib/validation/selector.js +0 -36
  205. package/dist/lib/validation/syntax.js +0 -1073
  206. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
  207. package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
  208. package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
  209. package/dist/lib/validation/syntaxes/family-name.js +0 -57
  210. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
  211. package/dist/lib/validation/syntaxes/layer-name.js +0 -57
  212. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
  213. package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
  214. package/dist/lib/validation/syntaxes/selector-list.js +0 -5
  215. package/dist/lib/validation/syntaxes/selector.js +0 -5
  216. package/dist/lib/validation/syntaxes/url.js +0 -40
@@ -0,0 +1 @@
1
+ {"/Users/thierrybela/web/WebstormProjects/css/src/lib/validation/json.ts":{"path":"/Users/thierrybela/web/WebstormProjects/css/src/lib/validation/json.ts","statementMap":{},"fnMap":{},"branchMap":{},"s":{},"f":{},"b":{},"all":true},"/Users/thierrybela/web/WebstormProjects/css/src/lib/parser/utils/at-rule-token.ts":{"path":"/Users/thierrybela/web/WebstormProjects/css/src/lib/parser/utils/at-rule-token.ts","statementMap":{},"fnMap":{"0":{"name":"parseAtRuleToken","decl":{"start":{"line":3,"column":16},"end":{"line":3,"column":32}},"loc":{"start":{"line":3,"column":35},"end":{"line":5,"column":1}},"line":3}},"branchMap":{},"s":{},"f":{"0":0},"b":{},"all":true},"/Users/thierrybela/web/WebstormProjects/css/src/lib/ast/features/index.ts":{"path":"/Users/thierrybela/web/WebstormProjects/css/src/lib/ast/features/index.ts","statementMap":{},"fnMap":{},"branchMap":{},"s":{},"f":{},"b":{},"all":true}}
@@ -0,0 +1 @@
1
+ {"parent":null,"pid":30852,"argv":["/Users/thierrybela/.nvm/versions/node/v25.9.0/bin/node","/Users/thierrybela/web/WebstormProjects/css/node_modules/.bin/nyc","test/specs/node.spec.js"],"execArgv":[],"cwd":"/Users/thierrybela/web/WebstormProjects/css","time":1778344578772,"ppid":30830,"coverageFilename":"/Users/thierrybela/web/WebstormProjects/css/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json","externalId":"","uuid":"4874b20e-6f53-4d7a-be5a-cf68316925f2","files":["/Users/thierrybela/web/WebstormProjects/css/src/lib/validation/json.ts","/Users/thierrybela/web/WebstormProjects/css/src/lib/parser/utils/at-rule-token.ts","/Users/thierrybela/web/WebstormProjects/css/src/lib/ast/features/index.ts"]}
@@ -0,0 +1 @@
1
+ {"parent":null,"pid":30856,"argv":["/Users/thierrybela/.nvm/versions/node/v25.9.0/bin/node","undefined"],"execArgv":["-e","\nconst pid = parseInt(process.argv[1], 10)\nprocess.title = 'node (foreground-child watchdog pid=' + pid + ')'\nif (!isNaN(pid)) {\n let barked = false\n // keepalive\n const interval = setInterval(() => {}, 60000)\n const bark = () => {\n clearInterval(interval)\n if (barked) return\n barked = true\n process.removeListener('SIGHUP', bark)\n setTimeout(() => {\n try {\n process.kill(pid, 'SIGKILL')\n setTimeout(() => process.exit(), 200)\n } catch (_) {}\n }, 500)\n })\n process.on('SIGHUP', bark)\n}\n"],"cwd":"/Users/thierrybela/web/WebstormProjects/css","time":1778344579338,"ppid":1,"coverageFilename":"/Users/thierrybela/web/WebstormProjects/css/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json","externalId":"","uuid":"6193bc4c-6f5f-4898-8950-c628825e6342","files":[]}
package/.repl_history ADDED
@@ -0,0 +1,4 @@
1
+ exit()
2
+ exit
3
+ quit()
4
+ quit
package/CHANGELOG.md CHANGED
@@ -1,11 +1,175 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.4.3
4
+
5
+
6
+ ### CSS Modules
7
+
8
+ - [x] Add css module scope 'shortest' to produce short scoped names
9
+
10
+ ```typescript
11
+
12
+ result = await transform(css, {
13
+
14
+ beautify: true,
15
+ module: {scoped: ModuleScopeEnumOptions.Shortest
16
+ }
17
+
18
+ });
19
+
20
+ console.log(result.code);
21
+ ```
22
+
23
+ output
24
+
25
+ ```css
26
+ .a {
27
+ background: red;
28
+ color: #ff0
29
+ }
30
+ .b {
31
+ background: blue
32
+ }
33
+ ```
34
+
35
+ ### CSS if() function
36
+
37
+ - [x] support if() css function syntax https://drafts.csswg.org/css-values-5/#if-notation
38
+ - [x] convert css if() function into legacy syntax
39
+
40
+ ```typescript
41
+
42
+ const css = `
43
+ button {
44
+ background: linear-gradient(
45
+ if(media(min-width: 768px): to right; else: to bottom),
46
+ if(style(--dark-mode): #333; else: #fff),
47
+ if(style(--dark-mode): #000; else: #ccc)
48
+ );
49
+ }`;
50
+
51
+ result = await transform(css, {
52
+
53
+ beautify: true,
54
+ expandIfSyntax: true
55
+ }
56
+
57
+ });
58
+
59
+ console.log(result.code);
60
+ ```
61
+
62
+ output
63
+
64
+ ```css
65
+ button {
66
+ background: linear-gradient(to bottom,#fff,#ccc);
67
+ @media (min-width:768px) {
68
+ background: linear-gradient(to right,#fff,#ccc);
69
+ @container style(--dark-mode) {
70
+ background: linear-gradient(to right,#333,#000)
71
+ }
72
+ }
73
+ @container style(--dark-mode) {
74
+ background: linear-gradient(to bottom,#333,#000)
75
+ }
76
+ }
77
+ ```
78
+
79
+
80
+ ### CSS Color Module Level 5 (Draft)
81
+ - [x] support contrast-color() https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/color_value/contrast-color
82
+ - [x] custom color space in color() https://drafts.csswg.org/css-color-5/#custom-color
83
+ - [x] relative color syntax
84
+ - [x] color syntax
85
+
86
+ ### Media Queries
87
+ - [x] media queries validation
88
+ - [x] automatically generate range media query
89
+ - [x] add at-rule() and named-feature() to @support-condition syntax https://drafts.csswg.org/css-conditional-5/#changes-from-L4
90
+ - [x] support calc() in media features
91
+
92
+
93
+ ```typescript
94
+
95
+ const css = `
96
+
97
+ @media (width >= calc(1024px + 50px)) {
98
+ h1 {
99
+ color: Highlight;
100
+ }
101
+ }`;
102
+
103
+ result = await transform(css, {
104
+
105
+ beautify: true,
106
+ validation: true
107
+ }
108
+
109
+ });
110
+
111
+ console.log(result.code);
112
+ ```
113
+
114
+ output
115
+
116
+ ```css
117
+ @media (width>=1074px) {
118
+ h1 {
119
+ color: Highlight
120
+ }
121
+ }
122
+ ```
123
+
124
+ ### Ast
125
+
126
+ - [x] add ast search functions
127
+ - [x] find() search the ast tree and return the first match
128
+ - [x] findAll() search the ast tree and return all matches
129
+ - [x] findLast() search the ast tree and return the last match
130
+ - [x] findByValue() search the ast tree by checking each node's value and return the first match
131
+
132
+ ### Other Changes
133
+ - [x] fix parsing bugs
134
+ - [x] automatically rename standard declaration names : color-adjust => print-color-adjust
135
+ - [x] rewrite parsing and validation logic
136
+ - [x] selector
137
+ - [x] declaration
138
+ - [x] at-rules
139
+ - [x] @charset
140
+ - [x] @color-profile
141
+ - [x] @container
142
+ - [x] @counter-style
143
+ - [x] @custom-media
144
+ - [x] @document
145
+ - [x] @font-face
146
+ - [x] @font-feature-values
147
+ - [x] @font-palette-values
148
+ - [x] @import
149
+ - [x] @keyframes
150
+ - [x] @layer
151
+ - [x] @media
152
+ - [x] @namespace
153
+ - [x] @page
154
+ - [x] @position-try
155
+ - [x] @property
156
+ - [x] @scope
157
+ - [x] @starting-style
158
+ - [x] @supports
159
+ - [x] @view-transition
160
+ - [x] introduce rawToken type to capture unparseable tokens
161
+
162
+ ## v1.4.2
163
+
164
+ - [x] add css-conditional-5 @support at-rule(<at-keyword-token>) function
165
+ - [x] fix bug when using remove prefix #120
166
+
3
167
  ## v1.4.0
4
168
 
5
169
  ### CSS Module support
6
170
 
7
171
  - [x] scoped name generation
8
- - composes:
172
+ - [x] composes:
9
173
  - [x] compose from local selector
10
174
  - [x] compose from other files
11
175
  - [x] compose from global selector
@@ -20,17 +184,17 @@
20
184
  - [x] css at-rule value
21
185
  - [x] keyframe animations
22
186
  - [x] grid
23
- - naming
187
+ - [x] naming
24
188
  - [x] ignore
25
189
  - [x] camelCase
26
190
  - [x] camelCaseOnly
27
191
  - [x] dashCase
28
192
  - [x] dashCaseOnly
29
- - default mode
193
+ - [x] default mode
30
194
  - [x] global
31
195
  - [x] local
32
196
  - [x] pure(at least one class or id)
33
- - icss
197
+ - [x] icss
34
198
  - [x] :import
35
199
  - [x] :export
36
200
 
package/README.md CHANGED
@@ -33,6 +33,7 @@ $ deno add @tbela99/css-parser
33
33
  - color conversion to any supported color format
34
34
  - automatic nested css rules generation
35
35
  - nested css rules conversion to legacy syntax
36
+ - convert css if() function to legacy syntax
36
37
  - sourcemap generation
37
38
  - css shorthands computation. see the supported properties list below
38
39
  - css transform functions minification
@@ -221,6 +222,7 @@ Include ParseOptions and RenderOptions
221
222
  - nestingRules: boolean, optional. automatically generated nested rules.
222
223
  - expandNestingRules: boolean, optional. convert nesting rules into separate rules. will automatically set nestingRules
223
224
  to false.
225
+ - expandIfSyntax: experimental, convert css if() function into legacy syntax.
224
226
  - removeDuplicateDeclarations: boolean, optional. remove duplicate declarations.
225
227
  - computeTransform: boolean, optional. compute css transform functions.
226
228
  - computeShorthand: boolean, optional. compute shorthand properties.
@@ -365,6 +367,45 @@ console.debug(render(result.ast.chi[0].chi[1].chi[1], {withParents: true}));
365
367
 
366
368
  ```
367
369
 
370
+ ### CSS Modules
371
+
372
+ CSS modules features are fully supported. refer to the [CSS modules](https://tbela99.github.io/css-parser/docs/documents/Guide.CSS_modules.html) documentation for more information.
373
+
374
+ ```javascript
375
+ import {transform} from '@tbela99/css-parser';
376
+
377
+ const css = `
378
+ .table {
379
+ border-collapse: collapse;
380
+ width: 100%;
381
+ }
382
+
383
+ .table td, .table th {
384
+ border: 1px solid #ddd;
385
+ padding: 8px;
386
+ }
387
+
388
+ .table tr:nth-child(even){background-color: #f2f2f2;}
389
+
390
+ .table tr:hover {background-color: #ddd;}
391
+
392
+ .table th {
393
+ padding-top: 12px;
394
+ padding-bottom: 12px;
395
+ text-align: left;
396
+ background-color: #4CAF50;
397
+ color: white;
398
+ }
399
+ `;
400
+
401
+ const result = await transform(css, {module: true});
402
+
403
+ // css code
404
+ console.log(result.code);
405
+ // css mapping
406
+ console.log(result.mapping);
407
+ ```
408
+
368
409
  ### Convert colors
369
410
 
370
411
  ```javascript
@@ -649,6 +690,47 @@ table.colortable th {
649
690
  }
650
691
  ```
651
692
 
693
+ ### CSS if() function expansion
694
+
695
+ ```typescript
696
+
697
+ const css = `
698
+ button {
699
+ background: linear-gradient(
700
+ if(media(min-width: 768px): to right; else: to bottom),
701
+ if(style(--dark-mode): #333; else: #fff),
702
+ if(style(--dark-mode): #000; else: #ccc)
703
+ );
704
+ }`;
705
+
706
+ result = await transform(css, {
707
+
708
+ beautify: true,
709
+ expandIfSyntax: true
710
+ }
711
+
712
+ });
713
+
714
+ console.log(result.code);
715
+ ```
716
+
717
+ output
718
+
719
+ ```css
720
+ button {
721
+ background: linear-gradient(to bottom,#fff,#ccc);
722
+ @media (min-width:768px) {
723
+ background: linear-gradient(to right,#fff,#ccc);
724
+ @container style(--dark-mode) {
725
+ background: linear-gradient(to right,#333,#000)
726
+ }
727
+ }
728
+ @container style(--dark-mode) {
729
+ background: linear-gradient(to bottom,#333,#000)
730
+ }
731
+ }
732
+ ```
733
+
652
734
  ### Calc() resolution
653
735
 
654
736
  ```javascript
@@ -0,0 +1,20 @@
1
+ <svg width="114.3" height="20" viewBox="0 0 1143 200" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="coverage: 85.25%">
2
+ <title>coverage: 85.25%</title>
3
+ <linearGradient id="AQOpN" x2="0" y2="100%">
4
+ <stop offset="0" stop-opacity=".1" stop-color="#EEE"/>
5
+ <stop offset="1" stop-opacity=".1"/>
6
+ </linearGradient>
7
+ <mask id="sgbWQ"><rect width="1143" height="200" rx="30" fill="#FFF"/></mask>
8
+ <g mask="url(#sgbWQ)">
9
+ <rect width="603" height="200" fill="#555"/>
10
+ <rect width="540" height="200" fill="#F73" x="603"/>
11
+ <rect width="1143" height="200" fill="url(#AQOpN)"/>
12
+ </g>
13
+ <g aria-hidden="true" fill="#fff" text-anchor="start" font-family="Verdana,DejaVu Sans,sans-serif" font-size="110">
14
+ <text x="60" y="148" textLength="503" fill="#000" opacity="0.25">coverage</text>
15
+ <text x="50" y="138" textLength="503">coverage</text>
16
+ <text x="658" y="148" textLength="440" fill="#000" opacity="0.25">85.25%</text>
17
+ <text x="648" y="138" textLength="440">85.25%</text>
18
+ </g>
19
+
20
+ </svg>