@tbela99/css-parser 0.7.1 → 0.9.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.
Files changed (90) hide show
  1. package/.editorconfig +484 -0
  2. package/README.md +140 -84
  3. package/dist/index-umd-web.js +8461 -51655
  4. package/dist/index.cjs +8437 -51636
  5. package/dist/index.d.ts +220 -68
  6. package/dist/lib/ast/expand.js +46 -9
  7. package/dist/lib/ast/features/calc.js +76 -12
  8. package/dist/lib/ast/features/inlinecssvariables.js +6 -1
  9. package/dist/lib/ast/features/prefix.js +17 -9
  10. package/dist/lib/ast/features/shorthand.js +1 -0
  11. package/dist/lib/ast/math/expression.js +299 -11
  12. package/dist/lib/ast/math/math.js +7 -1
  13. package/dist/lib/ast/minify.js +30 -16
  14. package/dist/lib/ast/types.js +59 -49
  15. package/dist/lib/ast/walk.js +92 -18
  16. package/dist/lib/parser/declaration/list.js +1 -0
  17. package/dist/lib/parser/declaration/map.js +60 -52
  18. package/dist/lib/parser/declaration/set.js +1 -12
  19. package/dist/lib/parser/parse.js +371 -119
  20. package/dist/lib/parser/tokenize.js +31 -6
  21. package/dist/lib/parser/utils/declaration.js +2 -2
  22. package/dist/lib/parser/utils/type.js +6 -6
  23. package/dist/lib/renderer/color/a98rgb.js +1 -0
  24. package/dist/lib/renderer/color/color.js +1 -0
  25. package/dist/lib/renderer/color/colormix.js +1 -0
  26. package/dist/lib/renderer/color/hex.js +2 -1
  27. package/dist/lib/renderer/color/hsl.js +2 -1
  28. package/dist/lib/renderer/color/hwb.js +3 -2
  29. package/dist/lib/renderer/color/lab.js +2 -1
  30. package/dist/lib/renderer/color/lch.js +2 -1
  31. package/dist/lib/renderer/color/oklab.js +3 -2
  32. package/dist/lib/renderer/color/oklch.js +2 -1
  33. package/dist/lib/renderer/color/p3.js +2 -1
  34. package/dist/lib/renderer/color/prophotoRgb.js +56 -0
  35. package/dist/lib/renderer/color/prophotorgb.js +1 -1
  36. package/dist/lib/renderer/color/rec2020.js +1 -0
  37. package/dist/lib/renderer/color/relativecolor.js +52 -28
  38. package/dist/lib/renderer/color/rgb.js +2 -1
  39. package/dist/lib/renderer/color/srgb.js +3 -2
  40. package/dist/lib/renderer/color/utils/components.js +1 -0
  41. package/dist/lib/renderer/color/utils/constants.js +2 -1
  42. package/dist/lib/renderer/color/xyz.js +2 -1
  43. package/dist/lib/renderer/color/xyzd50.js +1 -0
  44. package/dist/lib/renderer/render.js +62 -12
  45. package/dist/lib/syntax/syntax.js +362 -4
  46. package/dist/lib/validation/at-rules/container.js +353 -0
  47. package/dist/lib/validation/at-rules/counter-style.js +78 -0
  48. package/dist/lib/validation/at-rules/custom-media.js +52 -0
  49. package/dist/lib/validation/at-rules/document.js +114 -0
  50. package/dist/lib/validation/at-rules/else.js +5 -0
  51. package/dist/lib/validation/at-rules/font-feature-values.js +52 -0
  52. package/dist/lib/validation/at-rules/import.js +199 -0
  53. package/dist/lib/validation/at-rules/keyframes.js +70 -0
  54. package/dist/lib/validation/at-rules/layer.js +30 -0
  55. package/dist/lib/validation/at-rules/media.js +254 -0
  56. package/dist/lib/validation/at-rules/namespace.js +85 -0
  57. package/dist/lib/validation/at-rules/page-margin-box.js +56 -0
  58. package/dist/lib/validation/at-rules/page.js +88 -0
  59. package/dist/lib/validation/at-rules/supports.js +262 -0
  60. package/dist/lib/validation/at-rules/when.js +178 -0
  61. package/dist/lib/validation/atrule.js +187 -0
  62. package/dist/lib/validation/config.js +35 -2
  63. package/dist/lib/validation/config.json.js +1683 -50905
  64. package/dist/lib/validation/declaration.js +102 -0
  65. package/dist/lib/validation/parser/parse.js +1137 -7
  66. package/dist/lib/validation/parser/types.js +28 -12
  67. package/dist/lib/validation/selector.js +26 -444
  68. package/dist/lib/validation/syntax.js +1475 -0
  69. package/dist/lib/validation/syntaxes/complex-selector-list.js +45 -0
  70. package/dist/lib/validation/syntaxes/complex-selector.js +53 -0
  71. package/dist/lib/validation/syntaxes/compound-selector.js +226 -0
  72. package/dist/lib/validation/syntaxes/family-name.js +91 -0
  73. package/dist/lib/validation/syntaxes/image.js +29 -0
  74. package/dist/lib/validation/syntaxes/keyframe-block-list.js +27 -0
  75. package/dist/lib/validation/syntaxes/keyframe-selector.js +137 -0
  76. package/dist/lib/validation/syntaxes/layer-name.js +67 -0
  77. package/dist/lib/validation/syntaxes/relative-selector-list.js +57 -0
  78. package/dist/lib/validation/syntaxes/relative-selector.js +36 -0
  79. package/dist/lib/validation/syntaxes/selector-list.js +5 -0
  80. package/dist/lib/validation/syntaxes/selector.js +5 -0
  81. package/dist/lib/validation/syntaxes/url.js +75 -0
  82. package/dist/lib/validation/utils/list.js +24 -0
  83. package/dist/lib/validation/utils/whitespace.js +22 -0
  84. package/dist/node/index.js +5 -5
  85. package/dist/web/index.js +5 -1
  86. package/dist/web/load.js +1 -0
  87. package/package.json +16 -14
  88. package/dist/lib/ast/utils/minifyfeature.js +0 -9
  89. package/dist/lib/iterable/weakset.js +0 -58
  90. package/dist/lib/parser/utils/syntax.js +0 -450
