@tbela99/css-parser 1.4.3 → 1.4.5
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 +196 -2
- package/README.md +68 -1120
- package/dist/config.json.js +43 -2
- package/dist/index-umd-web.js +18118 -15886
- package/dist/index.cjs +16838 -14611
- package/dist/index.d.ts +1804 -1684
- package/dist/lib/ast/clone.js +4 -3
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/calc.js +59 -54
- package/dist/lib/ast/features/if.js +64 -17
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +343 -6
- package/dist/lib/ast/features/transform.js +7 -4
- package/dist/lib/ast/find.js +5 -5
- package/dist/lib/ast/math/expression.js +12 -8
- package/dist/lib/ast/minify.js +28 -33
- package/dist/lib/ast/transform/minify.js +135 -131
- package/dist/lib/ast/transform/utils.js +3 -2
- package/dist/lib/ast/types.js +69 -8
- package/dist/lib/ast/walk.js +4 -5
- package/dist/lib/fs/resolve.js +71 -57
- package/dist/lib/parser/declaration/list.js +92 -3
- package/dist/lib/parser/declaration/map.js +5 -5
- package/dist/lib/parser/parse.js +530 -466
- package/dist/lib/parser/tokenize.js +110 -4
- package/dist/lib/parser/utils/angle.js +29 -0
- package/dist/lib/parser/utils/at-rule-container.js +2 -2
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +2 -2
- package/dist/lib/parser/utils/at-rule-generic.js +1 -1
- package/dist/lib/parser/utils/at-rule-media.js +2 -2
- package/dist/lib/parser/utils/at-rule-support.js +73 -8
- package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
- package/dist/lib/parser/utils/at-rule.js +2 -8
- package/dist/lib/parser/utils/declaration.js +179 -76
- package/dist/lib/parser/utils/selector.js +53 -11
- package/dist/lib/parser/utils/token.js +13 -11
- package/dist/lib/renderer/render.js +501 -59
- package/dist/lib/syntax/color/alpha.js +64 -0
- package/dist/lib/syntax/color/cmyk.js +2 -2
- package/dist/lib/syntax/color/color-mix.js +283 -220
- package/dist/lib/syntax/color/color.js +37 -28
- package/dist/lib/syntax/color/hex.js +2 -2
- package/dist/lib/syntax/color/hsl.js +3 -3
- package/dist/lib/syntax/color/hwb.js +7 -7
- package/dist/lib/syntax/color/lab.js +5 -5
- package/dist/lib/syntax/color/lch.js +4 -4
- package/dist/lib/syntax/color/oklab.js +3 -3
- package/dist/lib/syntax/color/oklch.js +3 -3
- package/dist/lib/syntax/color/relativecolor.js +97 -12
- package/dist/lib/syntax/color/srgb.js +5 -5
- package/dist/lib/syntax/color/utils/color-type.js +18 -0
- package/dist/lib/syntax/color/utils/colorspace.js +46 -0
- package/dist/lib/syntax/color/utils/components.js +7 -3
- package/dist/lib/syntax/color/utils/distance.js +21 -4
- package/dist/lib/syntax/color/utils/make-color.js +56 -0
- package/dist/lib/syntax/color/xyz.js +2 -2
- package/dist/lib/syntax/constants.js +29 -1
- package/dist/lib/syntax/syntax.js +307 -39
- package/dist/lib/validation/config.js +2 -2
- package/dist/lib/validation/config.json.js +32 -17
- package/dist/lib/validation/match.js +239 -104
- package/dist/lib/validation/parser/parse.js +0 -1
- package/dist/lib/validation/parser/typedef.js +6 -0
- package/dist/node.js +64 -22
- package/dist/web.js +65 -18
- package/package.json +26 -15
- package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.repl_history +0 -4
- package/badges/coverage.svg +0 -20
- package/deno.lock +0 -2861
- package/dist/lib/ast/clone.d.ts +0 -10
- package/dist/lib/ast/expand.d.ts +0 -14
- package/dist/lib/ast/features/calc.d.ts +0 -10
- package/dist/lib/ast/features/if.d.ts +0 -10
- package/dist/lib/ast/features/index.d.ts +0 -6
- package/dist/lib/ast/features/inlinecssvariables.d.ts +0 -15
- package/dist/lib/ast/features/prefix.d.ts +0 -8
- package/dist/lib/ast/features/shorthand.d.ts +0 -12
- package/dist/lib/ast/features/transform.d.ts +0 -10
- package/dist/lib/ast/features/type.d.ts +0 -15
- package/dist/lib/ast/find.d.ts +0 -165
- package/dist/lib/ast/math/expression.d.ts +0 -18
- package/dist/lib/ast/math/math.d.ts +0 -6
- package/dist/lib/ast/minify.d.ts +0 -19
- package/dist/lib/ast/transform/compute.d.ts +0 -8
- package/dist/lib/ast/transform/matrix.d.ts +0 -22
- package/dist/lib/ast/transform/minify.d.ts +0 -5
- package/dist/lib/ast/transform/perspective.d.ts +0 -3
- package/dist/lib/ast/transform/rotate.d.ts +0 -12
- package/dist/lib/ast/transform/scale.d.ts +0 -6
- package/dist/lib/ast/transform/skew.d.ts +0 -4
- package/dist/lib/ast/transform/translate.d.ts +0 -6
- package/dist/lib/ast/transform/utils.d.ts +0 -9
- package/dist/lib/ast/types.d.ts +0 -903
- package/dist/lib/ast/walk.d.ts +0 -162
- package/dist/lib/fs/resolve.d.ts +0 -20
- package/dist/lib/parser/declaration/list.d.ts +0 -16
- package/dist/lib/parser/declaration/map.d.ts +0 -15
- package/dist/lib/parser/declaration/set.d.ts +0 -9
- package/dist/lib/parser/node.d.ts +0 -7
- package/dist/lib/parser/parse.d.ts +0 -107
- package/dist/lib/parser/tokenize.d.ts +0 -57
- package/dist/lib/parser/utils/at-rule-container.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-generic.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-import.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-media.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.js +0 -28
- package/dist/lib/parser/utils/at-rule-support.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-token.d.ts +0 -1
- package/dist/lib/parser/utils/at-rule-when-else.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule.d.ts +0 -13
- package/dist/lib/parser/utils/cache.d.ts +0 -6
- package/dist/lib/parser/utils/config.d.ts +0 -2
- package/dist/lib/parser/utils/declaration-list.d.ts +0 -5
- package/dist/lib/parser/utils/declaration.d.ts +0 -18
- package/dist/lib/parser/utils/eq.d.ts +0 -1
- package/dist/lib/parser/utils/hash.d.ts +0 -21
- package/dist/lib/parser/utils/selector.d.ts +0 -5
- package/dist/lib/parser/utils/text.d.ts +0 -3
- package/dist/lib/parser/utils/token.d.ts +0 -14
- package/dist/lib/parser/utils/type.d.ts +0 -2
- package/dist/lib/renderer/render.d.ts +0 -28
- package/dist/lib/renderer/sourcemap/lib/encode.d.ts +0 -1
- package/dist/lib/renderer/sourcemap/sourcemap.d.ts +0 -26
- package/dist/lib/syntax/color/a98rgb.d.ts +0 -2
- package/dist/lib/syntax/color/cmyk.d.ts +0 -10
- package/dist/lib/syntax/color/color-mix.d.ts +0 -2
- package/dist/lib/syntax/color/color.d.ts +0 -42
- package/dist/lib/syntax/color/hex.d.ts +0 -16
- package/dist/lib/syntax/color/hsl.d.ts +0 -20
- package/dist/lib/syntax/color/hsv.d.ts +0 -2
- package/dist/lib/syntax/color/hwb.d.ts +0 -21
- package/dist/lib/syntax/color/lab.d.ts +0 -25
- package/dist/lib/syntax/color/lch.d.ts +0 -23
- package/dist/lib/syntax/color/oklab.d.ts +0 -22
- package/dist/lib/syntax/color/oklch.d.ts +0 -20
- package/dist/lib/syntax/color/p3.d.ts +0 -6
- package/dist/lib/syntax/color/prophotorgb.d.ts +0 -2
- package/dist/lib/syntax/color/rec2020.d.ts +0 -2
- package/dist/lib/syntax/color/relativecolor.d.ts +0 -13
- package/dist/lib/syntax/color/rgb.d.ts +0 -20
- package/dist/lib/syntax/color/srgb.d.ts +0 -23
- package/dist/lib/syntax/color/utils/components.d.ts +0 -2
- package/dist/lib/syntax/color/utils/distance.d.ts +0 -18
- package/dist/lib/syntax/color/utils/matrix.d.ts +0 -6
- package/dist/lib/syntax/color/xyz.d.ts +0 -5
- package/dist/lib/syntax/color/xyzd50.d.ts +0 -4
- package/dist/lib/syntax/constants.d.ts +0 -67
- package/dist/lib/syntax/syntax.d.ts +0 -38
- package/dist/lib/validation/config.d.ts +0 -14
- package/dist/lib/validation/json.d.ts +0 -2
- package/dist/lib/validation/match.d.ts +0 -38
- package/dist/lib/validation/parser/parse.d.ts +0 -8
- package/dist/lib/validation/parser/typedef.d.ts +0 -95
- package/dist/lib/validation/utils/list.d.ts +0 -4
- package/dist/lib/validation/utils/whitespace.d.ts +0 -2
- package/dist/node.d.ts +0 -207
- package/dist/web.d.ts +0 -169
- package/playground/index.html +0 -1328
- package/playground/sw.js +0 -55
- package/playground/tree.js +0 -176
package/dist/lib/ast/clone.js
CHANGED
|
@@ -2,9 +2,10 @@ import { EnumToken } from './types.js';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
5
|
+
* Clone an ast node or value
|
|
6
|
+
* @param node
|
|
7
|
+
* @param cloneChildren
|
|
8
|
+
* @param cloneMap
|
|
8
9
|
* @returns
|
|
9
10
|
*/
|
|
10
11
|
function cloneNode(node, cloneChildren = false, cloneMap = null) {
|
package/dist/lib/ast/expand.js
CHANGED
|
@@ -2,7 +2,7 @@ import { splitRule } from './minify.js';
|
|
|
2
2
|
import { combinators } from '../syntax/constants.js';
|
|
3
3
|
import { parseString } from '../parser/parse.js';
|
|
4
4
|
import { walkValues } from './walk.js';
|
|
5
|
-
import {
|
|
5
|
+
import { renderValue } from '../renderer/render.js';
|
|
6
6
|
import { EnumToken } from './types.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -229,7 +229,7 @@ function replaceCompound(input, replace) {
|
|
|
229
229
|
});
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
-
return tokens.reduce((acc, curr) => acc +
|
|
232
|
+
return tokens.reduce((acc, curr) => acc + renderValue(curr), "");
|
|
233
233
|
}
|
|
234
234
|
function replaceCompoundLiteral(selector, replace) {
|
|
235
235
|
const tokens = [""];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EnumToken } from '../types.js';
|
|
2
2
|
import { walkValues, WalkerEvent, WalkerOptionEnum } from '../walk.js';
|
|
3
3
|
import { evaluate } from '../math/expression.js';
|
|
4
|
-
import {
|
|
4
|
+
import { renderValue } from '../../renderer/render.js';
|
|
5
5
|
import { FeatureWalkMode } from './type.js';
|
|
6
|
-
import { mathFuncs } from '../../syntax/constants.js';
|
|
6
|
+
import { mathFuncs, tokensfuncSet } from '../../syntax/constants.js';
|
|
7
7
|
|
|
8
8
|
class ComputeCalcExpressionFeature {
|
|
9
9
|
accept = new Set([EnumToken.RuleNodeType, EnumToken.AtRuleNodeType]);
|
|
@@ -49,6 +49,7 @@ class ComputeCalcExpressionFeature {
|
|
|
49
49
|
EnumToken.MathFunctionTokenType,
|
|
50
50
|
EnumToken.ColorTokenType,
|
|
51
51
|
EnumToken.DeclarationNodeType,
|
|
52
|
+
EnumToken.ImageFunc,
|
|
52
53
|
EnumToken.RuleNodeType,
|
|
53
54
|
EnumToken.AtRuleNodeType,
|
|
54
55
|
EnumToken.StyleSheetNodeType,
|
|
@@ -67,9 +68,9 @@ class ComputeCalcExpressionFeature {
|
|
|
67
68
|
mathFuncs.includes(node.val)))) {
|
|
68
69
|
// @ts-ignore
|
|
69
70
|
const key = "chi" in node ? "chi" : "val";
|
|
70
|
-
const str1 =
|
|
71
|
-
const str2 =
|
|
72
|
-
if (str1.length
|
|
71
|
+
const str1 = renderValue({ ...node, [key]: slice });
|
|
72
|
+
const str2 = renderValue(node); // values.reduce((acc: string, curr: Token): string => acc + renderValue(curr), '');
|
|
73
|
+
if (str1.length < str2.length) {
|
|
73
74
|
// @ts-ignore
|
|
74
75
|
node[key] = slice;
|
|
75
76
|
}
|
|
@@ -78,63 +79,67 @@ class ComputeCalcExpressionFeature {
|
|
|
78
79
|
return null;
|
|
79
80
|
},
|
|
80
81
|
})) {
|
|
81
|
-
if (value != null &&
|
|
82
|
-
(value.typ === EnumToken.MathFunctionTokenType ||
|
|
83
|
-
(value.typ == EnumToken.FunctionTokenType && mathFuncs.includes(value.val)))) {
|
|
82
|
+
if (value != null && tokensfuncSet.has(value.typ)) {
|
|
84
83
|
if (!set.has(value)) {
|
|
85
84
|
set.add(value);
|
|
86
85
|
if (parent != null) {
|
|
87
|
-
|
|
88
|
-
const cp = (value.typ === EnumToken.MathFunctionTokenType ||
|
|
86
|
+
const shouldEvaluate = value.typ === EnumToken.MathFunctionTokenType ||
|
|
89
87
|
(value.typ == EnumToken.FunctionTokenType &&
|
|
90
|
-
mathFuncs.includes(value.val))
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
? value
|
|
95
|
-
: value.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
88
|
+
mathFuncs.includes(value.val));
|
|
89
|
+
if (shouldEvaluate) {
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
const cp = value.val != "calc"
|
|
92
|
+
? [value]
|
|
93
|
+
: value.typ == EnumToken.DeclarationNodeType
|
|
94
|
+
? value.val
|
|
95
|
+
: value.chi;
|
|
96
|
+
const values = evaluate(cp);
|
|
97
|
+
// fix a + -b to a - b
|
|
98
|
+
for (const { value, parent: p } of walkValues(values)) {
|
|
99
|
+
if (value.typ === EnumToken.BinaryExpressionTokenType) {
|
|
100
|
+
if (value.op === EnumToken.Add &&
|
|
101
|
+
Math.sign(value.r.val) == -1) {
|
|
102
|
+
value.op = EnumToken.Sub;
|
|
103
|
+
// @ts-expect-error
|
|
104
|
+
value.r.val *=
|
|
105
|
+
-1;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
105
108
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
children
|
|
113
|
-
(parent.typ
|
|
114
|
-
parent.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
(values[0].typ == EnumToken.
|
|
118
|
-
|
|
119
|
-
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
const children = parent.typ == EnumToken.DeclarationNodeType
|
|
111
|
+
? parent.val
|
|
112
|
+
: parent.chi;
|
|
113
|
+
if (values.length == 1 && values[0].typ != EnumToken.BinaryExpressionTokenType) {
|
|
114
|
+
for (let i = 0; i < children.length; i++) {
|
|
115
|
+
if (children[i] == value) {
|
|
116
|
+
children.splice(i, 1, !(parent.typ === EnumToken.MathFunctionTokenType ||
|
|
117
|
+
(parent.typ == EnumToken.FunctionTokenType &&
|
|
118
|
+
parent.val == "calc")) &&
|
|
119
|
+
typeof values[0].val != "number" &&
|
|
120
|
+
!(values[0].typ == EnumToken.MathFunctionTokenType ||
|
|
121
|
+
(values[0].typ == EnumToken.FunctionTokenType &&
|
|
122
|
+
mathFuncs.includes(values[0].val)))
|
|
123
|
+
? {
|
|
124
|
+
typ: EnumToken.MathFunctionTokenType,
|
|
125
|
+
val: "calc",
|
|
126
|
+
chi: values,
|
|
127
|
+
}
|
|
128
|
+
: values[0]);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
for (let i = 0; i < children.length; i++) {
|
|
135
|
+
if (children[i] == value) {
|
|
136
|
+
children.splice(i, 1, {
|
|
120
137
|
typ: EnumToken.MathFunctionTokenType,
|
|
121
138
|
val: "calc",
|
|
122
139
|
chi: values,
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
for (let i = 0; i < children.length; i++) {
|
|
131
|
-
if (children[i] == value) {
|
|
132
|
-
children.splice(i, 1, {
|
|
133
|
-
typ: EnumToken.MathFunctionTokenType,
|
|
134
|
-
val: "calc",
|
|
135
|
-
chi: values,
|
|
136
|
-
});
|
|
137
|
-
break;
|
|
140
|
+
});
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
138
143
|
}
|
|
139
144
|
}
|
|
140
145
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { EnumToken } from '../types.js';
|
|
2
|
-
import {
|
|
2
|
+
import { renderValue } from '../../renderer/render.js';
|
|
3
3
|
import { FeatureWalkMode } from './type.js';
|
|
4
4
|
import { definedPropertySettings } from '../../syntax/constants.js';
|
|
5
5
|
import { equalsIgnoreCase } from '../../parser/utils/text.js';
|
|
6
|
-
import {
|
|
6
|
+
import { replaceNodeOrValue } from '../../parser/utils/token.js';
|
|
7
7
|
import { cloneNode } from '../clone.js';
|
|
8
8
|
import { trimArray } from '../../validation/match.js';
|
|
9
9
|
import { findByValue } from '../find.js';
|
|
10
|
-
import { walk } from '../walk.js';
|
|
10
|
+
import { walk, walkValues } from '../walk.js';
|
|
11
11
|
import { eq } from '../../parser/utils/eq.js';
|
|
12
12
|
|
|
13
13
|
const nodeMatcher = (value) => value.typ === EnumToken.IfConditionTokenType ||
|
|
@@ -30,7 +30,7 @@ function substituteIfElseNode(declaration, node, wrapper, parentWrapper, cache)
|
|
|
30
30
|
}
|
|
31
31
|
//
|
|
32
32
|
if (target.typ === EnumToken.IdenTokenType && equalsIgnoreCase("else", target.val)) {
|
|
33
|
-
|
|
33
|
+
replaceNodeOrValue(nodeMap.get(targetParentWrapper), nodeMap.get(targetWrapper), node.r.r.at(-1)?.typ ===
|
|
34
34
|
EnumToken.SemiColonTokenType
|
|
35
35
|
? trimArray(node.r.r.slice(0, -1))
|
|
36
36
|
: node.r.r);
|
|
@@ -49,7 +49,7 @@ function substituteIfElseNode(declaration, node, wrapper, parentWrapper, cache)
|
|
|
49
49
|
let leftSide = siblingWrapper.chi[k].l.l.find((t) => t.typ != EnumToken.CommentTokenType &&
|
|
50
50
|
t.typ != EnumToken.WhitespaceTokenType);
|
|
51
51
|
if (eq(left, leftSide)) {
|
|
52
|
-
|
|
52
|
+
replaceNodeOrValue(nodeMap.get(targetParentWrapper), nodeMap.get(targetParentWrapper.chi[i]), siblingWrapper.chi[k]
|
|
53
53
|
.r.r.at(-1)?.typ === EnumToken.SemiColonTokenType
|
|
54
54
|
? trimArray(siblingWrapper.chi[k]
|
|
55
55
|
.r.r.slice(0, -1))
|
|
@@ -67,12 +67,12 @@ function substituteIfElseNode(declaration, node, wrapper, parentWrapper, cache)
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
if (replaceRight) {
|
|
70
|
-
|
|
70
|
+
replaceNodeOrValue(nodeMap.get(targetParentWrapper), nodeMap.get(targetWrapper), node.r);
|
|
71
71
|
}
|
|
72
72
|
result.push(clonedDeclaration);
|
|
73
73
|
nodeMap.clear();
|
|
74
74
|
clonedDeclaration = cloneNode(declaration, true, nodeMap);
|
|
75
|
-
|
|
75
|
+
replaceNodeOrValue(nodeMap.get(targetParentWrapper), nodeMap.get(targetWrapper), node.l);
|
|
76
76
|
result.push(clonedDeclaration);
|
|
77
77
|
}
|
|
78
78
|
else if (node.typ === EnumToken.IfConditionTokenType) {
|
|
@@ -82,7 +82,7 @@ function substituteIfElseNode(declaration, node, wrapper, parentWrapper, cache)
|
|
|
82
82
|
}
|
|
83
83
|
if (left.typ === EnumToken.IdenTokenType && equalsIgnoreCase("else", left.val)) {
|
|
84
84
|
clonedDeclaration = cloneNode(declaration, true, nodeMap);
|
|
85
|
-
|
|
85
|
+
replaceNodeOrValue(nodeMap.get(parentWrapper), nodeMap.get(targetWrapper.typ === EnumToken.DeclarationNodeType ? node : targetWrapper), node.r.at(-1)?.typ === EnumToken.SemiColonTokenType ? trimArray(node.r.slice(0, -1)) : node.r);
|
|
86
86
|
result.push(clonedDeclaration);
|
|
87
87
|
}
|
|
88
88
|
else if (left?.typ === EnumToken.WhenElseFunctionTokenType) {
|
|
@@ -95,9 +95,14 @@ function substituteIfElseNode(declaration, node, wrapper, parentWrapper, cache)
|
|
|
95
95
|
...definedPropertySettings,
|
|
96
96
|
value: [{ typ: EnumToken.ParensTokenType, chi: left.chi.slice() }],
|
|
97
97
|
});
|
|
98
|
-
|
|
98
|
+
const minify = atRule.nam !== "supports";
|
|
99
|
+
const options = {
|
|
100
|
+
minify,
|
|
101
|
+
convertColor: minify,
|
|
102
|
+
};
|
|
103
|
+
atRule.val = atRule.tokens.reduce((acc, curr) => acc + renderValue(curr, options), "");
|
|
99
104
|
clonedDeclaration = cloneNode(declaration, true, nodeMap);
|
|
100
|
-
|
|
105
|
+
replaceNodeOrValue(nodeMap.get(targetWrapper), nodeMap.get(node), node.r.at(-1)?.typ === EnumToken.SemiColonTokenType ? trimArray(node.r.slice(0, -1)) : node.r);
|
|
101
106
|
clonedDeclaration.parent = atRule;
|
|
102
107
|
atRule.chi.push(clonedDeclaration);
|
|
103
108
|
result.push(atRule);
|
|
@@ -111,9 +116,9 @@ function substituteIfElseNode(declaration, node, wrapper, parentWrapper, cache)
|
|
|
111
116
|
chi: [],
|
|
112
117
|
});
|
|
113
118
|
Object.defineProperty(atRule, "tokens", { ...definedPropertySettings, value: [left] });
|
|
114
|
-
atRule.val = atRule.tokens.reduce((acc, curr) => acc +
|
|
119
|
+
atRule.val = atRule.tokens.reduce((acc, curr) => acc + renderValue(curr), "");
|
|
115
120
|
clonedDeclaration = cloneNode(declaration, true, nodeMap);
|
|
116
|
-
|
|
121
|
+
replaceNodeOrValue(nodeMap.get(targetWrapper.typ === EnumToken.WildCardFunctionTokenType ? targetParentWrapper : targetWrapper), nodeMap.get(targetWrapper.typ === EnumToken.WildCardFunctionTokenType ? targetWrapper : node), node.r.at(-1)?.typ === EnumToken.SemiColonTokenType
|
|
117
122
|
? trimArray(node.r.slice(0, -1))
|
|
118
123
|
: node.r);
|
|
119
124
|
clonedDeclaration.parent = atRule;
|
|
@@ -124,7 +129,7 @@ function substituteIfElseNode(declaration, node, wrapper, parentWrapper, cache)
|
|
|
124
129
|
}
|
|
125
130
|
else if (wrapper.typ === EnumToken.WildCardFunctionTokenType) {
|
|
126
131
|
clonedDeclaration = cloneNode(declaration, true, nodeMap);
|
|
127
|
-
|
|
132
|
+
replaceNodeOrValue(nodeMap.get(parentWrapper), nodeMap.get(wrapper), node);
|
|
128
133
|
result.push(clonedDeclaration);
|
|
129
134
|
}
|
|
130
135
|
return result;
|
|
@@ -164,7 +169,48 @@ function processNode(declarationNode, cache) {
|
|
|
164
169
|
}
|
|
165
170
|
}
|
|
166
171
|
if (result.length > 0) {
|
|
167
|
-
|
|
172
|
+
let invalidTokensTypes = new Set([
|
|
173
|
+
EnumToken.WhitespaceTokenType,
|
|
174
|
+
EnumToken.SemiColonTokenType,
|
|
175
|
+
EnumToken.ColonTokenType
|
|
176
|
+
]);
|
|
177
|
+
for (i = 0; i < result.length; i++) {
|
|
178
|
+
if (result[i].typ === EnumToken.DeclarationNodeType) {
|
|
179
|
+
for (const { value } of walkValues(result[i].val, result[i])) {
|
|
180
|
+
if (value.typ === EnumToken.ImageFunctionTokenType && value.val.includes('-gradient')) {
|
|
181
|
+
let valid = true;
|
|
182
|
+
let j;
|
|
183
|
+
for (j = 0; j < value.chi.length; j++) {
|
|
184
|
+
if (value.chi[j].typ === EnumToken.IdenTokenType && 'else' == value.chi[j].val) {
|
|
185
|
+
valid = false;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
if (invalidTokensTypes.has(value.chi[j].typ) &&
|
|
189
|
+
(value.chi[j + 1]?.typ === EnumToken.CommaTokenType || j == value.chi.length - 1) &&
|
|
190
|
+
(j == 0 || EnumToken.CommaTokenType == value.chi[j - 1]?.typ)) {
|
|
191
|
+
valid = false;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (!valid) {
|
|
196
|
+
result.splice(i--, 1);
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
// const res = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (value as FunctionToken).val + '()'), createValidationContext((value as FunctionToken).chi), {
|
|
200
|
+
// });
|
|
201
|
+
// if (!res.success) {
|
|
202
|
+
// result.splice(i--, 1);
|
|
203
|
+
// break;
|
|
204
|
+
// }
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// console.debug({result});
|
|
210
|
+
// throw new Error("Not implemented");
|
|
211
|
+
if (result.length > 0) {
|
|
212
|
+
replaceNodeOrValue(declarationNode.parent, declarationNode, result);
|
|
213
|
+
}
|
|
168
214
|
}
|
|
169
215
|
// else remove node?
|
|
170
216
|
return result;
|
|
@@ -184,10 +230,9 @@ class ExpandIfFeature {
|
|
|
184
230
|
}
|
|
185
231
|
}
|
|
186
232
|
run(declaration) {
|
|
187
|
-
|
|
188
|
-
const result = processNode(declaration, cache);
|
|
233
|
+
processNode(declaration, new Set());
|
|
189
234
|
let i;
|
|
190
|
-
for (const n of
|
|
235
|
+
for (const n of declaration.parent.chi) {
|
|
191
236
|
for (const { node } of walk(n)) {
|
|
192
237
|
if (node.typ === EnumToken.AtRuleNodeType && Array.isArray(node.chi)) {
|
|
193
238
|
for (i = 0; i < node.chi.length; i++) {
|
|
@@ -197,6 +242,7 @@ class ExpandIfFeature {
|
|
|
197
242
|
node.chi[i].val === node.chi[i + 1].val) {
|
|
198
243
|
node.chi[i].chi.push(...node.chi[i + 1].chi);
|
|
199
244
|
node.chi.splice(i + 1, 1);
|
|
245
|
+
i--;
|
|
200
246
|
}
|
|
201
247
|
}
|
|
202
248
|
for (i = 0; i < node.chi.length; i++) {
|
|
@@ -204,6 +250,7 @@ class ExpandIfFeature {
|
|
|
204
250
|
node.chi[i].nam === node.nam &&
|
|
205
251
|
node.chi[i].val === node.val) {
|
|
206
252
|
node.chi.splice(i, 1, ...node.chi[i].chi);
|
|
253
|
+
i--;
|
|
207
254
|
}
|
|
208
255
|
}
|
|
209
256
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EnumToken } from '../types.js';
|
|
2
2
|
import { walkValues } from '../walk.js';
|
|
3
|
-
import {
|
|
3
|
+
import { renderValue } from '../../renderer/render.js';
|
|
4
4
|
import { splitRule } from '../minify.js';
|
|
5
5
|
import { FeatureWalkMode } from './type.js';
|
|
6
6
|
import { mathFuncs } from '../../syntax/constants.js';
|
|
@@ -135,7 +135,7 @@ class InlineCssVariablesFeature {
|
|
|
135
135
|
// @ts-ignore
|
|
136
136
|
parent.chi.splice(i, 1, {
|
|
137
137
|
typ: EnumToken.CommentTokenType,
|
|
138
|
-
val: `/* ${info.node.nam}: ${info.values.reduce((acc, curr) => acc +
|
|
138
|
+
val: `/* ${info.node.nam}: ${info.values.reduce((acc, curr) => acc + renderValue(curr, { convertColor: false }), "")} */`,
|
|
139
139
|
});
|
|
140
140
|
break;
|
|
141
141
|
}
|