@tbela99/css-parser 1.6.9 → 1.7.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 (102) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/dist/index-umd-web.js +221 -244
  3. package/dist/index.cjs +220 -243
  4. package/dist/index.d.ts +8 -1
  5. package/dist/package.json.js +2 -2
  6. package/dist/src/data/properties.json.js +1 -1
  7. package/dist/src/data/validation.json.js +8 -2
  8. package/dist/src/lib/ast/clone.js +1 -1
  9. package/dist/src/lib/ast/expand.js +1 -1
  10. package/dist/src/lib/ast/features/calc.js +1 -1
  11. package/dist/src/lib/ast/features/if.js +1 -1
  12. package/dist/src/lib/ast/features/index.js +1 -1
  13. package/dist/src/lib/ast/features/inlinecssvariables.js +1 -1
  14. package/dist/src/lib/ast/features/prefix.js +1 -1
  15. package/dist/src/lib/ast/features/shorthand.js +39 -22
  16. package/dist/src/lib/ast/features/transform.js +1 -1
  17. package/dist/src/lib/ast/features/type.js +1 -1
  18. package/dist/src/lib/ast/find.js +1 -1
  19. package/dist/src/lib/ast/math/expression.js +1 -1
  20. package/dist/src/lib/ast/math/math.js +1 -1
  21. package/dist/src/lib/ast/minify.js +31 -3
  22. package/dist/src/lib/ast/node.js +1 -1
  23. package/dist/src/lib/ast/transform/compute.js +1 -1
  24. package/dist/src/lib/ast/transform/matrix.js +1 -1
  25. package/dist/src/lib/ast/transform/minify.js +1 -1
  26. package/dist/src/lib/ast/transform/perspective.js +1 -1
  27. package/dist/src/lib/ast/transform/rotate.js +1 -1
  28. package/dist/src/lib/ast/transform/scale.js +1 -1
  29. package/dist/src/lib/ast/transform/skew.js +1 -1
  30. package/dist/src/lib/ast/transform/translate.js +1 -1
  31. package/dist/src/lib/ast/transform/utils.js +1 -1
  32. package/dist/src/lib/ast/types.js +1 -1
  33. package/dist/src/lib/ast/walk.js +1 -1
  34. package/dist/src/lib/fs/resolve.js +1 -1
  35. package/dist/src/lib/parser/declaration/list.js +11 -1
  36. package/dist/src/lib/parser/declaration/map.js +2 -2
  37. package/dist/src/lib/parser/declaration/set.js +1 -1
  38. package/dist/src/lib/parser/linesmap.js +1 -1
  39. package/dist/src/lib/parser/parse.js +9 -18
  40. package/dist/src/lib/parser/source.js +1 -1
  41. package/dist/src/lib/parser/tokenize.js +1 -1
  42. package/dist/src/lib/parser/utils/angle.js +1 -1
  43. package/dist/src/lib/parser/utils/at-rule-container.js +1 -1
  44. package/dist/src/lib/parser/utils/at-rule-font-feature-values.js +1 -1
  45. package/dist/src/lib/parser/utils/at-rule-generic.js +1 -1
  46. package/dist/src/lib/parser/utils/at-rule-import.js +1 -1
  47. package/dist/src/lib/parser/utils/at-rule-media.js +2 -2
  48. package/dist/src/lib/parser/utils/at-rule-support.js +2 -2
  49. package/dist/src/lib/parser/utils/at-rule-when-else.js +1 -1
  50. package/dist/src/lib/parser/utils/at-rule.js +1 -1
  51. package/dist/src/lib/parser/utils/base64.js +1 -1
  52. package/dist/src/lib/parser/utils/cache.js +1 -1
  53. package/dist/src/lib/parser/utils/config.js +1 -1
  54. package/dist/src/lib/parser/utils/declaration.js +1 -1
  55. package/dist/src/lib/parser/utils/eq.js +1 -1
  56. package/dist/src/lib/parser/utils/hash.js +1 -1
  57. package/dist/src/lib/parser/utils/selector.js +1 -1
  58. package/dist/src/lib/parser/utils/text.js +1 -1
  59. package/dist/src/lib/parser/utils/token.js +2 -1
  60. package/dist/src/lib/parser/utils/type.js +1 -1
  61. package/dist/src/lib/printer/render.js +2 -2
  62. package/dist/src/lib/printer/sourcemap/lib/codec.js +1 -1
  63. package/dist/src/lib/printer/sourcemap/sourcemap.js +1 -1
  64. package/dist/src/lib/syntax/color/a98rgb.js +1 -1
  65. package/dist/src/lib/syntax/color/alpha.js +1 -1
  66. package/dist/src/lib/syntax/color/cmyk.js +1 -1
  67. package/dist/src/lib/syntax/color/color-mix.js +1 -1
  68. package/dist/src/lib/syntax/color/color.js +1 -1
  69. package/dist/src/lib/syntax/color/hex.js +1 -1
  70. package/dist/src/lib/syntax/color/hsl.js +1 -1
  71. package/dist/src/lib/syntax/color/hwb.js +1 -1
  72. package/dist/src/lib/syntax/color/lab.js +1 -1
  73. package/dist/src/lib/syntax/color/lch.js +1 -1
  74. package/dist/src/lib/syntax/color/oklab.js +1 -1
  75. package/dist/src/lib/syntax/color/oklch.js +1 -1
  76. package/dist/src/lib/syntax/color/p3.js +1 -1
  77. package/dist/src/lib/syntax/color/prophotorgb.js +1 -1
  78. package/dist/src/lib/syntax/color/rec2020.js +1 -1
  79. package/dist/src/lib/syntax/color/relative-color.js +1 -1
  80. package/dist/src/lib/syntax/color/rgb.js +1 -1
  81. package/dist/src/lib/syntax/color/srgb.js +1 -1
  82. package/dist/src/lib/syntax/color/utils/color-type.js +1 -1
  83. package/dist/src/lib/syntax/color/utils/colorspace.js +1 -1
  84. package/dist/src/lib/syntax/color/utils/components.js +1 -1
  85. package/dist/src/lib/syntax/color/utils/distance.js +1 -1
  86. package/dist/src/lib/syntax/color/utils/make-color.js +1 -1
  87. package/dist/src/lib/syntax/color/utils/matrix.js +1 -1
  88. package/dist/src/lib/syntax/color/xyz.js +1 -1
  89. package/dist/src/lib/syntax/color/xyzd50.js +1 -1
  90. package/dist/src/lib/syntax/constants.js +1 -1
  91. package/dist/src/lib/syntax/syntax.js +1 -1
  92. package/dist/src/lib/validation/config.js +20 -3
  93. package/dist/src/lib/validation/match.js +98 -196
  94. package/dist/src/lib/validation/parser/parse.js +8 -3
  95. package/dist/src/lib/validation/parser/typedef.js +1 -1
  96. package/dist/src/lib/validation/utils/list.js +1 -1
  97. package/dist/src/node.js +2 -1
  98. package/dist/src/types.js +1 -1
  99. package/dist/src/utils/sync.js +1 -1
  100. package/dist/src/web.js +2 -1
  101. package/package.json +6 -5
  102. package/CONTRIBUTING.md +0 -119
