@tbela99/css-parser 1.1.1-alpha4 → 1.2.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 (101) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/README.md +53 -6
  3. package/dist/index-umd-web.js +4195 -3375
  4. package/dist/index.cjs +5468 -4648
  5. package/dist/index.d.ts +42 -31
  6. package/dist/lib/ast/expand.js +81 -65
  7. package/dist/lib/ast/features/calc.js +37 -35
  8. package/dist/lib/ast/features/inlinecssvariables.js +25 -17
  9. package/dist/lib/ast/features/prefix.js +22 -19
  10. package/dist/lib/ast/features/shorthand.js +1 -1
  11. package/dist/lib/ast/features/transform.js +17 -2
  12. package/dist/lib/ast/math/expression.js +184 -159
  13. package/dist/lib/ast/math/math.js +22 -20
  14. package/dist/lib/ast/minify.js +249 -200
  15. package/dist/lib/ast/transform/compute.js +48 -38
  16. package/dist/lib/ast/transform/matrix.js +6 -5
  17. package/dist/lib/ast/transform/minify.js +31 -34
  18. package/dist/lib/ast/transform/utils.js +76 -16
  19. package/dist/lib/ast/types.js +32 -1
  20. package/dist/lib/fs/resolve.js +1 -14
  21. package/dist/lib/parser/declaration/list.js +1 -1
  22. package/dist/lib/parser/declaration/map.js +1 -1
  23. package/dist/lib/parser/declaration/set.js +1 -1
  24. package/dist/lib/parser/parse.js +19 -95
  25. package/dist/lib/parser/tokenize.js +1 -13
  26. package/dist/lib/parser/utils/declaration.js +1 -1
  27. package/dist/lib/parser/utils/type.js +1 -1
  28. package/dist/lib/renderer/render.js +44 -168
  29. package/dist/lib/{renderer → syntax}/color/a98rgb.js +2 -2
  30. package/dist/lib/syntax/color/cmyk.js +104 -0
  31. package/dist/lib/{renderer → syntax}/color/color-mix.js +20 -21
  32. package/dist/lib/syntax/color/color.js +581 -0
  33. package/dist/lib/syntax/color/hex.js +179 -0
  34. package/dist/lib/syntax/color/hsl.js +201 -0
  35. package/dist/lib/syntax/color/hwb.js +185 -0
  36. package/dist/lib/syntax/color/lab.js +262 -0
  37. package/dist/lib/syntax/color/lch.js +194 -0
  38. package/dist/lib/syntax/color/oklab.js +237 -0
  39. package/dist/lib/syntax/color/oklch.js +166 -0
  40. package/dist/lib/{renderer → syntax}/color/p3.js +3 -3
  41. package/dist/lib/{renderer → syntax}/color/rec2020.js +11 -11
  42. package/dist/lib/{renderer → syntax}/color/relativecolor.js +53 -40
  43. package/dist/lib/syntax/color/rgb.js +140 -0
  44. package/dist/lib/{renderer → syntax}/color/srgb.js +58 -46
  45. package/dist/lib/{renderer → syntax}/color/utils/components.js +7 -7
  46. package/dist/lib/{renderer → syntax}/color/utils/constants.js +7 -34
  47. package/dist/lib/syntax/color/utils/distance.js +30 -0
  48. package/dist/lib/{renderer → syntax}/color/xyz.js +27 -14
  49. package/dist/lib/{renderer → syntax}/color/xyzd50.js +8 -8
  50. package/dist/lib/syntax/syntax.js +77 -67
  51. package/dist/lib/syntax/utils.js +70 -0
  52. package/dist/lib/validation/at-rules/container.js +1 -1
  53. package/dist/lib/validation/at-rules/counter-style.js +1 -1
  54. package/dist/lib/validation/at-rules/custom-media.js +1 -1
  55. package/dist/lib/validation/at-rules/document.js +1 -1
  56. package/dist/lib/validation/at-rules/font-feature-values.js +2 -2
  57. package/dist/lib/validation/at-rules/import.js +1 -1
  58. package/dist/lib/validation/at-rules/keyframes.js +14 -13
  59. package/dist/lib/validation/at-rules/layer.js +1 -1
  60. package/dist/lib/validation/at-rules/media.js +1 -1
  61. package/dist/lib/validation/at-rules/namespace.js +1 -1
  62. package/dist/lib/validation/at-rules/page-margin-box.js +1 -1
  63. package/dist/lib/validation/at-rules/page.js +1 -1
  64. package/dist/lib/validation/at-rules/supports.js +1 -1
  65. package/dist/lib/validation/at-rules/when.js +1 -1
  66. package/dist/lib/validation/atrule.js +2 -2
  67. package/dist/lib/validation/config.js +4 -3
  68. package/dist/lib/validation/config.json.js +1 -1
  69. package/dist/lib/validation/parser/parse.js +12 -7
  70. package/dist/lib/validation/selector.js +9 -8
  71. package/dist/lib/validation/syntax.js +171 -132
  72. package/dist/lib/validation/syntaxes/complex-selector-list.js +13 -19
  73. package/dist/lib/validation/syntaxes/complex-selector.js +1 -1
  74. package/dist/lib/validation/syntaxes/compound-selector.js +5 -24
  75. package/dist/lib/validation/syntaxes/family-name.js +36 -39
  76. package/dist/lib/validation/syntaxes/keyframe-selector.js +14 -22
  77. package/dist/lib/validation/syntaxes/layer-name.js +1 -1
  78. package/dist/lib/validation/syntaxes/relative-selector-list.js +27 -25
  79. package/dist/lib/validation/syntaxes/relative-selector.js +1 -1
  80. package/dist/lib/validation/syntaxes/url.js +35 -33
  81. package/dist/lib/validation/utils/list.js +10 -9
  82. package/dist/lib/validation/utils/whitespace.js +1 -1
  83. package/dist/node/index.js +4 -2
  84. package/dist/web/index.js +4 -2
  85. package/package.json +4 -4
  86. package/.editorconfig +0 -484
  87. package/dist/lib/ast/transform/convert.js +0 -33
  88. package/dist/lib/ast/utils/utils.js +0 -104
  89. package/dist/lib/renderer/color/color.js +0 -654
  90. package/dist/lib/renderer/color/hex.js +0 -105
  91. package/dist/lib/renderer/color/hsl.js +0 -125
  92. package/dist/lib/renderer/color/hwb.js +0 -103
  93. package/dist/lib/renderer/color/lab.js +0 -148
  94. package/dist/lib/renderer/color/lch.js +0 -90
  95. package/dist/lib/renderer/color/oklab.js +0 -131
  96. package/dist/lib/renderer/color/oklch.js +0 -75
  97. package/dist/lib/renderer/color/rgb.js +0 -50
  98. package/dist/lib/validation/syntaxes/keyframe-block-list.js +0 -28
  99. package/dist/lib/{renderer → syntax}/color/hsv.js +0 -0
  100. package/dist/lib/{renderer → syntax}/color/prophotorgb.js +1 -1
  101. /package/dist/lib/{renderer → syntax}/color/utils/matrix.js +0 -0