@@ -2,6 +2,7 @@ var ValidationLevel;
2
2
  (function (ValidationLevel) {
3
3
  ValidationLevel[ValidationLevel["Valid"] = 0] = "Valid";
4
4
  ValidationLevel[ValidationLevel["Drop"] = 1] = "Drop";
5
+ ValidationLevel[ValidationLevel["Lenient"] = 2] = "Lenient"; /* preserve unknown at-rules, declarations and pseudo-classes */
5
6
  })(ValidationLevel || (ValidationLevel = {}));
6
7
  var EnumToken;
7
8
  (function (EnumToken) {
@@ -44,61 +45,70 @@ var EnumToken;
44
45
  EnumToken[EnumToken["WhitespaceTokenType"] = 36] = "WhitespaceTokenType";
45
46
  EnumToken[EnumToken["IncludeMatchTokenType"] = 37] = "IncludeMatchTokenType";
46
47
  EnumToken[EnumToken["DashMatchTokenType"] = 38] = "DashMatchTokenType";
47
- EnumToken[EnumToken["LtTokenType"] = 39] = "LtTokenType";
48
- EnumToken[EnumToken["LteTokenType"] = 40] = "LteTokenType";
49
- EnumToken[EnumToken["GtTokenType"] = 41] = "GtTokenType";
50
- EnumToken[EnumToken["GteTokenType"] = 42] = "GteTokenType";
51
- EnumToken[EnumToken["PseudoClassTokenType"] = 43] = "PseudoClassTokenType";
52
- EnumToken[EnumToken["PseudoClassFuncTokenType"] = 44] = "PseudoClassFuncTokenType";
53
- EnumToken[EnumToken["DelimTokenType"] = 45] = "DelimTokenType";
54
- EnumToken[EnumToken["UrlTokenTokenType"] = 46] = "UrlTokenTokenType";
55
- EnumToken[EnumToken["EOFTokenType"] = 47] = "EOFTokenType";
56
- EnumToken[EnumToken["ImportantTokenType"] = 48] = "ImportantTokenType";
57
- EnumToken[EnumToken["ColorTokenType"] = 49] = "ColorTokenType";
58
- EnumToken[EnumToken["AttrTokenType"] = 50] = "AttrTokenType";
59
- EnumToken[EnumToken["BadCommentTokenType"] = 51] = "BadCommentTokenType";
60
- EnumToken[EnumToken["BadCdoTokenType"] = 52] = "BadCdoTokenType";
61
- EnumToken[EnumToken["BadUrlTokenType"] = 53] = "BadUrlTokenType";
62
- EnumToken[EnumToken["BadStringTokenType"] = 54] = "BadStringTokenType";
63
- EnumToken[EnumToken["BinaryExpressionTokenType"] = 55] = "BinaryExpressionTokenType";
64
- EnumToken[EnumToken["UnaryExpressionTokenType"] = 56] = "UnaryExpressionTokenType";
65
- EnumToken[EnumToken["FlexTokenType"] = 57] = "FlexTokenType";
48
+ EnumToken[EnumToken["EqualMatchTokenType"] = 39] = "EqualMatchTokenType";
49
+ EnumToken[EnumToken["LtTokenType"] = 40] = "LtTokenType";
50
+ EnumToken[EnumToken["LteTokenType"] = 41] = "LteTokenType";
51
+ EnumToken[EnumToken["GtTokenType"] = 42] = "GtTokenType";
52
+ EnumToken[EnumToken["GteTokenType"] = 43] = "GteTokenType";
53
+ EnumToken[EnumToken["PseudoClassTokenType"] = 44] = "PseudoClassTokenType";
54
+ EnumToken[EnumToken["PseudoClassFuncTokenType"] = 45] = "PseudoClassFuncTokenType";
55
+ EnumToken[EnumToken["DelimTokenType"] = 46] = "DelimTokenType";
56
+ EnumToken[EnumToken["UrlTokenTokenType"] = 47] = "UrlTokenTokenType";
57
+ EnumToken[EnumToken["EOFTokenType"] = 48] = "EOFTokenType";
58
+ EnumToken[EnumToken["ImportantTokenType"] = 49] = "ImportantTokenType";
59
+ EnumToken[EnumToken["ColorTokenType"] = 50] = "ColorTokenType";
60
+ EnumToken[EnumToken["AttrTokenType"] = 51] = "AttrTokenType";
61
+ EnumToken[EnumToken["BadCommentTokenType"] = 52] = "BadCommentTokenType";
62
+ EnumToken[EnumToken["BadCdoTokenType"] = 53] = "BadCdoTokenType";
63
+ EnumToken[EnumToken["BadUrlTokenType"] = 54] = "BadUrlTokenType";
64
+ EnumToken[EnumToken["BadStringTokenType"] = 55] = "BadStringTokenType";
65
+ EnumToken[EnumToken["BinaryExpressionTokenType"] = 56] = "BinaryExpressionTokenType";
66
+ EnumToken[EnumToken["UnaryExpressionTokenType"] = 57] = "UnaryExpressionTokenType";
67
+ EnumToken[EnumToken["FlexTokenType"] = 58] = "FlexTokenType";
66
68
  /* catch all */
67
- EnumToken[EnumToken["ListToken"] = 58] = "ListToken";
69
+ EnumToken[EnumToken["ListToken"] = 59] = "ListToken";
68
70
  /* arithmetic tokens */
69
- EnumToken[EnumToken["Add"] = 59] = "Add";
70
- EnumToken[EnumToken["Mul"] = 60] = "Mul";
71
- EnumToken[EnumToken["Div"] = 61] = "Div";
72
- EnumToken[EnumToken["Sub"] = 62] = "Sub";
71
+ EnumToken[EnumToken["Add"] = 60] = "Add";
72
+ EnumToken[EnumToken["Mul"] = 61] = "Mul";
73
+ EnumToken[EnumToken["Div"] = 62] = "Div";
74
+ EnumToken[EnumToken["Sub"] = 63] = "Sub";
73
75
  /* new tokens */
74
- EnumToken[EnumToken["ColumnCombinatorTokenType"] = 63] = "ColumnCombinatorTokenType";
75
- EnumToken[EnumToken["ContainMatchTokenType"] = 64] = "ContainMatchTokenType";
76
- EnumToken[EnumToken["StartMatchTokenType"] = 65] = "StartMatchTokenType";
77
- EnumToken[EnumToken["EndMatchTokenType"] = 66] = "EndMatchTokenType";
78
- EnumToken[EnumToken["MatchExpressionTokenType"] = 67] = "MatchExpressionTokenType";
79
- EnumToken[EnumToken["NameSpaceAttributeTokenType"] = 68] = "NameSpaceAttributeTokenType";
80
- EnumToken[EnumToken["FractionTokenType"] = 69] = "FractionTokenType";
81
- EnumToken[EnumToken["IdenListTokenType"] = 70] = "IdenListTokenType";
82
- EnumToken[EnumToken["GridTemplateFuncTokenType"] = 71] = "GridTemplateFuncTokenType";
83
- EnumToken[EnumToken["KeyFrameRuleNodeType"] = 72] = "KeyFrameRuleNodeType";
84
- EnumToken[EnumToken["ClassSelectorTokenType"] = 73] = "ClassSelectorTokenType";
85
- EnumToken[EnumToken["UniversalSelectorTokenType"] = 74] = "UniversalSelectorTokenType";
86
- EnumToken[EnumToken["ChildCombinatorTokenType"] = 75] = "ChildCombinatorTokenType";
87
- EnumToken[EnumToken["DescendantCombinatorTokenType"] = 76] = "DescendantCombinatorTokenType";
88
- EnumToken[EnumToken["NextSiblingCombinatorTokenType"] = 77] = "NextSiblingCombinatorTokenType";
89
- EnumToken[EnumToken["SubsequentSiblingCombinatorTokenType"] = 78] = "SubsequentSiblingCombinatorTokenType";
90
- EnumToken[EnumToken["NestingSelectorTokenType"] = 79] = "NestingSelectorTokenType";
91
- EnumToken[EnumToken["InvalidRuleTokenType"] = 80] = "InvalidRuleTokenType";
92
- EnumToken[EnumToken["InvalidClassSelectorTokenType"] = 81] = "InvalidClassSelectorTokenType";
93
- EnumToken[EnumToken["InvalidAttrTokenType"] = 82] = "InvalidAttrTokenType";
76
+ EnumToken[EnumToken["ColumnCombinatorTokenType"] = 64] = "ColumnCombinatorTokenType";
77
+ EnumToken[EnumToken["ContainMatchTokenType"] = 65] = "ContainMatchTokenType";
78
+ EnumToken[EnumToken["StartMatchTokenType"] = 66] = "StartMatchTokenType";
79
+ EnumToken[EnumToken["EndMatchTokenType"] = 67] = "EndMatchTokenType";
80
+ EnumToken[EnumToken["MatchExpressionTokenType"] = 68] = "MatchExpressionTokenType";
81
+ EnumToken[EnumToken["NameSpaceAttributeTokenType"] = 69] = "NameSpaceAttributeTokenType";
82
+ EnumToken[EnumToken["FractionTokenType"] = 70] = "FractionTokenType";
83
+ EnumToken[EnumToken["IdenListTokenType"] = 71] = "IdenListTokenType";
84
+ EnumToken[EnumToken["GridTemplateFuncTokenType"] = 72] = "GridTemplateFuncTokenType";
85
+ EnumToken[EnumToken["KeyFrameRuleNodeType"] = 73] = "KeyFrameRuleNodeType";
86
+ EnumToken[EnumToken["ClassSelectorTokenType"] = 74] = "ClassSelectorTokenType";
87
+ EnumToken[EnumToken["UniversalSelectorTokenType"] = 75] = "UniversalSelectorTokenType";
88
+ EnumToken[EnumToken["ChildCombinatorTokenType"] = 76] = "ChildCombinatorTokenType";
89
+ EnumToken[EnumToken["DescendantCombinatorTokenType"] = 77] = "DescendantCombinatorTokenType";
90
+ EnumToken[EnumToken["NextSiblingCombinatorTokenType"] = 78] = "NextSiblingCombinatorTokenType";
91
+ EnumToken[EnumToken["SubsequentSiblingCombinatorTokenType"] = 79] = "SubsequentSiblingCombinatorTokenType";
92
+ EnumToken[EnumToken["NestingSelectorTokenType"] = 80] = "NestingSelectorTokenType";
93
+ EnumToken[EnumToken["InvalidRuleTokenType"] = 81] = "InvalidRuleTokenType";
94
+ EnumToken[EnumToken["InvalidClassSelectorTokenType"] = 82] = "InvalidClassSelectorTokenType";
95
+ EnumToken[EnumToken["InvalidAttrTokenType"] = 83] = "InvalidAttrTokenType";
96
+ EnumToken[EnumToken["InvalidAtRuleTokenType"] = 84] = "InvalidAtRuleTokenType";
97
+ EnumToken[EnumToken["MediaQueryConditionTokenType"] = 85] = "MediaQueryConditionTokenType";
98
+ EnumToken[EnumToken["MediaFeatureTokenType"] = 86] = "MediaFeatureTokenType";
99
+ EnumToken[EnumToken["MediaFeatureOnlyTokenType"] = 87] = "MediaFeatureOnlyTokenType";
100
+ EnumToken[EnumToken["MediaFeatureNotTokenType"] = 88] = "MediaFeatureNotTokenType";
101
+ EnumToken[EnumToken["MediaFeatureAndTokenType"] = 89] = "MediaFeatureAndTokenType";
102
+ EnumToken[EnumToken["MediaFeatureOrTokenType"] = 90] = "MediaFeatureOrTokenType";
103
+ EnumToken[EnumToken["PseudoPageTokenType"] = 91] = "PseudoPageTokenType";
94
104
  /* aliases */
95
105
  EnumToken[EnumToken["Time"] = 25] = "Time";
96
106
  EnumToken[EnumToken["Iden"] = 7] = "Iden";
97
- EnumToken[EnumToken["EOF"] = 47] = "EOF";
107
+ EnumToken[EnumToken["EOF"] = 48] = "EOF";
98
108
  EnumToken[EnumToken["Hash"] = 28] = "Hash";
99
- EnumToken[EnumToken["Flex"] = 57] = "Flex";
109
+ EnumToken[EnumToken["Flex"] = 58] = "Flex";
100
110
  EnumToken[EnumToken["Angle"] = 24] = "Angle";
101
- EnumToken[EnumToken["Color"] = 49] = "Color";
111
+ EnumToken[EnumToken["Color"] = 50] = "Color";
102
112
  EnumToken[EnumToken["Comma"] = 9] = "Comma";
103
113
  EnumToken[EnumToken["String"] = 20] = "String";
104
114
  EnumToken[EnumToken["Length"] = 23] = "Length";
@@ -111,9 +121,9 @@ var EnumToken;
111
121
  EnumToken[EnumToken["Frequency"] = 26] = "Frequency";
112
122
  EnumToken[EnumToken["Resolution"] = 27] = "Resolution";
113
123
  EnumToken[EnumToken["Whitespace"] = 36] = "Whitespace";
114
- EnumToken[EnumToken["IdenList"] = 70] = "IdenList";
124
+ EnumToken[EnumToken["IdenList"] = 71] = "IdenList";
115
125
  EnumToken[EnumToken["DashedIden"] = 8] = "DashedIden";
116
- EnumToken[EnumToken["GridTemplateFunc"] = 71] = "GridTemplateFunc";
126
+ EnumToken[EnumToken["GridTemplateFunc"] = 72] = "GridTemplateFunc";
117
127
  EnumToken[EnumToken["ImageFunc"] = 19] = "ImageFunc";
118
128
  EnumToken[EnumToken["CommentNodeType"] = 0] = "CommentNodeType";
119
129
  EnumToken[EnumToken["CDOCOMMNodeType"] = 1] = "CDOCOMMNodeType";
@@ -1,5 +1,15 @@
1
1
  import { EnumToken } from './types.js';
2
2
 
3
+ var WalkerValueEvent;
4
+ (function (WalkerValueEvent) {
5
+ WalkerValueEvent[WalkerValueEvent["Enter"] = 0] = "Enter";
6
+ WalkerValueEvent[WalkerValueEvent["Leave"] = 1] = "Leave";
7
+ })(WalkerValueEvent || (WalkerValueEvent = {}));
8
+ /**
9
+ * walk ast nodes
10
+ * @param node
11
+ * @param filter
12
+ */
3
13
  function* walk(node, filter) {
4
14
  const parents = [node];
5
15
  const root = node;
@@ -28,40 +38,104 @@ function* walk(node, filter) {
28
38
  }
29
39
  }
30
40
  }
31
- function* walkValues(values, root = null, filter) {
41
+ /**
42
+ * walk ast values
43
+ * @param values
44
+ * @param root
45
+ * @param filter
46
+ * @param reverse
47
+ */
48
+ function* walkValues(values, root = null, filter, reverse) {
49
+ // const set = new Set<Token>();
32
50
  const stack = values.slice();
33
51
  const map = new Map;
34
- let value;
35
52
  let previous = null;
36
- while ((value = stack.shift())) {
53
+ // let parent: FunctionToken | ParensToken | BinaryExpressionToken | null = null;
54
+ if (filter != null && typeof filter == 'function') {
55
+ filter = {
56
+ event: WalkerValueEvent.Enter,
57
+ fn: filter
58
+ };
59
+ }
60
+ else if (filter == null) {
61
+ filter = {
62
+ event: WalkerValueEvent.Enter
63
+ };
64
+ }
65
+ while (stack.length > 0) {
66
+ let value = reverse ? stack.pop() : stack.shift();
37
67
  let option = null;
38
- if (filter != null) {
39
- option = filter(value);
40
- if (option === 'ignore') {
41
- continue;
42
- }
43
- if (option === 'stop') {
44
- break;
68
+ if (filter.fn != null && filter.event == WalkerValueEvent.Enter) {
69
+ const isValid = filter.type == null || value.typ == filter.type ||
70
+ (Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
71
+ (typeof filter.type == 'function' && filter.type(value));
72
+ if (isValid) {
73
+ option = filter.fn(value, map.get(value) ?? root, WalkerValueEvent.Enter);
74
+ if (option === 'ignore') {
75
+ continue;
76
+ }
77
+ if (option === 'stop') {
78
+ break;
79
+ }
80
+ // @ts-ignore
81
+ if (option != null && typeof option == 'object' && 'typ' in option) {
82
+ map.set(option, map.get(value) ?? root);
83
+ }
45
84
  }
46
85
  }
47
86
  // @ts-ignore
48
- if (option !== 'children') {
49
- // @ts-ignore
50
- yield { value, parent: map.get(value), previousValue: previous, nextValue: stack[0] ?? null, root };
87
+ if (filter.event == WalkerValueEvent.Enter && option !== 'children') {
88
+ yield {
89
+ value,
90
+ parent: map.get(value) ?? root,
91
+ previousValue: previous,
92
+ nextValue: stack[0] ?? null,
93
+ // @ts-ignore
94
+ root: root ?? null
95
+ };
51
96
  }
52
97
  if (option !== 'ignore-children' && 'chi' in value) {
53
- for (const child of value.chi.slice()) {
98
+ const sliced = value.chi.slice();
99
+ for (const child of sliced) {
54
100
  map.set(child, value);
55
101
  }
56
- stack.unshift(...value.chi);
102
+ if (reverse) {
103
+ stack.push(...sliced);
104
+ }
105
+ else {
106
+ stack.unshift(...sliced);
107
+ }
57
108
  }
58
109
  else if (value.typ == EnumToken.BinaryExpressionTokenType) {
59
- map.set(value.l, value);
60
- map.set(value.r, value);
110
+ map.set(value.l, map.get(value) ?? root);
111
+ map.set(value.r, map.get(value) ?? root);
61
112
  stack.unshift(value.l, value.r);
62
113
  }
114
+ if (filter.event == WalkerValueEvent.Leave && filter.fn != null) {
115
+ const isValid = filter.type == null || value.typ == filter.type ||
116
+ (Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
117
+ (typeof filter.type == 'function' && filter.type(value));
118
+ if (isValid) {
119
+ option = filter.fn(value, map.get(value), WalkerValueEvent.Leave);
120
+ // @ts-ignore
121
+ if (option != null && 'typ' in option) {
122
+ map.set(option, map.get(value) ?? root);
123
+ }
124
+ }
125
+ }
126
+ // @ts-ignore
127
+ if (filter.event == WalkerValueEvent.Leave && option !== 'children') {
128
+ yield {
129
+ value,
130
+ parent: map.get(value) ?? root,
131
+ previousValue: previous,
132
+ nextValue: stack[0] ?? null,
133
+ // @ts-ignore
134
+ root: root ?? null
135
+ };
136
+ }
63
137
  previous = value;
64
138
  }
65
139
  }
66
140
 
67
- export { walk, walkValues };
141
+ export { WalkerValueEvent, walk, walkValues };
@@ -2,6 +2,7 @@ import { PropertySet } from './set.js';
2
2
  import { getConfig } from '../utils/config.js';
3
3
  import { EnumToken } from '../../ast/types.js';
4
4
  import '../../ast/minify.js';
5
+ import '../../ast/walk.js';
5
6
  import { parseString } from '../parse.js';
6
7
  import '../../renderer/color/utils/constants.js';
7
8
  import '../../renderer/sourcemap/lib/encode.js';
@@ -3,6 +3,7 @@ import { getConfig } from '../utils/config.js';
3
3
  import { matchType } from '../utils/type.js';
4
4
  import { EnumToken } from '../../ast/types.js';
5
5
  import '../../ast/minify.js';
6
+ import '../../ast/walk.js';
6
7
  import { parseString } from '../parse.js';
7
8
  import { renderToken } from '../../renderer/render.js';
8
9
  import '../../renderer/color/utils/constants.js';
@@ -161,55 +162,6 @@ class PropertyMap {
161
162
  }
162
163
  return this;
163
164
  }
164
- matchTypes(declaration) {
165
- const patterns = this.pattern.slice();
166
- const values = [...declaration.val];
167
- let i;
168
- let j;
169
- const map = new Map;
170
- for (i = 0; i < patterns.length; i++) {
171
- for (j = 0; j < values.length; j++) {
172
- if (!map.has(patterns[i])) {
173
- // @ts-ignore
174
- map.set(patterns[i], this.config.properties?.[patterns[i]]?.constraints?.mapping?.max ?? 1);
175
- }
176
- let count = map.get(patterns[i]);
177
- if (count > 0 && matchType(values[j], this.config.properties[patterns[i]])) {
178
- Object.defineProperty(values[j], 'propertyName', {
179
- enumerable: false,
180
- writable: true,
181
- value: patterns[i]
182
- });
183
- map.set(patterns[i], --count);
184
- values.splice(j--, 1);
185
- }
186
- }
187
- }
188
- if (this.config.set != null) {
189
- for (const [key, val] of Object.entries(this.config.set)) {
190
- if (map.has(key)) {
191
- for (const v of val) {
192
- // missing
193
- if (map.get(v) == 1) {
194
- let i = declaration.val.length;
195
- while (i--) {
196
- // @ts-ignore
197
- if (declaration.val[i].propertyName == key) {
198
- const val = { ...declaration.val[i] };
199
- Object.defineProperty(val, 'propertyName', {
200
- enumerable: false,
201
- writable: true,
202
- value: v
203
- });
204
- declaration.val.splice(i, 0, val, { typ: EnumToken.WhitespaceTokenType });
205
- }
206
- }
207
- }
208
- }
209
- }
210
- }
211
- }
212
- }
213
165
  [Symbol.iterator]() {
214
166
  let iterable;
215
167
  let requiredCount = 0;
@@ -248,9 +200,15 @@ class PropertyMap {
248
200
  // @ts-ignore
249
201
  let typ = (EnumToken[this.config.separator?.typ] ?? EnumToken.CommaTokenType);
250
202
  // @ts-ignore
251
- const sep = this.config.separator == null ? null : { ...this.config.separator, typ: EnumToken[this.config.separator.typ] };
203
+ const sep = this.config.separator == null ? null : {
204
+ ...this.config.separator,
205
+ typ: EnumToken[this.config.separator.typ]
206
+ };
252
207
  // @ts-ignore
253
- const separator = this.config.separator ? renderToken({ ...this.config.separator, typ: EnumToken[this.config.separator.typ] }) : ',';
208
+ const separator = this.config.separator ? renderToken({
209
+ ...this.config.separator,
210
+ typ: EnumToken[this.config.separator.typ]
211
+ }) : ',';
254
212
  this.matchTypes(declaration);
255
213
  values.push(value);
256
214
  for (i = 0; i < declaration.val.length; i++) {
@@ -445,7 +403,6 @@ class PropertyMap {
445
403
  acc.push(curr);
446
404
  return acc;
447
405
  }, []);
448
- // @todo remove renderToken call
449
406
  if (props.default.includes(curr[1][i].reduce((acc, curr) => acc + renderToken(curr) + ' ', '').trimEnd())) {
450
407
  if (!this.config.properties[curr[0]].required) {
451
408
  continue;
@@ -543,6 +500,7 @@ class PropertyMap {
543
500
  }
544
501
  // @ts-ignore
545
502
  if (values.length == 1 &&
503
+ // @ts-ignore
546
504
  typeof values[0].val == 'string' &&
547
505
  this.config.default.includes(values[0].val.toLowerCase()) &&
548
506
  this.config.default[0] != values[0].val.toLowerCase()) {
@@ -561,6 +519,7 @@ class PropertyMap {
561
519
  // @ts-ignore
562
520
  next() {
563
521
  let v = iterable.next();
522
+ // @ts-ignore
564
523
  while (v.done || v.value instanceof PropertySet) {
565
524
  if (v.value instanceof PropertySet) {
566
525
  // @ts-ignore
@@ -583,6 +542,55 @@ class PropertyMap {
583
542
  }
584
543
  };
585
544
  }
545
+ matchTypes(declaration) {
546
+ const patterns = this.pattern.slice();
547
+ const values = [...declaration.val];
548
+ let i;
549
+ let j;
550
+ const map = new Map;
551
+ for (i = 0; i < patterns.length; i++) {
552
+ for (j = 0; j < values.length; j++) {
553
+ if (!map.has(patterns[i])) {
554
+ // @ts-ignore
555
+ map.set(patterns[i], this.config.properties?.[patterns[i]]?.constraints?.mapping?.max ?? 1);
556
+ }
557
+ let count = map.get(patterns[i]);
558
+ if (count > 0 && matchType(values[j], this.config.properties[patterns[i]])) {
559
+ Object.defineProperty(values[j], 'propertyName', {
560
+ enumerable: false,
561
+ writable: true,
562
+ value: patterns[i]
563
+ });
564
+ map.set(patterns[i], --count);
565
+ values.splice(j--, 1);
566
+ }
567
+ }
568
+ }
569
+ if (this.config.set != null) {
570
+ for (const [key, val] of Object.entries(this.config.set)) {
571
+ if (map.has(key)) {
572
+ for (const v of val) {
573
+ // missing
574
+ if (map.get(v) == 1) {
575
+ let i = declaration.val.length;
576
+ while (i--) {
577
+ // @ts-ignore
578
+ if (declaration.val[i].propertyName == key) {
579
+ const val = { ...declaration.val[i] };
580
+ Object.defineProperty(val, 'propertyName', {
581
+ enumerable: false,
582
+ writable: true,
583
+ value: v
584
+ });
585
+ declaration.val.splice(i, 0, val, { typ: EnumToken.WhitespaceTokenType });
586
+ }
587
+ }
588
+ }
589
+ }
590
+ }
591
+ }
592
+ }
593
+ }
586
594
  removeDefaults(map, value) {
587
595
  for (const [key, val] of map) {
588
596
  const config = this.config.properties[key];
@@ -1,6 +1,7 @@
1
1
  import { eq } from '../utils/eq.js';
2
2
  import { EnumToken } from '../../ast/types.js';
3
3
  import '../../ast/minify.js';
4
+ import '../../ast/walk.js';
4
5
  import '../parse.js';
5
6
  import { isLength } from '../../syntax/syntax.js';
6
7
  import '../utils/config.js';
@@ -180,20 +181,8 @@ class PropertySet {
180
181
  return acc;
181
182
  }, [])
182
183
  }][Symbol.iterator]();
183
- // return {
184
- // next() {
185
- //
186
- // return iterator.next();
187
- // }
188
- // }
189
184
  }
190
185
  return iterator;
191
- // return {
192
- // next() {
193
- //
194
- // return iterator.next();
195
- // }
196
- // }
197
186
  }
198
187
  }
199
188