@tbela99/css-parser 1.4.6 → 1.4.8

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 (55) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +1 -0
  3. package/dist/index-umd-web.js +6578 -6969
  4. package/dist/index.cjs +7808 -8197
  5. package/dist/index.d.ts +923 -51
  6. package/dist/lib/ast/clone.js +16 -23
  7. package/dist/lib/ast/expand.js +2 -2
  8. package/dist/lib/ast/features/if.js +88 -87
  9. package/dist/lib/ast/features/inlinecssvariables.js +2 -2
  10. package/dist/lib/ast/features/prefix.js +26 -22
  11. package/dist/lib/ast/features/transform.js +3 -3
  12. package/dist/lib/ast/find.js +17 -14
  13. package/dist/lib/ast/minify.js +97 -94
  14. package/dist/lib/ast/types.js +10 -2
  15. package/dist/lib/ast/walk.js +1 -1
  16. package/dist/lib/fs/resolve.js +47 -45
  17. package/dist/lib/parser/arena.js +206 -0
  18. package/dist/lib/parser/declaration/list.js +9 -10
  19. package/dist/lib/parser/declaration/map.js +13 -18
  20. package/dist/lib/parser/linemap.js +62 -0
  21. package/dist/lib/parser/parse.js +331 -504
  22. package/dist/lib/parser/source.js +72 -0
  23. package/dist/lib/parser/tokenize.js +39 -33
  24. package/dist/lib/parser/utils/at-rule-container.js +244 -247
  25. package/dist/lib/parser/utils/at-rule-generic.js +25 -25
  26. package/dist/lib/parser/utils/at-rule-import.js +194 -234
  27. package/dist/lib/parser/utils/at-rule-media.js +284 -283
  28. package/dist/lib/parser/utils/at-rule-support.js +279 -251
  29. package/dist/lib/parser/utils/at-rule-when-else.js +256 -259
  30. package/dist/lib/parser/utils/at-rule.js +19 -16
  31. package/dist/lib/parser/utils/cache.js +33 -5
  32. package/dist/lib/parser/utils/declaration.js +260 -298
  33. package/dist/lib/parser/utils/hash.js +15 -15
  34. package/dist/lib/parser/utils/selector.js +182 -222
  35. package/dist/lib/parser/utils/token.js +4 -7
  36. package/dist/lib/renderer/render.js +152 -121
  37. package/dist/lib/syntax/color/alpha.js +1 -4
  38. package/dist/lib/syntax/color/color-mix.js +8 -1
  39. package/dist/lib/syntax/color/color.js +17 -9
  40. package/dist/lib/syntax/color/hex.js +1 -1
  41. package/dist/lib/syntax/color/p3.js +9 -1
  42. package/dist/lib/syntax/color/utils/colorspace.js +3 -3
  43. package/dist/lib/syntax/color/utils/components.js +21 -22
  44. package/dist/lib/syntax/color/utils/distance.js +6 -1
  45. package/dist/lib/syntax/color/utils/matrix.js +12 -11
  46. package/dist/lib/syntax/constants.js +25 -3
  47. package/dist/lib/syntax/syntax.js +240 -311
  48. package/dist/lib/validation/config.js +16 -17
  49. package/dist/lib/validation/match.js +1118 -1131
  50. package/dist/lib/validation/parser/parse.js +130 -286
  51. package/dist/node.js +18 -14
  52. package/dist/web.js +12 -10
  53. package/package.json +4 -4
  54. package/dist/lib/validation/utils/whitespace.js +0 -17
  55. /package/dist/lib/syntax/color/{relativecolor.js → relative-color.js} +0 -0