package/dist/index.d.ts CHANGED
@@ -142,6 +142,35 @@ declare enum EnumToken {
142
142
  TimingFunction = 17,
143
143
  TimelineFunction = 16
144
144
  }
145
+ declare enum ColorType {
146
+ SYS = 0,
147
+ DPSYS = 1,
148
+ LIT = 2,
149
+ HEX = 3,
150
+ RGBA = 4,
151
+ HSLA = 5,
152
+ HWB = 6,
153
+ CMYK = 7,
154
+ OKLAB = 8,
155
+ OKLCH = 9,
156
+ LAB = 10,
157
+ LCH = 11,
158
+ COLOR = 12,
159
+ SRGB = 13,
160
+ PROPHOTO_RGB = 14,
161
+ A98_RGB = 15,
162
+ REC2020 = 16,
163
+ DISPLAY_P3 = 17,
164
+ SRGB_LINEAR = 18,
165
+ XYZ_D50 = 19,
166
+ XYZ_D65 = 20,
167
+ LIGHT_DARK = 21,
168
+ COLOR_MIX = 22,
169
+ RGB = 4,
170
+ HSL = 5,
171
+ XYZ = 20,
172
+ DEVICE_CMYK = 7
173
+ }
145
174
 
146
175
  /**
147
176
  * minify ast
@@ -203,34 +232,8 @@ declare function renderToken(token: Token, options?: RenderOptions, cache?: {
203
232
  [key: string]: any;
204
233
  }, reducer?: (acc: string, curr: Token) => string, errors?: ErrorDescription[]): string;
205
234
 
206
- declare enum ColorKind {
207
- SYS = 0,
208
- DPSYS = 1,
209
- LIT = 2,
210
- HEX = 3,
211
- RGB = 4,
212
- RGBA = 5,
213
- HSL = 6,
214
- HSLA = 7,
215
- HWB = 8,
216
- DEVICE_CMYK = 9,
217
- OKLAB = 10,
218
- OKLCH = 11,
219
- LAB = 12,
220
- LCH = 13,
221
- COLOR = 14,
222
- SRGB = 15,
223
- PROPHOTO_RGB = 16,
224
- A98_RGB = 17,
225
- REC2020 = 18,
226
- DISPLAY_P3 = 19,
227
- SRGB_LINEAR = 20,
228
- XYZ = 21,
229
- XYZ_D50 = 22,
230
- XYZ_D65 = 23,
231
- LIGHT_DARK = 24,
232
- COLOR_MIX = 25
233
- }
235
+ declare function okLabDistance(okLab1: [number, number, number], okLab2: [number, number, number]): number;
236
+ declare function isOkLabClose(color1: ColorToken, color2: ColorToken, threshold?: number): boolean;
234
237
 
235
238
  /**
236
239
  * parse css string
@@ -625,7 +628,7 @@ export declare interface ColorToken extends BaseToken {
625
628
 
626
629
  typ: EnumToken.ColorTokenType;
627
630
  val: string;
628
- kin: ColorKind;
631
+ kin: ColorType;
629
632
  chi?: Token[];
630
633
  /* calculated */
