@tbela99/css-parser 1.4.2 → 1.4.3

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 (216) hide show
  1. package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
  2. package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
  3. package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
  4. package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
  5. package/.repl_history +4 -0
  6. package/CHANGELOG.md +164 -4
  7. package/README.md +43 -0
  8. package/badges/coverage.svg +20 -0
  9. package/deno.lock +2861 -0
  10. package/dist/config.json.js +33 -1
  11. package/dist/index-umd-web.js +24382 -18476
  12. package/dist/index.cjs +24522 -18618
  13. package/dist/index.d.ts +1396 -929
  14. package/dist/lib/ast/clone.d.ts +10 -0
  15. package/dist/lib/ast/clone.js +45 -0
  16. package/dist/lib/ast/expand.d.ts +14 -0
  17. package/dist/lib/ast/expand.js +89 -64
  18. package/dist/lib/ast/features/calc.d.ts +10 -0
  19. package/dist/lib/ast/features/calc.js +62 -24
  20. package/dist/lib/ast/features/if.d.ts +10 -0
  21. package/dist/lib/ast/features/if.js +215 -0
  22. package/dist/lib/ast/features/index.d.ts +6 -0
  23. package/dist/lib/ast/features/index.js +1 -0
  24. package/dist/lib/ast/features/inlinecssvariables.d.ts +15 -0
  25. package/dist/lib/ast/features/inlinecssvariables.js +32 -27
  26. package/dist/lib/ast/features/prefix.d.ts +8 -0
  27. package/dist/lib/ast/features/prefix.js +68 -43
  28. package/dist/lib/ast/features/shorthand.d.ts +12 -0
  29. package/dist/lib/ast/features/shorthand.js +6 -9
  30. package/dist/lib/ast/features/transform.d.ts +10 -0
  31. package/dist/lib/ast/features/transform.js +9 -13
  32. package/dist/lib/ast/features/type.d.ts +15 -0
  33. package/dist/lib/ast/find.d.ts +165 -0
  34. package/dist/lib/ast/find.js +175 -0
  35. package/dist/lib/ast/math/expression.d.ts +18 -0
  36. package/dist/lib/ast/math/expression.js +140 -98
  37. package/dist/lib/ast/math/math.d.ts +6 -0
  38. package/dist/lib/ast/math/math.js +30 -41
  39. package/dist/lib/ast/minify.d.ts +19 -0
  40. package/dist/lib/ast/minify.js +541 -217
  41. package/dist/lib/ast/transform/compute.d.ts +8 -0
  42. package/dist/lib/ast/transform/compute.js +82 -69
  43. package/dist/lib/ast/transform/matrix.d.ts +22 -0
  44. package/dist/lib/ast/transform/matrix.js +12 -26
  45. package/dist/lib/ast/transform/minify.d.ts +5 -0
  46. package/dist/lib/ast/transform/minify.js +20 -20
  47. package/dist/lib/ast/transform/perspective.d.ts +3 -0
  48. package/dist/lib/ast/transform/perspective.js +1 -1
  49. package/dist/lib/ast/transform/rotate.d.ts +12 -0
  50. package/dist/lib/ast/transform/rotate.js +1 -1
  51. package/dist/lib/ast/transform/scale.d.ts +6 -0
  52. package/dist/lib/ast/transform/scale.js +1 -1
  53. package/dist/lib/ast/transform/skew.d.ts +4 -0
  54. package/dist/lib/ast/transform/skew.js +1 -1
  55. package/dist/lib/ast/transform/translate.d.ts +6 -0
  56. package/dist/lib/ast/transform/translate.js +1 -1
  57. package/dist/lib/ast/transform/utils.d.ts +9 -0
  58. package/dist/lib/ast/types.d.ts +903 -0
  59. package/dist/lib/ast/types.js +277 -23
  60. package/dist/lib/ast/walk.d.ts +162 -0
  61. package/dist/lib/ast/walk.js +116 -60
  62. package/dist/lib/fs/resolve.d.ts +20 -0
  63. package/dist/lib/fs/resolve.js +37 -45
  64. package/dist/lib/parser/declaration/list.d.ts +16 -0
  65. package/dist/lib/parser/declaration/list.js +26 -24
  66. package/dist/lib/parser/declaration/map.d.ts +15 -0
  67. package/dist/lib/parser/declaration/map.js +140 -95
  68. package/dist/lib/parser/declaration/set.d.ts +9 -0
  69. package/dist/lib/parser/declaration/set.js +30 -25
  70. package/dist/lib/parser/node.d.ts +7 -0
  71. package/dist/lib/parser/parse.d.ts +107 -0
  72. package/dist/lib/parser/parse.js +1454 -1445
  73. package/dist/lib/parser/tokenize.d.ts +57 -0
  74. package/dist/lib/parser/tokenize.js +557 -404
  75. package/dist/lib/parser/utils/at-rule-container.d.ts +5 -0
  76. package/dist/lib/parser/utils/at-rule-container.js +486 -0
  77. package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +5 -0
  78. package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
  79. package/dist/lib/parser/utils/at-rule-generic.d.ts +5 -0
  80. package/dist/lib/parser/utils/at-rule-generic.js +118 -0
  81. package/dist/lib/parser/utils/at-rule-import.d.ts +5 -0
  82. package/dist/lib/parser/utils/at-rule-import.js +393 -0
  83. package/dist/lib/parser/utils/at-rule-media.d.ts +5 -0
  84. package/dist/lib/parser/utils/at-rule-media.js +603 -0
  85. package/dist/lib/parser/utils/at-rule-page.d.ts +5 -0
  86. package/dist/lib/parser/utils/at-rule-page.js +28 -0
  87. package/dist/lib/parser/utils/at-rule-support.d.ts +5 -0
  88. package/dist/lib/parser/utils/at-rule-support.js +366 -0
  89. package/dist/lib/parser/utils/at-rule-token.d.ts +1 -0
  90. package/dist/lib/parser/utils/at-rule-when-else.d.ts +5 -0
  91. package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
  92. package/dist/lib/parser/utils/at-rule.d.ts +13 -0
  93. package/dist/lib/parser/utils/at-rule.js +37 -0
  94. package/dist/lib/parser/utils/cache.d.ts +6 -0
  95. package/dist/lib/parser/utils/cache.js +19 -0
  96. package/dist/lib/parser/utils/config.d.ts +2 -0
  97. package/dist/lib/parser/utils/config.js +1 -0
  98. package/dist/lib/parser/utils/declaration-list.d.ts +5 -0
  99. package/dist/lib/parser/utils/declaration.d.ts +18 -0
  100. package/dist/lib/parser/utils/declaration.js +569 -91
  101. package/dist/lib/parser/utils/eq.d.ts +1 -0
  102. package/dist/lib/parser/utils/hash.d.ts +21 -0
  103. package/dist/lib/parser/utils/hash.js +1 -1
  104. package/dist/lib/parser/utils/selector.d.ts +5 -0
  105. package/dist/lib/parser/utils/selector.js +476 -0
  106. package/dist/lib/parser/utils/text.d.ts +3 -0
  107. package/dist/lib/parser/utils/text.js +17 -1
  108. package/dist/lib/parser/utils/token.d.ts +14 -0
  109. package/dist/lib/parser/utils/token.js +102 -0
  110. package/dist/lib/parser/utils/type.d.ts +2 -0
  111. package/dist/lib/parser/utils/type.js +29 -18
  112. package/dist/lib/renderer/render.d.ts +28 -0
  113. package/dist/lib/renderer/render.js +421 -262
  114. package/dist/lib/renderer/sourcemap/lib/encode.d.ts +1 -0
  115. package/dist/lib/renderer/sourcemap/sourcemap.d.ts +26 -0
  116. package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
  117. package/dist/lib/syntax/color/a98rgb.d.ts +2 -0
  118. package/dist/lib/syntax/color/a98rgb.js +8 -12
  119. package/dist/lib/syntax/color/cmyk.d.ts +10 -0
  120. package/dist/lib/syntax/color/cmyk.js +23 -21
  121. package/dist/lib/syntax/color/color-mix.d.ts +2 -0
  122. package/dist/lib/syntax/color/color-mix.js +88 -77
  123. package/dist/lib/syntax/color/color.d.ts +42 -0
  124. package/dist/lib/syntax/color/color.js +65 -68
  125. package/dist/lib/syntax/color/hex.d.ts +16 -0
  126. package/dist/lib/syntax/color/hex.js +27 -31
  127. package/dist/lib/syntax/color/hsl.d.ts +20 -0
  128. package/dist/lib/syntax/color/hsl.js +5 -12
  129. package/dist/lib/syntax/color/hsv.d.ts +2 -0
  130. package/dist/lib/syntax/color/hwb.d.ts +21 -0
  131. package/dist/lib/syntax/color/hwb.js +8 -21
  132. package/dist/lib/syntax/color/lab.d.ts +25 -0
  133. package/dist/lib/syntax/color/lab.js +20 -21
  134. package/dist/lib/syntax/color/lch.d.ts +23 -0
  135. package/dist/lib/syntax/color/lch.js +13 -15
  136. package/dist/lib/syntax/color/oklab.d.ts +22 -0
  137. package/dist/lib/syntax/color/oklab.js +20 -39
  138. package/dist/lib/syntax/color/oklch.d.ts +20 -0
  139. package/dist/lib/syntax/color/oklch.js +14 -16
  140. package/dist/lib/syntax/color/p3.d.ts +6 -0
  141. package/dist/lib/syntax/color/p3.js +0 -8
  142. package/dist/lib/syntax/color/prophotorgb.d.ts +2 -0
  143. package/dist/lib/syntax/color/rec2020.d.ts +2 -0
  144. package/dist/lib/syntax/color/rec2020.js +9 -13
  145. package/dist/lib/syntax/color/relativecolor.d.ts +13 -0
  146. package/dist/lib/syntax/color/relativecolor.js +68 -41
  147. package/dist/lib/syntax/color/rgb.d.ts +20 -0
  148. package/dist/lib/syntax/color/rgb.js +14 -18
  149. package/dist/lib/syntax/color/srgb.d.ts +23 -0
  150. package/dist/lib/syntax/color/srgb.js +27 -26
  151. package/dist/lib/syntax/color/utils/components.d.ts +2 -0
  152. package/dist/lib/syntax/color/utils/components.js +30 -14
  153. package/dist/lib/syntax/color/utils/distance.d.ts +18 -0
  154. package/dist/lib/syntax/color/utils/distance.js +1 -8
  155. package/dist/lib/syntax/color/utils/matrix.d.ts +6 -0
  156. package/dist/lib/syntax/color/xyz.d.ts +5 -0
  157. package/dist/lib/syntax/color/xyz.js +8 -20
  158. package/dist/lib/syntax/color/xyzd50.d.ts +4 -0
  159. package/dist/lib/syntax/color/xyzd50.js +6 -20
  160. package/dist/lib/syntax/constants.d.ts +67 -0
  161. package/dist/lib/syntax/constants.js +436 -0
  162. package/dist/lib/syntax/syntax.d.ts +38 -0
  163. package/dist/lib/syntax/syntax.js +533 -568
  164. package/dist/lib/validation/config.d.ts +14 -0
  165. package/dist/lib/validation/config.js +72 -33
  166. package/dist/lib/validation/config.json.js +1159 -74
  167. package/dist/lib/validation/json.d.ts +2 -0
  168. package/dist/lib/validation/match.d.ts +38 -0
  169. package/dist/lib/validation/match.js +2985 -0
  170. package/dist/lib/validation/parser/parse.d.ts +8 -0
  171. package/dist/lib/validation/parser/parse.js +684 -935
  172. package/dist/lib/validation/parser/typedef.d.ts +95 -0
  173. package/dist/lib/validation/parser/typedef.js +100 -0
  174. package/dist/lib/validation/utils/list.d.ts +4 -0
  175. package/dist/lib/validation/utils/list.js +4 -11
  176. package/dist/lib/validation/utils/whitespace.d.ts +2 -0
  177. package/dist/lib/validation/utils/whitespace.js +2 -8
  178. package/dist/node.d.ts +207 -0
  179. package/dist/node.js +42 -39
  180. package/dist/web.d.ts +169 -0
  181. package/dist/web.js +38 -33
  182. package/package.json +15 -12
  183. package/playground/index.html +1328 -0
  184. package/playground/sw.js +55 -0
  185. package/playground/tree.js +176 -0
  186. package/dist/lib/syntax/color/utils/constants.js +0 -214
  187. package/dist/lib/syntax/utils.js +0 -70
  188. package/dist/lib/validation/at-rules/container.js +0 -342
  189. package/dist/lib/validation/at-rules/counter-style.js +0 -90
  190. package/dist/lib/validation/at-rules/custom-media.js +0 -50
  191. package/dist/lib/validation/at-rules/document.js +0 -89
  192. package/dist/lib/validation/at-rules/else.js +0 -5
  193. package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
  194. package/dist/lib/validation/at-rules/import.js +0 -150
  195. package/dist/lib/validation/at-rules/keyframes.js +0 -67
  196. package/dist/lib/validation/at-rules/layer.js +0 -41
  197. package/dist/lib/validation/at-rules/media.js +0 -255
  198. package/dist/lib/validation/at-rules/namespace.js +0 -81
  199. package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
  200. package/dist/lib/validation/at-rules/page.js +0 -100
  201. package/dist/lib/validation/at-rules/supports.js +0 -295
  202. package/dist/lib/validation/at-rules/when.js +0 -185
  203. package/dist/lib/validation/atrule.js +0 -184
  204. package/dist/lib/validation/selector.js +0 -36
  205. package/dist/lib/validation/syntax.js +0 -1073
  206. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
  207. package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
  208. package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
  209. package/dist/lib/validation/syntaxes/family-name.js +0 -57
  210. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
  211. package/dist/lib/validation/syntaxes/layer-name.js +0 -57
  212. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
  213. package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
  214. package/dist/lib/validation/syntaxes/selector-list.js +0 -5
  215. package/dist/lib/validation/syntaxes/selector.js +0 -5
  216. package/dist/lib/validation/syntaxes/url.js +0 -40