package/dist/index.cjs CHANGED
@@ -5717,7 +5717,13 @@ var atRules = {
5717
5717
  syntax: " @bottom-right-corner { <declaration-list> }"
5718
5718
  },
5719
5719
  "@function": {
5720
- syntax: " @function <dashed-ident>(<function-parameter>#?) [returns <css-type>]? { <declaration-rule-list> }"
5720
+ syntax: " @function <dashed-function> <function-parameter>#?) [returns <css-type>]? { <declaration-rule-list> }"
5721
+ },
5722
+ "@mixin": {
5723
+ syntax: " @mixin [<dashed-function> <function-parameter>#? ) | <ident-token> ]{<block-contents>}"
5724
+ },
5725
+ "@apply": {
5726
+ syntax: " @apply [ <dashed-ident> | <dashed-function> ] [ { <declaration-list> } ]?;"
5721
5727
  },
5722
5728
  "@left-top": {
5723
5729
  syntax: " @left-top { <declaration-list> }"
@@ -11766,6 +11772,11 @@ function* tokenizeSyntax(syntax, position = {
11766
11772
  [LOC]: { ...position },
11767
11773
  };
11768
11774
  }
11775
+ /**
11776
+ * parse mdn data syntax
11777
+ * @param syntax
11778
+ * @returns
11779
+ */
11769
11780
  function parseSyntax(syntax) {
11770
11781
  const stack = [];
11771
11782
  let tokens = [];
@@ -12309,8 +12320,8 @@ const getSyntaxRule = memoize((group, key) => {
12309
12320
  }
12310
12321
  }
12311
12322
  }
12312
- const block = blockStart == -1 ? null : trimSyntaxArray(syntaxRules.slice(blockStart + 1, blockEnd));
12313
- const prelude = trimSyntaxArray(blockStart == -1 ? syntaxRules.slice() : syntaxRules.slice(0, blockStart));
12323
+ let block = blockStart == -1 ? null : trimSyntaxArray(syntaxRules.slice(blockStart + 1, blockEnd));
12324
+ let prelude = trimSyntaxArray(blockStart == -1 ? syntaxRules.slice() : syntaxRules.slice(0, blockStart));
12314
12325
  let propertyDescriptors = null;
12315
12326
  // @ts-expect-error
12316
12327
  if (node.descriptors != null) {
@@ -12321,7 +12332,24 @@ const getSyntaxRule = memoize((group, key) => {
12321
12332
  propertyDescriptors[key] = parseSyntax(typeof value === "string" ? value : value.syntax);
12322
12333
  }
12323
12334
  }
12335
+ let optionalBody = false;
12336
+ if (block == null || block.length === 0) {
12337
+ let k = prelude.length - 1;
12338
+ if (ValidationTokenEnum.SemiColon === prelude[k].typ) {
12339
+ k--;
12340
+ }
12341
+ if (k >= 0 && ValidationTokenEnum.Bracket === prelude[k].typ) {
12342
+ if (prelude[k].chi[0].typ ===
12343
+ ValidationTokenEnum.OpenCurlyBrace &&
12344
+ prelude[k].chi.at(-1).typ ===
12345
+ ValidationTokenEnum.CloseCurlyBrace) {
12346
+ block = prelude[k].chi.slice(1, -1);
12347
+ optionalBody = prelude[k].isOptional ?? false;
12348
+ }
12349
+ }
12350
+ }
12324
12351
  return {
12352
+ optionalBody,
12325
12353
  acceptAnyDeclaration: node.syntax.includes("<declaration-list>"),
12326
12354
  acceptAnyRule: node.syntax.includes("<group-rule-body>") ||
12327
12355
  node.syntax.includes("<stylesheet>"),
@@ -12409,15 +12437,6 @@ function trimArray(tokens) {
12409
12437
  }
12410
12438
  return tokens;
12411
12439
  }
12412
- /**
12413
- * is a media feature
12414
- * @param featureName
12415
- * @returns
12416
- */
12417
- // export function isMFName(featureName: string): boolean {
12418
- // // @ts-expect-error
12419
- // return featureName.startsWith("--") || config.mediaFeatures[featureName.toLowerCase()] != null;
12420
- // }
12421
12440
  /**
12422
12441
  *
12423
12442
  * @param featureName
@@ -12938,9 +12957,6 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
12938
12957
  case exports.EnumToken.NumberTokenType:
12939
12958
  case exports.EnumToken.LiteralTokenType:
12940
12959
  case exports.EnumToken.DimensionTokenType:
12941
- // if (stack.at(-1)?.typ === EnumToken.CommaTokenType) {
12942
- // stack.pop();
12943
- // }
12944
12960
  if (stack.at(-1)?.typ === exports.EnumToken.PseudoClassFunctionTokenDefType) {
12945
12961
  break;
12946
12962
  }
@@ -13209,43 +13225,9 @@ function matchSyntax(syntaxes, context, options) {
13209
13225
  continue;
13210
13226
  }
13211
13227
  }
13212
- // custom function token
13213
- if (token.typ === exports.EnumToken.CustomFunctionTokenDefType) {
13214
- if (syntaxes[i].typ != ValidationTokenEnum.PropertyType ||
13215
- syntaxes[i + 1]?.typ != ValidationTokenEnum.OpenParenthesis ||
13216
- syntaxes[i + 2]?.typ == null) {
13217
- if (!isOptional) {
13218
- return {
13219
- success: false,
13220
- errors: [
13221
- {
13222
- action: "drop",
13223
- message: "could not match syntax",
13224
- node: token,
13225
- syntax: syntaxes[i],
13226
- },
13227
- ],
13228
- syntaxToken: syntaxes[i],
13229
- valid: true,
13230
- context,
13231
- token: null,
13232
- };
13233
- }
13234
- break;
13235
- }
13236
- const range = trimArray(context.peekRange());
13237
- context.next();
13238
- i++;
13239
- result = matchSyntax([syntaxes[i + 1]], createValidationContext(range.slice(1, -1)), options);
13240
- if (result.success) {
13241
- context.update(range.at(-1));
13242
- i += 2;
13243
- }
13244
- return result;
13245
- }
13246
- if (tokensfuncDefMap.has(token.typ) &&
13247
- // @ts-ignore
13248
- token.typ === exports.EnumToken.WildCardFunctionTokenDefType) {
13228
+ if (
13229
+ // @ts-ignore
13230
+ token.typ === exports.EnumToken.WildCardFunctionTokenDefType) {
13249
13231
  const range = trimArray(context.peekRange());
13250
13232
  result = matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, token.val + "()")?.[0]?.chi, createValidationContext(range.slice(1, -1)), options);
13251
13233
  if (result.success) {
@@ -13270,6 +13252,9 @@ function matchSyntax(syntaxes, context, options) {
13270
13252
  context.update(result.context.current());
13271
13253
  continue;
13272
13254
  }
13255
+ if (isOptional) {
13256
+ continue;
13257
+ }
13273
13258
  return result;
13274
13259
  }
13275
13260
  if (syntaxes[i].isList) {
@@ -13290,6 +13275,9 @@ function matchSyntax(syntaxes, context, options) {
13290
13275
  context.update(result.context.current());
13291
13276
  continue;
13292
13277
  }
13278
+ if (isOptional) {
13279
+ continue;
13280
+ }
13293
13281
  return {
13294
13282
  success: false,
13295
13283
  valid: true,
@@ -13314,6 +13302,9 @@ function matchSyntax(syntaxes, context, options) {
13314
13302
  context.update(result.context.current());
13315
13303
  continue;
13316
13304
  }
13305
+ if (isOptional) {
13306
+ continue;
13307
+ }
13317
13308
  return {
13318
13309
  success: false,
13319
13310
  valid: true,
@@ -13718,6 +13709,20 @@ function matchSyntax(syntaxes, context, options) {
13718
13709
  syntaxToken: syntaxes[i],
13719
13710
  errors: [],
13720
13711
  };
13712
+ case ValidationTokenEnum.OpenCurlyBrace:
13713
+ if (token.typ === exports.EnumToken.BlockStartTokenType) {
13714
+ options.visited.get(token).delete(syntaxes[i]);
13715
+ context.next();
13716
+ break;
13717
+ }
13718
+ return {
13719
+ success: false,
13720
+ valid: true,
13721
+ token,
13722
+ context,
13723
+ syntaxToken: syntaxes[i],
13724
+ errors: [],
13725
+ };
13721
13726
  case ValidationTokenEnum.CloseParenthesis:
13722
13727
  if (token.typ === exports.EnumToken.EndParensTokenType) {
13723
13728
  options.visited.get(token).delete(syntaxes[i]);
@@ -13919,6 +13924,7 @@ function matchProperty(property, context, options) {
13919
13924
  };
13920
13925
  }
13921
13926
  switch (property.val) {
13927
+ case "function-parameter":
13922
13928
  case "declaration-value":
13923
13929
  {
13924
13930
  // consume a declaration value
@@ -13928,18 +13934,43 @@ function matchProperty(property, context, options) {
13928
13934
  // if semicolon or end curly brace is encountered, stop
13929
13935
  let expectToken = true;
13930
13936
  let token;
13937
+ const stack = [];
13931
13938
  token = context.peek();
13932
- while ((token = context.peek()) != null) {
13933
- if (token.typ == exports.EnumToken.StartParensTokenType || tokensfuncDefMap.has(token?.typ)) ;
13934
- if (expectToken) {
13935
- expectToken = false;
13936
- }
13937
- if (token.typ == exports.EnumToken.CommaTokenType) {
13938
- expectToken = true;
13939
+ if (token != null) {
13940
+ success = false;
13941
+ while ((token = context.peek()) != null) {
13942
+ if (token.typ == exports.EnumToken.StartParensTokenType || tokensfuncDefMap.has(token?.typ)) {
13943
+ stack.push(token);
13944
+ }
13945
+ if (expectToken) {
13946
+ expectToken = false;
13947
+ }
13948
+ if (token.typ == exports.EnumToken.CommaTokenType) {
13949
+ expectToken = true;
13950
+ }
13951
+ if (token.typ == exports.EnumToken.EndParensTokenType) {
13952
+ if (stack.length > 0) {
13953
+ stack.pop();
13954
+ }
13955
+ else {
13956
+ expectToken = false;
13957
+ break;
13958
+ }
13959
+ }
13960
+ context.next();
13939
13961
  }
13940
- context.next();
13941
13962
  }
13942
13963
  success = !expectToken;
13964
+ if (success) {
13965
+ return {
13966
+ success,
13967
+ valid: true,
13968
+ token: null,
13969
+ context,
13970
+ syntaxToken: property,
13971
+ errors: [],
13972
+ };
13973
+ }
13943
13974
  }
13944
13975
  break;
13945
13976
  case "calc-sum": {
@@ -13972,9 +14003,6 @@ function matchProperty(property, context, options) {
13972
14003
  }
13973
14004
  break;
13974
14005
  }
13975
- // case "at-keyword-token":
13976
- // success = context.peek()?.typ === EnumToken.AtRuleTokenType;
13977
- // break;
13978
14006
  case "an+b":
13979
14007
  {
13980
14008
  let token = context.peek();
@@ -14039,9 +14067,6 @@ function matchProperty(property, context, options) {
14039
14067
  Object.assign(token, { typ: exports.EnumToken.Add });
14040
14068
  }
14041
14069
  token = context.peek(2);
14042
- // if (token == null) {
14043
- // break;
14044
- // }
14045
14070
  if (token?.typ === exports.EnumToken.NumberTokenType &&
14046
14071
  Number.isInteger(token.val) &&
14047
14072
  !token.toString().includes(".") &&
@@ -14149,9 +14174,6 @@ function matchProperty(property, context, options) {
14149
14174
  break;
14150
14175
  case "dimension": {
14151
14176
  const token = context.peek();
14152
- // if (token == null) {
14153
- // break;
14154
- // }
14155
14177
  success =
14156
14178
  token?.typ == exports.EnumToken.DimensionTokenType ||
14157
14179
  token?.typ == exports.EnumToken.AngleTokenType ||
@@ -14166,18 +14188,12 @@ function matchProperty(property, context, options) {
14166
14188
  case "angle":
14167
14189
  {
14168
14190
  const token = context.peek();
14169
- // if (token == null) {
14170
- // break;
14171
- // }
14172
14191
  success = token?.typ === exports.EnumToken.AngleTokenType;
14173
14192
  }
14174
14193
  break;
14175
14194
  case "angle-percentage":
14176
14195
  {
14177
14196
  const token = context.peek();
14178
- // if (token == null) {
14179
- // break;
14180
- // }
14181
14197
  success = token?.typ === exports.EnumToken.AngleTokenType || token?.typ === exports.EnumToken.PercentageTokenType;
14182
14198
  }
14183
14199
  break;
@@ -14193,9 +14209,6 @@ function matchProperty(property, context, options) {
14193
14209
  case "length-percentage":
14194
14210
  {
14195
14211
  const token = context.peek();
14196
- // if (token == null) {
14197
- // break;
14198
- // }
14199
14212
  success =
14200
14213
  token?.typ == exports.EnumToken.PercentageTokenType ||
14201
14214
  token?.typ == exports.EnumToken.LengthTokenType ||
@@ -14207,9 +14220,6 @@ function matchProperty(property, context, options) {
14207
14220
  break;
14208
14221
  case "length": {
14209
14222
  const token = context.peek();
14210
- // if (token == null) {
14211
- // break;
14212
- // }
14213
14223
  success =
14214
14224
  token?.typ == exports.EnumToken.LengthTokenType ||
14215
14225
  (token?.typ == exports.EnumToken.NumberTokenType && token?.val === 0);
@@ -14224,12 +14234,6 @@ function matchProperty(property, context, options) {
14224
14234
  success = token.typ == exports.EnumToken.TimeTokenType;
14225
14235
  }
14226
14236
  break;
14227
- // case "hex-color": {
14228
- // const token = context.peek();
14229
- // success =
14230
- // token != null && token.typ == EnumToken.ColorTokenType && (token as ColorToken).kin == ColorType.HEX;
14231
- // break;
14232
- // }
14233
14237
  case "color":
14234
14238
  case "color-function":
14235
14239
  {
@@ -14237,13 +14241,6 @@ function matchProperty(property, context, options) {
14237
14241
  const errors = [];
14238
14242
  if (tokensfuncDefMap.has(token?.typ)) {
14239
14243
  const range = context.peekRange();
14240
- // if (
14241
- // range.some(
14242
- // (token) =>
14243
- // token.typ == EnumToken.IdenTokenType &&
14244
- // "hslrgbchwmyk".split("").some((t) => equalsIgnoreCase(t, (token as IdentToken).val)),
14245
- // )
14246
- // ) {
14247
14244
  const newRange = range.map((t) => cloneNode(t, true));
14248
14245
  // @ts-ignore
14249
14246
  parseTokens(newRange, { parseColor: true }, errors);
@@ -14268,27 +14265,6 @@ function matchProperty(property, context, options) {
14268
14265
  syntaxToken: null,
14269
14266
  errors,
14270
14267
  };
14271
- // }
14272
- // const result = matchSyntax(
14273
- // getParsedSyntax(
14274
- // ValidationSyntaxGroupEnum.Syntaxes,
14275
- // (token as FunctionToken).val + "()",
14276
- // ) as ValidationFunctionToken[],
14277
- // createValidationContext(range),
14278
- // options,
14279
- // );
14280
- // if (result.success) {
14281
- // context.update(range.at(-1) as Token);
14282
- // return {
14283
- // success: true,
14284
- // valid: true,
14285
- // token: context.peek(),
14286
- // context,
14287
- // syntaxToken: null,
14288
- // errors: [],
14289
- // };
14290
- // }
14291
- // return result;
14292
14268
  }
14293
14269
  // @ts-expect-error
14294
14270
  else if ("chi" in token) {
@@ -14307,10 +14283,6 @@ function matchProperty(property, context, options) {
14307
14283
  }
14308
14284
  }
14309
14285
  break;
14310
- // case "url-token":
14311
- // success =
14312
- // context.peek()?.typ == EnumToken.StringTokenType || context.peek()?.typ == EnumToken.UrlTokenTokenType;
14313
- // break;
14314
14286
  case "type-selector":
14315
14287
  case "compound-selector":
14316
14288
  case "complex-selector":
@@ -14335,15 +14307,6 @@ function matchProperty(property, context, options) {
14335
14307
  };
14336
14308
  }
14337
14309
  case "function-token":
14338
- // if (
14339
- // context.peek()?.typ == EnumToken.IdenTokenType &&
14340
- // context.peek(1, false)?.typ == EnumToken.StartParensTokenType
14341
- // ) {
14342
- // context.next();
14343
- // context.next();
14344
- // success = true;
14345
- // break;
14346
- // }
14347
14310
  if (tokensfuncDefMap.has(context.peek()?.typ)) {
14348
14311
  success = true;
14349
14312
  context.next();
@@ -14365,17 +14328,6 @@ function matchProperty(property, context, options) {
14365
14328
  config$3.languages.some((t) => t === token.val || token.val.startsWith(t + "-"));
14366
14329
  break;
14367
14330
  }
14368
- // case "named-color": {
14369
- // const token = context.peek();
14370
- // success =
14371
- // token != null &&
14372
- // token.typ == EnumToken.ColorTokenType &&
14373
- // ((token as ColorToken).kin == ColorType.LIT ||
14374
- // (token as ColorToken).kin == ColorType.SYS ||
14375
- // (token as ColorToken).kin == ColorType.DPSYS ||
14376
- // (token as ColorToken).kin == ColorType.NON_STD);
14377
- // break;
14378
- // }
14379
14331
  case "size-feature": {
14380
14332
  const range = context.peekRange();
14381
14333
  const filteredRange = range.filter((token) => token.typ !== exports.EnumToken.WhitespaceTokenType && token.typ !== exports.EnumToken.CommentTokenType);
@@ -14406,20 +14358,6 @@ function matchProperty(property, context, options) {
14406
14358
  errors: [],
14407
14359
  };
14408
14360
  }
14409
- // if (filteredRange.length === 3) {
14410
- // success = isValue(filteredRange[2]);
14411
- // if (success) {
14412
- // context.update(filteredRange[2]);
14413
- // return {
14414
- // success,
14415
- // valid: true,
14416
- // token: filteredRange[2],
14417
- // context,
14418
- // syntaxToken: property,
14419
- // errors: [],
14420
- // };
14421
- // }
14422
- // }
14423
14361
  break;
14424
14362
  }
14425
14363
  case "style-feature": {
@@ -14429,16 +14367,6 @@ function matchProperty(property, context, options) {
14429
14367
  // match <style-range>
14430
14368
  const range = context.peekRange();
14431
14369
  const filteredRange = range.filter((token) => token.typ !== exports.EnumToken.WhitespaceTokenType && token.typ !== exports.EnumToken.CommentTokenType);
14432
- // if (filteredRange.length === 0) {
14433
- // return {
14434
- // success: false,
14435
- // valid: true,
14436
- // token: context.peek(),
14437
- // context,
14438
- // syntaxToken: property,
14439
- // errors: [],
14440
- // };
14441
- // }
14442
14370
  if (filteredRange.length === 1) {
14443
14371
  success =
14444
14372
  filteredRange[0].typ === exports.EnumToken.IdenTokenType ||
@@ -14453,31 +14381,6 @@ function matchProperty(property, context, options) {
14453
14381
  errors: [],
14454
14382
  };
14455
14383
  }
14456
- // if (
14457
- // filteredRange[1]?.typ === EnumToken.ColonTokenType ||
14458
- // filteredRange[1]?.typ === EnumToken.DelimTokenType
14459
- // ) {
14460
- // const result = isDeclarationValue(filteredRange.slice(2));
14461
- // if (result.success) {
14462
- // context.update(filteredRange.at(-1)!);
14463
- // return {
14464
- // success: true,
14465
- // valid: true,
14466
- // token: filteredRange.at(-1)!,
14467
- // context,
14468
- // syntaxToken: property,
14469
- // errors: [],
14470
- // };
14471
- // }
14472
- // return {
14473
- // success: false,
14474
- // valid: false,
14475
- // token: context.peek(),
14476
- // context,
14477
- // syntaxToken: property,
14478
- // errors: result.errors,
14479
- // };
14480
- // }
14481
14384
  return {
14482
14385
  success: false,
14483
14386
  valid: false,
@@ -14489,10 +14392,6 @@ function matchProperty(property, context, options) {
14489
14392
  }
14490
14393
  case "url": {
14491
14394
  const token = context.peek();
14492
- // if (token == null) {
14493
- // success = false;
14494
- // break;
14495
- // }
14496
14395
  let l;
14497
14396
  if (token?.typ == exports.EnumToken.UrlFunctionTokenDefType) {
14498
14397
  l = 0;
@@ -14506,11 +14405,6 @@ function matchProperty(property, context, options) {
14506
14405
  (token.typ == exports.EnumToken.StringTokenType ||
14507
14406
  token.typ == exports.EnumToken.IdenTokenType ||
14508
14407
  token.typ == exports.EnumToken.UrlTokenTokenType)) {
14509
- // if (token.typ === EnumToken.IdenTokenType) {
14510
- // while (context.peek(l + 1)?.typ === EnumToken.ClassSelectorTokenType) {
14511
- // l++;
14512
- // }
14513
- // }
14514
14408
  while ((token = context.peek(++l))) {
14515
14409
  if (token.typ !== exports.EnumToken.WhitespaceTokenType && token.typ !== exports.EnumToken.CommentTokenType) {
14516
14410
  break;
@@ -14574,10 +14468,46 @@ function matchProperty(property, context, options) {
14574
14468
  }
14575
14469
  break;
14576
14470
  }
14471
+ case "dashed-function": {
14472
+ const token = context.peek();
14473
+ success = token?.typ == exports.EnumToken.CustomFunctionTokenDefType;
14474
+ if (success) {
14475
+ context.next();
14476
+ return {
14477
+ success: true,
14478
+ valid: true,
14479
+ token,
14480
+ context,
14481
+ syntaxToken: null,
14482
+ errors: [],
14483
+ };
14484
+ }
14485
+ break;
14486
+ }
14487
+ case "block-contents":
14488
+ success = context.peek()?.typ == exports.EnumToken.StartParensTokenType;
14489
+ if (success) {
14490
+ context.next();
14491
+ return {
14492
+ success: true,
14493
+ valid: true,
14494
+ token: null,
14495
+ context,
14496
+ syntaxToken: null,
14497
+ errors: [],
14498
+ };
14499
+ }
14500
+ return {
14501
+ success: false,
14502
+ valid: true,
14503
+ token,
14504
+ context,
14505
+ syntaxToken: property,
14506
+ errors: [],
14507
+ };
14577
14508
  default:
14578
14509
  if (!(property.val in config$3.syntaxes)) {
14579
14510
  console.debug("Unknown syntax", context.peek(), property);
14580
- console.debug(context.getRemainingTokens());
14581
14511
  throw new Error(`Unexpected validation property ${property.val}`);
14582
14512
  }
14583
14513
  return matchSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, property.val), context, options);
@@ -20081,7 +20011,7 @@ class PropertyMap {
20081
20011
  if (value instanceof PropertyMap) {
20082
20012
  for (const [k, v] of value.declarations) {
20083
20013
  if (k == value.config.shorthand) {
20084
- for (const [key, val] of Object.entries(value.config.properties)) {
20014
+ for (const [key] of Object.entries(value.config.properties)) {
20085
20015
  mapped[key] = cloneNode(v);
20086
20016
  for (let i = 0; i < v.val.length; i++) {
20087
20017
  // @ts-ignore
@@ -20869,6 +20799,16 @@ class PropertyList {
20869
20799
  let result;
20870
20800
  for (const declaration of declarations) {
20871
20801
  name = declaration.typ != exports.EnumToken.DeclarationNodeType ? null : declaration.nam;
20802
+ // do not compute shorthand for invalid declarations
20803
+ if (name == null) {
20804
+ this.declarations.set(objectHash(declaration), declaration);
20805
+ continue;
20806
+ }
20807
+ // @functiom / result
20808
+ if (declaration[STATE] & exports.EnumAstNodeStatus.Unknown && equalsIgnoreCase("result", name)) {
20809
+ this.declarations.set(declaration.nam, declaration);
20810
+ continue;
20811
+ }
20872
20812
  if (declaration[STATE] &
20873
20813
  (exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.Unknown | exports.EnumAstNodeStatus.ValidationFailed) ||
20874
20814
  declaration.typ != exports.EnumToken.DeclarationNodeType ||
@@ -21106,32 +21046,49 @@ class ComputeShorthandFeature {
21106
21046
  let l;
21107
21047
  const rules = [];
21108
21048
  const declarations = [];
21109
- // @ts-ignore
21110
- for (; k < j; k++) {
21111
- l = k;
21112
- // capture comments with the next token
21113
- while (l + 1 < j) {
21114
- // @ts-ignore
21115
- const node = ast.chi[l];
21116
- if (node.typ == exports.EnumToken.CommentNodeType) {
21117
- l++;
21118
- continue;
21119
- }
21120
- break;
21049
+ let doNotSort = false;
21050
+ if (ast.typ == exports.EnumToken.AtRuleNodeType) {
21051
+ switch (ast.nam) {
21052
+ case "function":
21053
+ case "mixin":
21054
+ doNotSort = true;
21055
+ break;
21121
21056
  }
21057
+ }
21058
+ // https://drafts.csswg.org/css-mixins/#:~:text=The%20value%20of%20the%20result%20descriptor%20is%20always%2016px%20in%20the%20above%20example
21059
+ if (doNotSort) {
21060
+ for (const node of ast.chi) {
21061
+ declarations.push(node);
21062
+ }
21063
+ }
21064
+ else {
21122
21065
  // @ts-ignore
21123
- const node = ast.chi[l];
21124
- if (node.typ == exports.EnumToken.DeclarationNodeType) {
21125
- for (let m = k; m <= l; m++) {
21126
- declarations.push(ast.chi[m]);
21066
+ for (; k < j; k++) {
21067
+ l = k;
21068
+ // capture comments with the next token
21069
+ while (l + 1 < j) {
21070
+ // @ts-ignore
21071
+ const node = ast.chi[l];
21072
+ if (node.typ == exports.EnumToken.CommentNodeType) {
21073
+ l++;
21074
+ continue;
21075
+ }
21076
+ break;
21127
21077
  }
21128
- }
21129
- else {
21130
- for (let m = k; m <= l; m++) {
21131
- rules.push(ast.chi[m]);
21078
+ // @ts-ignore
21079
+ const node = ast.chi[l];
21080
+ if (node.typ == exports.EnumToken.DeclarationNodeType) {
21081
+ for (let m = k; m <= l; m++) {
21082
+ declarations.push(ast.chi[m]);
21083
+ }
21132
21084
  }
21085
+ else {
21086
+ for (let m = k; m <= l; m++) {
21087
+ rules.push(ast.chi[m]);
21088
+ }
21089
+ }
21090
+ k = l;
21133
21091
  }
21134
- k = l;
21135
21092
  }
21136
21093
  if (declarations.length > 0) {
21137
21094
  ast.chi.length = 0;
@@ -21151,6 +21108,7 @@ const trimTokenSpace = new Set([
21151
21108
  exports.EnumToken.LteTokenType,
21152
21109
  exports.EnumToken.ChildCombinatorTokenType,
21153
21110
  exports.EnumToken.PipeTokenType,
21111
+ exports.EnumToken.ColonTokenType
21154
21112
  ]);
21155
21113
  const trimSpaceAfter = new Set([
21156
21114
  ...tokensfuncSet.values(),
@@ -23339,8 +23297,35 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
23339
23297
  previous = ast.chi[--nodeIndex];
23340
23298
  }
23341
23299
  node = ast.chi[i];
23342
- if (node.typ === exports.EnumToken.AtRuleNodeType && node.nam === "font-face") {
23343
- continue;
23300
+ if (node.typ === exports.EnumToken.AtRuleNodeType) {
23301
+ if (node.nam === "font-face") {
23302
+ continue;
23303
+ }
23304
+ // https://drafts.csswg.org/css-mixins/#:~:text=The%20value%20of%20the%20result%20descriptor%20is%20always%2016px%20in%20the%20above%20example
23305
+ if (equalsIgnoreCase(node.nam, "function")) {
23306
+ const chi = node.chi;
23307
+ let k = chi?.length;
23308
+ let slice = false;
23309
+ while (k--) {
23310
+ if (chi[k].typ === exports.EnumToken.CommentNodeType ||
23311
+ chi[k].typ === exports.EnumToken.WhitespaceTokenType) {
23312
+ continue;
23313
+ }
23314
+ if (chi[k].typ === exports.EnumToken.DeclarationNodeType &&
23315
+ equalsIgnoreCase(chi[k].nam, "result")) {
23316
+ slice = true;
23317
+ break;
23318
+ }
23319
+ }
23320
+ if (k > 0 && slice) {
23321
+ while (k--) {
23322
+ if (chi[k].typ === exports.EnumToken.AtRuleNodeType) {
23323
+ chi.splice(k, 1);
23324
+ continue;
23325
+ }
23326
+ }
23327
+ }
23328
+ }
23344
23329
  }
23345
23330
  if (node.typ === exports.EnumToken.KeyframesAtRuleNodeType) {
23346
23331
  if (previous?.typ === exports.EnumToken.KeyframesAtRuleNodeType &&
@@ -25875,7 +25860,7 @@ function renderAstNode(data, options, sourcemaps, sourceLocation, linesMap, erro
25875
25860
  case exports.EnumToken.KeyframesRuleNodeType:
25876
25861
  case exports.EnumToken.KeyframesAtRuleNodeType:
25877
25862
  if ([exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyframesAtRuleNodeType].includes(data.typ) && !("chi" in data)) {
25878
- return `${indent}@${data.nam}${data.val === "" ? "" : options.indent || " "}${data.val};`;
25863
+ return `${(indent.length > 0 ? options.newLine : "") + indent}@${data.nam}${data.val === "" ? "" : options.indent || " "}${data.val};`;
25879
25864
  }
25880
25865
  const lineMapLength = linesMap ? linesMap.getLineStarts().length : 0;
25881
25866
  const prelude = (indent.length > 0 ? options.newLine : "") +
@@ -29621,7 +29606,7 @@ function parseMediaqueryList(stream, options) {
29621
29606
  Object.assign(stream[i], {
29622
29607
  typ: val === "and" ? exports.EnumToken.AndTokenType : exports.EnumToken.OrTokenType,
29623
29608
  });
29624
- if (val === "or" && scopes.length <= 1) {
29609
+ if (val === "or" && (scopes.length == 1 && scopes[0].size > 0 && !scopes[0].has(exports.EnumToken.OrTokenType))) {
29625
29610
  success = false;
29626
29611
  errors.push({
29627
29612
  action: "drop",
@@ -30137,7 +30122,7 @@ function parseAtRuleSupportSyntax(stream, context, options = {}) {
30137
30122
  break;
30138
30123
  }
30139
30124
  if ("and" === val || "or" === val) {
30140
- if ("or" === val && scopes.length === 1) {
30125
+ if ("or" === val && scopes.length === 1 && scopes[0].size > 0) {
30141
30126
  const fileName = options.source.getFileName() ?? "";
30142
30127
  const [line, column] = options.source.getOffsets(stream[i]?.[LOCSTA]);
30143
30128
  return {
@@ -31220,19 +31205,10 @@ function parseVisitors(visitorsDef, errors) {
31220
31205
  key = visitors[i][0];
31221
31206
  value = visitors[i][1];
31222
31207
  if (Number.isInteger(+key)) {
31223
- // if (Array.isArray(value)) {
31224
- // visitors.splice(i + 1, 0, ...Object.entries(value));
31225
- // continue;
31226
- // }
31227
31208
  if (typeof value == "function") {
31228
31209
  key = value.name;
31229
31210
  }
31230
31211
  }
31231
- // if (Array.isArray(value)) {
31232
- // // @ts-ignore
31233
- // visitors.splice(i + 1, 0, ...value.map((item) => [key, item]));
31234
- // continue;
31235
- // }
31236
31212
  if (key in exports.EnumToken) {
31237
31213
  if (typeof value == "function") {
31238
31214
  if (!valuesHandlers.has(exports.EnumToken[key])) {
@@ -31592,7 +31568,7 @@ function doParseSync(tokenizer, options = {}) {
31592
31568
  if (tokens.length > 0) {
31593
31569
  node = parseNode(tokens, context, options, errors, stats, invalidNodes);
31594
31570
  if (node != null) {
31595
- if ("chi" in node /* && node.typ != EnumToken.InvalidRuleNodeType */) {
31571
+ if ("chi" in node) {
31596
31572
  stack.push(node);
31597
31573
  context = node;
31598
31574
  }
@@ -32364,14 +32340,9 @@ async function doParse(iter, options = {}) {
32364
32340
  let parensMatch = 0;
32365
32341
  let curlyBracketMatch = 0;
32366
32342
  let tokenizer = iter instanceof Promise ? await iter : iter;
32367
- // ast[ROOT] = ast;
32368
32343
  ast[LOCSRCID] = options.source.id;
32369
32344
  ast[LOCSTA] = 0;
32370
32345
  ast[LOCEND] = 0;
32371
- // if (Array.isArray(iter)) {
32372
- // // @ts-expect-error
32373
- // iter = iter[Symbol.iterator]() as Iterator<TokenizeResult>;
32374
- // }
32375
32346
  while (!tokenizer.done()) {
32376
32347
  tokenizer.next();
32377
32348
  if (tokenizer.unit != null) {
@@ -32612,6 +32583,11 @@ async function doParse(iter, options = {}) {
32612
32583
  case exports.EnumToken.AtRuleNodeType:
32613
32584
  case exports.EnumToken.KeyframesRuleNodeType:
32614
32585
  case exports.EnumToken.KeyframesAtRuleNodeType:
32586
+ if (nodes[i][TOKENS] == null) {
32587
+ if (nodes[i].typ == exports.EnumToken.RuleNodeType) {
32588
+ nodes[i][TOKENS] = parseString(nodes[i].sel);
32589
+ }
32590
+ }
32615
32591
  for (const token of nodes[i][TOKENS]) {
32616
32592
  subNodes.push(token);
32617
32593
  }
@@ -33606,7 +33582,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
33606
33582
  else if (context.typ === exports.EnumToken.AtRuleNodeType &&
33607
33583
  "page" === context.nam &&
33608
33584
  pageMarginBoxType.has(atRuleName.toLowerCase())) {
33609
- if (parseAsBlock === false) {
33585
+ if (parseAsBlock === false && syntaxRules.optionalBody === false) {
33610
33586
  errors.push({
33611
33587
  action: "drop",
33612
33588
  node: atRule,
@@ -33645,7 +33621,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
33645
33621
  if (parseAsBlock === null) {
33646
33622
  parseAsBlock = blockAllowed;
33647
33623
  }
33648
- if (syntax != null && atRule.nam !== "layer" && parseAsBlock !== blockAllowed) {
33624
+ if (syntax != null && atRule.nam !== "layer" && parseAsBlock !== blockAllowed && !syntaxRules.optionalBody) {
33649
33625
  errors.push({
33650
33626
  action: "drop",
33651
33627
  node: atRule,
@@ -34774,7 +34750,7 @@ function setNodeProperty(node, key, value) {
34774
34750
  }
34775
34751
  }
34776
34752
 
34777
- var version = "1.6.9";
34753
+ var version = "1.7.0";
34778
34754
 
34779
34755
  /**
34780
34756
  * Load file or url
@@ -35251,6 +35227,7 @@ exports.parseDeclarations = parseDeclarations;
35251
35227
  exports.parseFile = parseFile;
35252
35228
  exports.parseString = parseString;
35253
35229
  exports.parseSync = parseSync;
35230
+ exports.parseSyntax = parseSyntax;
35254
35231
  exports.render = render;
35255
35232
  exports.renderToken = renderValue;
35256
35233
  exports.replaceNodeOrValue = replaceNodeOrValue;