631
634
  cal?: 'rel' | 'mix';
@@ -938,6 +941,13 @@ interface ValidationToken {
938
941
  };
939
942
  }
940
943
 
944
+ /**
945
+ * Converts a color token to another color space
946
+ * @param token
947
+ * @param to
948
+ */
949
+ declare function convertColor(token: ColorToken, to: ColorType): ColorToken | null;
950
+
941
951
  export declare interface Position {
942
952
 
943
953
  ind: number;
@@ -1160,6 +1170,7 @@ interface ValidationOptions {
1160
1170
  validation?: boolean | ValidationLevel;
1161
1171
  lenient?: boolean;
1162
1172
  visited?: WeakMap<Token, Map<string, Set<ValidationToken>>>;
1173
+ isOptional?:boolean | null;
1163
1174
  isRepeatable?:boolean | null;
1164
1175
  isList?:boolean | null;
1165
1176
  occurence?:boolean | null;
@@ -1245,7 +1256,7 @@ export declare interface RenderOptions {
1245
1256
  indent?: string;
1246
1257
  newLine?: string;
1247
1258
  removeComments?: boolean;
1248
- convertColor?: boolean;
1259
+ convertColor?: boolean | ColorType;
1249
1260
  withParents?: boolean;
1250
1261
  output?: string;
1251
1262
  cwd?: string;
@@ -1355,4 +1366,4 @@ declare function parse(iterator: string, opt?: ParserOptions): Promise<ParseResu
1355
1366
  */
1356
1367
  declare function transform(css: string, options?: TransformOptions): Promise<TransformResult>;
1357
1368
 
1358
- export { EnumToken, ValidationLevel, dirname, expand, load, minify, parse, parseString, parseTokens, render, renderToken, resolve, transform, walk, walkValues };
1369
+ export { ColorType, EnumToken, ValidationLevel, convertColor, dirname, expand, isOkLabClose, load, minify, okLabDistance, parse, parseString, parseTokens, render, renderToken, resolve, transform, walk, walkValues };
@@ -5,7 +5,7 @@ import '../parser/utils/config.js';
5
5
  import { EnumToken } from './types.js';
6
6
  import { walkValues } from './walk.js';
7
7
  import { renderToken } from '../renderer/render.js';
8
- import '../renderer/color/utils/constants.js';
8
+ import '../syntax/color/utils/constants.js';
9
9
 
10
10
  /**
11
11
  * expand nested css ast
@@ -13,18 +13,22 @@ import '../renderer/color/utils/constants.js';
13
13
  */
14
14
  function expand(ast) {
15
15
  //
16
- if (![EnumToken.RuleNodeType, EnumToken.StyleSheetNodeType, EnumToken.AtRuleNodeType].includes(ast.typ)) {
17
- return ast;
18
- }
19
- if (EnumToken.RuleNodeType == ast.typ) {
20
- return {
21
- typ: EnumToken.StyleSheetNodeType,
22
- chi: expandRule(ast)
23
- };
24
- }
25
- if (!('chi' in ast)) {
26
- return ast;
27
- }
16
+ // if (![EnumToken.RuleNodeType, EnumToken.StyleSheetNodeType, EnumToken.AtRuleNodeType].includes(ast.typ)) {
17
+ //
18
+ // return ast;
19
+ // }
20
+ // if (EnumToken.RuleNodeType == ast.typ) {
21
+ //
22
+ // return <AstRuleStyleSheet>{
23
+ // typ: EnumToken.StyleSheetNodeType,
24
+ // chi: expandRule(<AstRule>ast)
25
+ // }
26
+ // }
27
+ //
28
+ // if (!('chi' in ast)) {
29
+ //
30
+ // return ast;
31
+ // }
28
32
  const result = { ...ast, chi: [] };
29
33
  // @ts-ignore
30
34
  for (let i = 0; i < ast.chi.length; i++) {
@@ -48,10 +52,11 @@ function expand(ast) {
48
52
  // @ts-ignore
49
53
  result.chi.push({ ...(hasRule ? expand(node) : node) });
50
54
  }
51
- else {
52
- // @ts-ignore
53
- result.chi.push(node);
54
- }
55
+ // else {
56
+ //
57
+ // // @ts-ignore
58
+ // result.chi.push(node);
59
+ // }
55
60
  }
56
61
  return result;
57
62
  }
@@ -65,24 +70,26 @@ function expandRule(node) {
65
70
  const rule = ast.chi[i];
66
71
  if (!rule.sel.includes('&')) {
67
72
  const selRule = splitRule(rule.sel);
68
- if (selRule.length > 1) {
69
- const r = ':is(' + selRule.map(a => a.join('')).join(',') + ')';
70
- rule.sel = splitRule(ast.sel).reduce((a, b) => a.concat([b.join('') + r]), []).join(',');
71
- }
72
- else {
73
- // selRule = splitRule(selRule.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.join(''), ''));
74
- const arSelf = splitRule(ast.sel).filter((r) => r.every((t) => t != ':before' && t != ':after' && !t.startsWith('::'))).reduce((acc, curr) => acc.concat([curr.join('')]), []).join(',');
75
- if (arSelf.length == 0) {
76
- ast.chi.splice(i--, 1);
77
- continue;
78
- }
79
- //
80
- selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(arSelf) : arr.unshift(arSelf, ' '));
81
- rule.sel = selRule.reduce((acc, curr) => {
82
- acc.push(curr.join(''));
83
- return acc;
84
- }, []).join(',');
73
+ // if (selRule.length > 1) {
74
+ //
75
+ // const r: string = ':is(' + selRule.map(a => a.join('')).join(',') + ')';
76
+ // rule.sel = splitRule(ast.sel).reduce((a: string[], b: string[]): string[] => a.concat([b.join('') + r]), <string[]>[]).join(',');
77
+ //
78
+ // }
79
+ // else {
80
+ // selRule = splitRule(selRule.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.join(''), ''));
81
+ const arSelf = splitRule(ast.sel).filter((r) => r.every((t) => t != ':before' && t != ':after' && !t.startsWith('::'))).reduce((acc, curr) => acc.concat([curr.join('')]), []).join(',');
82
+ if (arSelf.length == 0) {
83
+ ast.chi.splice(i--, 1);
84
+ continue;
85
85
  }
86
+ //
87
+ selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(arSelf) : arr.unshift(arSelf, ' '));
88
+ rule.sel = selRule.reduce((acc, curr) => {
89
+ acc.push(curr.join(''));
90
+ return acc;
91
+ }, []).join(',');
92
+ // }
86
93
  }
87
94
  else {
88
95
  let childSelectorCompound = [];
@@ -108,9 +115,10 @@ function expandRule(node) {
108
115
  if (s == '&' || parentSelector) {
109
116
  withCompound.push(s);
110
117
  }
111
- else {
112
- withoutCompound.push(s.slice(1));
113
- }
118
+ // else {
119
+ //
120
+ // withoutCompound.push(s.slice(1));
121
+ // }
114
122
  }
115
123
  }
116
124
  else {
@@ -121,9 +129,10 @@ function expandRule(node) {
121
129
  withCompound.push(s);
122
130
  }
123
131
  }
124
- else {
125
- withoutCompound.push(s);
126
- }
132
+ // else {
133
+ //
134
+ // withoutCompound.push(s);
135
+ // }
127
136
  }
128
137
  const selectors = [];
129
138
  const selector = rules.length > 1 ? ':is(' + rules.map(a => a.join('')).join(',') + ')' : rules[0].join('');
@@ -155,11 +164,13 @@ function expandRule(node) {
155
164
  if (withCompound.length == 1) {
156
165
  selectors.push(replaceCompound(withCompound[0], selector));
157
166
  }
158
- else {
159
- for (const w of withCompound) {
160
- selectors.push(replaceCompound(w, selector));
161
- }
162
- }
167
+ // else {
168
+ //
169
+ // for (const w of withCompound) {
170
+ //
171
+ // selectors.push(replaceCompound(w, selector));
172
+ // }
173
+ // }
163
174
  }
164
175
  rule.sel = selectors.reduce((acc, curr) => curr.length == 0 ? acc : acc + (acc.length > 0 ? ',' : '') + curr, '');
165
176
  }
@@ -200,10 +211,11 @@ function expandRule(node) {
200
211
  // @ts-ignore
201
212
  astAtRule.chi.push(...expandRule(r));
202
213
  }
203
- else {
204
- // @ts-ignore
205
- astAtRule.chi.push(r);
206
- }
214
+ // else {
215
+ //
216
+ // // @ts-ignore
217
+ // astAtRule.chi.push(r);
218
+ // }
207
219
  }