@@ -1,30 +1,12 @@
1
- import { getAngle, convertColor } from '../syntax/color/color.js';
2
- import { colorsFunc, funcLike } from '../syntax/color/utils/constants.js';
3
- import { EnumToken, ColorType } from '../ast/types.js';
4
- import '../ast/minify.js';
5
- import '../ast/walk.js';
1
+ import { convertColor, getAngle } from '../syntax/color/color.js';
2
+ import { reduceHexValue } from '../syntax/color/hex.js';
3
+ import { EnumToken, minifyNumber, ColorType } from '../ast/types.js';
6
4
  import { expand } from '../ast/expand.js';
7
- import { isColor, pseudoElements, mathFuncs, isNewLine } from '../syntax/syntax.js';
8
- import { minifyNumber } from '../syntax/utils.js';
9
5
  import { SourceMap } from './sourcemap/sourcemap.js';
6
+ import { colorsFunc, urlTokenMatcher, tokensfuncSet } from '../syntax/constants.js';
7
+ import { isColor, pseudoElements, parseColor } from '../syntax/syntax.js';
8
+ import { move } from '../parser/tokenize.js';
10
9
 
11
- /**
12
- * Update position
13
- * @param position
14
- * @param str
15
- */
16
- function update(position, str) {
17
- let i = 0;
18
- for (; i < str.length; i++) {
19
- if (isNewLine(str[i].charCodeAt(0))) {
20
- position.lin++;
21
- position.col = 0;
22
- }
23
- else {
24
- position.col++;
25
- }
26
- }
27
- }
28
10
  /**
29
11
  * render ast
30
12
  * @param data
@@ -36,21 +18,30 @@ function doRender(data, options = {}, mapping) {
36
18
  const minify = options.minify ?? true;
37
19
  const beautify = options.beautify ?? !minify;
38
20
  options = {
39
- ...(beautify ? {
40
- indent: ' ',
41
- newLine: '\n',
42
- } : {
43
- indent: '',
44
- newLine: '',
45
- }),
46
- ...(minify ? {
47
- removeEmpty: true,
48
- removeComments: true,
49
- minify: true
50
- } : {
51
- removeEmpty: false,
52
- removeComments: false,
53
- }), sourcemap: false, convertColor: true, expandNestingRules: false, preserveLicense: false, ...options
21
+ ...(beautify
22
+ ? {
23
+ indent: " ",
24
+ newLine: "\n",
25
+ }
26
+ : {
27
+ indent: "",
28
+ newLine: "",
29
+ }),
30
+ ...(minify
31
+ ? {
32
+ removeEmpty: true,
33
+ removeComments: true,
34
+ minify: true,
35
+ }
36
+ : {
37
+ removeEmpty: false,
38
+ removeComments: false,
39
+ }),
40
+ sourcemap: false,
41
+ convertColor: true,
42
+ expandNestingRules: false,
43
+ preserveLicense: false,
44
+ ...options,
54
45
  };
55
46
  if (options.withParents) {
56
47
  // @ts-ignore
@@ -67,35 +58,42 @@ function doRender(data, options = {}, mapping) {
67
58
  }
68
59
  const startTime = performance.now();
69
60
  const errors = [];
70
- const sourcemap = options.sourcemap ? new SourceMap : null;
61
+ const sourcemap = options.sourcemap ? new SourceMap() : null;
71
62
  const cache = Object.create(null);
72
63
  const position = {
73
64
  ind: 0,
74
65
  lin: 1,
75
- col: 1
66
+ col: 1,
76
67
  };
77
- let code = '';
68
+ let code = "";
78
69
  if (mapping != null) {
79
70
  if (mapping.importMapping != null) {
80
71
  for (const [key, value] of Object.entries(mapping.importMapping)) {
81
- code += `:import("${key}")${options.indent}{${options.newLine}${Object.entries(value).reduce((acc, [k, v]) => acc + (acc.length > 0 ? options.newLine : '') + `${options.indent}${v}:${options.indent}${k};`, '')}${options.newLine}}${options.newLine}`;
72
+ code += `:import("${key}")${options.indent}{${options.newLine}${Object.entries(value).reduce((acc, [k, v]) => acc + (acc.length > 0 ? options.newLine : "") + `${options.indent}${v}:${options.indent}${k};`, "")}${options.newLine}}${options.newLine}`;
82
73
  }
83
74
  }
84
- code += `:export${options.indent}{${options.newLine}${Object.entries(mapping.mapping).reduce((acc, [k, v]) => acc + (acc.length > 0 ? options.newLine : '') + `${options.indent}${k}:${options.indent}${v};`, '')}${options.newLine}}${options.newLine}`;
85
- update(position, code);
75
+ code += `:export${options.indent}{${options.newLine}${Object.entries(mapping.mapping).reduce((acc, [k, v]) => acc + (acc.length > 0 ? options.newLine : "") + `${options.indent}${k}:${options.indent}${v};`, "")}${options.newLine}}${options.newLine}`;
76
+ move(position, code);
86
77
  }
87
78
  const result = {
88
- code: code + renderAstNode(options.expandNestingRules && [EnumToken.StyleSheetNodeType, EnumToken.AtRuleNodeType, EnumToken.RuleNodeType].includes(data.typ) && 'chi' in data ? expand(data) : data, options, sourcemap, position, errors, function reducer(acc, curr) {
89
- if (curr.typ == EnumToken.CommentTokenType && options.removeComments) {
90
- if (!options.preserveLicense || !curr.val.startsWith('/*!')) {
91
- return acc;
79
+ code: code +
80
+ renderAstNode(options.expandNestingRules &&
81
+ [EnumToken.StyleSheetNodeType, EnumToken.AtRuleNodeType, EnumToken.RuleNodeType].includes(data.typ) &&
82
+ "chi" in data
83
+ ? expand(data)
84
+ : data, options, sourcemap, position, errors, function reducer(acc, curr) {
85
+ if (curr.typ == EnumToken.CommentTokenType && options.removeComments) {
86
+ if (!options.preserveLicense || !curr.val.startsWith("/*!")) {
87
+ return acc;
88
+ }
89
+ return acc + curr.val;
92
90
  }
93
- return acc + curr.val;
94
- }
95
- return acc + renderToken(curr, options, cache, reducer, errors);
96
- }, cache), errors, stats: {
97
- total: `${(performance.now() - startTime).toFixed(2)}ms`
98
- }
91
+ return acc + renderToken(curr, options, cache, reducer, errors);
92
+ }, cache),
93
+ errors,
94
+ stats: {
95
+ total: `${(performance.now() - startTime).toFixed(2)}ms`,
96
+ },
99
97
  };
100
98
  if (options.output != null) {
101
99
  // @ts-ignore
@@ -103,7 +101,7 @@ function doRender(data, options = {}, mapping) {
103
101
  }
104
102
  if (sourcemap != null) {
105
103
  result.map = sourcemap;
106
- if (options.sourcemap === 'inline') {
104
+ if (options.sourcemap === "inline") {
107
105
  result.code += `\n/*# sourceMappingURL=data:application/json,${encodeURIComponent(JSON.stringify(result.map))} */`;
108
106
  }
109
107
  }
@@ -122,27 +120,21 @@ function doRender(data, options = {}, mapping) {
122
120
  */
123
121
  function updateSourceMap(node, options, cache, sourcemap, position, str) {
124
122
  if ([
125
- EnumToken.RuleNodeType, EnumToken.AtRuleNodeType,
126
- EnumToken.KeyFramesRuleNodeType, EnumToken.KeyframesAtRuleNodeType
123
+ EnumToken.RuleNodeType,
124
+ EnumToken.AtRuleNodeType,
125
+ EnumToken.KeyFramesRuleNodeType,
126
+ EnumToken.KeyframesAtRuleNodeType,
127
127
  ].includes(node.typ)) {
128
- let src = node.loc?.src ?? '';
129
- let output = options.output ?? '';
130
- if (!(src in cache)) {
131
- // @ts-ignore
132
- cache[src] = options.resolve(src, options.cwd ?? '').relative;
133
- }
134
- if (!(output in cache)) {
135
- // @ts-ignore
136
- cache[output] = options.resolve(output, options.cwd).relative;
137
- }
128
+ let src = node.loc?.src ?? "";
129
+ sourcemap.add(
138
130
  // @ts-ignore
139
- sourcemap.add({ src: cache[output], sta: { ...position } }, {
131
+ { src, sta: { ...position } }, {
140
132
  ...node.loc,
141
133
  // @ts-ignore
142
- src: options.resolve(cache[src], options.cwd).relative
134
+ src
143
135
  });
144
136
  }
145
- update(position, str);
137
+ move(position, str);
146
138
  }
147
139
  /**
148
140
  * render ast node
@@ -169,103 +161,131 @@ function renderAstNode(data, options, sourcemap, position, errors, reducer, cach
169
161
  const indentSub = indents[level + 1];
170
162
  switch (data.typ) {
171
163
  case EnumToken.DeclarationNodeType:
172
- return `${data.nam}:${options.indent}${(options.minify ? filterValues(data.val) : data.val).reduce(reducer, '')}`;
164
+ return `${data.nam}:${options.indent}${(options.minify
165
+ ? filterValues(data.val)
166
+ : data.val).reduce(reducer, "")}`;
173
167
  case EnumToken.CommentNodeType:
174
168
  case EnumToken.CDOCOMMNodeType:
175
- if (data.val.startsWith('/*# sourceMappingURL=')) {
169
+ if (data.val.startsWith("/*# sourceMappingURL=")) {
176
170
  // ignore sourcemap
177
- return '';
171
+ return "";
178
172
  }
179
- return !options.removeComments || (options.preserveLicense && data.val.startsWith('/*!')) ? data.val : '';
173
+ return !options.removeComments || (options.preserveLicense && data.val.startsWith("/*!"))
174
+ ? data.val
175
+ : "";
180
176
  case EnumToken.StyleSheetNodeType:
181
177
  return data.chi.reduce((css, node) => {
182
178
  const str = renderAstNode(node, options, sourcemap, { ...position }, errors, reducer, cache, level, indents);
183
- if (str === '') {
179
+ if (str === "") {
184
180
  return css;
185
181
  }
186
- if (css === '') {
182
+ if (css === "") {
187
183
  if (sourcemap != null && node.loc != null) {
188
184
  updateSourceMap(node, options, cache, sourcemap, position, str);
189
185
  }
190
186
  return str;
191
187
  }
192
188
  if (sourcemap != null && node.loc != null) {
193
- update(position, options.newLine);
189
+ move(position, options.newLine);
194
190
  updateSourceMap(node, options, cache, sourcemap, position, str);
195
191
  }
196
192
  return `${css}${options.newLine}${str}`;
197
- }, '');
193
+ }, "");
198
194
  case EnumToken.AtRuleNodeType:
199
195
  case EnumToken.RuleNodeType:
200
196
  case EnumToken.KeyFramesRuleNodeType:
201
197
  case EnumToken.KeyframesAtRuleNodeType:
202
- if ([EnumToken.AtRuleNodeType, EnumToken.KeyframesAtRuleNodeType].includes(data.typ) && !('chi' in data)) {
203
- return `${indent}@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val};`;
198
+ if ([EnumToken.AtRuleNodeType, EnumToken.KeyframesAtRuleNodeType].includes(data.typ) && !("chi" in data)) {
199
+ return `${indent}@${data.nam}${data.val === "" ? "" : options.indent || " "}${data.val};`;
204
200
  }
205
201
  // @ts-ignore
206
202
  let children = data.chi.reduce((css, node) => {
207
203
  let str;
208
204
  if (node.typ == EnumToken.CommentNodeType) {
209
- str = options.removeComments && (!options.preserveLicense || !node.val.startsWith('/*!')) ? '' : node.val;
205
+ str =
206
+ options.removeComments &&
207
+ (!options.preserveLicense || !node.val.startsWith("/*!"))
208
+ ? ""
209
+ : node.val;
210
210
  }
211
211
  else if (node.typ == EnumToken.DeclarationNodeType) {
212
- if (!node.nam.startsWith('--') && node.val.length == 0) {
212
+ if (!node.nam.startsWith("--") && node.val.length === 0) {
213
213
  // @ts-ignore
214
214
  errors.push({
215
- action: 'ignore',
215
+ action: "ignore",
216
216
  message: `render: invalid declaration ${JSON.stringify(node)}`,
217
- location: node.loc
217
+ location: node.loc,
218
218
  });
219
- return '';
219
+ return "";
220
220
  }
221
- str = `${node.nam}:${options.indent}${(options.minify ? filterValues(node.val) : node.val).reduce(reducer, '').trimEnd()};`;
221
+ str = `${node.nam}:${options.indent}${(options.minify
222
+ ? filterValues(node.val)
223
+ : node.val)
224
+ .reduce(reducer, "")
225
+ .trimEnd()};`;
222
226
  }
223
- else if (node.typ == EnumToken.AtRuleNodeType && !('chi' in node)) {
224
- str = `${node.val === '' ? '' : options.indent || ' '}${node.val};`;
227
+ else if (node.typ == EnumToken.AtRuleNodeType && !("chi" in node)) {
228
+ str = `${node.val === "" ? "" : options.indent || " "}${node.val};`;
225
229
  }
226
230
  else {
227
231
  str = renderAstNode(node, options, sourcemap, { ...position }, errors, reducer, cache, level + 1, indents);
228
232
  }
229
- if (css === '') {
233
+ if (css === "") {
230
234
  return str;
231
235
  }
232
- if (str === '') {
236
+ if (str === "") {
233
237
  return css;
234
238
  }
235
239
  return `${css}${options.newLine}${indentSub}${str}`;
236
- }, '');
237
- if (options.removeEmpty && children === '') {
238
- return '';
240
+ }, "");
241
+ if (options.removeEmpty && children === "") {
242
+ return "";
239
243
  }
240
- if (children.endsWith(';')) {
244
+ if (children.endsWith(";")) {
241
245
  children = children.slice(0, -1);
242
246
  }
243
247
  if ([EnumToken.AtRuleNodeType, EnumToken.KeyframesAtRuleNodeType].includes(data.typ)) {
244
- return `@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val}${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
248
+ return (`@${data.nam}${data.val === "" ? "" : options.indent || " "}${data.val}${options.indent}{${options.newLine}` +
249
+ (children === "" ? "" : indentSub + children + options.newLine) +
250
+ indent +
251
+ `}`);
245
252
  }