@@ -11,36 +11,29 @@ import { EnumToken } from './types.js';
11
11
  function cloneNode(node, cloneChildren = false, cloneMap = null) {
12
12
  const checkNode = node.typ == EnumToken.DeclarationNodeType ? "val" : "chi";
13
13
  const clone = {};
14
- const properties = {};
15
14
  cloneMap?.set?.(node, clone);
16
- for (const [name, value] of Object.entries(Object.getOwnPropertyDescriptors(node))) {
17
- // @ts-expect-error
18
- if (value.value == null || typeof value.value != "object" || name == "parent") {
19
- // @ts-expect-error
20
- properties[name] = { ...value };
21
- // @ts-expect-error
15
+ for (const [name, value] of Object.entries(node)) {
16
+ if (value == null || typeof value != "object") {
17
+ clone[name] = value;
22
18
  }
23
- else if (Array.isArray(value.value)) {
24
- // @ts-expect-error
25
- properties[name] = {
26
- // @ts-expect-error
27
- ...value,
28
- value: !cloneChildren && name == checkNode
19
+ else if (Array.isArray(value)) {
20
+ clone[name] =
21
+ !cloneChildren && name == checkNode
29
22
  ? []
30
- : // @ts-expect-error
31
- value.value.map((c) => {
32
- const newObj = cloneNode(c, cloneChildren, cloneMap);
33
- cloneMap?.set?.(c, newObj);
34
- return newObj;
35
- }),
36
- };
23
+ : value.map((c) => {
24
+ const newObj = cloneNode(c, cloneChildren, cloneMap);
25
+ cloneMap?.set?.(c, newObj);
26
+ return newObj;
27
+ });
37
28
  }
38
29
  else {
39
- // @ts-expect-error
40
- properties[name] = { ...value, value: cloneNode(value.value, clone) };
30
+ clone[name] = { ...value };
41
31
  }
42
32
  }
43
- return Object.defineProperties(clone, properties);
33
+ for (const symbol of Object.getOwnPropertySymbols(node)) {
34
+ clone[symbol] = node[symbol];
35
+ }
36
+ return clone;
44
37
  }
45
38
 
46
39
  export { cloneNode };
@@ -1,5 +1,5 @@
1
1
  import { splitRule } from './minify.js';
2
- import { combinators } from '../syntax/constants.js';
2
+ import { combinators, RAW } from '../syntax/constants.js';
3
3
  import { parseString } from '../parser/parse.js';
4
4
  import { walkValues } from './walk.js';
5
5
  import { renderValue } from '../renderer/render.js';
@@ -77,7 +77,7 @@ function expandRule(node) {
77
77
  ast.chi.splice(i--, 1);
78
78
  continue;
79
79
  }
80
- for (const sel of rule.raw ?? splitRule(rule.sel)) {
80
+ for (const sel of rule[RAW] ?? splitRule(rule.sel)) {
81
81
  const s = sel.join("");
82
82
  if (s.includes("&") || parentSelector) {
83
83
  if (s.indexOf("&", 1) == -1) {
@@ -1,13 +1,13 @@
1
1
  import { EnumToken } from '../types.js';
2
2
  import { renderValue } from '../../renderer/render.js';
3
3
  import { FeatureWalkMode } from './type.js';
4
- import { definedPropertySettings } from '../../syntax/constants.js';
4
+ import { PARENT, TOKENS } from '../../syntax/constants.js';
5
5
  import { equalsIgnoreCase } from '../../parser/utils/text.js';
6
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, walkValues } from '../walk.js';
10
+ import { walk } from '../walk.js';
11
11
  import { eq } from '../../parser/utils/eq.js';
12
12
 
13
13
  const nodeMatcher = (value) => value.typ === EnumToken.IfConditionTokenType ||
@@ -21,13 +21,12 @@ function substituteIfElseNode(declaration, node, wrapper, parentWrapper, cache)
21
21
  if (node.typ === EnumToken.IfElseConditionTokenType) {
22
22
  //
23
23
  clonedDeclaration = cloneNode(declaration, true, nodeMap);
24
- let replaceRight = true;
25
24
  // replace else: ... with the actual value
26
25
  if (node.r.typ === EnumToken.IfConditionTokenType) {
27
26
  const target = node.r.l.find((t) => t.typ != EnumToken.CommentTokenType && t.typ != EnumToken.WhitespaceTokenType);
28
- if (target == null) {
29
- return result;
30
- }
27
+ // if (target == null) {
28
+ // return result;
29
+ // }
31
30
  //
32
31
  if (target.typ === EnumToken.IdenTokenType && equalsIgnoreCase("else", target.val)) {
33
32
  replaceNodeOrValue(nodeMap.get(targetParentWrapper), nodeMap.get(targetWrapper), node.r.r.at(-1)?.typ ===
@@ -63,12 +62,15 @@ function substituteIfElseNode(declaration, node, wrapper, parentWrapper, cache)
63
62
  }
64
63
  }
65
64
  }
66
- replaceRight = false;
67
65
  }
68
66
  }
69
- if (replaceRight) {
70
- replaceNodeOrValue(nodeMap.get(targetParentWrapper), nodeMap.get(targetWrapper), node.r);
71
- }
67
+ // if (replaceRight) {
68
+ // replaceNodeOrValue(
69
+ // nodeMap.get(targetParentWrapper),
70
+ // nodeMap.get(targetWrapper),
71
+ // (node as IfElseConditionToken).r,
72
+ // );
73
+ // }
72
74
  result.push(clonedDeclaration);
73
75
  nodeMap.clear();
74
76
  clonedDeclaration = cloneNode(declaration, true, nodeMap);
@@ -91,23 +93,19 @@ function substituteIfElseNode(declaration, node, wrapper, parentWrapper, cache)
91
93
  nam: left.val,
92
94
  chi: [],
93
95
  });
94
- Object.defineProperty(atRule, "tokens", {
95
- ...definedPropertySettings,
96
- value: [{ typ: EnumToken.ParensTokenType, chi: left.chi.slice() }],
97
- });
96
+ atRule[TOKENS] = [{ typ: EnumToken.ParensTokenType, chi: left.chi.slice() }];
98
97
  const minify = atRule.nam !== "supports";
99
98
  const options = {
100
99
  minify,
101
100
  convertColor: minify,
102
101
  };
103
- atRule.val = atRule.tokens.reduce((acc, curr) => acc + renderValue(curr, options), "");
102
+ atRule.val = atRule[TOKENS].reduce((acc, curr) => acc + renderValue(curr, options), "");
104
103
  clonedDeclaration = cloneNode(declaration, true, nodeMap);
105
104
  replaceNodeOrValue(nodeMap.get(targetWrapper), nodeMap.get(node), node.r.at(-1)?.typ === EnumToken.SemiColonTokenType ? trimArray(node.r.slice(0, -1)) : node.r);
106
- clonedDeclaration.parent = atRule;
105
+ clonedDeclaration[PARENT] = atRule;
107
106
  atRule.chi.push(clonedDeclaration);
108
107
  result.push(atRule);
109
108
  processNode(clonedDeclaration, cache);
110
- // nodeMap.clear();
111
109
  }
112
110
  else if (left.typ === EnumToken.ContainerFunctionTokenType) {
113
111
  const atRule = Object.assign(cloneNode(declaration), {
@@ -115,23 +113,23 @@ function substituteIfElseNode(declaration, node, wrapper, parentWrapper, cache)
115
113
  nam: "container",
116
114
  chi: [],
117
115
  });
118
- Object.defineProperty(atRule, "tokens", { ...definedPropertySettings, value: [left] });
119
- atRule.val = atRule.tokens.reduce((acc, curr) => acc + renderValue(curr), "");
116
+ atRule[TOKENS] = [left];
117
+ atRule.val = atRule[TOKENS].reduce((acc, curr) => acc + renderValue(curr), "");
120
118
  clonedDeclaration = cloneNode(declaration, true, nodeMap);
121
119
  replaceNodeOrValue(nodeMap.get(targetWrapper.typ === EnumToken.WildCardFunctionTokenType ? targetParentWrapper : targetWrapper), nodeMap.get(targetWrapper.typ === EnumToken.WildCardFunctionTokenType ? targetWrapper : node), node.r.at(-1)?.typ === EnumToken.SemiColonTokenType
122
120
  ? trimArray(node.r.slice(0, -1))
123
121
  : node.r);
124
- clonedDeclaration.parent = atRule;
122
+ clonedDeclaration[PARENT] = atRule;
125
123
  atRule.chi.push(clonedDeclaration);
126
124
  result.push(atRule);
127
125
  processNode(clonedDeclaration, cache);
128
126
  }
129
127
  }
130
- else if (wrapper.typ === EnumToken.WildCardFunctionTokenType) {
131
- clonedDeclaration = cloneNode(declaration, true, nodeMap);
132
- replaceNodeOrValue(nodeMap.get(parentWrapper), nodeMap.get(wrapper), node);
133
- result.push(clonedDeclaration);
134
- }
128
+ // else if (wrapper.typ === EnumToken.WildCardFunctionTokenType) {
129
+ // clonedDeclaration = cloneNode(declaration, true, nodeMap) as AstDeclaration;
130
+ // replaceNodeOrValue(nodeMap.get(parentWrapper), nodeMap.get(wrapper), node);
131
+ // result.push(clonedDeclaration);
132
+ // }
135
133
  return result;
136
134
  }