208
220
  }
209
221
  // @ts-ignore
@@ -230,21 +242,23 @@ function replaceCompound(input, replace) {
230
242
  if (replacement == null) {
231
243
  replacement = parseString(replace);
232
244
  }
233
- if (tokens[1].typ == EnumToken.IdenTokenType) {
234
- t.value.val = replacement.length == 1 || (!replace.includes(' ') && replace.charAt(0).match(/[:.]/)) ? tokens[1].val + replace : replaceCompoundLiteral(tokens[1].val + '&', replace);
235
- tokens.splice(1, 1);
236
- }
237
- else {
238
- t.value.val = replaceCompoundLiteral(t.value.val, replace);
239
- }
245
+ // if (tokens[1].typ == EnumToken.IdenTokenType) {
246
+ //
247
+ //
248
+ // (t.value as LiteralToken).val = (replacement as Token[]).length == 1 || (!replace.includes(' ') && replace.charAt(0).match(/[:.]/)) ? (tokens[1] as IdentToken).val + replace : replaceCompoundLiteral((tokens[1] as IdentToken).val + '&', replace);
249
+ // tokens.splice(1, 1);
250
+ // } else {
251
+ t.value.val = replaceCompoundLiteral(t.value.val, replace);
252
+ // }
240
253
  continue;
241
254
  }
