@tbela99/css-parser 0.0.1-alpha4 → 0.0.1-rc1

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.
package/.gitattributes CHANGED
@@ -1,9 +1,11 @@
1
1
  /test/ export-ignore
2
2
  /docs/ export-ignore
3
+ /benchmark
3
4
  /tools/ export-ignore
4
5
  /package-lock.json export-ignore
5
6
  /.gitignore export-ignore
6
7
  /.gitattributes export-ignore
8
+ /coverage/ export-ignore
7
9
  /rollup.config.mjs export-ignore
8
10
  /tsconfig.json export-ignore
9
11
  # exclude all files in test/ from stats
@@ -11,6 +13,7 @@
11
13
  /docs/** linguist-vendored
12
14
  /tools/** linguist-vendored
13
15
  /dist/** linguist-vendored
16
+ /coverage/** linguist-vendored
14
17
  #
15
18
  # do not replace lf by crlf
16
19
  *.css text
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![cov](https://tbela99.github.io/css-parser/badges/coverage.svg)](https://github.com/tbela99/css-parser/actions)
2
+
1
3
  # css-parser
2
4
 
3
5
  CSS parser for node and the browser
@@ -6,9 +8,20 @@ CSS parser for node and the browser
6
8
 
7
9
  ```shell
8
10
  $ npm install @tbela99/css-parser
9
-
10
11
  ```
11
12
 
13
+ ### Features
14
+
15
+ - [x] fault tolerant parser, will try to fix invalid tokens according to the CSS syntax module 3 recommendations.
16
+ - [x] efficient minification, see benchmark.
17
+ - [x] replace @import at-rules with actual css content of the imported rule
18
+ - [x] CSS nesting: automatically create nested rules.
19
+ - [x] works the same way in node and web browser
20
+
21
+ ### Performance
22
+
23
+ - [x] flatten @import
24
+
12
25
  ## Transform
13
26
 
14
27
  Parse and render css in a single pass.
@@ -26,7 +39,7 @@ transform(css, transformOptions = {})
26
39
 
27
40
  import {transform} from '@tbela99/css-parser';
28
41
 
29
- const {ast, code, errors, stats} = await transform(css, {compress: true, resolveImport: true, cwd: 'files/css'});
42
+ const {ast, code, errors, stats} = await transform(css, {minify: true, resolveImport: true, cwd: 'files/css'});
30
43
  ```
31
44
 
32
45
  ### TransformOptions
@@ -36,7 +49,8 @@ Include ParseOptions and RenderOptions
36
49
  #### ParseOptions
37
50
 
38
51
  - src: string, optional. css file location to be used with sourcemap.
39
- - compress: boolean, optional. default to _true_. optimize ast and minify css.
52
+ - minify: boolean, optional. default to _true_. optimize ast.
53
+ - nestingRules: boolean, optional. automatically nest rules.
40
54
  - removeEmpty: boolean, remove empty nodes from the ast.
41
55
  - location: boolean, optional. includes node location in the ast, required for sourcemap generation.
42
56
  - cwd: string, optional. the current working directory. when specified url() are resolved using this value
@@ -44,11 +58,11 @@ Include ParseOptions and RenderOptions
44
58
  - resolveUrls: boolean, optional. resolve css url() according to the parameters 'src' and 'cwd'
45
59
 
46
60
  #### RenderOptions
47
- - compress: boolean, optional. default to _true_. optimize ast and minify css.
61
+ - minify: boolean, optional. default to _true_. minify css output.
48
62
  - indent: string, optional. css indention string. uses space character by default.
49
63
  - newLine: string, new line character.
50
64
  - removeComments: boolean, remove comments in generated css.
51
- - preserveLicense: boolean, force preserving comments starting with '/\*!' when compress is enabling.
65
+ - preserveLicense: boolean, force preserving comments starting with '/\*!' when minify is enabled.
52
66
  - colorConvert: boolean, convert colors to hex.
53
67
 
54
68
 
@@ -82,7 +96,7 @@ render(ast, RenderOptions = {});
82
96
  import {render} from '@tbela99/css-parser';
83
97
 
84
98
  // minified
85
- const {code} = render(ast, {compress: true});
99
+ const {code} = render(ast, {minify: true});
86
100
 
87
101
  console.log(code);
88
102
  ```
@@ -117,6 +117,7 @@ var properties = {
117
117
  },
118
118
  "border-width": {
119
119
  shorthand: "border-width",
120
+ map: "border",
120
121
  properties: [
121
122
  "border-top-width",
122
123
  "border-right-width",
@@ -127,6 +128,9 @@ var properties = {
127
128
  "Length",
128
129
  "Perc"
129
130
  ],
131
+ "default": [
132
+ "medium"
133
+ ],
130
134
  keywords: [
131
135
  "thin",
132
136
  "medium",
@@ -134,19 +138,24 @@ var properties = {
134
138
  ]
135
139
  },
136
140
  "border-top-width": {
141
+ map: "border",
137
142
  shorthand: "border-width"
138
143
  },
139
144
  "border-right-width": {
145
+ map: "border",
140
146
  shorthand: "border-width"
141
147
  },
142
148
  "border-bottom-width": {
149
+ map: "border",
143
150
  shorthand: "border-width"
144
151
  },
145
152
  "border-left-width": {
153
+ map: "border",
146
154
  shorthand: "border-width"
147
155
  },
148
156
  "border-style": {
149
157
  shorthand: "border-style",
158
+ map: "border",
150
159
  properties: [
151
160
  "border-top-style",
152
161
  "border-right-style",
@@ -155,6 +164,9 @@ var properties = {
155
164
  ],
156
165
  types: [
157
166
  ],
167
+ "default": [
168
+ "none"
169
+ ],
158
170
  keywords: [
159
171
  "none",
160
172
  "hidden",
@@ -169,19 +181,24 @@ var properties = {
169
181
  ]
170
182
  },
171
183
  "border-top-style": {
184
+ map: "border",
172
185
  shorthand: "border-style"
173
186
  },
174
187
  "border-right-style": {
188
+ map: "border",
175
189
  shorthand: "border-style"
176
190
  },
177
191
  "border-bottom-style": {
192
+ map: "border",
178
193
  shorthand: "border-style"
179
194
  },
180
195
  "border-left-style": {
196
+ map: "border",
181
197
  shorthand: "border-style"
182
198
  },
183
199
  "border-color": {
184
200
  shorthand: "border-color",
201
+ map: "border",
185
202
  properties: [
186
203
  "border-top-color",
187
204
  "border-right-color",
@@ -191,23 +208,95 @@ var properties = {
191
208
  types: [
192
209
  "Color"
193
210
  ],
211
+ "default": [
212
+ "currentcolor"
213
+ ],
194
214
  keywords: [
195
215
  ]
196
216
  },
197
217
  "border-top-color": {
218
+ map: "border",
198
219
  shorthand: "border-color"
199
220
  },
200
221
  "border-right-color": {
222
+ map: "border",
201
223
  shorthand: "border-color"
202
224
  },
203
225
  "border-bottom-color": {
226
+ map: "border",
204
227
  shorthand: "border-color"
205
228
  },
206
229
  "border-left-color": {
230
+ map: "border",
207
231
  shorthand: "border-color"
208
232
  }
209
233
  };
210
234
  var map = {
235
+ border: {
236
+ shorthand: "border",
237
+ pattern: "border-color border-style border-width",
238
+ keywords: [
239
+ "none"
240
+ ],
241
+ "default": [
242
+ "0",
243
+ "none"
244
+ ],
245
+ properties: {
246
+ "border-color": {
247
+ types: [
248
+ "Color"
249
+ ],
250
+ "default": [
251
+ "currentcolor"
252
+ ],
253
+ keywords: [
254
+ ]
255
+ },
256
+ "border-style": {
257
+ types: [
258
+ ],
259
+ "default": [
260
+ "none"
261
+ ],
262
+ keywords: [
263
+ "none",
264
+ "hidden",
265
+ "dotted",
266
+ "dashed",
267
+ "solid",
268
+ "double",
269
+ "groove",
270
+ "ridge",
271
+ "inset",
272
+ "outset"
273
+ ]
274
+ },
275
+ "border-width": {
276
+ types: [
277
+ "Length",
278
+ "Perc"
279
+ ],
280
+ "default": [
281
+ "medium"
282
+ ],
283
+ keywords: [
284
+ "thin",
285
+ "medium",
286
+ "thick"
287
+ ]
288
+ }
289
+ }
290
+ },
291
+ "border-color": {
292
+ shorthand: "border"
293
+ },
294
+ "border-style": {
295
+ shorthand: "border"
296
+ },
297
+ "border-width": {
298
+ shorthand: "border"
299
+ },
211
300
  outline: {
212
301
  shorthand: "outline",
213
302
  pattern: "outline-color outline-style outline-width",
@@ -224,12 +313,10 @@ var map = {
224
313
  "Color"
225
314
  ],
226
315
  "default": [
227
- "currentColor",
228
- "invert"
316
+ "currentColor"
229
317
  ],
230
318
  keywords: [
231
- "currentColor",
232
- "invert"
319
+ "currentColor"
233
320
  ]
234
321
  },
235
322
  "outline-style": {
@@ -567,6 +654,7 @@ var map = {
567
654
  "default": [
568
655
  "transparent"
569
656
  ],
657
+ multiple: true,
570
658
  keywords: [
571
659
  ]
572
660
  },
@@ -587,6 +675,7 @@ var map = {
587
675
  "default": [
588
676
  "scroll"
589
677
  ],
678
+ multiple: true,
590
679
  keywords: [
591
680
  "scroll",
592
681
  "fixed",
@@ -599,6 +688,7 @@ var map = {
599
688
  "default": [
600
689
  "border-box"
601
690
  ],
691
+ multiple: true,
602
692
  keywords: [
603
693
  "border-box",
604
694
  "padding-box",
@@ -612,6 +702,7 @@ var map = {
612
702
  "default": [
613
703
  "padding-box"
614
704
  ],
705
+ multiple: true,
615
706
  keywords: [
616
707
  "border-box",
617
708
  "padding-box",