@tbela99/css-parser 1.3.2 → 1.3.4
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/CHANGELOG.md +12 -0
- package/README.md +59 -20
- package/dist/index-umd-web.js +1846 -1075
- package/dist/index.cjs +1941 -1202
- package/dist/index.d.ts +914 -181
- package/dist/lib/ast/expand.js +5 -10
- package/dist/lib/ast/features/calc.js +8 -8
- package/dist/lib/ast/features/inlinecssvariables.js +9 -8
- package/dist/lib/ast/features/prefix.js +5 -15
- package/dist/lib/ast/features/shorthand.js +5 -6
- package/dist/lib/ast/features/transform.js +18 -25
- package/dist/lib/ast/features/type.js +4 -2
- package/dist/lib/ast/minify.js +56 -112
- package/dist/lib/ast/transform/compute.js +2 -4
- package/dist/lib/ast/transform/matrix.js +20 -20
- package/dist/lib/ast/transform/minify.js +105 -12
- package/dist/lib/ast/transform/rotate.js +11 -11
- package/dist/lib/ast/transform/scale.js +6 -6
- package/dist/lib/ast/transform/skew.js +4 -4
- package/dist/lib/ast/transform/translate.js +3 -3
- package/dist/lib/ast/transform/utils.js +30 -37
- package/dist/lib/ast/types.js +16 -4
- package/dist/lib/ast/walk.js +172 -70
- package/dist/lib/fs/resolve.js +12 -7
- package/dist/lib/parser/declaration/list.js +3 -1
- package/dist/lib/parser/parse.js +441 -161
- package/dist/lib/parser/tokenize.js +12 -14
- package/dist/lib/renderer/render.js +7 -7
- package/dist/lib/syntax/color/cmyk.js +6 -3
- package/dist/lib/syntax/color/color-mix.js +2 -3
- package/dist/lib/syntax/color/color.js +28 -6
- package/dist/lib/syntax/color/hex.js +3 -0
- package/dist/lib/syntax/color/hsl.js +18 -7
- package/dist/lib/syntax/color/hwb.js +3 -3
- package/dist/lib/syntax/color/lab.js +4 -4
- package/dist/lib/syntax/color/lch.js +7 -4
- package/dist/lib/syntax/color/oklab.js +4 -4
- package/dist/lib/syntax/color/oklch.js +18 -6
- package/dist/lib/syntax/color/relativecolor.js +9 -56
- package/dist/lib/syntax/color/srgb.js +1 -1
- package/dist/lib/syntax/syntax.js +36 -18
- package/dist/lib/validation/at-rules/container.js +11 -0
- package/dist/lib/validation/at-rules/counter-style.js +11 -0
- package/dist/lib/validation/at-rules/font-feature-values.js +11 -0
- package/dist/lib/validation/at-rules/keyframes.js +11 -0
- package/dist/lib/validation/at-rules/layer.js +11 -0
- package/dist/lib/validation/at-rules/media.js +11 -0
- package/dist/lib/validation/at-rules/page-margin-box.js +11 -0
- package/dist/lib/validation/at-rules/page.js +11 -0
- package/dist/lib/validation/at-rules/supports.js +11 -0
- package/dist/lib/validation/at-rules/when.js +11 -0
- package/dist/lib/validation/config.js +0 -2
- package/dist/lib/validation/config.json.js +21 -9
- package/dist/lib/validation/parser/parse.js +53 -2
- package/dist/lib/validation/syntax.js +199 -36
- package/dist/node.js +63 -36
- package/dist/web.js +84 -25
- package/package.json +7 -5
- package/dist/lib/validation/parser/types.js +0 -54
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v1.3.4
|
|
4
|
+
|
|
5
|
+
- [x] make streaming optional #109
|
|
6
|
+
- [x] patch at-rule syntax for @font-feature-value #110
|
|
7
|
+
- [x] support percentage in transform() and scale() #111
|
|
8
|
+
- [x] allow arrays in visitor definition #112
|
|
9
|
+
|
|
10
|
+
## v1.3.3
|
|
11
|
+
|
|
12
|
+
- [x] relative color computation bug #105
|
|
13
|
+
- [x] allow duplicated declarations of whitelisted properties #106
|
|
14
|
+
|
|
3
15
|
## v1.3.2
|
|
4
16
|
|
|
5
17
|
- [x] add missing return type
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
# css-parser
|
|
6
6
|
|
|
7
|
-
CSS parser and
|
|
7
|
+
CSS parser, minifier and validator for node and the browser
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
@@ -41,6 +41,10 @@ $ deno add @tbela99/css-parser
|
|
|
41
41
|
- flatten @import rules
|
|
42
42
|
- experimental CSS prefix removal
|
|
43
43
|
|
|
44
|
+
## Online documentation
|
|
45
|
+
|
|
46
|
+
See the full documentation at the [CSS Parser](https://tbela99.github.io/css-parser/docs) documentation site
|
|
47
|
+
|
|
44
48
|
## Playground
|
|
45
49
|
|
|
46
50
|
Try it [online](https://tbela99.github.io/css-parser/playground/)
|
|
@@ -97,8 +101,7 @@ Javascript module from cdn
|
|
|
97
101
|
|
|
98
102
|
<script type="module">
|
|
99
103
|
|
|
100
|
-
import {transform} from 'https://esm.sh/@tbela99/css-parser@1.3.
|
|
101
|
-
|
|
104
|
+
import {transform} from 'https://esm.sh/@tbela99/css-parser@1.3.4/web';
|
|
102
105
|
|
|
103
106
|
const css = `
|
|
104
107
|
.s {
|
|
@@ -119,11 +122,44 @@ Javascript module
|
|
|
119
122
|
<script src="dist/web.js" type="module"></script>
|
|
120
123
|
```
|
|
121
124
|
|
|
122
|
-
|
|
125
|
+
Javascript umd module from cdn
|
|
123
126
|
|
|
124
|
-
```
|
|
127
|
+
```html
|
|
128
|
+
|
|
129
|
+
<script src="https://unpkg.com/@tbela99/css-parser@1.3.4/dist/index-umd-web.js"></script>
|
|
130
|
+
<script>
|
|
131
|
+
|
|
132
|
+
(async () => {
|
|
133
|
+
|
|
134
|
+
const css = `
|
|
135
|
+
|
|
136
|
+
.table {
|
|
137
|
+
border-collapse: collapse;
|
|
138
|
+
width: 100%;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.table td, .table th {
|
|
142
|
+
border: 1px solid #ddd;
|
|
143
|
+
padding: 8px;
|
|
144
|
+
}
|
|
125
145
|
|
|
126
|
-
|
|
146
|
+
.table tr:nth-child(even){background-color: #f2f2f2;}
|
|
147
|
+
|
|
148
|
+
.table tr:hover {background-color: #ddd;}
|
|
149
|
+
|
|
150
|
+
.table th {
|
|
151
|
+
padding-top: 12px;
|
|
152
|
+
padding-bottom: 12px;
|
|
153
|
+
text-align: left;
|
|
154
|
+
background-color: #4CAF50;
|
|
155
|
+
color: white;
|
|
156
|
+
}
|
|
157
|
+
`;
|
|
158
|
+
|
|
159
|
+
console.debug(await CSSParser.transform(css, {beautify: true, convertColor: CSSParser.ColorType.OKLCH}).then(r => r.code));
|
|
160
|
+
})();
|
|
161
|
+
|
|
162
|
+
</script>
|
|
127
163
|
```
|
|
128
164
|
|
|
129
165
|
## Transform
|
|
@@ -728,6 +764,7 @@ result
|
|
|
728
764
|
# Node Walker
|
|
729
765
|
|
|
730
766
|
```javascript
|
|
767
|
+
|
|
731
768
|
import {walk} from '@tbela99/css-parser';
|
|
732
769
|
|
|
733
770
|
for (const {node, parent, root} of walk(ast)) {
|
|
@@ -887,7 +924,8 @@ const css = `
|
|
|
887
924
|
}
|
|
888
925
|
`;
|
|
889
926
|
|
|
890
|
-
|
|
927
|
+
const result = await transform(css, options);
|
|
928
|
+
console.debug(result.code);
|
|
891
929
|
|
|
892
930
|
// .foo{transform:scale(calc(40/3))}
|
|
893
931
|
```
|
|
@@ -898,9 +936,7 @@ the visitor is called only on 'height' declarations
|
|
|
898
936
|
|
|
899
937
|
```typescript
|
|
900
938
|
|
|
901
|
-
import {AstDeclaration, LengthToken, ParserOptions} from
|
|
902
|
-
import {EnumToken} from "../src/lib";
|
|
903
|
-
import {transform} from "../src/node";
|
|
939
|
+
import {AstDeclaration, EnumToken, LengthToken, ParserOptions, transform} from '@tbela99/css-parser';
|
|
904
940
|
|
|
905
941
|
const options: ParserOptions = {
|
|
906
942
|
|
|
@@ -942,7 +978,8 @@ color: lch(from peru calc(l * 0.8) calc(c * 0.7) calc(h + 180))
|
|
|
942
978
|
}
|
|
943
979
|
`;
|
|
944
980
|
|
|
945
|
-
|
|
981
|
+
const result = await transform(css, options);
|
|
982
|
+
console.debug(result.code);
|
|
946
983
|
|
|
947
984
|
// .foo{height:calc(40px/3);width:3px}.selector{color:#0880b0}
|
|
948
985
|
|
|
@@ -983,7 +1020,8 @@ const css = `
|
|
|
983
1020
|
}
|
|
984
1021
|
`;
|
|
985
1022
|
|
|
986
|
-
|
|
1023
|
+
const result = await transform(css, options);
|
|
1024
|
+
console.debug(result.code);
|
|
987
1025
|
|
|
988
1026
|
// .foo{height:calc(40px/3)}
|
|
989
1027
|
|
|
@@ -1024,7 +1062,8 @@ const css = `
|
|
|
1024
1062
|
}
|
|
1025
1063
|
`;
|
|
1026
1064
|
|
|
1027
|
-
|
|
1065
|
+
const result = await transform(css, options);
|
|
1066
|
+
console.debug(result.code);
|
|
1028
1067
|
|
|
1029
1068
|
// .foo{height:calc(40px/3)}
|
|
1030
1069
|
|
|
@@ -1043,10 +1082,10 @@ const options: ParserOptions = {
|
|
|
1043
1082
|
|
|
1044
1083
|
visitor: {
|
|
1045
1084
|
|
|
1046
|
-
|
|
1047
1085
|
Rule(node: AstRule): AstRule {
|
|
1048
1086
|
|
|
1049
|
-
|
|
1087
|
+
node.sel = '.foo,.bar,.fubar'
|
|
1088
|
+
return node;
|
|
1050
1089
|
}
|
|
1051
1090
|
}
|
|
1052
1091
|
};
|
|
@@ -1059,7 +1098,8 @@ const css = `
|
|
|
1059
1098
|
}
|
|
1060
1099
|
`;
|
|
1061
1100
|
|
|
1062
|
-
|
|
1101
|
+
const result = await transform(css, options);
|
|
1102
|
+
console.debug(result.code);
|
|
1063
1103
|
|
|
1064
1104
|
// .foo,.bar,.fubar{height:calc(40px/3)}
|
|
1065
1105
|
|
|
@@ -1071,9 +1111,7 @@ Adding declarations to any rule
|
|
|
1071
1111
|
|
|
1072
1112
|
```typescript
|
|
1073
1113
|
|
|
1074
|
-
import {transform} from
|
|
1075
|
-
import {AstRule, ParserOptions} from "../src/@types";
|
|
1076
|
-
import {parseDeclarations} from "../src/lib";
|
|
1114
|
+
import {AstRule, parseDeclarations, ParserOptions, transform} from '@tbela99/css-parser';
|
|
1077
1115
|
|
|
1078
1116
|
const options: ParserOptions = {
|
|
1079
1117
|
|
|
@@ -1099,7 +1137,8 @@ const css = `
|
|
|
1099
1137
|
}
|
|
1100
1138
|
`;
|
|
1101
1139
|
|
|
1102
|
-
|
|
1140
|
+
const result = await transform(css, options);
|
|
1141
|
+
console.debug(result.code);
|
|
1103
1142
|
|
|
1104
1143
|
// .foo{width:3px}
|
|
1105
1144
|
|