@tbela99/css-parser 0.0.1-alpha5 → 0.0.1-rc2

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,5 +1,6 @@
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
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![cov](https://tbela99.github.io/css-parser/badges/coverage.svg)](https://github.com/tbela99/css-parser/actions)
1
+ [![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) [![cov](https://tbela99.github.io/css-parser/badges/coverage.svg)](https://github.com/tbela99/css-parser/actions)
2
2
 
3
3
  # css-parser
4
4
 
@@ -8,9 +8,20 @@ CSS parser for node and the browser
8
8
 
9
9
  ```shell
10
10
  $ npm install @tbela99/css-parser
11
-
12
11
  ```
13
12
 
13
+ ### Features
14
+
15
+ - fault tolerant parser, will try to fix invalid tokens according to the CSS syntax module 3 recommendations.
16
+ - efficient minification, see [benchmark](https://tbela99.github.io/css-parser/benchmark/index.html)
17
+ - replace @import at-rules with actual css content of the imported rule
18
+ - automatically create nested css rules
19
+ - works the same way in node and web browser
20
+
21
+ ### Performance
22
+
23
+ - flatten @import
24
+
14
25
  ## Transform
15
26
 
16
27
  Parse and render css in a single pass.
@@ -28,7 +39,7 @@ transform(css, transformOptions = {})
28
39
 
29
40
  import {transform} from '@tbela99/css-parser';
30
41
 
31
- 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'});
32
43
  ```
33
44
 
34
45
  ### TransformOptions
@@ -38,7 +49,8 @@ Include ParseOptions and RenderOptions
38
49
  #### ParseOptions
39
50
 
40
51
  - src: string, optional. css file location to be used with sourcemap.
41
- - 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 generated nested rules.
42
54
  - removeEmpty: boolean, remove empty nodes from the ast.
43
55
  - location: boolean, optional. includes node location in the ast, required for sourcemap generation.
44
56
  - cwd: string, optional. the current working directory. when specified url() are resolved using this value
@@ -46,11 +58,11 @@ Include ParseOptions and RenderOptions
46
58
  - resolveUrls: boolean, optional. resolve css url() according to the parameters 'src' and 'cwd'
47
59
 
48
60
  #### RenderOptions
49
- - compress: boolean, optional. default to _true_. optimize ast and minify css.
61
+ - minify: boolean, optional. default to _true_. minify css output.
50
62
  - indent: string, optional. css indention string. uses space character by default.
51
63
  - newLine: string, new line character.
52
64
  - removeComments: boolean, remove comments in generated css.
53
- - preserveLicense: boolean, force preserving comments starting with '/\*!' when compress is enabling.
65
+ - preserveLicense: boolean, force preserving comments starting with '/\*!' when minify is enabled.
54
66
  - colorConvert: boolean, convert colors to hex.
55
67
 
56
68
 
@@ -84,7 +96,7 @@ render(ast, RenderOptions = {});
84
96
  import {render} from '@tbela99/css-parser';
85
97
 
86
98
  // minified
87
- const {code} = render(ast, {compress: true});
99
+ const {code} = render(ast, {minify: true});
88
100
 
89
101
  console.log(code);
90
102
  ```
@@ -176,4 +188,4 @@ Single JavaScript file
176
188
  ### AtRuleStyleSheet
177
189
 
178
190
  - typ: string 'Stylesheet'
179
- - chi: array of children
191
+ - chi: array of children
@@ -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",