242
255
  const rule = splitRule(replace);
243
256
  t.value.val = rule.length > 1 ? ':is(' + replace + ')' : replace;
244
257
  }
245
- else if (t.value.val.length > 1 && t.value.val.charAt(0) == '&') {
246
- t.value.val = replaceCompoundLiteral(t.value.val, replace);
247
- }
258
+ // else if ((t.value as LiteralToken).val.length > 1 && (t.value as LiteralToken).val.charAt(0) == '&') {
259
+ //
260
+ // (t.value as LiteralToken).val = replaceCompoundLiteral((t.value as LiteralToken).val, replace);
261
+ // }
248
262
  }
249
263
  }
250
264
  return tokens.reduce((acc, curr) => acc + renderToken(curr), '');
@@ -257,9 +271,10 @@ function replaceCompoundLiteral(selector, replace) {
257
271
  tokens.push('&');
258
272
  tokens.push('');
259
273
  }
260
- else {
261
- tokens[tokens.length - 1] += selector.charAt(i);
262
- }
274
+ // else {
275
+ //
276
+ // tokens[tokens.length - 1] += selector.charAt(i);
277
+ // }
263
278
  }
264
279
  return tokens.sort((a, b) => {
265
280
  if (a == '&') {
@@ -267,9 +282,10 @@ function replaceCompoundLiteral(selector, replace) {
267
282
  }
268
283
  return b == '&' ? -1 : 0;
269
284
  }).reduce((acc, curr) => {
270
- if (acc.length > 0 && curr == '&' && (replace.charAt(0) != '.' || replace.includes(' '))) {
271
- return acc + ':is(' + replace + ')';
272
- }
285
+ // if (acc.length > 0 && curr == '&' && (replace.charAt(0) != '.' || replace.includes(' '))) {
286
+ //
287
+ // return acc + ':is(' + replace + ')';
288
+ // }
273
289
  return acc + (curr == '&' ? replace : curr);
274
290
  }, '');
275
291
  }
