@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.
Files changed (166) hide show
  1. package/CHANGELOG.md +196 -2
  2. package/README.md +68 -1120
  3. package/dist/config.json.js +43 -2
  4. package/dist/index-umd-web.js +18118 -15886
  5. package/dist/index.cjs +16838 -14611
  6. package/dist/index.d.ts +1804 -1684
  7. package/dist/lib/ast/clone.js +4 -3
  8. package/dist/lib/ast/expand.js +2 -2
  9. package/dist/lib/ast/features/calc.js +59 -54
  10. package/dist/lib/ast/features/if.js +64 -17
  11. package/dist/lib/ast/features/inlinecssvariables.js +2 -2
  12. package/dist/lib/ast/features/prefix.js +343 -6
  13. package/dist/lib/ast/features/transform.js +7 -4
  14. package/dist/lib/ast/find.js +5 -5
  15. package/dist/lib/ast/math/expression.js +12 -8
  16. package/dist/lib/ast/minify.js +28 -33
  17. package/dist/lib/ast/transform/minify.js +135 -131
  18. package/dist/lib/ast/transform/utils.js +3 -2
  19. package/dist/lib/ast/types.js +69 -8
  20. package/dist/lib/ast/walk.js +4 -5
  21. package/dist/lib/fs/resolve.js +71 -57
  22. package/dist/lib/parser/declaration/list.js +92 -3
  23. package/dist/lib/parser/declaration/map.js +5 -5
  24. package/dist/lib/parser/parse.js +530 -466
  25. package/dist/lib/parser/tokenize.js +110 -4
  26. package/dist/lib/parser/utils/angle.js +29 -0
  27. package/dist/lib/parser/utils/at-rule-container.js +2 -2
  28. package/dist/lib/parser/utils/at-rule-font-feature-values.js +2 -2
  29. package/dist/lib/parser/utils/at-rule-generic.js +1 -1
  30. package/dist/lib/parser/utils/at-rule-media.js +2 -2
  31. package/dist/lib/parser/utils/at-rule-support.js +73 -8
  32. package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
  33. package/dist/lib/parser/utils/at-rule.js +2 -8
  34. package/dist/lib/parser/utils/declaration.js +179 -76
  35. package/dist/lib/parser/utils/selector.js +53 -11
  36. package/dist/lib/parser/utils/token.js +13 -11
  37. package/dist/lib/renderer/render.js +501 -59
  38. package/dist/lib/syntax/color/alpha.js +64 -0
  39. package/dist/lib/syntax/color/cmyk.js +2 -2
  40. package/dist/lib/syntax/color/color-mix.js +283 -220
  41. package/dist/lib/syntax/color/color.js +37 -28
  42. package/dist/lib/syntax/color/hex.js +2 -2
  43. package/dist/lib/syntax/color/hsl.js +3 -3
  44. package/dist/lib/syntax/color/hwb.js +7 -7
  45. package/dist/lib/syntax/color/lab.js +5 -5
  46. package/dist/lib/syntax/color/lch.js +4 -4
  47. package/dist/lib/syntax/color/oklab.js +3 -3
  48. package/dist/lib/syntax/color/oklch.js +3 -3
  49. package/dist/lib/syntax/color/relativecolor.js +97 -12
  50. package/dist/lib/syntax/color/srgb.js +5 -5
  51. package/dist/lib/syntax/color/utils/color-type.js +18 -0
  52. package/dist/lib/syntax/color/utils/colorspace.js +46 -0
  53. package/dist/lib/syntax/color/utils/components.js +7 -3
  54. package/dist/lib/syntax/color/utils/distance.js +21 -4
  55. package/dist/lib/syntax/color/utils/make-color.js +56 -0
  56. package/dist/lib/syntax/color/xyz.js +2 -2
  57. package/dist/lib/syntax/constants.js +29 -1
  58. package/dist/lib/syntax/syntax.js +307 -39
  59. package/dist/lib/validation/config.js +2 -2
  60. package/dist/lib/validation/config.json.js +32 -17
  61. package/dist/lib/validation/match.js +239 -104
  62. package/dist/lib/validation/parser/parse.js +0 -1
  63. package/dist/lib/validation/parser/typedef.js +6 -0
  64. package/dist/node.js +64 -22
  65. package/dist/web.js +65 -18
  66. package/package.json +26 -15
  67. package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
  68. package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
  69. package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
  70. package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
  71. package/.repl_history +0 -4
  72. package/badges/coverage.svg +0 -20
  73. package/deno.lock +0 -2861
  74. package/dist/lib/ast/clone.d.ts +0 -10
  75. package/dist/lib/ast/expand.d.ts +0 -14
  76. package/dist/lib/ast/features/calc.d.ts +0 -10
  77. package/dist/lib/ast/features/if.d.ts +0 -10
  78. package/dist/lib/ast/features/index.d.ts +0 -6
  79. package/dist/lib/ast/features/inlinecssvariables.d.ts +0 -15
  80. package/dist/lib/ast/features/prefix.d.ts +0 -8
  81. package/dist/lib/ast/features/shorthand.d.ts +0 -12
  82. package/dist/lib/ast/features/transform.d.ts +0 -10
  83. package/dist/lib/ast/features/type.d.ts +0 -15
  84. package/dist/lib/ast/find.d.ts +0 -165
  85. package/dist/lib/ast/math/expression.d.ts +0 -18
  86. package/dist/lib/ast/math/math.d.ts +0 -6
  87. package/dist/lib/ast/minify.d.ts +0 -19
  88. package/dist/lib/ast/transform/compute.d.ts +0 -8
  89. package/dist/lib/ast/transform/matrix.d.ts +0 -22
  90. package/dist/lib/ast/transform/minify.d.ts +0 -5
  91. package/dist/lib/ast/transform/perspective.d.ts +0 -3
  92. package/dist/lib/ast/transform/rotate.d.ts +0 -12
  93. package/dist/lib/ast/transform/scale.d.ts +0 -6
  94. package/dist/lib/ast/transform/skew.d.ts +0 -4
  95. package/dist/lib/ast/transform/translate.d.ts +0 -6
  96. package/dist/lib/ast/transform/utils.d.ts +0 -9
  97. package/dist/lib/ast/types.d.ts +0 -903
  98. package/dist/lib/ast/walk.d.ts +0 -162
  99. package/dist/lib/fs/resolve.d.ts +0 -20
  100. package/dist/lib/parser/declaration/list.d.ts +0 -16
  101. package/dist/lib/parser/declaration/map.d.ts +0 -15
  102. package/dist/lib/parser/declaration/set.d.ts +0 -9
  103. package/dist/lib/parser/node.d.ts +0 -7
  104. package/dist/lib/parser/parse.d.ts +0 -107
  105. package/dist/lib/parser/tokenize.d.ts +0 -57
  106. package/dist/lib/parser/utils/at-rule-container.d.ts +0 -5
  107. package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +0 -5
  108. package/dist/lib/parser/utils/at-rule-generic.d.ts +0 -5
  109. package/dist/lib/parser/utils/at-rule-import.d.ts +0 -5
  110. package/dist/lib/parser/utils/at-rule-media.d.ts +0 -5
  111. package/dist/lib/parser/utils/at-rule-page.d.ts +0 -5
  112. package/dist/lib/parser/utils/at-rule-page.js +0 -28
  113. package/dist/lib/parser/utils/at-rule-support.d.ts +0 -5
  114. package/dist/lib/parser/utils/at-rule-token.d.ts +0 -1
  115. package/dist/lib/parser/utils/at-rule-when-else.d.ts +0 -5
  116. package/dist/lib/parser/utils/at-rule.d.ts +0 -13
  117. package/dist/lib/parser/utils/cache.d.ts +0 -6
  118. package/dist/lib/parser/utils/config.d.ts +0 -2
  119. package/dist/lib/parser/utils/declaration-list.d.ts +0 -5
  120. package/dist/lib/parser/utils/declaration.d.ts +0 -18
  121. package/dist/lib/parser/utils/eq.d.ts +0 -1
  122. package/dist/lib/parser/utils/hash.d.ts +0 -21
  123. package/dist/lib/parser/utils/selector.d.ts +0 -5
  124. package/dist/lib/parser/utils/text.d.ts +0 -3
  125. package/dist/lib/parser/utils/token.d.ts +0 -14
  126. package/dist/lib/parser/utils/type.d.ts +0 -2
  127. package/dist/lib/renderer/render.d.ts +0 -28
  128. package/dist/lib/renderer/sourcemap/lib/encode.d.ts +0 -1
  129. package/dist/lib/renderer/sourcemap/sourcemap.d.ts +0 -26
  130. package/dist/lib/syntax/color/a98rgb.d.ts +0 -2
  131. package/dist/lib/syntax/color/cmyk.d.ts +0 -10
  132. package/dist/lib/syntax/color/color-mix.d.ts +0 -2
  133. package/dist/lib/syntax/color/color.d.ts +0 -42
  134. package/dist/lib/syntax/color/hex.d.ts +0 -16
  135. package/dist/lib/syntax/color/hsl.d.ts +0 -20
  136. package/dist/lib/syntax/color/hsv.d.ts +0 -2
  137. package/dist/lib/syntax/color/hwb.d.ts +0 -21
  138. package/dist/lib/syntax/color/lab.d.ts +0 -25
  139. package/dist/lib/syntax/color/lch.d.ts +0 -23
  140. package/dist/lib/syntax/color/oklab.d.ts +0 -22
  141. package/dist/lib/syntax/color/oklch.d.ts +0 -20
  142. package/dist/lib/syntax/color/p3.d.ts +0 -6
  143. package/dist/lib/syntax/color/prophotorgb.d.ts +0 -2
  144. package/dist/lib/syntax/color/rec2020.d.ts +0 -2
  145. package/dist/lib/syntax/color/relativecolor.d.ts +0 -13
  146. package/dist/lib/syntax/color/rgb.d.ts +0 -20
  147. package/dist/lib/syntax/color/srgb.d.ts +0 -23
  148. package/dist/lib/syntax/color/utils/components.d.ts +0 -2
  149. package/dist/lib/syntax/color/utils/distance.d.ts +0 -18
  150. package/dist/lib/syntax/color/utils/matrix.d.ts +0 -6
  151. package/dist/lib/syntax/color/xyz.d.ts +0 -5
  152. package/dist/lib/syntax/color/xyzd50.d.ts +0 -4
  153. package/dist/lib/syntax/constants.d.ts +0 -67
  154. package/dist/lib/syntax/syntax.d.ts +0 -38
  155. package/dist/lib/validation/config.d.ts +0 -14
  156. package/dist/lib/validation/json.d.ts +0 -2
  157. package/dist/lib/validation/match.d.ts +0 -38
  158. package/dist/lib/validation/parser/parse.d.ts +0 -8
  159. package/dist/lib/validation/parser/typedef.d.ts +0 -95
  160. package/dist/lib/validation/utils/list.d.ts +0 -4
  161. package/dist/lib/validation/utils/whitespace.d.ts +0 -2
  162. package/dist/node.d.ts +0 -207
  163. package/dist/web.d.ts +0 -169
  164. package/playground/index.html +0 -1328
  165. package/playground/sw.js +0 -55
  166. package/playground/tree.js +0 -176
