@tbela99/css-parser 0.0.1-rc7 → 0.0.1
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/README.md +42 -7
- package/dist/index-umd-web.js +2 -8
- package/dist/index.cjs +2 -8
- package/dist/lib/ast/expand.js +0 -6
- package/dist/lib/parser/utils/eq.js +1 -1
- package/dist/lib/parser/utils/syntax.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,19 +10,15 @@ CSS parser for node and the browser
|
|
|
10
10
|
$ npm install @tbela99/css-parser
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
## Features
|
|
14
14
|
|
|
15
15
|
- fault tolerant parser, will try to fix invalid tokens according to the CSS syntax module 3 recommendations.
|
|
16
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
17
|
- automatically generate nested css rules
|
|
18
|
+
- compute css shorthands. see the list below
|
|
19
19
|
- expand nested css
|
|
20
20
|
- works the same way in node and web browser
|
|
21
21
|
|
|
22
|
-
### Performance
|
|
23
|
-
|
|
24
|
-
- flatten @import
|
|
25
|
-
|
|
26
22
|
## Transform
|
|
27
23
|
|
|
28
24
|
Parse and render css in a single pass.
|
|
@@ -131,7 +127,7 @@ import as a CommonJS module
|
|
|
131
127
|
|
|
132
128
|
```javascript
|
|
133
129
|
|
|
134
|
-
|
|
130
|
+
const {transform} = require('@tbela99/css-parser/cjs');
|
|
135
131
|
|
|
136
132
|
// ...
|
|
137
133
|
```
|
|
@@ -303,3 +299,42 @@ table.colortable th {
|
|
|
303
299
|
|
|
304
300
|
- typ: string 'Stylesheet'
|
|
305
301
|
- chi: array of children
|
|
302
|
+
|
|
303
|
+
## Minification
|
|
304
|
+
|
|
305
|
+
- [x] merge identical rules
|
|
306
|
+
- [x] merge adjacent rules
|
|
307
|
+
- [x] minify colors
|
|
308
|
+
- [x] minify numbers and Dimensions tokens
|
|
309
|
+
- [x] compute shorthand: see the list below
|
|
310
|
+
- [x] remove redundant declarations
|
|
311
|
+
- [x] conditionally unwrap :is()
|
|
312
|
+
- [x] automatic css nesting
|
|
313
|
+
- [x] automatically wrap selectors using :is()
|
|
314
|
+
- [x] multi-level shorthand properties (border - [border-width, border-color, border-style, etc.]) https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties
|
|
315
|
+
- [x] avoid reparsing (declarations, selectors, at-rule)
|
|
316
|
+
- [x] node and browser versions
|
|
317
|
+
- [x] decode and replace utf-8 escape sequence
|
|
318
|
+
|
|
319
|
+
## Computed shorthands
|
|
320
|
+
- [x] background
|
|
321
|
+
- [x] border
|
|
322
|
+
- [x] border-bottom
|
|
323
|
+
- [x] border-color
|
|
324
|
+
- [x] border-left
|
|
325
|
+
- [x] border-radius
|
|
326
|
+
- [x] border-right
|
|
327
|
+
- [x] border-style
|
|
328
|
+
- [x] border-top
|
|
329
|
+
- [x] border-width
|
|
330
|
+
- [x] font
|
|
331
|
+
- [x] inset
|
|
332
|
+
- [x] margin
|
|
333
|
+
- [x] outline
|
|
334
|
+
- [x] overflow
|
|
335
|
+
- [x] padding
|
|
336
|
+
- [x] text-decoration
|
|
337
|
+
|
|
338
|
+
## Performance
|
|
339
|
+
|
|
340
|
+
- [x] flatten @import
|
package/dist/index-umd-web.js
CHANGED
|
@@ -830,7 +830,7 @@
|
|
|
830
830
|
if (token.typ == 'Func' && token.chi.length > 0 && colorsFunc.includes(token.val)) {
|
|
831
831
|
// @ts-ignore
|
|
832
832
|
for (const v of token.chi) {
|
|
833
|
-
if (!['Number', 'Perc', 'Comma', 'Whitespace'].includes(v.typ)) {
|
|
833
|
+
if (!['Number', 'Angle', 'Perc', 'Comma', 'Whitespace', 'Literal'].includes(v.typ)) {
|
|
834
834
|
return false;
|
|
835
835
|
}
|
|
836
836
|
}
|
|
@@ -1950,7 +1950,7 @@
|
|
|
1950
1950
|
}
|
|
1951
1951
|
let key;
|
|
1952
1952
|
for (key of k1) {
|
|
1953
|
-
if (!eq(a[key], b[key])) {
|
|
1953
|
+
if (!(key in b) || !eq(a[key], b[key])) {
|
|
1954
1954
|
return false;
|
|
1955
1955
|
}
|
|
1956
1956
|
}
|
|
@@ -3897,10 +3897,6 @@
|
|
|
3897
3897
|
const result = [];
|
|
3898
3898
|
if (ast.typ == 'Rule') {
|
|
3899
3899
|
let i = 0;
|
|
3900
|
-
// @ts-ignore
|
|
3901
|
-
delete ast.raw;
|
|
3902
|
-
// @ts-ignore
|
|
3903
|
-
delete ast.optimized;
|
|
3904
3900
|
for (; i < ast.chi.length; i++) {
|
|
3905
3901
|
if (ast.chi[i].typ == 'Rule') {
|
|
3906
3902
|
const rule = ast.chi[i];
|
|
@@ -3915,8 +3911,6 @@
|
|
|
3915
3911
|
else {
|
|
3916
3912
|
rule.sel = replaceCompound(rule.sel, ast.sel);
|
|
3917
3913
|
}
|
|
3918
|
-
delete rule.raw;
|
|
3919
|
-
delete rule.optimized;
|
|
3920
3914
|
ast.chi.splice(i--, 1);
|
|
3921
3915
|
result.push(...expandRule(rule));
|
|
3922
3916
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -828,7 +828,7 @@ function isColor(token) {
|
|
|
828
828
|
if (token.typ == 'Func' && token.chi.length > 0 && colorsFunc.includes(token.val)) {
|
|
829
829
|
// @ts-ignore
|
|
830
830
|
for (const v of token.chi) {
|
|
831
|
-
if (!['Number', 'Perc', 'Comma', 'Whitespace'].includes(v.typ)) {
|
|
831
|
+
if (!['Number', 'Angle', 'Perc', 'Comma', 'Whitespace', 'Literal'].includes(v.typ)) {
|
|
832
832
|
return false;
|
|
833
833
|
}
|
|
834
834
|
}
|
|
@@ -1948,7 +1948,7 @@ function eq(a, b) {
|
|
|
1948
1948
|
}
|
|
1949
1949
|
let key;
|
|
1950
1950
|
for (key of k1) {
|
|
1951
|
-
if (!eq(a[key], b[key])) {
|
|
1951
|
+
if (!(key in b) || !eq(a[key], b[key])) {
|
|
1952
1952
|
return false;
|
|
1953
1953
|
}
|
|
1954
1954
|
}
|
|
@@ -3895,10 +3895,6 @@ function expandRule(node) {
|
|
|
3895
3895
|
const result = [];
|
|
3896
3896
|
if (ast.typ == 'Rule') {
|
|
3897
3897
|
let i = 0;
|
|
3898
|
-
// @ts-ignore
|
|
3899
|
-
delete ast.raw;
|
|
3900
|
-
// @ts-ignore
|
|
3901
|
-
delete ast.optimized;
|
|
3902
3898
|
for (; i < ast.chi.length; i++) {
|
|
3903
3899
|
if (ast.chi[i].typ == 'Rule') {
|
|
3904
3900
|
const rule = ast.chi[i];
|
|
@@ -3913,8 +3909,6 @@ function expandRule(node) {
|
|
|
3913
3909
|
else {
|
|
3914
3910
|
rule.sel = replaceCompound(rule.sel, ast.sel);
|
|
3915
3911
|
}
|
|
3916
|
-
delete rule.raw;
|
|
3917
|
-
delete rule.optimized;
|
|
3918
3912
|
ast.chi.splice(i--, 1);
|
|
3919
3913
|
result.push(...expandRule(rule));
|
|
3920
3914
|
}
|
package/dist/lib/ast/expand.js
CHANGED
|
@@ -52,10 +52,6 @@ function expandRule(node) {
|
|
|
52
52
|
const result = [];
|
|
53
53
|
if (ast.typ == 'Rule') {
|
|
54
54
|
let i = 0;
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
delete ast.raw;
|
|
57
|
-
// @ts-ignore
|
|
58
|
-
delete ast.optimized;
|
|
59
55
|
for (; i < ast.chi.length; i++) {
|
|
60
56
|
if (ast.chi[i].typ == 'Rule') {
|
|
61
57
|
const rule = ast.chi[i];
|
|
@@ -70,8 +66,6 @@ function expandRule(node) {
|
|
|
70
66
|
else {
|
|
71
67
|
rule.sel = replaceCompound(rule.sel, ast.sel);
|
|
72
68
|
}
|
|
73
|
-
delete rule.raw;
|
|
74
|
-
delete rule.optimized;
|
|
75
69
|
ast.chi.splice(i--, 1);
|
|
76
70
|
result.push(...expandRule(rule));
|
|
77
71
|
}
|
|
@@ -37,7 +37,7 @@ function isColor(token) {
|
|
|
37
37
|
if (token.typ == 'Func' && token.chi.length > 0 && colorsFunc.includes(token.val)) {
|
|
38
38
|
// @ts-ignore
|
|
39
39
|
for (const v of token.chi) {
|
|
40
|
-
if (!['Number', 'Perc', 'Comma', 'Whitespace'].includes(v.typ)) {
|
|
40
|
+
if (!['Number', 'Angle', 'Perc', 'Comma', 'Whitespace', 'Literal'].includes(v.typ)) {
|
|
41
41
|
return false;
|
|
42
42
|
}
|
|
43
43
|
}
|