Skip to content

Commit 6c27892

Browse files
committed
compute border shorthand #3bun run build
1 parent e3e7031 commit 6c27892

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+7711
-9257
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/test/ export-ignore
22
/docs/ export-ignore
3+
/benchmark
34
/tools/ export-ignore
45
/package-lock.json export-ignore
56
/.gitignore export-ignore

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/test
2+
/benchmark
23
/tools
34
/ROADMAP.md
45
/rollup.config.mjs

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@ CSS parser for node and the browser
88

99
```shell
1010
$ npm install @tbela99/css-parser
11-
1211
```
1312

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] automatically create nested css rules
19+
- [x] works the same way in node and web browser
20+
21+
### Performance
22+
23+
- [x] flatten @import
24+
1425
## Transform
1526

1627
Parse and render css in a single pass.
@@ -28,7 +39,7 @@ transform(css, transformOptions = {})
2839

2940
import {transform} from '@tbela99/css-parser';
3041

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'});
3243
```
3344

3445
### TransformOptions
@@ -38,19 +49,20 @@ Include ParseOptions and RenderOptions
3849
#### ParseOptions
3950

4051
- 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 nest rules.
4254
- removeEmpty: boolean, remove empty nodes from the ast.
4355
- location: boolean, optional. includes node location in the ast, required for sourcemap generation.
4456
- cwd: string, optional. the current working directory. when specified url() are resolved using this value
4557
- resolveImport: boolean, optional. replace @import node by the content of the referenced stylesheet.
4658
- resolveUrls: boolean, optional. resolve css url() according to the parameters 'src' and 'cwd'
4759

4860
#### RenderOptions
49-
- compress: boolean, optional. default to _true_. optimize ast and minify css.
61+
- minify: boolean, optional. default to _true_. minify css output.
5062
- indent: string, optional. css indention string. uses space character by default.
5163
- newLine: string, new line character.
5264
- 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.
5466
- colorConvert: boolean, convert colors to hex.
5567

5668

@@ -84,7 +96,7 @@ render(ast, RenderOptions = {});
8496
import {render} from '@tbela99/css-parser';
8597

8698
// minified
87-
const {code} = render(ast, {compress: true});
99+
const {code} = render(ast, {minify: true});
88100

89101
console.log(code);
90102
```

dist/config.json.js

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ var properties = {
117117
},
118118
"border-width": {
119119
shorthand: "border-width",
120+
map: "border",
120121
properties: [
121122
"border-top-width",
122123
"border-right-width",
@@ -127,26 +128,34 @@ var properties = {
127128
"Length",
128129
"Perc"
129130
],
131+
"default": [
132+
"medium"
133+
],
130134
keywords: [
131135
"thin",
132136
"medium",
133137
"thick"
134138
]
135139
},
136140
"border-top-width": {
141+
map: "border",
137142
shorthand: "border-width"
138143
},
139144
"border-right-width": {
145+
map: "border",
140146
shorthand: "border-width"
141147
},
142148
"border-bottom-width": {
149+
map: "border",
143150
shorthand: "border-width"
144151
},
145152
"border-left-width": {
153+
map: "border",
146154
shorthand: "border-width"
147155
},
148156
"border-style": {
149157
shorthand: "border-style",
158+
map: "border",
150159
properties: [
151160
"border-top-style",
152161
"border-right-style",
@@ -155,6 +164,9 @@ var properties = {
155164
],
156165
types: [
157166
],
167+
"default": [
168+
"none"
169+
],
158170
keywords: [
159171
"none",
160172
"hidden",
@@ -169,19 +181,24 @@ var properties = {
169181
]
170182
},
171183
"border-top-style": {
184+
map: "border",
172185
shorthand: "border-style"
173186
},
174187
"border-right-style": {
188+
map: "border",
175189
shorthand: "border-style"
176190
},
177191
"border-bottom-style": {
192+
map: "border",
178193
shorthand: "border-style"
179194
},
180195
"border-left-style": {
196+
map: "border",
181197
shorthand: "border-style"
182198
},
183199
"border-color": {
184200
shorthand: "border-color",
201+
map: "border",
185202
properties: [
186203
"border-top-color",
187204
"border-right-color",
@@ -191,23 +208,95 @@ var properties = {
191208
types: [
192209
"Color"
193210
],
211+
"default": [
212+
"currentcolor"
213+
],
194214
keywords: [
195215
]
196216
},
197217
"border-top-color": {
218+
map: "border",
198219
shorthand: "border-color"
199220
},
200221
"border-right-color": {
222+
map: "border",
201223
shorthand: "border-color"
202224
},
203225
"border-bottom-color": {
226+
map: "border",
204227
shorthand: "border-color"
205228
},
206229
"border-left-color": {
230+
map: "border",
207231
shorthand: "border-color"
208232
}
209233
};
210234
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+
},
211300
outline: {
212301
shorthand: "outline",
213302
pattern: "outline-color outline-style outline-width",
@@ -224,12 +313,10 @@ var map = {
224313
"Color"
225314
],
226315
"default": [
227-
"currentColor",
228-
"invert"
316+
"currentColor"
229317
],
230318
keywords: [
231-
"currentColor",
232-
"invert"
319+
"currentColor"
233320
]
234321
},
235322
"outline-style": {
@@ -567,6 +654,7 @@ var map = {
567654
"default": [
568655
"transparent"
569656
],
657+
multiple: true,
570658
keywords: [
571659
]
572660
},
@@ -587,6 +675,7 @@ var map = {
587675
"default": [
588676
"scroll"
589677
],
678+
multiple: true,
590679
keywords: [
591680
"scroll",
592681
"fixed",
@@ -599,6 +688,7 @@ var map = {
599688
"default": [
600689
"border-box"
601690
],
691+
multiple: true,
602692
keywords: [
603693
"border-box",
604694
"padding-box",
@@ -612,6 +702,7 @@ var map = {
612702
"default": [
613703
"padding-box"
614704
],
705+
multiple: true,
615706
keywords: [
616707
"border-box",
617708
"padding-box",

0 commit comments

Comments
 (0)