137
135
  function processNode(declarationNode, cache) {
@@ -143,13 +141,13 @@ function processNode(declarationNode, cache) {
143
141
  while (++k < stack.length) {
144
142
  astNode = stack[k];
145
143
  const { node: declaration, value: node } = findByValue(astNode, nodeMatcher) ?? {};
146
- if (node != null && cache.has(node.node)) {
147
- continue;
148
- }
144
+ // if (node != null && cache.has(node.node)) {
145
+ // continue;
146
+ // }
149
147
  if (declaration == null || node == null) {
150
- while (astNode.parent != null && astNode.parent != declarationNode.parent) {
151
- astNode = astNode.parent;
152
- }
148
+ // while (astNode[PARENT] != null && astNode[PARENT] != declarationNode[PARENT]) {
149
+ // astNode = astNode[PARENT];
150
+ // }
153
151
  result.push(astNode);
154
152
  continue;
155
153
  }
@@ -158,9 +156,9 @@ function processNode(declarationNode, cache) {
158
156
  const parentWrapper = node.parent ?? parents.find((node) => !nodeMatcher(node));
159
157
  if (node.node.typ === EnumToken.WildCardFunctionTokenType) {
160
158
  for (i = 0; i < node.node.chi.length; i++) {
161
- if (cache.has(node.node.chi[i])) {
162
- continue;
163
- }
159
+ // if (cache.has((node!.node as FunctionToken).chi[i])) {
160
+ // continue;
161
+ // }
164
162
  stack.push(...substituteIfElseNode(declaration, node.node.chi[i], node.node, parentWrapper, cache));
165
163
  }
166
164
  }
@@ -169,48 +167,49 @@ function processNode(declarationNode, cache) {
169
167
  }
170
168
  }
171
169
  if (result.length > 0) {
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
- }
170
+ // let invalidTokensTypes = new Set([
171
+ // EnumToken.WhitespaceTokenType,
172
+ // EnumToken.SemiColonTokenType,
173
+ // EnumToken.ColonTokenType,
174
+ // ]);
175
+ // for (i = 0; i < result.length; i++) {
176
+ // if (result[i].typ === EnumToken.DeclarationNodeType) {
177
+ // for (const { value } of walkValues((result[i] as AstDeclaration).val, result[i])) {
178
+ // if (
179
+ // value.typ === EnumToken.ImageFunctionTokenType &&
180
+ // (value as FunctionToken).val.includes("-gradient")
181
+ // ) {
182
+ // let valid: boolean = true;
183
+ // let j: number;
184
+ // for (j = 0; j < (value as FunctionToken).chi.length; j++) {
185
+ // if (
186
+ // (value as FunctionToken).chi[j].typ === EnumToken.IdenTokenType &&
187
+ // "else" == ((value as FunctionToken).chi[j] as IdentToken).val
188
+ // ) {
189
+ // valid = false;
190
+ // break;
191
+ // }
192
+ // if (
193
+ // invalidTokensTypes.has((value as FunctionToken).chi[j].typ) &&
194
+ // ((value as FunctionToken).chi[j + 1]?.typ === EnumToken.CommaTokenType ||
195
+ // j == (value as FunctionToken).chi.length - 1) &&
196
+ // (j == 0 || EnumToken.CommaTokenType == (value as FunctionToken).chi[j - 1]?.typ)
197
+ // ) {
198
+ // valid = false;
199
+ // break;
200
+ // }
201
+ // }
202
+ // if (!valid) {
203
+ // result.splice(i--, 1);
204
+ // break;
205
+ // }
206
+ // }
207
+ // }
208
+ // }
209
+ // }
210
+ // if (result.length > 0) {
211
+ replaceNodeOrValue(declarationNode[PARENT], declarationNode, result);
212
+ // }
214
213
  }
215
214
  // else remove node?
216
215
  return result;
@@ -232,19 +231,21 @@ class ExpandIfFeature {
232
231
  run(declaration) {
233
232
  processNode(declaration, new Set());
234
233
  let i;
235
- for (const n of declaration.parent.chi) {
234
+ for (const n of declaration[PARENT].chi) {
236
235
  for (const { node } of walk(n)) {
237
236
  if (node.typ === EnumToken.AtRuleNodeType && Array.isArray(node.chi)) {
238
- for (i = 0; i < node.chi.length; i++) {
239
- if (node.chi[i].typ === EnumToken.AtRuleNodeType &&
240
- node.chi[i + 1]?.typ === EnumToken.AtRuleNodeType &&
241
- node.chi[i].nam === node.chi[i + 1].nam &&
242
- node.chi[i].val === node.chi[i + 1].val) {
243
- node.chi[i].chi.push(...node.chi[i + 1].chi);
244
- node.chi.splice(i + 1, 1);
245
- i--;
246
- }
247
- }
237
+ // for (i = 0; i < (node as AstAtRule).chi!.length; i++) {
238
+ // if (
239
+ // (node as AstAtRule).chi![i]!.typ === EnumToken.AtRuleNodeType &&
240
+ // (node as AstAtRule).chi![i + 1]?.typ === EnumToken.AtRuleNodeType &&
241
+ // (node as AstAtRule).chi![i]!.nam === (node as AstAtRule).chi![i + 1]!.nam &&
242
+ // (node as AstAtRule).chi![i]!.val === (node as AstAtRule).chi![i + 1]!.val
243
+ // ) {
244
+ // (node as AstAtRule).chi![i]!.chi.push(...(node as AstAtRule).chi![i + 1]!.chi);
245
+ // (node as AstAtRule).chi!.splice(i + 1, 1);
246
+ // i--;
247
+ // }
248
+ // }
248
249
  for (i = 0; i < node.chi.length; i++) {
249
250
  if (node.chi[i].typ === EnumToken.AtRuleNodeType &&
250
251
  node.chi[i].nam === node.nam &&
@@ -3,7 +3,7 @@ import { walkValues } from '../walk.js';
3
3
  import { renderValue } from '../../renderer/render.js';
4
4
  import { splitRule } from '../minify.js';
5
5
  import { FeatureWalkMode } from './type.js';
6
- import { mathFuncs } from '../../syntax/constants.js';
6
+ import { RAW, mathFuncs } from '../../syntax/constants.js';
7
7
 
8
8
  function inlineExpression(token) {
9
9
  const result = [];
@@ -77,7 +77,7 @@ class InlineCssVariablesFeature {
77
77
  // [':root', 'html']
78
78
  const isRoot = parent.typ == EnumToken.StyleSheetNodeType &&
79
79
  ast.typ == EnumToken.RuleNodeType &&
80
- (ast.raw ?? splitRule(ast.sel)).some((segment) => segment.some((s) => s == ":root" || s == "html"));
80
+ (ast[RAW] ?? splitRule(ast.sel)).some((segment) => segment.some((s) => s == ":root" || s == "html"));
81
81
  const variableScope = context.variableScope;
82
82
  // @ts-ignore
83
83
  for (const node of ast.chi) {
@@ -3,7 +3,7 @@ import { walkValues } from '../walk.js';
3
3
  import { pseudoAliasMap } from '../../syntax/syntax.js';
4
4
  import { splitRule } from '../minify.js';
5
5
  import { renderValue } from '../../renderer/render.js';
6
- import { funcLike, regMatchLinearGradient, regMatchRadialGradient } from '../../syntax/constants.js';
6
+ import { TOKENS, funcLike, regMatchLinearGradient, regMatchRadialGradient } from '../../syntax/constants.js';
7
7
  import { FeatureWalkMode } from './type.js';
8
8
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
9
9
  import { getSyntaxConfig } from '../../validation/config.js';
@@ -110,8 +110,8 @@ class ComputePrefixFeature {
110
110
  run(node) {
111
111
  if (node.typ == EnumToken.RuleNodeType) {
112
112
  node.sel = replacePseudo(splitRule(node.sel)).reduce((acc, curr, index) => acc + (index > 0 ? "," : "") + curr.join(""), "");
113
- if (node.tokens != null) {
114
- replaceAstNodes(node.tokens);
113
+ if (node[TOKENS] != null) {
114
+ replaceAstNodes(node[TOKENS]);
115
115
  }
116
116
  }
117
117
  else if (node.typ == EnumToken.DeclarationNodeType) {
@@ -172,8 +172,8 @@ class ComputePrefixFeature {
172
172
  }
173
173
  }
174
174
  if (node.typ == EnumToken.AtRuleNodeType && node.val !== "") {
175
- if (replaceAstNodes(node.tokens)) {
176
- node.val = node.tokens.reduce((acc, curr) => acc + renderValue(curr), "");
175
+ if (replaceAstNodes(node[TOKENS])) {
176
+ node.val = node[TOKENS].reduce((acc, curr) => acc + renderValue(curr), "");
177
177
  }
178
178
  }
179
179
  }
@@ -274,28 +274,32 @@ class ComputePrefixFeature {
274
274
  let commaCount;
275
275
  let type = "";
276
276
  let tokens = token.chi.slice();
277
- while (i < tokens.length &&
278
- (tokens[i].typ === EnumToken.WhitespaceTokenType || tokens[i].typ === EnumToken.CommentTokenType)) {
279
- i++;
280
- }
281
- if (i >= tokens.length || tokens[i].typ !== EnumToken.IdenTokenType) {
282
- return;
283
- }
277
+ // while (
278
+ // i < tokens.length &&
279
+ // (tokens[i].typ === EnumToken.WhitespaceTokenType || tokens[i].typ === EnumToken.CommentTokenType)
280
+ // ) {
281
+ // i++;
282
+ // }
283
+ // if (i >= tokens.length || tokens[i].typ !== EnumToken.IdenTokenType) {
284
+ // return;
285
+ // }
284
286
  // linear or radial
285
287
  if (equalsIgnoreCase(tokens[i].val, "linear")) {
286
288
  type = "linear-gradient";
287
289
  i++;
288
290
  }
289
- else {
290
- return;
291
- }
292
- while (i < tokens.length &&
293
- (tokens[i].typ === EnumToken.WhitespaceTokenType || tokens[i].typ === EnumToken.CommentTokenType)) {
294
- i++;
295
- }
296
- if (tokens[i].typ !== EnumToken.CommaTokenType) {
297
- return;
298
- }
291
+ // else {
292
+ // return;
293
+ // }
294
+ // while (
295
+ // i < tokens.length &&
296
+ // (tokens[i].typ === EnumToken.WhitespaceTokenType || tokens[i].typ === EnumToken.CommentTokenType)
297
+ // ) {
298
+ // i++;
299
+ // }
300
+ // if (tokens[i].typ !== EnumToken.CommaTokenType) {
301
+ // return;
302
+ // }
299
303
  tokens.splice(0, i + 1);
300
304
  commaCount = 0;
301
305
  for (i = 0; i < tokens.length; i++) {
@@ -1,9 +1,9 @@
1
1
  import { EnumToken, EnumAstNodeStatus } from '../types.js';
2
- import { consumeWhitespace } from '../../validation/utils/whitespace.js';
3
2
  import { compute } from '../transform/compute.js';
4
3
  import { filterValues, renderValue } from '../../renderer/render.js';
5
4
  import { minifyTransformFunctions, eqMatrix } from '../transform/minify.js';
6
5
  import { FeatureWalkMode } from './type.js';
6
+ import { STATE } from '../../syntax/constants.js';
7
7
 
8
8
  class TransformCssFeature {
9
9
  accept = new Set([EnumToken.RuleNodeType, EnumToken.KeyFramesRuleNodeType]);
@@ -30,7 +30,7 @@ class TransformCssFeature {
30
30
  for (; i < ast.chi.length; i++) {
31
31
  // @ts-ignore
32
32
  node = ast.chi[i];
33
- if (node.state == EnumAstNodeStatus.Invalid || node.state == EnumAstNodeStatus.ValidationFailed) {
33
+ if (node[STATE] == EnumAstNodeStatus.Invalid || node[STATE] == EnumAstNodeStatus.ValidationFailed) {
34
34
  continue;
35
35
  }
36
36
  if (node.typ != EnumToken.DeclarationNodeType ||
@@ -43,7 +43,7 @@ class TransformCssFeature {
43
43
  ? minifyTransformFunctions(child)
44
44
  : child);
45
45
  }
46
- consumeWhitespace(children);
46
+ // consumeWhitespace(children);
47
47
  let { matrix, cumulative, minified } = compute(children) ?? {
48
48
  matrix: null,
49
49
  cumulative: null,
@@ -1,8 +1,9 @@
1
1
  import { EnumToken } from './types.js';
2
2
  import { walk, walkValues } from './walk.js';
3
+ import { TOKENS } from '../syntax/constants.js';
3
4
 
4
5
  /**
5
- * Search the ast tree and return the first match
6
+ * Search the ast sub-tree and return the first match
6
7
  *
7
8
  * ```ts
8
9
  * // find the first ast declaration node which name is 'aspect-ratio'
@@ -41,14 +42,14 @@ function find(ast, matcher) {
41
42
  return null;
42
43
  }
43
44
  /**
44
- * Search the ast tree by checking each node's value token and return the first match
45
+ * Search the ast sub-tree by checking each node's value token and return the first match
45
46
  *
46
- * ```ts
47
- * // find the first ast node which contains the length token '30px'
47
+ ```ts
48
+ // find the first ast node which contains the length token '30px'
48
49
  import { findByValue, EnumToken, transform } from "@tbela99/css-parser";
49
50
  import type { AstNode } from "@tbela99/css-parser";
50
51
 
51
- * const css = `
52
+ const css = `
52
53
 
53
54
  button {
54
55
  aspect-ratio: 1;
@@ -78,8 +79,8 @@ function findByValue(ast, matcher) {
78
79
  if (node.typ === EnumToken.DeclarationNodeType) {
79
80
  source = node.val;
80
81
  }
81
- else if (Array.isArray(node.tokens)) {
82
- source = node.tokens;
82
+ else if (Array.isArray(node[TOKENS])) {
83
+ source = node[TOKENS];
83
84
  }
84
85
  if (source == null) {
85
86
  continue;
@@ -93,22 +94,25 @@ function findByValue(ast, matcher) {
93
94
  return null;
94
95
  }
95
96
  /**
96
- * Search the ast tree and return all matches
97
+ * Search the ast sub-tree and return all matches
97
98
  *
98
99
  * ```ts
99
100
  * // find the first ast declaration node which name is 'aspect-ratio'
100
- import { findAll, EnumToken, transform } from "@tbela99/css-parser";
101
- import type { AstNode } from "@tbela99/css-parser";
101
+ * import { findAll, EnumToken, transform } from "@tbela99/css-parser";
102
+ * import type { AstNode } from "@tbela99/css-parser";
102
103
 
103
- * const css = `
104
+ const css = `
104
105
 
105
106
  button {
106
107
  aspect-ratio: 1;
107
108
  width: if(media(any-pointer: fine): 30px; else: 44px);
109
+ }
110
+ button-small {
111
+ aspect-ratio: 1;
112
+ width: if(media(any-pointer: fine): 20px; else: 30px);
108
113
  }
109
114
  `;
110
115
 
111
- // find declaration which contain a '30px'
112
116
  const nodeMatcher = (node: AstNode) =>
113
117
  return node.typ == EnumToken.DeclarationNodeType && (node as AstDeclaration).nam == 'aspect-ratio';
114
118
 
@@ -133,7 +137,7 @@ function findAll(ast, matcher) {
133
137
  return result;
134
138
  }
135
139
  /**
136
- * Search the ast tree and return the last match.
140
+ * Search the ast sub-tree and return the last match.
137
141
  *
138
142
  * ```ts
139
143
  * // find the first ast declaration node which name is 'aspect-ratio'
@@ -148,7 +152,6 @@ button {
148
152
  }
149
153
  `;
150
154
 
151
- // find declaration which contain a '30px'
152
155
  const nodeMatcher = (node: AstNode) =>
153
156
  return node.typ == EnumToken.DeclarationNodeType && (node as AstDeclaration).nam == 'aspect-ratio';
154
157