@tbela99/css-parser 0.0.1 → 0.1.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 +117 -36
- package/dist/index-umd-web.js +2057 -1235
- package/dist/index.cjs +2051 -1231
- package/dist/index.d.ts +677 -332
- package/dist/lib/ast/expand.js +14 -14
- package/dist/lib/ast/features/calc.js +256 -0
- package/dist/lib/ast/features/index.js +3 -0
- package/dist/lib/ast/features/inlinecssvariables.js +115 -0
- package/dist/lib/ast/features/shorthand.js +45 -0
- package/dist/lib/ast/minify.js +395 -371
- package/dist/lib/ast/types.js +88 -0
- package/dist/lib/ast/utiles/minifyfeature.js +8 -0
- package/dist/lib/ast/walk.js +24 -9
- package/dist/lib/parser/declaration/list.js +18 -4
- package/dist/lib/parser/declaration/map.js +51 -30
- package/dist/lib/parser/declaration/set.js +18 -12
- package/dist/lib/parser/parse.js +176 -136
- package/dist/lib/parser/tokenize.js +42 -35
- package/dist/lib/parser/utils/syntax.js +13 -10
- package/dist/lib/parser/utils/type.js +18 -6
- package/dist/lib/renderer/render.js +201 -79
- 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 +29 -10
- package/dist/web/index.js +33 -12
- package/package.json +5 -4
- package/dist/lib/transform.js +0 -24
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
var NodeType;
|
|
2
|
+
(function (NodeType) {
|
|
3
|
+
NodeType[NodeType["CommentNodeType"] = 0] = "CommentNodeType";
|
|
4
|
+
NodeType[NodeType["CDOCOMMNodeType"] = 1] = "CDOCOMMNodeType";
|
|
5
|
+
NodeType[NodeType["StyleSheetNodeType"] = 2] = "StyleSheetNodeType";
|
|
6
|
+
NodeType[NodeType["AtRuleNodeType"] = 3] = "AtRuleNodeType";
|
|
7
|
+
NodeType[NodeType["RuleNodeType"] = 4] = "RuleNodeType";
|
|
8
|
+
NodeType[NodeType["DeclarationNodeType"] = 5] = "DeclarationNodeType";
|
|
9
|
+
})(NodeType || (NodeType = {}));
|
|
10
|
+
var EnumToken;
|
|
11
|
+
(function (EnumToken) {
|
|
12
|
+
EnumToken[EnumToken["CommentTokenType"] = 0] = "CommentTokenType";
|
|
13
|
+
EnumToken[EnumToken["CDOCOMMTokenType"] = 1] = "CDOCOMMTokenType";
|
|
14
|
+
EnumToken[EnumToken["LiteralTokenType"] = 2] = "LiteralTokenType";
|
|
15
|
+
EnumToken[EnumToken["IdenTokenType"] = 3] = "IdenTokenType";
|
|
16
|
+
EnumToken[EnumToken["CommaTokenType"] = 4] = "CommaTokenType";
|
|
17
|
+
EnumToken[EnumToken["ColonTokenType"] = 5] = "ColonTokenType";
|
|
18
|
+
EnumToken[EnumToken["SemiColonTokenType"] = 6] = "SemiColonTokenType";
|
|
19
|
+
EnumToken[EnumToken["NumberTokenType"] = 7] = "NumberTokenType";
|
|
20
|
+
EnumToken[EnumToken["AtRuleTokenType"] = 8] = "AtRuleTokenType";
|
|
21
|
+
EnumToken[EnumToken["PercentageTokenType"] = 9] = "PercentageTokenType";
|
|
22
|
+
EnumToken[EnumToken["FunctionTokenType"] = 10] = "FunctionTokenType";
|
|
23
|
+
EnumToken[EnumToken["UrlFunctionTokenType"] = 11] = "UrlFunctionTokenType";
|
|
24
|
+
EnumToken[EnumToken["StringTokenType"] = 12] = "StringTokenType";
|
|
25
|
+
EnumToken[EnumToken["UnclosedStringTokenType"] = 13] = "UnclosedStringTokenType";
|
|
26
|
+
EnumToken[EnumToken["DimensionTokenType"] = 14] = "DimensionTokenType";
|
|
27
|
+
EnumToken[EnumToken["LengthTokenType"] = 15] = "LengthTokenType";
|
|
28
|
+
EnumToken[EnumToken["AngleTokenType"] = 16] = "AngleTokenType";
|
|
29
|
+
EnumToken[EnumToken["TimeTokenType"] = 17] = "TimeTokenType";
|
|
30
|
+
EnumToken[EnumToken["FrequencyTokenType"] = 18] = "FrequencyTokenType";
|
|
31
|
+
EnumToken[EnumToken["ResolutionTokenType"] = 19] = "ResolutionTokenType";
|
|
32
|
+
EnumToken[EnumToken["HashTokenType"] = 20] = "HashTokenType";
|
|
33
|
+
EnumToken[EnumToken["BlockStartTokenType"] = 21] = "BlockStartTokenType";
|
|
34
|
+
EnumToken[EnumToken["BlockEndTokenType"] = 22] = "BlockEndTokenType";
|
|
35
|
+
EnumToken[EnumToken["AttrStartTokenType"] = 23] = "AttrStartTokenType";
|
|
36
|
+
EnumToken[EnumToken["AttrEndTokenType"] = 24] = "AttrEndTokenType";
|
|
37
|
+
EnumToken[EnumToken["StartParensTokenType"] = 25] = "StartParensTokenType";
|
|
38
|
+
EnumToken[EnumToken["EndParensTokenType"] = 26] = "EndParensTokenType";
|
|
39
|
+
EnumToken[EnumToken["ParensTokenType"] = 27] = "ParensTokenType";
|
|
40
|
+
EnumToken[EnumToken["WhitespaceTokenType"] = 28] = "WhitespaceTokenType";
|
|
41
|
+
EnumToken[EnumToken["IncludesTokenType"] = 29] = "IncludesTokenType";
|
|
42
|
+
EnumToken[EnumToken["DashMatchTokenType"] = 30] = "DashMatchTokenType";
|
|
43
|
+
EnumToken[EnumToken["LtTokenType"] = 31] = "LtTokenType";
|
|
44
|
+
EnumToken[EnumToken["LteTokenType"] = 32] = "LteTokenType";
|
|
45
|
+
EnumToken[EnumToken["GtTokenType"] = 33] = "GtTokenType";
|
|
46
|
+
EnumToken[EnumToken["GteTokenType"] = 34] = "GteTokenType";
|
|
47
|
+
EnumToken[EnumToken["PseudoClassTokenType"] = 35] = "PseudoClassTokenType";
|
|
48
|
+
EnumToken[EnumToken["PseudoClassFuncTokenType"] = 36] = "PseudoClassFuncTokenType";
|
|
49
|
+
EnumToken[EnumToken["DelimTokenType"] = 37] = "DelimTokenType";
|
|
50
|
+
EnumToken[EnumToken["UrlTokenTokenType"] = 38] = "UrlTokenTokenType";
|
|
51
|
+
EnumToken[EnumToken["EOFTokenType"] = 39] = "EOFTokenType";
|
|
52
|
+
EnumToken[EnumToken["ImportantTokenType"] = 40] = "ImportantTokenType";
|
|
53
|
+
EnumToken[EnumToken["ColorTokenType"] = 41] = "ColorTokenType";
|
|
54
|
+
EnumToken[EnumToken["AttrTokenType"] = 42] = "AttrTokenType";
|
|
55
|
+
EnumToken[EnumToken["BadCommentTokenType"] = 43] = "BadCommentTokenType";
|
|
56
|
+
EnumToken[EnumToken["BadCdoTokenType"] = 44] = "BadCdoTokenType";
|
|
57
|
+
EnumToken[EnumToken["BadUrlTokenType"] = 45] = "BadUrlTokenType";
|
|
58
|
+
EnumToken[EnumToken["BadStringTokenType"] = 46] = "BadStringTokenType";
|
|
59
|
+
EnumToken[EnumToken["BinaryExpressionTokenType"] = 47] = "BinaryExpressionTokenType";
|
|
60
|
+
EnumToken[EnumToken["UnaryExpressionTokenType"] = 48] = "UnaryExpressionTokenType";
|
|
61
|
+
/* catch all */
|
|
62
|
+
EnumToken[EnumToken["ListToken"] = 49] = "ListToken";
|
|
63
|
+
/* arithmetic tokens */
|
|
64
|
+
EnumToken[EnumToken["Add"] = 50] = "Add";
|
|
65
|
+
EnumToken[EnumToken["Mul"] = 51] = "Mul";
|
|
66
|
+
EnumToken[EnumToken["Div"] = 52] = "Div";
|
|
67
|
+
EnumToken[EnumToken["Sub"] = 53] = "Sub";
|
|
68
|
+
/* aliases */
|
|
69
|
+
EnumToken[EnumToken["Time"] = 17] = "Time";
|
|
70
|
+
EnumToken[EnumToken["Iden"] = 3] = "Iden";
|
|
71
|
+
EnumToken[EnumToken["Hash"] = 20] = "Hash";
|
|
72
|
+
EnumToken[EnumToken["Angle"] = 16] = "Angle";
|
|
73
|
+
EnumToken[EnumToken["Color"] = 41] = "Color";
|
|
74
|
+
EnumToken[EnumToken["Comma"] = 4] = "Comma";
|
|
75
|
+
EnumToken[EnumToken["String"] = 12] = "String";
|
|
76
|
+
EnumToken[EnumToken["Length"] = 15] = "Length";
|
|
77
|
+
EnumToken[EnumToken["Number"] = 7] = "Number";
|
|
78
|
+
EnumToken[EnumToken["Perc"] = 9] = "Perc";
|
|
79
|
+
EnumToken[EnumToken["Literal"] = 2] = "Literal";
|
|
80
|
+
EnumToken[EnumToken["Comment"] = 0] = "Comment";
|
|
81
|
+
EnumToken[EnumToken["UrlFunc"] = 11] = "UrlFunc";
|
|
82
|
+
EnumToken[EnumToken["Dimension"] = 14] = "Dimension";
|
|
83
|
+
EnumToken[EnumToken["Frequency"] = 18] = "Frequency";
|
|
84
|
+
EnumToken[EnumToken["Resolution"] = 19] = "Resolution";
|
|
85
|
+
EnumToken[EnumToken["Whitespace"] = 28] = "Whitespace";
|
|
86
|
+
})(EnumToken || (EnumToken = {}));
|
|
87
|
+
|
|
88
|
+
export { EnumToken, NodeType };
|
package/dist/lib/ast/walk.js
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
function* walk(node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
function* walk(node) {
|
|
2
|
+
const parents = [node];
|
|
3
|
+
const root = node;
|
|
4
|
+
const weakMap = new WeakMap;
|
|
5
|
+
while (parents.length > 0) {
|
|
6
|
+
node = parents.shift();
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
yield { node, parent: weakMap.get(node), root };
|
|
9
|
+
if ('chi' in node) {
|
|
10
|
+
for (const child of node.chi) {
|
|
11
|
+
weakMap.set(child, node);
|
|
12
|
+
}
|
|
13
|
+
parents.unshift(...node.chi);
|
|
6
14
|
}
|
|
7
15
|
}
|
|
8
16
|
}
|
|
9
|
-
function* walkValues(values
|
|
10
|
-
|
|
17
|
+
function* walkValues(values) {
|
|
18
|
+
const stack = values.slice();
|
|
19
|
+
const weakMap = new WeakMap;
|
|
20
|
+
let value;
|
|
21
|
+
while (stack.length > 0) {
|
|
22
|
+
value = stack.shift();
|
|
11
23
|
// @ts-ignore
|
|
12
|
-
yield { value, parent };
|
|
24
|
+
yield { value, parent: weakMap.get(value) };
|
|
13
25
|
if ('chi' in value) {
|
|
14
|
-
|
|
26
|
+
for (const child of value.chi) {
|
|
27
|
+
weakMap.set(child, value);
|
|
28
|
+
}
|
|
29
|
+
stack.unshift(...value.chi);
|
|
15
30
|
}
|
|
16
31
|
}
|
|
17
32
|
}
|
|
@@ -1,23 +1,37 @@
|
|
|
1
1
|
import { PropertySet } from './set.js';
|
|
2
2
|
import '../../renderer/utils/color.js';
|
|
3
|
-
import
|
|
3
|
+
import '../../ast/types.js';
|
|
4
|
+
import '../../ast/minify.js';
|
|
4
5
|
import { parseString } from '../parse.js';
|
|
6
|
+
import '../../renderer/sourcemap/lib/encode.js';
|
|
5
7
|
import { getConfig } from '../utils/config.js';
|
|
8
|
+
import { PropertyMap } from './map.js';
|
|
6
9
|
|
|
7
10
|
const config = getConfig();
|
|
8
11
|
class PropertyList {
|
|
12
|
+
options = { removeDuplicateDeclarations: true, computeShorthand: true };
|
|
9
13
|
declarations;
|
|
10
|
-
constructor() {
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
for (const key of Object.keys(this.options)) {
|
|
16
|
+
if (key in options) {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
this.options[key] = options[key];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
11
21
|
this.declarations = new Map;
|
|
12
22
|
}
|
|
13
23
|
set(nam, value) {
|
|
14
|
-
return this.add({ typ:
|
|
24
|
+
return this.add({ typ: 5 /* NodeType.DeclarationNodeType */, nam, val: Array.isArray(value) ? value : parseString(String(value)) });
|
|
15
25
|
}
|
|
16
26
|
add(declaration) {
|
|
17
|
-
if (declaration.typ !=
|
|
27
|
+
if (declaration.typ != 5 /* NodeType.DeclarationNodeType */ || !this.options.removeDuplicateDeclarations) {
|
|
18
28
|
this.declarations.set(Number(Math.random().toString().slice(2)).toString(36), declaration);
|
|
19
29
|
return this;
|
|
20
30
|
}
|
|
31
|
+
if (!this.options.computeShorthand) {
|
|
32
|
+
this.declarations.set(declaration.nam, declaration);
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
21
35
|
let propertyName = declaration.nam;
|
|
22
36
|
let shortHandType;
|
|
23
37
|
let shorthand;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { eq } from '../utils/eq.js';
|
|
2
2
|
import { renderToken } from '../../renderer/render.js';
|
|
3
3
|
import '../../renderer/utils/color.js';
|
|
4
|
+
import { EnumToken } from '../../ast/types.js';
|
|
5
|
+
import '../../ast/minify.js';
|
|
6
|
+
import { parseString } from '../parse.js';
|
|
4
7
|
import { getConfig } from '../utils/config.js';
|
|
5
8
|
import { matchType } from '../utils/type.js';
|
|
6
|
-
import { parseString } from '../parse.js';
|
|
7
9
|
import { PropertySet } from './set.js';
|
|
8
10
|
|
|
9
11
|
const propertiesConfig = getConfig();
|
|
@@ -28,21 +30,23 @@ class PropertyMap {
|
|
|
28
30
|
this.declarations.set(declaration.nam, declaration);
|
|
29
31
|
}
|
|
30
32
|
else {
|
|
31
|
-
const separator = this.config.separator
|
|
33
|
+
const separator = this.config.separator != null ? {
|
|
34
|
+
...this.config.separator,
|
|
35
|
+
typ: EnumToken[this.config.separator.typ]
|
|
36
|
+
} : null;
|
|
32
37
|
// expand shorthand
|
|
33
38
|
if (declaration.nam != this.config.shorthand && this.declarations.has(this.config.shorthand)) {
|
|
34
39
|
const tokens = {};
|
|
35
40
|
const values = [];
|
|
36
41
|
// @ts-ignore
|
|
37
42
|
this.declarations.get(this.config.shorthand).val.slice().reduce((acc, curr) => {
|
|
43
|
+
// @ts-ignore
|
|
38
44
|
if (separator != null && separator.typ == curr.typ && eq(separator, curr)) {
|
|
39
45
|
acc.push([]);
|
|
40
46
|
return acc;
|
|
41
47
|
}
|
|
42
|
-
// else {
|
|
43
48
|
// @ts-ignore
|
|
44
49
|
acc.at(-1).push(curr);
|
|
45
|
-
// }
|
|
46
50
|
return acc;
|
|
47
51
|
}, [[]]).
|
|
48
52
|
// @ts-ignore
|
|
@@ -51,7 +55,7 @@ class PropertyMap {
|
|
|
51
55
|
// let current: number = 0;
|
|
52
56
|
const props = this.config.properties[property];
|
|
53
57
|
for (let i = 0; i < acc.length; i++) {
|
|
54
|
-
if (acc[i].typ ==
|
|
58
|
+
if (acc[i].typ == EnumToken.CommentTokenType || acc[i].typ == EnumToken.WhitespaceTokenType) {
|
|
55
59
|
acc.splice(i, 1);
|
|
56
60
|
i--;
|
|
57
61
|
continue;
|
|
@@ -67,18 +71,20 @@ class PropertyMap {
|
|
|
67
71
|
else {
|
|
68
72
|
if (current == tokens[property].length) {
|
|
69
73
|
tokens[property].push([acc[i]]);
|
|
70
|
-
// tokens[property][current].push();
|
|
71
74
|
}
|
|
72
75
|
else {
|
|
73
|
-
tokens[property][current].push({ typ:
|
|
76
|
+
tokens[property][current].push({ typ: EnumToken.WhitespaceTokenType }, acc[i]);
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
acc.splice(i, 1);
|
|
77
80
|
i--;
|
|
78
81
|
// @ts-ignore
|
|
79
|
-
if ('prefix' in props && acc[i]?.typ == props.prefix.typ) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
if ('prefix' in props && acc[i]?.typ == EnumToken[props.prefix.typ]) {
|
|
83
|
+
if (eq(acc[i], {
|
|
84
|
+
...this.config.properties[property].prefix,
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
typ: EnumToken[props.prefix.typ]
|
|
87
|
+
})) {
|
|
82
88
|
acc.splice(i, 1);
|
|
83
89
|
i--;
|
|
84
90
|
}
|
|
@@ -111,7 +117,7 @@ class PropertyMap {
|
|
|
111
117
|
tokens[property][current].push(...defaults);
|
|
112
118
|
}
|
|
113
119
|
else {
|
|
114
|
-
tokens[property][current].push({ typ:
|
|
120
|
+
tokens[property][current].push({ typ: EnumToken.WhitespaceTokenType }, ...defaults);
|
|
115
121
|
}
|
|
116
122
|
}
|
|
117
123
|
}
|
|
@@ -122,7 +128,7 @@ class PropertyMap {
|
|
|
122
128
|
if (values.length == 0) {
|
|
123
129
|
this.declarations = Object.entries(tokens).reduce((acc, curr) => {
|
|
124
130
|
acc.set(curr[0], {
|
|
125
|
-
typ:
|
|
131
|
+
typ: 5 /* NodeType.DeclarationNodeType */,
|
|
126
132
|
nam: curr[0],
|
|
127
133
|
val: curr[1].reduce((acc, curr) => {
|
|
128
134
|
if (acc.length > 0) {
|
|
@@ -192,7 +198,10 @@ class PropertyMap {
|
|
|
192
198
|
else {
|
|
193
199
|
let count = 0;
|
|
194
200
|
let match;
|
|
195
|
-
const separator = this.config.separator
|
|
201
|
+
const separator = this.config.separator != null ? {
|
|
202
|
+
...this.config.separator,
|
|
203
|
+
typ: EnumToken[this.config.separator.typ]
|
|
204
|
+
} : null;
|
|
196
205
|
const tokens = {};
|
|
197
206
|
// @ts-ignore
|
|
198
207
|
/* const valid: string[] =*/
|
|
@@ -216,14 +225,18 @@ class PropertyMap {
|
|
|
216
225
|
}
|
|
217
226
|
continue;
|
|
218
227
|
}
|
|
219
|
-
if (val.typ ==
|
|
228
|
+
if (val.typ == EnumToken.WhitespaceTokenType || val.typ == EnumToken.CommentTokenType) {
|
|
220
229
|
continue;
|
|
221
230
|
}
|
|
222
|
-
|
|
231
|
+
// @ts-ignore
|
|
232
|
+
if (props.multiple && props.separator != null && EnumToken[props.separator.typ] == val.typ && eq({
|
|
233
|
+
...props.separator,
|
|
234
|
+
typ: EnumToken[props.separator.typ]
|
|
235
|
+
}, val)) {
|
|
223
236
|
continue;
|
|
224
237
|
}
|
|
225
238
|
// @ts-ignore
|
|
226
|
-
match = val.typ ==
|
|
239
|
+
match = val.typ == EnumToken.CommentTokenType || matchType(val, curr[1]);
|
|
227
240
|
if (isShorthand) {
|
|
228
241
|
isShorthand = match;
|
|
229
242
|
}
|
|
@@ -252,7 +265,7 @@ class PropertyMap {
|
|
|
252
265
|
return entry[1].required && !(entry[0] in tokens);
|
|
253
266
|
}) ||
|
|
254
267
|
// @ts-ignore
|
|
255
|
-
!Object.values(tokens).every(v => v.filter(t => t.typ !=
|
|
268
|
+
!Object.values(tokens).every(v => v.filter(t => t.typ != EnumToken.CommentTokenType).length == count)) {
|
|
256
269
|
// @ts-ignore
|
|
257
270
|
iterable = this.declarations.values();
|
|
258
271
|
}
|
|
@@ -265,7 +278,7 @@ class PropertyMap {
|
|
|
265
278
|
}
|
|
266
279
|
let values = curr[1][i].reduce((acc, curr) => {
|
|
267
280
|
if (acc.length > 0) {
|
|
268
|
-
acc.push({ typ:
|
|
281
|
+
acc.push({ typ: EnumToken.WhitespaceTokenType });
|
|
269
282
|
}
|
|
270
283
|
acc.push(curr);
|
|
271
284
|
return acc;
|
|
@@ -277,8 +290,8 @@ class PropertyMap {
|
|
|
277
290
|
let doFilterDefault = true;
|
|
278
291
|
if (curr[0] in propertiesConfig.properties) {
|
|
279
292
|
for (let v of values) {
|
|
280
|
-
if (![
|
|
281
|
-
|| (v.typ ==
|
|
293
|
+
if (![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType, EnumToken.IdenTokenType].includes(v.typ)
|
|
294
|
+
|| (v.typ == EnumToken.IdenTokenType && !this.config.properties[curr[0]].default.includes(v.val))) {
|
|
282
295
|
doFilterDefault = false;
|
|
283
296
|
break;
|
|
284
297
|
}
|
|
@@ -286,10 +299,10 @@ class PropertyMap {
|
|
|
286
299
|
}
|
|
287
300
|
// remove default values
|
|
288
301
|
values = values.filter((val) => {
|
|
289
|
-
if (val.typ ==
|
|
302
|
+
if (val.typ == EnumToken.WhitespaceTokenType || val.typ == EnumToken.CommentTokenType) {
|
|
290
303
|
return false;
|
|
291
304
|
}
|
|
292
|
-
return !doFilterDefault || !(val.typ ==
|
|
305
|
+
return !doFilterDefault || !(val.typ == EnumToken.IdenTokenType && props.default.includes(val.val));
|
|
293
306
|
});
|
|
294
307
|
if (values.length > 0) {
|
|
295
308
|
if ('mapping' in props) {
|
|
@@ -298,7 +311,7 @@ class PropertyMap {
|
|
|
298
311
|
let i = values.length;
|
|
299
312
|
while (i--) {
|
|
300
313
|
// @ts-ignore
|
|
301
|
-
if (values[i].typ ==
|
|
314
|
+
if (values[i].typ == EnumToken.IdenTokenType && values[i].val in props.mapping) {
|
|
302
315
|
// @ts-ignore
|
|
303
316
|
values.splice(i, 1, ...parseString(props.mapping[values[i].val]));
|
|
304
317
|
}
|
|
@@ -307,15 +320,20 @@ class PropertyMap {
|
|
|
307
320
|
}
|
|
308
321
|
if ('prefix' in props) {
|
|
309
322
|
// @ts-ignore
|
|
310
|
-
acc[i].push({ ...props.prefix });
|
|
323
|
+
acc[i].push({ ...props.prefix, typ: EnumToken[props.prefix.typ] });
|
|
311
324
|
}
|
|
312
325
|
else if (acc[i].length > 0) {
|
|
313
|
-
acc[i].push({ typ:
|
|
326
|
+
acc[i].push({ typ: EnumToken.WhitespaceTokenType });
|
|
314
327
|
}
|
|
315
328
|
acc[i].push(...values.reduce((acc, curr) => {
|
|
316
329
|
if (acc.length > 0) {
|
|
317
330
|
// @ts-ignore
|
|
318
|
-
acc.push({
|
|
331
|
+
acc.push({
|
|
332
|
+
...((props.separator && {
|
|
333
|
+
...props.separator,
|
|
334
|
+
typ: EnumToken[props.separator.typ]
|
|
335
|
+
}) ?? { typ: EnumToken.WhitespaceTokenType })
|
|
336
|
+
});
|
|
319
337
|
}
|
|
320
338
|
// @ts-ignore
|
|
321
339
|
acc.push(curr);
|
|
@@ -331,7 +349,7 @@ class PropertyMap {
|
|
|
331
349
|
if (curr.length == 0 && this.config.default.length > 0) {
|
|
332
350
|
curr.push(...parseString(this.config.default[0]).reduce((acc, curr) => {
|
|
333
351
|
if (acc.length > 0) {
|
|
334
|
-
acc.push({ typ:
|
|
352
|
+
acc.push({ typ: EnumToken.WhitespaceTokenType });
|
|
335
353
|
}
|
|
336
354
|
acc.push(curr);
|
|
337
355
|
return acc;
|
|
@@ -344,12 +362,15 @@ class PropertyMap {
|
|
|
344
362
|
const val = values.reduce((acc, curr) => acc + renderToken(curr, { removeComments: true }), '');
|
|
345
363
|
if (val in this.config.mapping) {
|
|
346
364
|
values.length = 0;
|
|
347
|
-
|
|
348
|
-
|
|
365
|
+
values.push({
|
|
366
|
+
typ: ['"', "'"].includes(val.charAt(0)) ? EnumToken.StringTokenType : EnumToken.IdenTokenType,
|
|
367
|
+
// @ts-ignore
|
|
368
|
+
val: this.config.mapping[val]
|
|
369
|
+
});
|
|
349
370
|
}
|
|
350
371
|
}
|
|
351
372
|
iterable = [{
|
|
352
|
-
typ:
|
|
373
|
+
typ: 5 /* NodeType.DeclarationNodeType */,
|
|
353
374
|
nam: this.config.shorthand,
|
|
354
375
|
val: values
|
|
355
376
|
}][Symbol.iterator]();
|
|
@@ -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: 5 /* NodeType.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: 5 /* NodeType.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;
|