@@ -2,9 +2,10 @@ import { EnumToken } from './types.js';
2
2
 
3
3
  /**
4
4
  *
5
- * @param node he nod to clone
6
- * @param cloneChildren deep clone
7
- * @param cloneMap a map of existing children as keys and their clones as values
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) {
@@ -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 { renderToken } from '../renderer/render.js';
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 + renderToken(curr), "");
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 { renderToken } from '../../renderer/render.js';
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 = renderToken({ ...node, [key]: slice });
71
- const str2 = renderToken(node); // values.reduce((acc: string, curr: Token): string => acc + renderToken(curr), '');
72
- if (str1.length <= str2.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
- // @ts-ignore
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
- 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 } of walkValues(values)) {
99
- if (value.typ === EnumToken.BinaryExpressionTokenType &&
100
- value.op === EnumToken.Add &&
101
- Math.sign(value.r.val) == -1) {
102
- value.op = EnumToken.Sub;
103
- // @ts-expect-error
104
- value.r.val *= -1;
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
- // @ts-ignore
108
- const children = parent.typ == EnumToken.DeclarationNodeType ? parent.val : parent.chi;
109
- if (values.length == 1 && values[0].typ != EnumToken.BinaryExpressionTokenType) {
110
- for (let i = 0; i < children.length; i++) {
111
- if (children[i] == value) {
112
- children.splice(i, 1, !(parent.typ === EnumToken.MathFunctionTokenType ||
113
- (parent.typ == EnumToken.FunctionTokenType &&
114
- parent.val == "calc")) &&
115
- typeof values[0].val != "number" &&
116
- !(values[0].typ == EnumToken.MathFunctionTokenType ||
117
- (values[0].typ == EnumToken.FunctionTokenType &&
118
- mathFuncs.includes(values[0].val)))
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
- : values[0]);
125
- break;
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 { renderToken } from '../../renderer/render.js';
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 { replaceToken } from '../../parser/utils/token.js';
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
- replaceToken(nodeMap.get(targetParentWrapper), nodeMap.get(targetWrapper), node.r.r.at(-1)?.typ ===
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
- replaceToken(nodeMap.get(targetParentWrapper), nodeMap.get(targetParentWrapper.chi[i]), siblingWrapper.chi[k]
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
- replaceToken(nodeMap.get(targetParentWrapper), nodeMap.get(targetWrapper), node.r);
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
- replaceToken(nodeMap.get(targetParentWrapper), nodeMap.get(targetWrapper), node.l);
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
- replaceToken(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);
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
- atRule.val = atRule.tokens.reduce((acc, curr) => acc + renderToken(curr), "");
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
- replaceToken(nodeMap.get(targetWrapper), nodeMap.get(node), node.r.at(-1)?.typ === EnumToken.SemiColonTokenType ? trimArray(node.r.slice(0, -1)) : node.r);
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 + renderToken(curr), "");
119
+ atRule.val = atRule.tokens.reduce((acc, curr) => acc + renderValue(curr), "");
115
120
  clonedDeclaration = cloneNode(declaration, true, nodeMap);
116
- replaceToken(nodeMap.get(targetWrapper.typ === EnumToken.WildCardFunctionTokenType ? targetParentWrapper : targetWrapper), nodeMap.get(targetWrapper.typ === EnumToken.WildCardFunctionTokenType ? targetWrapper : node), node.r.at(-1)?.typ === EnumToken.SemiColonTokenType
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
- replaceToken(nodeMap.get(parentWrapper), nodeMap.get(wrapper), node);
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
- replaceToken(declarationNode.parent, declarationNode, result);
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
- const cache = new Set();
188
- const result = processNode(declaration, cache);
233
+ processNode(declaration, new Set());
189
234
  let i;
190
- for (const n of result) {
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 { renderToken } from '../../renderer/render.js';
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 + renderToken(curr, { convertColor: false }), "")} */`,
138
+ val: `/* ${info.node.nam}: ${info.values.reduce((acc, curr) => acc + renderValue(curr, { convertColor: false }), "")} */`,
139
139
  });
140
140
  break;
141
141
  }