246
- return data.sel + `${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
253
+ return (data.sel +
254
+ `${options.indent}{${options.newLine}` +
255
+ (children === "" ? "" : indentSub + children + options.newLine) +
256
+ indent +
257
+ `}`);
247
258
  case EnumToken.CssVariableTokenType:
248
259
  case EnumToken.CssVariableImportTokenType:
249
- return `@value ${data.nam}:${options.indent}${filterValues((options.minify ? data.val : data.val)).reduce(reducer, '').trim()};`;
260
+ return `@value ${data.val}:${options.indent}${filterValues(options.minify
261
+ ? data.val
262
+ : data.val)
263
+ .reduce(reducer, "")
264
+ .trim()};`;
250
265
  case EnumToken.CssVariableDeclarationMapTokenType:
251
- return `@value ${filterValues(data.vars).reduce((acc, curr) => acc + renderToken(curr), '').trim()} from ${filterValues(data.from).reduce((acc, curr) => acc + renderToken(curr), '').trim()};`;
266
+ return `@value ${filterValues(data.vars)
267
+ .reduce((acc, curr) => acc + renderToken(curr), "")
268
+ .trim()} from ${filterValues(data.from)
269
+ .reduce((acc, curr) => acc + renderToken(curr), "")
270
+ .trim()};`;
252
271
  case EnumToken.InvalidDeclarationNodeType:
253
- case EnumToken.InvalidRuleTokenType:
254
- case EnumToken.InvalidAtRuleTokenType:
272
+ case EnumToken.InvalidRuleNodeType:
273
+ case EnumToken.InvalidAtRuleNodeType:
255
274
  default:
256
- return '';
275
+ return "";
257
276
  }
258
277
  }
259
278
  /**
260
279
  * render ast token
261
280
  * @param token
262
281
  * @param options
282
+ * @private
263
283
  */
264
284
  function renderToken(token, options = {}, cache = Object.create(null), reducer, errors) {
265
285
  if (reducer == null) {
266
286
  reducer = function (acc, curr) {
267
287
  if (curr.typ == EnumToken.CommentTokenType && options.removeComments) {
268
- if (!options.preserveLicense || !curr.val.startsWith('/*!')) {
288
+ if (!options.preserveLicense || !curr.val.startsWith("/*!")) {
269
289
  return acc;
270
290
  }
271
291
  return acc + curr.val;
@@ -277,54 +297,84 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
277
297
  if (isColor(token)) {
278
298
  // @ts-ignore
279
299
  token.typ = EnumToken.ColorTokenType;
300
+ if (
280
301
  // @ts-ignore
281
- if (token.chi[0].typ == EnumToken.IdenTokenType && token.chi[0].val == 'from') {
302
+ token.chi[0].typ == EnumToken.IdenTokenType &&
303
+ // @ts-ignore
304
+ token.chi[0].val == "from") {
282
305
  // @ts-ignore
283
- token.cal = 'rel';
306
+ token.cal = "rel";
284
307
  }
285
- else { // @ts-ignore
286
- if (token.val == 'color-mix' && token.chi[0].typ == EnumToken.IdenTokenType && token.chi[0].val == 'in') {
308
+ else {
309
+ // @ts-ignore
310
+ if (token.val == "color-mix" &&
311
+ token.chi?.[0]?.typ == EnumToken.IdenTokenType &&
312
+ (token.chi?.[0]).val == "in") {
287
313
  // @ts-ignore
288
- token.cal = 'mix';
314
+ token.cal = "mix";
289
315
  }
290
316
  else {
291
317
  // @ts-ignore
292
- if (token.val == 'color') {
318
+ if (token.val == "color") {
293
319
  // @ts-ignore
294
- token.cal = 'col';
320
+ token.cal = "col";
295
321
  }
296
322
  // @ts-ignore
297
- token.chi = token.chi.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.CommaTokenType, EnumToken.CommentTokenType].includes(t.typ));
323
+ token.chi = token.chi.filter((t) => ![
324
+ EnumToken.WhitespaceTokenType,
325
+ EnumToken.CommaTokenType,
326
+ EnumToken.CommentTokenType,
327
+ ].includes(t.typ));
298
328
  }
299
329
  }
300
330
  }
301
331
  }
302
332
  switch (token.typ) {
333
+ case EnumToken.FunctionTokenDefType:
334
+ case EnumToken.UrlFunctionTokenDefType:
335
+ case EnumToken.MathFunctionTokenDefType:
336
+ case EnumToken.ImageFunctionTokenDefType:
337
+ case EnumToken.ColorFunctionTokenDefType:
338
+ case EnumToken.TimingFunctionTokenDefType:
339
+ case EnumToken.WhenElseFunctionTokenDefType:
340
+ case EnumToken.SupportsFunctionTokenDefType:
341
+ case EnumToken.TimelineFunctionTokenDefType:
342
+ case EnumToken.GridTemplateFuncTokenDefType:
343
+ case EnumToken.TransformFunctionTokenDefType:
344
+ case EnumToken.ContainerFunctionTokenDefType:
345
+ case EnumToken.PseudoClassFunctionTokenDefType:
346
+ case EnumToken.GeneralEnclosedFunctionTokenDefType:
347
+ case EnumToken.CustomFunctionTokenDefType:
348
+ case EnumToken.WildCardFunctionTokenDefType:
349
+ return token.val + "(";
303
350
  case EnumToken.ListToken:
304
- return token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
351
+ return token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache), "");
305
352
  case EnumToken.BinaryExpressionTokenType:
306
- if ([EnumToken.Mul, EnumToken.Div].includes(token.op)) {
307
- let result = '';
353
+ if (EnumToken.Mul === token.op ||
354
+ EnumToken.Div === token.op) {
355
+ let result = "";
308
356
  if (token.l.typ == EnumToken.BinaryExpressionTokenType &&
309
357
  [EnumToken.Add, EnumToken.Sub].includes(token.l.op)) {
310
- result = '(' + renderToken(token.l, options, cache) + ')';
358
+ result = "(" + renderToken(token.l, options, cache) + ")";
311
359
  }
312
360
  else {
313
361
  result = renderToken(token.l, options, cache);
314
362
  }
315
- result += token.op == EnumToken.Mul ? '*' : '/';
363
+ result += token.op == EnumToken.Mul ? "*" : "/";
316
364
  if (token.r.typ == EnumToken.BinaryExpressionTokenType &&
317
365
  [EnumToken.Add, EnumToken.Sub].includes(token.r.op)) {
318
- result += '(' + renderToken(token.r, options, cache) + ')';
366
+ result += "(" + renderToken(token.r, options, cache) + ")";
319
367
  }
320
368
  else {
321
369
  result += renderToken(token.r, options, cache);
322
370
  }
323
371
  return result;
324
372
  }
325
- return renderToken(token.l, options, cache) + (token.op == EnumToken.Add ? ' + ' : (token.op == EnumToken.Sub ? ' - ' : (token.op == EnumToken.Mul ? '*' : '/'))) + renderToken(token.r, options, cache);
373
+ return (renderToken(token.l, options, cache) +
374
+ (token.op == EnumToken.Add ? " + " : " - ") +
375
+ renderToken(token.r, options, cache));
326
376
  case EnumToken.FractionTokenType:
327
- const fraction = renderToken(token.l) + '/' + renderToken(token.r);
377
+ const fraction = renderToken(token.l) + "/" + renderToken(token.r);
328
378
  if (+token.r.val != 0) {
329
379
  const value = minifyNumber(+token.l.val / +token.r.val);
330
380
  if (value.length <= fraction.length) {
@@ -333,150 +383,227 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
333
383
  }
334
384
  return fraction;
335
385
  case EnumToken.Add:
336
- return ' + ';
386
+ return " + ";
337
387
  case EnumToken.Sub:
338
- return ' - ';
388
+ return " - ";
389
+ case EnumToken.Star:
339
390
  case EnumToken.UniversalSelectorTokenType:
340
391
  case EnumToken.Mul:
341
- return '*';
392
+ return "*";
342
393
  case EnumToken.Div:
343
- return '/';
394
+ return "/";
344
395
  case EnumToken.ColorTokenType:
345
- if (token.kin == ColorType.LIGHT_DARK || ('chi' in token && options.convertColor === false)) {
346
- return token.val + '(' + token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache), '') + ')';
396
+ if (token.kin == ColorType.LIGHT_DARK ||
397
+ ("chi" in token && options.convertColor === false && token.chi.length == 2)) {
398
+ return (token.val +
399
+ "(" +
400
+ token.chi.reduce((acc, curr) => {
401
+ if (curr.typ === EnumToken.IdenTokenType) {
402
+ parseColor(curr);
403
+ }
404
+ return acc + renderToken(curr, options, cache);
405
+ }, "") +
406
+ ")");
347
407
  }
348
408
  if (options.convertColor !== false) {
349
- const value = convertColor(token, typeof options.convertColor == 'boolean' ? ColorType.HEX : ColorType[ColorType[options.convertColor ?? 'HEX']?.toUpperCase?.().replaceAll?.('-', '_')] ?? ColorType.HEX);
350
- //
409
+ const value = convertColor(token, typeof options.convertColor == "boolean"
410
+ ? ColorType.HEX
411
+ : (ColorType[ColorType[options.convertColor ?? "HEX"]
412
+ ?.toUpperCase?.()
413
+ .replaceAll?.("-", "_")] ?? ColorType.HEX));
351
414
  if (value != null) {
352
415
  token = value;
353
416
  }
417
+ if (token.kin == ColorType.HEX || token.kin == ColorType.LIT) {
418
+ return reduceHexValue(token.val);
419
+ }
420
+ }
421
+ if (token.kin === ColorType.SYS ||
422
+ token.kin === ColorType.DPSYS ||
423
+ token.kin === ColorType.NON_STD) {
424
+ return token.val;
354
425
  }
355
- if ([ColorType.HEX, ColorType.LIT, ColorType.SYS, ColorType.DPSYS].includes(token.kin)) {
426
+ if (token.kin == ColorType.HEX || token.kin == ColorType.LIT) {
356
427
  return token.val;
357
428
  }
358
429
  if (Array.isArray(token.chi)) {
359
- const isLegacy = ['rgb', 'rgba', 'hsl', 'hsla'].includes(token.val.toLowerCase());
360
- const useAlpha = (['rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'oklab', 'oklch', 'lab', 'lch'].includes(token.val.toLowerCase()) && token.chi.length == 4) ||
361
- ('color' == token.val.toLowerCase() && token.chi.length == 5);
362
- return (token.val.endsWith('a') ? token.val.slice(0, -1) : token.val) + '(' + token.chi.reduce((acc, curr, index, array) => {
363
- if (/[,/]\s*$/.test(acc)) {
430
+ const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val.toLowerCase());
431
+ const useAlpha = (["rgb", "rgba", "hsl", "hsla", "hwb", "oklab", "oklch", "lab", "lch"].includes(token.val.toLowerCase()) &&
432
+ token.chi.length == 4) ||
433
+ ("color" == token.val.toLowerCase() && token.chi.length == 5);
434
+ return ((token.val.endsWith("a")
435
+ ? token.val.slice(0, -1)
436
+ : token.val) +
437
+ "(" +
438
+ token
439
+ .chi.reduce((acc, curr, index, array) => {
440
+ if (/[,/]\s*$/.test(acc)) {
441
+ if (curr.typ == EnumToken.WhitespaceTokenType) {
442
+ return acc.trimEnd();
443
+ }
444
+ return acc.trimStart() + renderToken(curr, options, cache);
445
+ }
446
+ if (isLegacy && curr.typ == EnumToken.CommaTokenType) {
447
+ return acc.trimEnd() + " ";
448
+ }
364
449
  if (curr.typ == EnumToken.WhitespaceTokenType) {
365
- return acc.trimEnd();
450
+ return acc.trimEnd() + " ";
366
451
  }
367
- return acc.trimStart() + renderToken(curr, options, cache);
368
- }
369
- if (isLegacy && curr.typ == EnumToken.CommaTokenType) {
370
- return acc.trimEnd() + ' ';
371
- }
372
- if (curr.typ == EnumToken.WhitespaceTokenType) {
373
- return acc.trimEnd() + ' ';
374
- }
375
- if (curr.typ == EnumToken.CommaTokenType || (curr.typ == EnumToken.LiteralTokenType && curr.val == '/')) {
376
- return acc.trimEnd() + (curr.typ == EnumToken.CommaTokenType ? ',' : '/');
452
+ if (curr.typ == EnumToken.CommaTokenType ||
453
+ (curr.typ == EnumToken.LiteralTokenType && curr.val == "/")) {
454
+ return acc.trimEnd() + (curr.typ == EnumToken.CommaTokenType ? "," : "/");
455
+ }
456
+ return (acc.trimEnd() +
457
+ (useAlpha && index == array.length - 1 ? "/" : " ") +
458
+ renderToken(curr, options, cache));
459
+ }, "")
460
+ .trimStart() +
461
+ ")");
462
+ }
463
+ case EnumToken.UrlFunctionTokenType:
464
+ if (options.minify && token.typ === EnumToken.UrlFunctionTokenType) {
465
+ for (const child of token.chi) {
466
+ if (child.typ === EnumToken.StringTokenType) {
467
+ if (child.val.slice(1, 5) !== "data:" &&
468
+ urlTokenMatcher.test(child.val)) {
469
+ Object.assign(child, {
470
+ typ: EnumToken.UrlTokenTokenType,
471
+ val: child.val.slice(1, -1),
472
+ });
473
+ }
474
+ break;
377
475
  }
378
- return acc.trimEnd() + (useAlpha && index == array.length - 1 ? '/' : ' ') + renderToken(curr, options, cache);
379
- }, '').trimStart() + ')';
476
+ }
380
477
  }
381
478
  case EnumToken.ParensTokenType:
382
479
  case EnumToken.FunctionTokenType:
383
- case EnumToken.UrlFunctionTokenType:
480
+ case EnumToken.MathFunctionTokenType:
384
481
  case EnumToken.ImageFunctionTokenType:
385
482
  case EnumToken.TimingFunctionTokenType:
386
483
  case EnumToken.PseudoClassFuncTokenType:
484
+ case EnumToken.WhenElseFunctionTokenType:
387
485
  case EnumToken.TimelineFunctionTokenType:
388
486
  case EnumToken.GridTemplateFuncTokenType:
389
- if (token.typ == EnumToken.FunctionTokenType &&
390
- mathFuncs.includes(token.val) &&
487
+ case EnumToken.SupportsFunctionTokenType:
488
+ case EnumToken.ContainerFunctionTokenType:
489
+ case EnumToken.TransformFunctionTokenType:
490
+ case EnumToken.GeneralEnclosedFunctionTokenType:
491
+ case EnumToken.CustomFunctionTokenType:
492
+ case EnumToken.WildCardFunctionTokenType:
493
+ if (token.typ == EnumToken.MathFunctionTokenType &&
391
494
  token.chi.length == 1 &&
392
495
  ![EnumToken.BinaryExpressionTokenType, EnumToken.FractionTokenType, EnumToken.IdenTokenType].includes(token.chi[0].typ) &&
393
496
  // @ts-ignore
394
- token.chi[0].val?.typ != EnumToken.FractionTokenType) {
395
- return token.val + '(' + token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache, reducer), '') + ')';
497
+ token.chi[0].val
498
+ ?.typ != EnumToken.FractionTokenType) {
499
+ return (token.val +
500
+ "(" +
501
+ token.chi.reduce((acc, curr) => acc +
502
+ renderToken(curr, token.typ == EnumToken.FunctionTokenType ? { minify: false } : options, cache, reducer), "") +
503
+ ")");
396
504
  }
397
- return ( /* options.minify && 'Pseudo-class-func' == token.typ && token.val.slice(0, 2) == '::' ? token.val.slice(1) :*/token.val ?? '') + '(' + token.chi.reduce(reducer, '') + ')';
505
+ return (
506
+ /* options.minify && 'Pseudo-class-func' == token.typ && token.val.slice(0, 2) == '::' ? token.val.slice(1) :*/ (token.val ?? "") +
507
+ "(" +
508
+ token.chi.reduce(reducer, "") +
509
+ ")");
398
510
  case EnumToken.MatchExpressionTokenType:
399
- return renderToken(token.l, options, cache, reducer, errors) +
511
+ return (renderToken(token.l, options, cache, reducer, errors) +
400
512
  renderToken(token.op, options, cache, reducer, errors) +
401
513
  renderToken(token.r, options, cache, reducer, errors) +
402
- (token.attr ? ' ' + token.attr : '');
514
+ (token.attr ? " " + token.attr : ""));
403
515
  case EnumToken.NameSpaceAttributeTokenType:
404
- return (token.l == null ? '' : renderToken(token.l, options, cache, reducer, errors)) + '|' +
405
- renderToken(token.r, options, cache, reducer, errors);
516
+ return ((token.l == null
517
+ ? ""
518
+ : renderToken(token.l, options, cache, reducer, errors)) +
519
+ "|" +
520
+ renderToken(token.r, options, cache, reducer, errors));
406
521
  case EnumToken.ComposesSelectorNodeType:
407
- return token.l.reduce((acc, curr) => acc + renderToken(curr, options, cache), '') + (token.r == null ? '' : ' from ' + renderToken(token.r, options, cache, reducer, errors));
522
+ return (token.l.reduce((acc, curr) => acc + renderToken(curr, options, cache), "") +
523
+ (token.r == null
524
+ ? ""
525
+ : " from " +
526
+ renderToken(token.r, options, cache, reducer, errors)));
408
527
  case EnumToken.BlockStartTokenType:
409
- return '{';
528
+ return "{";
410
529
  case EnumToken.BlockEndTokenType:
411
- return '}';
530
+ return "}";
412
531
  case EnumToken.StartParensTokenType:
413
- return '(';
532
+ return "(";
414
533
  case EnumToken.DelimTokenType:
415
534
  case EnumToken.EqualMatchTokenType:
416
- return '=';
535
+ return "=";
417
536
  case EnumToken.IncludeMatchTokenType:
418
- return '~=';
537
+ return "~=";
419
538
  case EnumToken.DashMatchTokenType:
420
- return '|=';
539
+ return "|=";
421
540
  case EnumToken.StartMatchTokenType:
422
- return '^=';
541
+ return "^=";
423
542
  case EnumToken.EndMatchTokenType:
424
- return '$=';
543
+ return "$=";
425
544
  case EnumToken.ContainMatchTokenType:
426
- return '*=';
545
+ return "*=";
427
546
  case EnumToken.LtTokenType:
428
- return '<';
547
+ return "<";
429
548
  case EnumToken.LteTokenType:
430
- return '<=';
549
+ return "<=";
550
+ case EnumToken.Tilda:
431
551
  case EnumToken.SubsequentSiblingCombinatorTokenType:
432
- return '~';
552
+ return "~";
553
+ case EnumToken.Plus:
433
554
  case EnumToken.NextSiblingCombinatorTokenType:
434
- return '+';
555
+ return "+";
435
556
  case EnumToken.GtTokenType:
436
557
  case EnumToken.ChildCombinatorTokenType:
437
- return '>';
558
+ return ">";
438
559
  case EnumToken.GteTokenType:
439
- return '>=';
560
+ return ">=";
440
561
  case EnumToken.ColumnCombinatorTokenType:
441
- return '||';
562
+ return "||";
442
563
  case EnumToken.EndParensTokenType:
443
- return ')';
564
+ return ")";
444
565
  case EnumToken.AttrStartTokenType:
445
- return '[';
566
+ return "[";
446
567
  case EnumToken.AttrEndTokenType:
447
- return ']';
568
+ return "]";
448
569
  case EnumToken.DescendantCombinatorTokenType:
449
570
  case EnumToken.WhitespaceTokenType:
450
- return ' ';
571
+ return " ";
451
572
  case EnumToken.ColonTokenType:
452
- return ':';
573
+ return ":";
574
+ case EnumToken.DoubleColonTokenType:
575
+ return "::";
453
576
  case EnumToken.SemiColonTokenType:
454
- return ';';
577
+ return ";";
455
578
  case EnumToken.CommaTokenType:
456
- return ',';
579
+ return ",";
457
580
  case EnumToken.ImportantTokenType:
458
- return '!important';
581
+ return "!important";
582
+ case EnumToken.Pipe:
583
+ return "|";
459
584
  case EnumToken.AttrTokenType:
460
585
  case EnumToken.IdenListTokenType:
461
- return '[' + token.chi.reduce(reducer, '') + ']';
586
+ return "[" + token.chi.reduce(reducer, "") + "]";
462
587
  case EnumToken.TimeTokenType:
463
588
  case EnumToken.AngleTokenType:
464
589
  case EnumToken.LengthTokenType:
465
590
  case EnumToken.DimensionTokenType:
466
591
  case EnumToken.FrequencyTokenType:
467
592
  case EnumToken.ResolutionTokenType:
468
- let val = token.val.typ == EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : minifyNumber(token.val);
593
+ let val = token.val.typ == EnumToken.FractionTokenType
594
+ ? renderToken(token.val, options, cache)
595
+ : minifyNumber(token.val);
469
596
  let unit = token.unit;
470
- if (token.typ == EnumToken.AngleTokenType && !val.includes('/')) {
597
+ if (token.typ == EnumToken.AngleTokenType && !val.includes("/")) {
471
598
  const angle = getAngle(token);
472
599
  let v;
473
600
  let value = val + unit;
474
- for (const u of ['turn', 'deg', 'rad', 'grad']) {
601
+ for (const u of ["turn", "deg", "rad", "grad"]) {
475
602
  if (token.unit == u) {
476
603
  continue;
477
604
  }
478
605
  switch (u) {
479
- case 'turn':
606
+ case "turn":
480
607
  v = minifyNumber(angle);
481
608
  if (v.length + 4 < value.length) {
482
609
  val = v;
@@ -484,7 +611,7 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
484
611
  value = v + u;
485
612
  }
486
613
  break;
487
- case 'deg':
614
+ case "deg":
488
615
  v = minifyNumber(angle * 360);
489
616
  if (v.length + 3 < value.length) {
490
617
  val = v;
@@ -492,7 +619,7 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
492
619
  value = v + u;
493
620
  }
494
621
  break;
495
- case 'rad':
622
+ case "rad":
496
623
  v = minifyNumber(angle * (2 * Math.PI));
497
624
  if (v.length + 3 < value.length) {
498
625
  val = v;
@@ -500,7 +627,7 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
500
627
  value = v + u;
501
628
  }
502
629
  break;
503
- case 'grad':
630
+ case "grad":
504
631
  v = minifyNumber(angle * 400);
505
632
  if (v.length + 4 < value.length) {
506
633
  val = v;
@@ -511,119 +638,148 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
511
638
  }
512
639
  }
513
640
  }
514
- if (val === '0') {
641
+ if (val === "0") {
515
642
  if (token.typ == EnumToken.TimeTokenType) {
516
- return '0s';
643
+ return "0s";
517
644
  }
518
645
  if (token.typ == EnumToken.FrequencyTokenType) {
519
- return '0Hz';
646
+ return "0Hz";
520
647
  }
521
648
  // @ts-ignore
522
649
  if (token.typ == EnumToken.ResolutionTokenType) {
523
- return '0x';
650
+ return "0x";
524
651
  }
525
- return '0';
652
+ return "0";
526
653
  }
527
654
  if (token.typ == EnumToken.TimeTokenType) {
528
- if (unit == 'ms') {
655
+ if (unit == "ms") {
529
656
  // @ts-ignore
530
657
  const v = minifyNumber(val / 1000);
531
658
  if (v.length + 1 <= val.length) {
532
- return v + 's';
659
+ return v + "s";
533
660
  }
534
- return val + 'ms';
661
+ return val + "ms";
535
662
  }
536
- return val + 's';
663
+ return val + "s";
537
664
  }
538
- if (token.typ == EnumToken.ResolutionTokenType && unit == 'dppx') {
539
- unit = 'x';
665
+ if (token.typ == EnumToken.ResolutionTokenType && unit == "dppx") {
666
+ unit = "x";
540
667
  }
541
- return val.includes('/') ? val.replace('/', unit + '/') : val + unit;
668
+ return val.includes("/") ? val.replace("/", unit + "/") : val + unit;
542
669
  case EnumToken.FlexTokenType:
543
670
  case EnumToken.PercentageTokenType:
544
- const uni = token.typ == EnumToken.PercentageTokenType ? '%' : 'fr';
545
- const perc = token.val.typ == EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : minifyNumber(token.val);
546
- return options.minify && perc == '0' ? '0' : (perc.includes('/') ? perc.replace('/', uni + '/') : perc + uni);
671
+ const uni = token.typ == EnumToken.PercentageTokenType ? "%" : "fr";
672
+ const perc = token.val.typ == EnumToken.FractionTokenType
673
+ ? renderToken(token.val, options, cache)
674
+ : minifyNumber(token.val);
675
+ return options.minify && perc == "0" ? "0" : perc.includes("/") ? perc.replace("/", uni + "/") : perc + uni;
547
676
  case EnumToken.NumberTokenType:
548
- return token.val.typ == EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : minifyNumber(token.val);
677
+ return token.val.typ == EnumToken.FractionTokenType
678
+ ? renderToken(token.val, options, cache)
679
+ : minifyNumber(token.val);
680
+ case EnumToken.AtRuleTokenType:
681
+ return "@" + token.nam;
549
682
  case EnumToken.CommentTokenType:
550
- if (options.removeComments && (!options.preserveLicense || !token.val.startsWith('/*!'))) {
551
- return '';
683
+ case EnumToken.CDOCOMMNodeType:
684
+ if (options.removeComments &&
685
+ (!options.preserveLicense || !token.val.startsWith("/*!"))) {
686
+ return "";
552
687
  }
553
688
  case EnumToken.PseudoClassTokenType:
554
689
  case EnumToken.PseudoElementTokenType:
555
690
  // https://www.w3.org/TR/selectors-4/#single-colon-pseudos
556
- if (token.typ == EnumToken.PseudoElementTokenType && pseudoElements.includes(token.val.slice(1))) {
691
+ if (token.typ == EnumToken.PseudoElementTokenType &&
692
+ pseudoElements.includes(token.val.slice(1))) {
557
693
  return token.val.slice(1);
558
694
  }
559
695
  case EnumToken.UrlTokenTokenType:
560
- // if (token.typ == EnumToken.UrlTokenTokenType) {
561
- //
562
- // if (options.output != null) {
563
- //
564
- // if (!('original' in token)) {
565
- //
566
- // // do not modify original token
567
- // token = {...token};
568
- // Object.defineProperty(token, 'original', {
569
- // enumerable: false,
570
- // writable: false,
571
- // value: (token as UrlToken).val
572
- // })
573
- // }
574
- //
575
- // // @ts-ignore
576
- // if (!(token.original in cache)) {
577
- //
578
- // let output: string = <string>options.output ?? '';
579
- // const key = output + 'abs';
580
- //
581
- // if (!(key in cache)) {
582
- //
583
- // // @ts-ignore
584
- // cache[key] = options.dirname(options.resolve(output, options.cwd).absolute);
585
- // }
586
- //
587
- // // @ts-ignore
588
- // cache[token.original] = options.resolve(token.original, cache[key]).relative;
589
- // }
590
- //
591
- // // @ts-ignore
592
- // token.val = cache[token.original];
593
- // }
594
- // }
595
696
  case EnumToken.HashTokenType:
596
697
  case EnumToken.IdenTokenType:
597
- case EnumToken.AtRuleTokenType:
598
698
  case EnumToken.StringTokenType:
599
699
  case EnumToken.LiteralTokenType:
600
700
  case EnumToken.DashedIdenTokenType:
601
701
  case EnumToken.PseudoPageTokenType:
602
702
  case EnumToken.ClassSelectorTokenType:
603
- return /* options.minify && 'Pseudo-class' == token.typ && '::' == token.val.slice(0, 2) ? token.val.slice(1) : */ token.val;
703
+ return token.val;
604
704
  case EnumToken.NestingSelectorTokenType:
605
- return '&';
705
+ return "&";
606
706
  case EnumToken.InvalidAttrTokenType:
607
- return '[' + token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
707
+ return ("[" +
708
+ token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache), ""));
608
709
  case EnumToken.InvalidClassSelectorTokenType:
609
710
  return token.val;
711
+ case EnumToken.SupportsQueryUnaryConditionTokenType:
712
+ case EnumToken.WhenElseUnaryConditionTokenType:
713
+ return (renderToken(token.l, options, cache, reducer, errors) +
714
+ " " +
715
+ token.r.reduce((acc, curr) => acc + renderToken(curr, options, cache, reducer, errors), ""));
716
+ case EnumToken.SupportsQueryConditionTokenType:
717
+ case EnumToken.WhenElseQueryConditionTokenType:
718
+ return (token.l.reduce((acc, curr) => acc + renderToken(curr, options, cache, reducer, errors), "") +
719
+ " " +
720
+ renderToken(token.op, options, cache, reducer, errors) +
721
+ " " +
722
+ token.r.reduce((acc, curr) => acc + renderToken(curr, options, cache, reducer, errors), ""));
723
+ case EnumToken.IfConditionTokenType:
724
+ return token.l.length == 0 ? '' : (token.l.reduce((acc, curr) => acc + renderToken(curr, options, cache, reducer, errors), "") +
725
+ ':' +
726
+ token.r.reduce((acc, curr) => acc + renderToken(curr, options, cache, reducer, errors), ""));
727
+ case EnumToken.IfElseConditionTokenType:
728
+ return (renderToken(token.l) +
729
+ renderToken(token.r));
610
730
  case EnumToken.DeclarationNodeType:
611
- return token.nam + ':' + (options.minify ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
612
- case EnumToken.MediaQueryConditionTokenType:
613
- return renderToken(token.l, options, cache, reducer, errors) + renderToken(token.op, options, cache, reducer, errors) + token.r.reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
731
+ return (token.nam +
732
+ ":" +
733
+ (options.minify ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderToken(curr, options, cache), ""));
734
+ case EnumToken.MediaQueryUnaryFeatureTokenType:
735
+ return (renderToken(token.l, options, cache, reducer, errors) +
736
+ " " +
737
+ token.r.reduce((acc, curr) => acc + renderToken(curr, options, cache), ""));
738
+ case EnumToken.MediaQueryConditionTokenType: {
739
+ const indent = token.op.typ == EnumToken.LtTokenType ||
740
+ token.op.typ == EnumToken.GtTokenType ||
741
+ token.op.typ == EnumToken.ColonTokenType ||
742
+ token.op.typ == EnumToken.DelimTokenType ||
743
+ token.op.typ == EnumToken.LteTokenType ||
744
+ token.op.typ == EnumToken.GteTokenType
745
+ ? ""
746
+ : " ";
747
+ return (token.l.reduce((acc, curr) => acc + renderToken(curr, options, cache, reducer, errors), "") +
748
+ indent +
749
+ renderToken(token.op, options, cache, reducer, errors) +
750
+ indent +
751
+ token.r.reduce((acc, curr) => acc + renderToken(curr, options, cache), ""));
752
+ }
753
+ case EnumToken.MediaRangeQueryTokenType:
754
+ return (token.l.reduce((acc, curr) => acc + renderToken(curr, options, cache), "") +
755
+ renderToken(token.op1) +
756
+ token.val.reduce((acc, curr) => acc + renderToken(curr, options, cache, reducer, errors), "") +
757
+ renderToken(token.op2) +
758
+ token.r.reduce((acc, curr) => acc + renderToken(curr, options, cache), ""));
614
759
  case EnumToken.MediaFeatureTokenType:
615
760
  return token.val;
616
- case EnumToken.MediaFeatureNotTokenType:
617
- return 'not ' + renderToken(token.val, options, cache, reducer, errors);
618
- case EnumToken.MediaFeatureOnlyTokenType:
619
- return 'only ' + renderToken(token.val, options, cache, reducer, errors);
620
- case EnumToken.MediaFeatureAndTokenType:
621
- return 'and';
622
- case EnumToken.MediaFeatureOrTokenType:
623
- return 'or';
761
+ case EnumToken.NotTokenType:
762
+ return "not";
763
+ case EnumToken.OnlyTokenType:
764
+ return "only";
765
+ case EnumToken.AndTokenType:
766
+ return "and";
767
+ case EnumToken.OrTokenType:
768
+ return "or";
769
+ case EnumToken.InvalidMediaQueryTokenType:
770
+ case EnumToken.InvalidDeclarationNodeType:
771
+ case EnumToken.InvalidCommentTokenType:
772
+ case EnumToken.BadCommentTokenType:
773
+ case EnumToken.BadCdoTokenType:
774
+ case EnumToken.BadStringTokenType:
775
+ case EnumToken.EOFTokenType:
776
+ return "";
777
+ default:
778
+ console.debug({ token });
779
+ throw new Error(`Unsupported token type for ${EnumToken[token.typ]}`);
624
780
  }
625
- errors?.push({ action: 'ignore', message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
626
- return '';
781
+ errors?.push({ action: "ignore", message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
782
+ return "";
627
783
  }
628
784
  /**
629
785
  * Remove whitespace tokens that are not needed
@@ -634,10 +790,13 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
634
790
  function filterValues(values) {
635
791
  let i = 0;
636
792
  for (; i < values.length; i++) {
637
- if (values[i].typ == EnumToken.ImportantTokenType && values[i - 1]?.typ == EnumToken.WhitespaceTokenType) {
793
+ if (values[i].typ == EnumToken.ImportantTokenType && values[i - 1]?.typ === EnumToken.WhitespaceTokenType) {
638
794
  values.splice(i - 1, 1);
639
795
  }
640
- else if (funcLike.includes(values[i].typ) && !['var', 'calc'].includes(values[i].val) && values[i + 1]?.typ == EnumToken.WhitespaceTokenType) {
796
+ else if (tokensfuncSet.has(values[i].typ) &&
797
+ "chi" in values[i] &&
798
+ values[i].typ != EnumToken.WildCardFunctionTokenType &&
799
+ values[i + 1]?.typ == EnumToken.WhitespaceTokenType) {
641
800
  values.splice(i + 1, 1);
642
801
  }
643
802
  }