@tbela99/css-parser 0.0.1 → 0.2.0
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 +318 -34
- package/dist/config.json.js +386 -4
- package/dist/index-umd-web.js +3260 -1563
- package/dist/index.cjs +3259 -1564
- package/dist/index.d.ts +687 -536
- package/dist/lib/ast/expand.js +14 -14
- package/dist/lib/ast/features/calc.js +225 -0
- package/dist/lib/ast/features/index.js +3 -0
- package/dist/lib/ast/features/inlinecssvariables.js +130 -0
- package/dist/lib/ast/features/shorthand.js +46 -0
- package/dist/lib/ast/features/utils/math.js +95 -0
- package/dist/lib/ast/minify.js +401 -372
- package/dist/lib/ast/types.js +101 -0
- package/dist/lib/ast/utils/minifyfeature.js +8 -0
- package/dist/lib/ast/walk.js +37 -9
- package/dist/lib/iterable/set.js +48 -0
- package/dist/lib/iterable/weakmap.js +53 -0
- package/dist/lib/parser/declaration/list.js +18 -4
- package/dist/lib/parser/declaration/map.js +102 -33
- package/dist/lib/parser/declaration/set.js +18 -12
- package/dist/lib/parser/parse.js +661 -421
- package/dist/lib/parser/tokenize.js +82 -46
- package/dist/lib/parser/utils/syntax.js +13 -10
- package/dist/lib/parser/utils/type.js +23 -6
- package/dist/lib/renderer/render.js +253 -84
- package/dist/lib/renderer/sourcemap/lib/encode.js +37 -0
- package/dist/lib/renderer/sourcemap/sourcemap.js +58 -0
- package/dist/lib/renderer/utils/color.js +25 -20
- package/dist/node/index.js +30 -15
- package/dist/web/index.js +36 -19
- package/package.json +9 -6
- package/dist/lib/transform.js +0 -24
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { eq } from '../utils/eq.js';
|
|
2
2
|
import { isLength } from '../utils/syntax.js';
|
|
3
|
+
import { EnumToken } from '../../ast/types.js';
|
|
4
|
+
import '../../ast/minify.js';
|
|
5
|
+
import '../parse.js';
|
|
6
|
+
import '../../renderer/utils/color.js';
|
|
7
|
+
import '../../renderer/sourcemap/lib/encode.js';
|
|
3
8
|
|
|
4
9
|
class PropertySet {
|
|
5
10
|
config;
|
|
@@ -20,7 +25,8 @@ class PropertySet {
|
|
|
20
25
|
const tokens = [];
|
|
21
26
|
// @ts-ignore
|
|
22
27
|
for (let token of this.declarations.get(this.config.shorthand).val) {
|
|
23
|
-
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
if (this.config.types.some(t => token.typ == EnumToken[t]) || (token.typ == EnumToken.NumberTokenType && token.val == '0' &&
|
|
24
30
|
(this.config.types.includes('Length') ||
|
|
25
31
|
this.config.types.includes('Angle') ||
|
|
26
32
|
this.config.types.includes('Dimension')))) {
|
|
@@ -31,15 +37,15 @@ class PropertySet {
|
|
|
31
37
|
tokens[current].push(token);
|
|
32
38
|
continue;
|
|
33
39
|
}
|
|
34
|
-
if (token.typ !=
|
|
35
|
-
if (token.typ ==
|
|
40
|
+
if (token.typ != EnumToken.WhitespaceTokenType && token.typ != EnumToken.CommentTokenType) {
|
|
41
|
+
if (token.typ == EnumToken.IdenTokenType && this.config.keywords.includes(token.val)) {
|
|
36
42
|
if (tokens.length == 0) {
|
|
37
43
|
tokens.push([]);
|
|
38
44
|
current++;
|
|
39
45
|
}
|
|
40
46
|
tokens[current].push(token);
|
|
41
47
|
}
|
|
42
|
-
if (token.typ ==
|
|
48
|
+
if (token.typ == EnumToken.LiteralTokenType && token.val == this.config.separator) {
|
|
43
49
|
tokens.push([]);
|
|
44
50
|
current++;
|
|
45
51
|
continue;
|
|
@@ -54,7 +60,7 @@ class PropertySet {
|
|
|
54
60
|
this.config.properties.forEach((property, index) => {
|
|
55
61
|
if (!this.declarations.has(property)) {
|
|
56
62
|
this.declarations.set(property, {
|
|
57
|
-
typ:
|
|
63
|
+
typ: EnumToken.DeclarationNodeType,
|
|
58
64
|
nam: property,
|
|
59
65
|
val: []
|
|
60
66
|
});
|
|
@@ -71,7 +77,7 @@ class PropertySet {
|
|
|
71
77
|
// @ts-ignore
|
|
72
78
|
const val = this.declarations.get(property).val;
|
|
73
79
|
if (val.length > 0) {
|
|
74
|
-
val.push({ typ:
|
|
80
|
+
val.push({ typ: EnumToken.WhitespaceTokenType });
|
|
75
81
|
}
|
|
76
82
|
val.push({ ...values[index] });
|
|
77
83
|
});
|
|
@@ -102,7 +108,7 @@ class PropertySet {
|
|
|
102
108
|
let index = 0;
|
|
103
109
|
// @ts-ignore
|
|
104
110
|
for (const token of this.declarations.get(property).val) {
|
|
105
|
-
if (token.typ ==
|
|
111
|
+
if (token.typ == EnumToken.WhitespaceTokenType) {
|
|
106
112
|
continue;
|
|
107
113
|
}
|
|
108
114
|
if (values.length == index) {
|
|
@@ -118,8 +124,8 @@ class PropertySet {
|
|
|
118
124
|
const t = value[i];
|
|
119
125
|
const k = value[i == 1 ? 0 : i % 2];
|
|
120
126
|
if (t.val == k.val && t.val == '0') {
|
|
121
|
-
if ((t.typ ==
|
|
122
|
-
(k.typ ==
|
|
127
|
+
if ((t.typ == EnumToken.NumberTokenType && isLength(k)) ||
|
|
128
|
+
(k.typ == EnumToken.NumberTokenType && isLength(t)) ||
|
|
123
129
|
(isLength(k) || isLength(t))) {
|
|
124
130
|
value.splice(i, 1);
|
|
125
131
|
continue;
|
|
@@ -133,19 +139,19 @@ class PropertySet {
|
|
|
133
139
|
}
|
|
134
140
|
}
|
|
135
141
|
iterator = [{
|
|
136
|
-
typ:
|
|
142
|
+
typ: EnumToken.DeclarationNodeType,
|
|
137
143
|
nam: this.config.shorthand,
|
|
138
144
|
val: values.reduce((acc, curr) => {
|
|
139
145
|
if (curr.length > 1) {
|
|
140
146
|
const k = curr.length * 2 - 1;
|
|
141
147
|
let i = 1;
|
|
142
148
|
while (i < k) {
|
|
143
|
-
curr.splice(i, 0, { typ:
|
|
149
|
+
curr.splice(i, 0, { typ: EnumToken.WhitespaceTokenType });
|
|
144
150
|
i += 2;
|
|
145
151
|
}
|
|
146
152
|
}
|
|
147
153
|
if (acc.length > 0) {
|
|
148
|
-
acc.push({ typ:
|
|
154
|
+
acc.push({ typ: EnumToken.LiteralTokenType, val: this.config.separator });
|
|
149
155
|
}
|
|
150
156
|
acc.push(...curr);
|
|
151
157
|
return acc;
|