@@ -2,7 +2,7 @@ import { EnumToken } from '../types.js';
2
2
  import { walkValues, WalkerValueEvent, WalkerOptionEnum } from '../walk.js';
3
3
  import { evaluate } from '../math/expression.js';
4
4
  import { renderToken } from '../../renderer/render.js';
5
- import '../../renderer/color/utils/constants.js';
5
+ import '../../syntax/color/utils/constants.js';
6
6
  import '../minify.js';
7
7
  import '../../parser/parse.js';
8
8
  import '../../parser/tokenize.js';
@@ -57,7 +57,7 @@ class ComputeCalcExpressionFeature {
57
57
  if (slice != null && node.typ == EnumToken.FunctionTokenType && mathFuncs.includes(node.val)) {
58
58
  // @ts-ignore
59
59
  const cp = (node.typ == EnumToken.FunctionTokenType && mathFuncs.includes(node.val) && node.val != 'calc' ? [node] : (node.typ == EnumToken.DeclarationNodeType ? node.val : node.chi)).slice();
60
- const values = evaluate(cp);
60
+ evaluate(cp);
61
61
  const key = 'chi' in node ? 'chi' : 'val';
62
62
  const str1 = renderToken({ ...node, [key]: slice });
63
63
  const str2 = renderToken(node); // values.reduce((acc: string, curr: Token): string => acc + renderToken(curr), '');
@@ -65,10 +65,11 @@ class ComputeCalcExpressionFeature {
65
65
  // @ts-ignore
66
66
  node[key] = slice;
67
67
  }
68
- else {
69
- // @ts-ignore
70
- node[key] = values;
71
- }
68
+ // else {
69
+ //
70
+ // // @ts-ignore
71
+ // node[key] = values;
72
+ // }
72
73
  return WalkerOptionEnum.Ignore;
73
74
  }
74
75
  return null;
@@ -84,41 +85,42 @@ class ComputeCalcExpressionFeature {
84
85
  // @ts-ignore
85
86
  const children = parent.typ == EnumToken.DeclarationNodeType ? parent.val : parent.chi;
86
87
  if (values.length == 1 && values[0].typ != EnumToken.BinaryExpressionTokenType) {
87
- if (parent.typ == EnumToken.BinaryExpressionTokenType) {
88
- if (parent.l == value) {
89
- parent.l = values[0];
90
- }
91
- else {
92
- parent.r = values[0];
93
- }
94
- }
95
- else {
96
- for (let i = 0; i < children.length; i++) {
97
- if (children[i] == value) {
98
- // @ts-ignore
99
- children.splice(i, 1, !(parent.typ == EnumToken.FunctionTokenType && parent.val == 'calc') && typeof values[0].val != 'string' ? {
100
- typ: EnumToken.FunctionTokenType,
101
- val: 'calc',
102
- chi: values
103
- } : values[0]);
104
- break;
105
- }
88
+ // if (parent.typ == EnumToken.BinaryExpressionTokenType) {
89
+ //
90
+ // if ((parent as BinaryExpressionToken).l == value) {
91
+ //
92
+ // (parent as BinaryExpressionToken).l = values[0];
93
+ // } else {
94
+ //
95
+ // (parent as BinaryExpressionToken).r = values[0];
96
+ // }
97
+ // } else {
98
+ for (let i = 0; i < children.length; i++) {
99
+ if (children[i] == value) {
100
+ // @ts-ignore
101
+ children.splice(i, 1, !(parent.typ == EnumToken.FunctionTokenType && parent.val == 'calc') && typeof values[0].val != 'string' ? {
102
+ typ: EnumToken.FunctionTokenType,
103
+ val: 'calc',
104
+ chi: values
105
+ } : values[0]);
106
+ break;
106
107
  }
107
108
  }
109
+ // }
108
110
  }
109
111
  else {
110
112
  for (let i = 0; i < children.length; i++) {
111
113
  if (children[i] == value) {
112
- if (parent.typ == EnumToken.FunctionTokenType && parent.val == 'calc') {
113
- children.splice(i, 1, ...values);
114
- }
115
- else {
116
- children.splice(i, 1, {
117
- typ: EnumToken.FunctionTokenType,
118
- val: 'calc',
119
- chi: values
120
- });
121
- }
114
+ // if (parent.typ == EnumToken.FunctionTokenType && (parent as FunctionToken).val == 'calc') {
115
+ //
116
+ // children.splice(i, 1, ...values);
117
+ // } else {
118
+ children.splice(i, 1, {
119
+ typ: EnumToken.FunctionTokenType,
120
+ val: 'calc',
121
+ chi: values
122
+ });
123
+ // }
122
124
  break;
123
125
  }
124
126
  }
@@ -1,7 +1,7 @@
1
1
  import { EnumToken } from '../types.js';
2
2
  import { walkValues } from '../walk.js';
3
3
  import { renderToken } from '../../renderer/render.js';
4
- import '../../renderer/color/utils/constants.js';
4
+ import '../../syntax/color/utils/constants.js';
5
5
  import { splitRule } from '../minify.js';
6
6
  import '../../parser/parse.js';
7
7
  import '../../parser/tokenize.js';
@@ -106,18 +106,25 @@ class InlineCssVariablesFeature {
106
106
  replace(node, variableScope);
107
107
  }
108
108
  }
109
- else {
110
- const info = variableScope.get(node.nam);
111
- info.globalScope = isRoot;
112
- if (!isRoot) {
113
- ++info.declarationCount;
114
- }
115
- if (info.replaceable) {
116
- info.replaceable = isRoot && info.declarationCount == 1;
117
- }
118
- info.parent.add(ast);
119
- info.node = node;
120
- }
109
+ // else {
110
+ //
111
+ // const info: VariableScopeInfo = <VariableScopeInfo>variableScope.get((<AstDeclaration>node).nam);
112
+ //
113
+ // info.globalScope = isRoot;
114
+ //
115
+ // if (!isRoot) {
116
+ //
117
+ // ++info.declarationCount;
118
+ // }
119
+ //
120
+ // if (info.replaceable) {
121
+ //
122
+ // info.replaceable = isRoot && info.declarationCount == 1;
123
+ // }
124
+ //
125
+ // info.parent.add(ast);
126
+ // info.node = (<AstDeclaration>node);
127
+ // }
121
128
  }
122
129
  else {
123
130
  replace(node, variableScope);
@@ -126,9 +133,10 @@ class InlineCssVariablesFeature {
126
133
  }
127
134
  cleanup(ast, options = {}, context) {
128
135
  const variableScope = context.variableScope;
129
- if (variableScope == null) {
130
- return;
131
- }
136
+ // if (variableScope == null) {
137
+ //
138
+ // return;
139
+ // }
132
140
  for (const info of variableScope.values()) {
133
141
  if (info.replaceable) {
134
142
  let i;
@@ -140,7 +148,7 @@ class InlineCssVariablesFeature {
140
148
  // @ts-ignore
141
149
  parent.chi.splice(i, 1, {
142
150
  typ: EnumToken.CommentTokenType,
143
- val: `/* ${info.node.nam}: ${info.values.reduce((acc, curr) => acc + renderToken(curr), '')} */`
151
+ val: `/* ${info.node.nam}: ${info.values.reduce((acc, curr) => acc + renderToken(curr, { convertColor: false }), '')} */`
144
152
  });
145
153
  break;
146
154
  }
@@ -2,14 +2,14 @@ import { EnumToken, SyntaxValidationResult } from '../types.js';
2
2
  import { getSyntaxConfig } from '../../validation/config.js';
3
3
  import '../../validation/parser/types.js';
4
4
  import '../../validation/parser/parse.js';
5
- import { splitRule, definedPropertySettings } from '../minify.js';
5
+ import { splitRule } from '../minify.js';
6
6
  import { walkValues } from '../walk.js';
7
- import { parseAtRulePrelude, parseString } from '../../parser/parse.js';
7
+ import '../../parser/parse.js';
8
8
  import '../../parser/tokenize.js';
9
9
  import '../../parser/utils/config.js';
10
10
  import { pseudoAliasMap } from '../../syntax/syntax.js';
11
11
  import { renderToken } from '../../renderer/render.js';
12
- import { funcLike } from '../../renderer/color/utils/constants.js';
12
+ import { funcLike } from '../../syntax/color/utils/constants.js';
13
13
  import '../../validation/syntaxes/complex-selector.js';
14
14
  import { evaluateSyntax } from '../../validation/syntax.js';
15
15
 
@@ -73,12 +73,15 @@ class ComputePrefixFeature {
73
73
  run(node) {
74
74
  if (node.typ == EnumToken.RuleNodeType) {
75
75
  node.sel = replacePseudo(splitRule(node.sel)).reduce((acc, curr, index) => acc + (index > 0 ? ',' : '') + curr.join(''), '');
76
- if (node.raw != null) {
77
- node.raw = replacePseudo(node.raw);
78
- }
79
- if (node.optimized != null) {
80
- node.optimized.selector = replacePseudo(node.optimized.selector);
81
- }
76
+ // if ((node as AstRule).raw != null) {
77
+ //
78
+ // (node as AstRule).raw = replacePseudo((node as AstRule).raw as string[][]);
79
+ // }
80
+ //
81
+ // if ((node as AstRule).optimized != null) {
82
+ //
83
+ // (node as AstRule).optimized!.selector = replacePseudo((node as AstRule).optimized!.selector as string[][]);
84
+ // }
82
85
  if (node.tokens != null) {
83
86
  replaceAstNodes(node.tokens);
84
87
  }
@@ -114,10 +117,9 @@ class ComputePrefixFeature {
114
117
  for (const { value } of walkValues(nodes)) {
115
118
  if ((value.typ == EnumToken.IdenTokenType || funcLike.includes(value.typ))) {
116
119
  const match = value.val.match(/^-([^-]+)-(.+)$/);
117
- if (match == null) {
118
- continue;
120
+ if (match != null) {
121
+ value.val = match[2];
119
122
  }
120
- value.val = match[2];
121
123
  }
122
124
  }
123
125
  if (SyntaxValidationResult.Valid == evaluateSyntax({ ...node, val: nodes }, {}).valid) {
@@ -133,13 +135,14 @@ class ComputePrefixFeature {
133
135
  }
134
136
  }
135
137
  if (node.typ == EnumToken.AtRuleNodeType && node.val !== '') {
136
- if (node.tokens == null) {
137
- Object.defineProperty(node, 'tokens', {
138
- // @ts-ignore
139
- ...definedPropertySettings,
140
- value: parseAtRulePrelude(parseString(node.val), node),
141
- });
142
- }
138
+ // if ((node as AstAtRule).tokens == null) {
139
+ //
140
+ // Object.defineProperty(node, 'tokens', {
141
+ // // @ts-ignore
142
+ // ...definedPropertySettings,
143
+ // value: parseAtRulePrelude(parseString((node as AstAtRule).val), node as AstAtRule),
144
+ // })
145
+ // }
143
146
  if (replaceAstNodes(node.tokens)) {
144
147
  node.val = node.tokens.reduce((acc, curr) => acc + renderToken(curr), '');
145
148
  }
@@ -5,7 +5,7 @@ import '../walk.js';
5
5
  import '../../parser/parse.js';
6
6
  import '../../parser/tokenize.js';
7
7
  import '../../parser/utils/config.js';
8
- import '../../renderer/color/utils/constants.js';
8
+ import '../../syntax/color/utils/constants.js';
9
9
  import '../../renderer/sourcemap/lib/encode.js';
10
10
 
11
11
  class ComputeShorthandFeature {
@@ -6,7 +6,7 @@ import '../../parser/parse.js';
6
6
  import '../../parser/tokenize.js';
7
7
  import '../../parser/utils/config.js';
8
8
  import { filterValues, renderToken } from '../../renderer/render.js';
9
- import '../../renderer/color/utils/constants.js';
9
+ import '../../syntax/color/utils/constants.js';
10
10
  import { compute } from '../transform/compute.js';
11
11
  import { eqMatrix } from '../transform/minify.js';
12
12
 
@@ -40,7 +40,22 @@ class TransformCssFeature {
40
40
  if (node.typ != EnumToken.DeclarationNodeType || !node.nam.match(/^(-[a-z]+-)?transform$/)) {
41
41
  continue;
42
42
  }
43
- const children = node.val.slice();
43
+ const children = node.val.reduce((acc, curr) => {
44
+ if (curr.typ == EnumToken.FunctionTokenType && 'skew' == curr.val.toLowerCase()) {
45
+ if (curr.chi.length == 3) {
46
+ if (curr.chi[2].val == '0') {
47
+ curr.chi.length = 1;
48
+ curr.val = 'skew';
49
+ }
50
+ else if (curr.chi[0].val == '0') {
51
+ curr.chi = [curr.chi[2]];
52
+ curr.val = 'skewY';
53
+ }
54
+ }
55
+ }
56
+ acc.push(curr);
57
+ return acc;
58
+ }, []);
44
59
  consumeWhitespace(children);
45
60
  let { matrix, cumulative, minified } = compute(children) ?? {};
46
61
  if (matrix == null || cumulative == null || minified == null) {