@tbela99/css-parser 1.6.0 → 1.6.2

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 (48) hide show
  1. package/CHANGELOG.md +118 -2
  2. package/README.md +4 -3
  3. package/dist/index-umd-web.js +1629 -467
  4. package/dist/index.cjs +1629 -467
  5. package/dist/index.d.ts +72 -7
  6. package/dist/lib/ast/features/prefix.js +9 -1
  7. package/dist/lib/ast/features/shorthand.js +1 -1
  8. package/dist/lib/ast/features/transform.js +1 -1
  9. package/dist/lib/ast/math/expression.js +175 -5
  10. package/dist/lib/ast/minify.js +84 -10
  11. package/dist/lib/ast/transform/compute.js +24 -55
  12. package/dist/lib/ast/transform/minify.js +1 -1
  13. package/dist/lib/ast/types.js +12 -0
  14. package/dist/{config.json.js → lib/data/properties.json.js} +106 -0
  15. package/dist/lib/{validation/config.json.js → data/validation.json.js} +11 -8
  16. package/dist/lib/parser/declaration/list.js +8 -10
  17. package/dist/lib/parser/parse.js +8 -14
  18. package/dist/lib/parser/tokenize.js +89 -58
  19. package/dist/lib/parser/utils/at-rule-font-feature-values.js +1 -1
  20. package/dist/lib/parser/utils/at-rule-media.js +66 -0
  21. package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
  22. package/dist/lib/parser/utils/base64.js +14 -0
  23. package/dist/lib/parser/utils/config.js +1 -1
  24. package/dist/lib/parser/utils/declaration.js +18 -17
  25. package/dist/lib/parser/utils/eq.js +6 -0
  26. package/dist/lib/parser/utils/hash.js +1 -0
  27. package/dist/lib/parser/utils/selector.js +99 -89
  28. package/dist/lib/parser/utils/text.js +16 -0
  29. package/dist/lib/renderer/render.js +20 -6
  30. package/dist/lib/renderer/sourcemap/lib/codec.js +8 -3
  31. package/dist/lib/renderer/sourcemap/sourcemap.js +35 -5
  32. package/dist/lib/syntax/color/alpha.js +57 -22
  33. package/dist/lib/syntax/color/cmyk.js +4 -3
  34. package/dist/lib/syntax/color/color-mix.js +18 -18
  35. package/dist/lib/syntax/color/srgb.js +11 -5
  36. package/dist/lib/syntax/color/utils/components.js +1 -1
  37. package/dist/lib/syntax/color/utils/distance.js +2 -2
  38. package/dist/lib/syntax/color/utils/matrix.js +1 -0
  39. package/dist/lib/syntax/color/xyz.js +5 -0
  40. package/dist/lib/syntax/color/xyzd50.js +17 -0
  41. package/dist/lib/syntax/constants.js +1 -1
  42. package/dist/lib/syntax/syntax.js +549 -13
  43. package/dist/lib/validation/config.js +27 -1
  44. package/dist/lib/validation/match.js +16 -4
  45. package/dist/lib/validation/parser/parse.js +7 -3
  46. package/dist/node.js +8 -14
  47. package/dist/web.js +8 -14
  48. package/package.json +4 -4
package/dist/index.cjs CHANGED
@@ -669,6 +669,18 @@ exports.EnumToken = void 0;
669
669
  * wrapped values token type like {Arial, sans-serif}
670
670
  */
671
671
  EnumToken[EnumToken["WrappedValuesTokenType"] = 140] = "WrappedValuesTokenType";
672
+ /**
673
+ * infinity token
674
+ */
675
+ EnumToken[EnumToken["NaNTokenType"] = 141] = "NaNTokenType";
676
+ /**
677
+ * infinity token
678
+ */
679
+ EnumToken[EnumToken["InfinityTokenType"] = 142] = "InfinityTokenType";
680
+ /**
681
+ * negative infinity token
682
+ */
683
+ EnumToken[EnumToken["NegativeInfinityTokenType"] = 143] = "NegativeInfinityTokenType";
672
684
  /* aliases */
673
685
  /**
674
686
  * alias for time token type
@@ -2572,7 +2584,7 @@ var declarations = {
2572
2584
  syntax: "none | nearest"
2573
2585
  },
2574
2586
  "scroll-margin": {
2575
- syntax: "<length>{1,4}"
2587
+ syntax: " <length>{1,4}"
2576
2588
  },
2577
2589
  "scroll-margin-block": {
2578
2590
  syntax: "<length>{1,2}"
@@ -2584,7 +2596,7 @@ var declarations = {
2584
2596
  syntax: "<length>"
2585
2597
  },
2586
2598
  "scroll-margin-bottom": {
2587
- syntax: "<length>"
2599
+ syntax: " auto | <length-percentage [0,∞]>"
2588
2600
  },
2589
2601
  "scroll-margin-inline": {
2590
2602
  syntax: "<length>{1,2}"
@@ -2596,13 +2608,13 @@ var declarations = {
2596
2608
  syntax: "<length>"
2597
2609
  },
2598
2610
  "scroll-margin-left": {
2599
- syntax: "<length>"
2611
+ syntax: " auto | <length-percentage [0,∞]>"
2600
2612
  },
2601
2613
  "scroll-margin-right": {
2602
- syntax: "<length>"
2614
+ syntax: " auto | <length-percentage [0,∞]>"
2603
2615
  },
2604
2616
  "scroll-margin-top": {
2605
- syntax: "<length>"
2617
+ syntax: " auto | <length-percentage [0,∞]>"
2606
2618
  },
2607
2619
  "scroll-marker-group": {
2608
2620
  syntax: "none | before | after"
@@ -2671,13 +2683,13 @@ var declarations = {
2671
2683
  syntax: "none | auto"
2672
2684
  },
2673
2685
  "scroll-timeline": {
2674
- syntax: "[ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#"
2686
+ syntax: " [ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#"
2675
2687
  },
2676
2688
  "scroll-timeline-axis": {
2677
- syntax: "[ block | inline | x | y ]#"
2689
+ syntax: " [ block | inline | x | y ]#"
2678
2690
  },
2679
2691
  "scroll-timeline-name": {
2680
- syntax: "[ none | <dashed-ident> ]#"
2692
+ syntax: " [ none | <dashed-ident> ]#"
2681
2693
  },
2682
2694
  "scrollbar-color": {
2683
2695
  syntax: "auto | <color>{2}"
@@ -3170,6 +3182,9 @@ var functions = {
3170
3182
  acos: {
3171
3183
  syntax: "acos( <calc-sum> )"
3172
3184
  },
3185
+ alpha: {
3186
+ syntax: "alpha( from <color> / [ <alpha-value> | none ] )"
3187
+ },
3173
3188
  anchor: {
3174
3189
  syntax: "anchor( <anchor-name>? && <anchor-side>, <length-percentage>? )"
3175
3190
  },
@@ -6838,12 +6853,28 @@ const trimTokenSpace$1 = new Set([
6838
6853
  ]);
6839
6854
  const combinators = ["+", ">", "~", "||", "|"];
6840
6855
 
6856
+ /**
6857
+ *
6858
+ * @param value
6859
+ * @returns
6860
+ */
6841
6861
  function dasherize(value) {
6842
6862
  return value.replace(/([A-Z])/g, (all, one) => `-${one.toLowerCase()}`);
6843
6863
  }
6864
+ /**
6865
+ *
6866
+ * @param value
6867
+ * @returns
6868
+ */
6844
6869
  function camelize(value) {
6845
6870
  return value.replace(/-([a-z])/g, (all, one) => one.toUpperCase());
6846
6871
  }
6872
+ /**
6873
+ *
6874
+ * @param a
6875
+ * @param b
6876
+ * @returns
6877
+ */
6847
6878
  function equalsIgnoreCase(a, b) {
6848
6879
  if (a.length !== b.length)
6849
6880
  return false;
@@ -6872,7 +6903,7 @@ function getColorComponents(token) {
6872
6903
  // }
6873
6904
  // }
6874
6905
  if (token.kin == exports.ColorType.HEX || token.kin == exports.ColorType.LIT) {
6875
- if (equalsIgnoreCase('currentcolor', token.val)) {
6906
+ if (equalsIgnoreCase("currentcolor", token.val)) {
6876
6907
  return null;
6877
6908
  }
6878
6909
  const value = expandHexValue(token.kin == exports.ColorType.LIT ? COLORS_NAMES[token.val.toLowerCase()] : token.val);
@@ -6930,6 +6961,7 @@ function getColorComponents(token) {
6930
6961
  */
6931
6962
  // A is m x n. B is n x p. product is m x p.
6932
6963
  function multiplyMatrices(A, B) {
6964
+ // let m: number = A.length;
6933
6965
  // if (!Array.isArray(A[0])) {
6934
6966
  // // A is vector, convert to [[a, b, c, ...]]
6935
6967
  // A = <number[][]>[A];
@@ -7145,6 +7177,23 @@ function getLCHComponents(token) {
7145
7177
  return alpha == null ? [l, c, h] : [l, c, h, alpha];
7146
7178
  }
7147
7179
 
7180
+ // export function srgb2xyzd50values(r: number, g: number, b: number, alpha: number | null = null): number[] {
7181
+ // [r, g, b] = srgb2lsrgbvalues(r, g, b);
7182
+ //
7183
+ // const rgb: number[] = [
7184
+ // 0.436065742824811 * r + 0.3851514688337912 * g + 0.14307845442264197 * b,
7185
+ //
7186
+ // 0.22249319175623702 * r + 0.7168870538238823 * g + 0.06061979053616537 * b,
7187
+ //
7188
+ // 0.013923904500943465 * r + 0.09708128566574634 * g + 0.7140993584005155 * b,
7189
+ // ];
7190
+ //
7191
+ // if (alpha != null && alpha != 1) {
7192
+ // rgb.push(alpha);
7193
+ // }
7194
+ //
7195
+ // return rgb;
7196
+ // }
7148
7197
  /*
7149
7198
  */
7150
7199
  function xyzd502lch(x, y, z, alpha) {
@@ -7178,6 +7227,11 @@ function xyzd502srgb(x, y, z, alpha = null) {
7178
7227
  x * 0.07195537988411677 - y * 0.2289768264158322 + 1.405386058324125 * z, alpha);
7179
7228
  }
7180
7229
 
7230
+ // export function lab2xyz(l: number, a: number, b: number, alpha?: number): number[] {
7231
+ // const [x, y, z] = Lab_to_XYZ(l, a, b);
7232
+ //
7233
+ // return alpha == null || alpha == 1 ? [x, y, z] : [x, y, z, alpha];
7234
+ // }
7181
7235
  function XYZ_to_lin_sRGB(x, y, z, alpha = null) {
7182
7236
  // convert XYZ to linear-light sRGB
7183
7237
  const M = [
@@ -7894,6 +7948,15 @@ function rgb2srgbvalues(token) {
7894
7948
  ? getNumber(t)
7895
7949
  : getNumber(t) / 255) ?? null);
7896
7950
  }
7951
+ // export function rgbvalues2srgbvalues(r: number, g: number, b: number, a: number | null = null): number[] | null {
7952
+ // const result = [r / 255, g / 255, b / 255];
7953
+ //
7954
+ // if (a != null && a != 1) {
7955
+ // result.push(a);
7956
+ // }
7957
+ //
7958
+ // return result;
7959
+ // }
7897
7960
  function hex2srgbvalues(token) {
7898
7961
  const value = expandHexValue(token.kin == exports.ColorType.LIT ? COLORS_NAMES[token.val.toLowerCase()] : token.val);
7899
7962
  const rgb = [];
@@ -7954,11 +8017,8 @@ function cmyk2srgbvalues(token) {
7954
8017
  t = components[3];
7955
8018
  // @ts-ignore
7956
8019
  const k = getNumber(t);
7957
- const rgb = [
7958
- 1 - Math.min(1, c * (1 - k) + k),
7959
- 1 - Math.min(1, m * (1 - k) + k),
7960
- 1 - Math.min(1, y * (1 - k) + k),
7961
- ];
8020
+ const mul = 1 - k;
8021
+ const rgb = [1 - Math.min(1, c * mul + k), 1 - Math.min(1, m * mul + k), 1 - Math.min(1, y * mul + k)];
7962
8022
  if (components.length == 5) {
7963
8023
  rgb.push(getNumber(components[4]));
7964
8024
  }
@@ -9130,7 +9190,7 @@ function colorMix(...args) {
9130
9190
  let colorSpace = "oklab";
9131
9191
  let hueInterpolationMethod = "shorter";
9132
9192
  let values = null;
9133
- const colors = [];
9193
+ // const colors: ColorToken[] = [];
9134
9194
  const percentages = [];
9135
9195
  const srgbComponentValues = [];
9136
9196
  const colorComponents = [];
@@ -9239,7 +9299,8 @@ function colorMix(...args) {
9239
9299
  return null;
9240
9300
  }
9241
9301
  srgbComponentValues.push(values);
9242
- colors.push(args[i++]);
9302
+ // colors.push(args[i++] as ColorToken);
9303
+ i++;
9243
9304
  if (i >= args.length) {
9244
9305
  missingPercentageCount++;
9245
9306
  percentages.push(null);
@@ -9281,9 +9342,16 @@ function colorMix(...args) {
9281
9342
  for (i = 0; i < percentages.length; i++) {
9282
9343
  percentages[i] = percentages[i] / perc;
9283
9344
  }
9284
- totalPercentage = 1;
9285
9345
  }
9286
- i = colors.length;
9346
+ const stack = [];
9347
+ const lchSpaces = ["lch", "oklch"];
9348
+ i = srgbComponentValues.length;
9349
+ while (i--) {
9350
+ stack.push({
9351
+ color: srgbComponentValues[i],
9352
+ alpha: percentages[i],
9353
+ });
9354
+ }
9287
9355
  let currentIndex = 0;
9288
9356
  let r1;
9289
9357
  let r2;
@@ -9294,18 +9362,11 @@ function colorMix(...args) {
9294
9362
  let premult1;
9295
9363
  let premult2;
9296
9364
  let mixedPremult;
9297
- let colorSpace1;
9298
- const stack = [];
9299
- const lchSpaces = ["lch", "oklch"];
9300
- i = srgbComponentValues.length;
9301
- while (i--) {
9302
- stack.push({
9303
- color: srgbComponentValues[i],
9304
- alpha: percentages[i],
9305
- });
9306
- }
9365
+ let colorSpace1 = exports.ColorType[
9366
+ // @ts-expect-error
9367
+ colorComponents.at(-1).kin
9307
9368
  // @ts-expect-error
9308
- colorSpace1 = exports.ColorType[colorComponents.at(-1).kin]?.toLowerCase?.();
9369
+ ]?.toLowerCase?.();
9309
9370
  if (colorComponents[0][3] != null &&
9310
9371
  colorComponents[0][3].typ == exports.EnumToken.IdenTokenType &&
9311
9372
  colorComponents[0][3].val == "none" &&
@@ -9387,14 +9448,13 @@ function colorMix(...args) {
9387
9448
  else {
9388
9449
  values = xyz2lchvalues(values[0], values[1], values[2], values[3]);
9389
9450
  }
9390
- // @ts-ignore
9391
9451
  return {
9392
9452
  typ: exports.EnumToken.ColorTokenType,
9393
9453
  val: "lch",
9394
- chi: values.map((v) => {
9454
+ chi: values.map((val) => {
9395
9455
  return {
9396
9456
  typ: exports.EnumToken.NumberTokenType,
9397
- val: v,
9457
+ val,
9398
9458
  };
9399
9459
  }),
9400
9460
  kin: exports.ColorType.LCH,
@@ -10127,6 +10187,35 @@ function doEvaluate(l, r, op) {
10127
10187
  if (!isScalarToken(l) || !isScalarToken(r) || (l.typ == r.typ && "unit" in l && "unit" in r && l.unit != r.unit)) {
10128
10188
  return defaultReturn;
10129
10189
  }
10190
+ if (l.typ == exports.EnumToken.IdenTokenType) {
10191
+ if (equalsIgnoreCase(l.val, "Infinity")) {
10192
+ Object.assign(l, { typ: exports.EnumToken.InfinityTokenType });
10193
+ }
10194
+ else if (equalsIgnoreCase(l.val, "-Infinity")) {
10195
+ Object.assign(l, { typ: exports.EnumToken.NegativeInfinityTokenType });
10196
+ }
10197
+ else if (equalsIgnoreCase(l.val, "NaN")) {
10198
+ Object.assign(l, { typ: exports.EnumToken.NaNTokenType });
10199
+ }
10200
+ }
10201
+ if (r.typ == exports.EnumToken.IdenTokenType) {
10202
+ if (equalsIgnoreCase(r.val, "Infinity")) {
10203
+ Object.assign(r, { typ: exports.EnumToken.InfinityTokenType });
10204
+ }
10205
+ else if (equalsIgnoreCase(r.val, "-Infinity")) {
10206
+ Object.assign(r, { typ: exports.EnumToken.NegativeInfinityTokenType });
10207
+ }
10208
+ }
10209
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/calc-keyword#notes
10210
+ if (l.typ == exports.EnumToken.NaNTokenType || r.typ == exports.EnumToken.NaNTokenType) {
10211
+ return computeNaN(l, r, defaultReturn);
10212
+ }
10213
+ if (l.typ == exports.EnumToken.InfinityTokenType ||
10214
+ l.typ == exports.EnumToken.NegativeInfinityTokenType ||
10215
+ r.typ == exports.EnumToken.InfinityTokenType ||
10216
+ r.typ == exports.EnumToken.NegativeInfinityTokenType) {
10217
+ return computeInfinity(l, r, op, defaultReturn);
10218
+ }
10130
10219
  if (r.typ == exports.EnumToken.FunctionTokenType || r.typ == exports.EnumToken.MathFunctionTokenType) {
10131
10220
  const val = evaluateFunc(r);
10132
10221
  if (val == null) {
@@ -10197,6 +10286,18 @@ function doEvaluate(l, r, op) {
10197
10286
  }
10198
10287
  }
10199
10288
  }
10289
+ if (op == exports.EnumToken.Div && v2 == 0) {
10290
+ if (v1 == 0) {
10291
+ return Object.assign(l, { typ: exports.EnumToken.IdenTokenType, val: "NaN" });
10292
+ }
10293
+ let sign = Math.sign(v1) * Math.sign(v2);
10294
+ sign = Object.is(sign, -0) ? -1 : 1;
10295
+ Object.assign(l, {
10296
+ typ: l.typ == exports.EnumToken.IdenTokenType ? exports.EnumToken.NumberTokenType : l.typ,
10297
+ val: Object.is(sign, -0) ? -1 : sign,
10298
+ });
10299
+ return defaultReturn;
10300
+ }
10200
10301
  // @ts-ignore
10201
10302
  const val = compute$1(v1, v2, op);
10202
10303
  const token = {
@@ -10213,6 +10314,112 @@ function doEvaluate(l, r, op) {
10213
10314
  }
10214
10315
  return token;
10215
10316
  }
10317
+ /**
10318
+ *
10319
+ * @param l
10320
+ * @param r
10321
+ * @param defaultReturn
10322
+ * @returns
10323
+ */
10324
+ function computeNaN(l, r, defaultReturn) {
10325
+ if (l.typ == exports.EnumToken.NaNTokenType) {
10326
+ if (r.typ == exports.EnumToken.NumberTokenType ||
10327
+ // @ts-expect-error
10328
+ (r.typ == exports.EnumToken.IdenTokenType && typeof Math[r.val.toUpperCase()] == "string")) {
10329
+ return l;
10330
+ }
10331
+ // NaN Infinity e pi ...
10332
+ if (r.typ == exports.EnumToken.IdenTokenType ||
10333
+ r.typ == exports.EnumToken.InfinityTokenType ||
10334
+ r.typ == exports.EnumToken.NegativeInfinityTokenType) {
10335
+ return l;
10336
+ }
10337
+ if (typeof r.val == "number") {
10338
+ Object.assign(r, { val: 1 });
10339
+ }
10340
+ return r.typ == exports.EnumToken.NaNTokenType ? l : defaultReturn;
10341
+ }
10342
+ if (r.typ == exports.EnumToken.NaNTokenType) {
10343
+ // if ((r as IdentToken).val == "NaN") {
10344
+ if (l.typ == exports.EnumToken.NumberTokenType ||
10345
+ // @ts-expect-error
10346
+ (l.typ == exports.EnumToken.IdenTokenType && typeof Math[l.val.toUpperCase()] == "string")) {
10347
+ return r;
10348
+ }
10349
+ if (typeof l.val == "number") {
10350
+ Object.assign(l, { val: 1 });
10351
+ }
10352
+ // return defaultReturn;
10353
+ }
10354
+ // }
10355
+ return defaultReturn;
10356
+ }
10357
+ /**
10358
+ *
10359
+ * @param l
10360
+ * @param r
10361
+ * @param op
10362
+ * @param defaultReturn
10363
+ * @returns
10364
+ */
10365
+ function computeInfinity(l, r, op, defaultReturn) {
10366
+ if (l.typ == exports.EnumToken.InfinityTokenType || l.typ == exports.EnumToken.NegativeInfinityTokenType) {
10367
+ if (r.typ == exports.EnumToken.InfinityTokenType || r.typ == exports.EnumToken.NegativeInfinityTokenType) {
10368
+ // Infinity / Infinity Infinity - Infinity
10369
+ if (op == exports.EnumToken.Div ||
10370
+ (op == exports.EnumToken.Add && l.typ != r.typ) ||
10371
+ (op == exports.EnumToken.Sub && l.typ == r.typ)) {
10372
+ return Object.assign(l, { typ: exports.EnumToken.NaNTokenType });
10373
+ }
10374
+ if (l.typ != r.typ) {
10375
+ l.typ = exports.EnumToken.NegativeInfinityTokenType;
10376
+ }
10377
+ return l;
10378
+ }
10379
+ const value = getValue$1(r);
10380
+ const sign = Math.sign(value);
10381
+ const isNumber = r.typ == exports.EnumToken.NumberTokenType || r.typ == exports.EnumToken.IdenTokenType;
10382
+ // Infinity * 0
10383
+ if (value == 0 && op == exports.EnumToken.Mul) {
10384
+ l.typ = exports.EnumToken.NaNTokenType;
10385
+ return isNumber ? l : defaultReturn;
10386
+ }
10387
+ if (isNumber) {
10388
+ // @ts-ignore
10389
+ r.val /= r.val * sign;
10390
+ }
10391
+ if (op == exports.EnumToken.Div) {
10392
+ return isNumber
10393
+ ? Object.assign(r, { typ: exports.EnumToken.NumberTokenType, val: sign < 0 ? -0 : 0 })
10394
+ : defaultReturn;
10395
+ }
10396
+ if (sign == -1) {
10397
+ l.typ =
10398
+ l.typ == exports.EnumToken.InfinityTokenType
10399
+ ? exports.EnumToken.NegativeInfinityTokenType
10400
+ : exports.EnumToken.InfinityTokenType;
10401
+ }
10402
+ return isNumber ? l : defaultReturn;
10403
+ }
10404
+ if (r.typ == exports.EnumToken.InfinityTokenType || r.typ == exports.EnumToken.NegativeInfinityTokenType) {
10405
+ const value = getValue$1(l);
10406
+ let sign = Math.sign(value);
10407
+ const isNumber = l.typ == exports.EnumToken.NumberTokenType || l.typ == exports.EnumToken.IdenTokenType;
10408
+ if (isNumber) {
10409
+ Object.assign(l, { typ: exports.EnumToken.NumberTokenType, val: sign });
10410
+ }
10411
+ if (value == 0 && op == exports.EnumToken.Mul) {
10412
+ return Object.assign(l, { typ: exports.EnumToken.NaNTokenType });
10413
+ }
10414
+ if (op == exports.EnumToken.Div) {
10415
+ return isNumber
10416
+ ? Object.assign(l, { typ: exports.EnumToken.NumberTokenType, val: sign < 0 ? -0 : 0 })
10417
+ : defaultReturn;
10418
+ }
10419
+ return l.typ == isNumber || value == 0 ? r : defaultReturn;
10420
+ }
10421
+ return defaultReturn;
10422
+ }
10216
10423
  function getValue$1(t) {
10217
10424
  if (t.typ == exports.EnumToken.IdenTokenType) {
10218
10425
  // @ts-ignore
@@ -10265,7 +10472,9 @@ function evaluateFunc(token) {
10265
10472
  }
10266
10473
  const value = evaluate(values);
10267
10474
  // @ts-ignore
10268
- let val = value[0].typ == exports.EnumToken.NumberTokenType || value[0].typ == exports.EnumToken.AngleTokenType
10475
+ let val = value[0].typ == exports.EnumToken.NumberTokenType ||
10476
+ value[0].typ == exports.EnumToken.AngleTokenType ||
10477
+ value[0].typ == exports.EnumToken.PercentageTokenType
10269
10478
  ? +value[0].val
10270
10479
  : // @ts-expect-error
10271
10480
  value[0].l.val / value[0].r.val;
@@ -10280,7 +10489,7 @@ function evaluateFunc(token) {
10280
10489
  [LOCEND]: value[0][LOCEND],
10281
10490
  }
10282
10491
  : {
10283
- typ: exports.EnumToken.NumberTokenType,
10492
+ typ: token.val == "sign" ? exports.EnumToken.NumberTokenType : value[0].typ,
10284
10493
  val: Math[token.val](val),
10285
10494
  [LOCSRCID]: value[0][LOCSRCID],
10286
10495
  [LOCSTA]: value[0][LOCSTA],
@@ -10310,10 +10519,23 @@ function evaluateFunc(token) {
10310
10519
  },
10311
10520
  ];
10312
10521
  }
10522
+ case "mod":
10313
10523
  case "atan2":
10314
10524
  case "pow":
10315
- case "rem":
10316
- case "mod": {
10525
+ case "rem": {
10526
+ {
10527
+ let typ = token.chi[0]?.typ;
10528
+ for (let i = 1; i < token.chi.length; i++) {
10529
+ if (token.chi[i].typ == exports.EnumToken.WhitespaceTokenType ||
10530
+ token.chi[i].typ == exports.EnumToken.CommaTokenType ||
10531
+ token.chi[i].typ == exports.EnumToken.CommentTokenType) {
10532
+ continue;
10533
+ }
10534
+ if (token.chi[i].typ != typ) {
10535
+ return null;
10536
+ }
10537
+ }
10538
+ }
10317
10539
  const chi = values.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ));
10318
10540
  if (token.val == "atan2") {
10319
10541
  for (let i = 0; i < chi.length; i++) {
@@ -10532,7 +10754,14 @@ function isScalarToken(token) {
10532
10754
  (token.typ == exports.EnumToken.FunctionTokenType && mathFuncs.includes(token.val)) ||
10533
10755
  // @ts-ignore
10534
10756
  (token.typ == exports.EnumToken.IdenTokenType && typeof Math[token.val.toUpperCase()] == "number") ||
10535
- [exports.EnumToken.NumberTokenType, exports.EnumToken.FractionTokenType, exports.EnumToken.PercentageTokenType].includes(token.typ));
10757
+ (token.typ == exports.EnumToken.IdenTokenType && token.val == "NaN") ||
10758
+ (token.typ == exports.EnumToken.IdenTokenType &&
10759
+ (equalsIgnoreCase(token.val, "Infinity") ||
10760
+ equalsIgnoreCase(token.val, "-Infinity"))) ||
10761
+ [exports.EnumToken.NumberTokenType, exports.EnumToken.FractionTokenType, exports.EnumToken.PercentageTokenType].includes(token.typ) ||
10762
+ token.typ == exports.EnumToken.NaNTokenType ||
10763
+ token.typ == exports.EnumToken.InfinityTokenType ||
10764
+ token.typ == exports.EnumToken.NegativeInfinityTokenType);
10536
10765
  }
10537
10766
  /**
10538
10767
  *
@@ -10934,9 +11163,10 @@ function color2cmykToken(token) {
10934
11163
  }
10935
11164
  function srgb2cmykvalues(r, g, b, a = null) {
10936
11165
  const k = 1 - Math.max(r, g, b);
10937
- const c = k == 1 ? 0 : (1 - r - k) / (1 - k);
10938
- const m = k == 1 ? 0 : (1 - g - k) / (1 - k);
10939
- const y = k == 1 ? 0 : (1 - b - k) / (1 - k);
11166
+ const div = 1 - k;
11167
+ const c = k == 1 ? 0 : (1 - r - k) / div;
11168
+ const m = k == 1 ? 0 : (1 - g - k) / div;
11169
+ const y = k == 1 ? 0 : (1 - b - k) / div;
10940
11170
  const result = [c, m, y, k];
10941
11171
  if (a != null && a < 1) {
10942
11172
  result.push(a);
@@ -11750,9 +11980,13 @@ function parseSyntax(syntax) {
11750
11980
  stack.pop();
11751
11981
  }
11752
11982
  }
11753
- if (stack.length > 0) {
11754
- throw new SyntaxError(`Unexpected token ${ValidationTokenEnum[stack.at(-1)?.typ]} at ${stack.at(-1)?.[LOC]?.lin}:${stack.at(-1)?.[LOC]?.col}`);
11755
- }
11983
+ // if (stack.length > 0) {
11984
+ // throw new SyntaxError(
11985
+ // `Unexpected token ${ValidationTokenEnum[stack.at(-1)?.typ as ValidationTokenEnum]} at ${
11986
+ // stack.at(-1)?.[LOC]?.lin
11987
+ // }:${stack.at(-1)?.[LOC]?.col}`,
11988
+ // );
11989
+ // }
11756
11990
  return trimSyntaxArray(tokens);
11757
11991
  }
11758
11992
 
@@ -11808,6 +12042,32 @@ function getSyntaxConfig() {
11808
12042
  // @ts-expect-error
11809
12043
  return config$4;
11810
12044
  }
12045
+ // export const getSyntax = memoize((group: ValidationSyntaxGroupEnum, key: string | string[]): null | string => {
12046
+ // // @ts-expect-error
12047
+ // let obj = config[group] as Record<ValidationSyntaxGroupEnum, ValidationSyntaxNode>;
12048
+ //
12049
+ // const keys: string[] = Array.isArray(key) ? key : [key];
12050
+ //
12051
+ // for (let i = 0; i < keys.length; i++) {
12052
+ // key = keys[i];
12053
+ //
12054
+ // if (!(key in obj)) {
12055
+ // if ((i == 0 && key.charAt(0) == "@") || key.charAt(0) == "-") {
12056
+ // const matches: RegExpMatchArray = key.match(/^(@?)(-[a-zA-Z]+)-(.*?)$/) as RegExpMatchArray;
12057
+ //
12058
+ // if (matches != null) {
12059
+ // key = matches[1] + matches[3];
12060
+ // }
12061
+ // }
12062
+ // }
12063
+ //
12064
+ // // @ts-expect-error
12065
+ // obj = obj[key];
12066
+ // }
12067
+ //
12068
+ // // @ts-expect-error
12069
+ // return obj?.syntax ?? null;
12070
+ // }) as (group: ValidationSyntaxGroupEnum, key: string | string[]) => null | string;
11811
12071
  function findNode(group, key) {
11812
12072
  // @ts-expect-error
11813
12073
  let obj = config$4[group];
@@ -11957,6 +12217,15 @@ function trimArray(tokens) {
11957
12217
  }
11958
12218
  return tokens;
11959
12219
  }
12220
+ /**
12221
+ * is a media feature
12222
+ * @param featureName
12223
+ * @returns
12224
+ */
12225
+ // export function isMFName(featureName: string): boolean {
12226
+ // // @ts-expect-error
12227
+ // return featureName.startsWith("--") || config.mediaFeatures[featureName.toLowerCase()] != null;
12228
+ // }
11960
12229
  /**
11961
12230
  *
11962
12231
  * @param featureName
@@ -11970,6 +12239,7 @@ function getMFInfo(featureName) {
11970
12239
  *
11971
12240
  * @param featureName
11972
12241
  * @param tokens
12242
+ * @param isMFRange
11973
12243
  * @returns object with:
11974
12244
  * - valid: boolean. true the media feaure is known or is a custom property. false otherwise
11975
12245
  * - success: boolean. validation result
@@ -12087,9 +12357,10 @@ function createValidationContext(tokens) {
12087
12357
  },
12088
12358
  /**
12089
12359
  *
12090
- * @param stopCondition
12091
- * @param matchCount
12092
12360
  * @returns
12361
+ * @param open
12362
+ * @param close
12363
+ * @param counter
12093
12364
  */
12094
12365
  peekRange(open = exports.EnumToken.StartParensTokenType, close = exports.EnumToken.EndParensTokenType, counter = 0) {
12095
12366
  let index = this.index;
@@ -12312,7 +12583,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
12312
12583
  case exports.EnumToken.CDOCOMMTokenType:
12313
12584
  break;
12314
12585
  case exports.EnumToken.NestingSelectorTokenType:
12315
- if (nested === false && !options.nestedRule) {
12586
+ if (!nested && !options.nestedRule) {
12316
12587
  return {
12317
12588
  success: false,
12318
12589
  errors: [
@@ -13353,7 +13624,8 @@ function matchSyntax(syntaxes, context, options) {
13353
13624
  errors: [],
13354
13625
  };
13355
13626
  case ValidationTokenEnum.FunctionDefinition:
13356
- if (equalsIgnoreCase(token.val, syntaxes[i].val)) {
13627
+ if (token.val &&
13628
+ equalsIgnoreCase(token.val, syntaxes[i].val)) {
13357
13629
  if (tokensfuncDefMap.has(token.typ)) {
13358
13630
  const children = trimArray(context.peekRange());
13359
13631
  result = matchSyntax((getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()")?.[0]).chi ?? [], createValidationContext(children.slice(1, -1)), options);
@@ -14378,104 +14650,6 @@ function getColorType(color) {
14378
14650
  return color.kin;
14379
14651
  }
14380
14652
 
14381
- const trimTokenSpace = new Set([
14382
- exports.EnumToken.CommaTokenType,
14383
- exports.EnumToken.DelimTokenType,
14384
- exports.EnumToken.GtTokenType,
14385
- exports.EnumToken.GteTokenType,
14386
- exports.EnumToken.LtTokenType,
14387
- exports.EnumToken.LteTokenType,
14388
- exports.EnumToken.ChildCombinatorTokenType,
14389
- ]);
14390
- const trimSpaceAfter = new Set([
14391
- ...tokensfuncSet.values(),
14392
- exports.EnumToken.ChildCombinatorTokenType,
14393
- exports.EnumToken.SupportsQueryConditionTokenType,
14394
- exports.EnumToken.SupportsQueryUnaryConditionTokenType,
14395
- ]);
14396
- /**
14397
- * Replace token in its parent node
14398
- * @param parent
14399
- * @param node
14400
- * @param replacement
14401
- * @throws TypeError replacement is null
14402
- * @throws ReferenceError node not found in parent
14403
- */
14404
- function replaceNodeOrValue(parent, node, replacement) {
14405
- if (replacement == null || (Array.isArray(replacement) && replacement.length === 0)) {
14406
- throw new TypeError(`replacement is null`);
14407
- }
14408
- for (const newNode of Array.isArray(replacement) ? replacement : [replacement]) {
14409
- if (newNode[PARENT] != node[PARENT]) {
14410
- newNode[PARENT] = node[PARENT];
14411
- }
14412
- }
14413
- if (parent.typ == exports.EnumToken.BinaryExpressionTokenType) {
14414
- if (parent.l == node) {
14415
- parent.l = replacement;
14416
- }
14417
- else if (parent.r == node) {
14418
- parent.r = replacement;
14419
- }
14420
- else {
14421
- throw new ReferenceError("Node not found");
14422
- }
14423
- }
14424
- else {
14425
- const target = "val" in parent && Array.isArray(parent.val)
14426
- ? parent.val
14427
- : (parent.chi ?? parent);
14428
- if (Array.isArray(target)) {
14429
- // @ts-ignore
14430
- const index = target.indexOf(node);
14431
- if (index == -1) {
14432
- throw new ReferenceError("Node not found");
14433
- }
14434
- target.splice(index, 1, ...(Array.isArray(replacement) ? replacement : [replacement]));
14435
- }
14436
- else if ("l" in target && target.l == node) {
14437
- target.l = replacement;
14438
- }
14439
- else if ("r" in target && target.r == node) {
14440
- target.r = replacement;
14441
- }
14442
- else {
14443
- throw new ReferenceError("Node not found");
14444
- }
14445
- }
14446
- node[PARENT] = null;
14447
- return true;
14448
- }
14449
- function trimWhiteSpaceTokens(tokens) {
14450
- let i = 0;
14451
- if (tokens[0]?.typ === exports.EnumToken.WhitespaceTokenType) {
14452
- tokens.shift();
14453
- }
14454
- if (tokens[tokens.length - 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
14455
- tokens.pop();
14456
- }
14457
- if (tokens.length === 1) {
14458
- if (tokens[0].typ === exports.EnumToken.WhitespaceTokenType) {
14459
- tokens.length = 0;
14460
- }
14461
- return tokens;
14462
- }
14463
- for (; i < tokens.length; i++) {
14464
- if (trimSpaceAfter.has(tokens[i].typ) && tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
14465
- tokens.splice(i + 1, 1);
14466
- }
14467
- else if (trimTokenSpace.has(tokens[i].typ)) {
14468
- if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
14469
- tokens.splice(i + 1, 1);
14470
- }
14471
- if (i > 0 && tokens[i - 1].typ === exports.EnumToken.Whitespace) {
14472
- tokens.splice(--i, 1);
14473
- }
14474
- }
14475
- }
14476
- return tokens;
14477
- }
14478
-
14479
14653
  /**
14480
14654
  * Compute alpha color
14481
14655
  * @param color
@@ -14486,40 +14660,76 @@ function alpha(color, alpha) {
14486
14660
  if (alpha == null) {
14487
14661
  return color;
14488
14662
  }
14663
+ // https://www.w3.org/TR/css-color-5/#:~:text=There%20is%20no%20relative%20device%2Dcmyk%28%29%20syntax
14489
14664
  if (color.kin === exports.ColorType.DEVICE_CMYK) {
14490
14665
  return null;
14491
14666
  }
14667
+ let components = getColorComponents(color);
14668
+ if (alpha.typ === exports.EnumToken.MathFunctionTokenType) {
14669
+ const originalAlpha = cloneNode(alpha, true);
14670
+ for (const { value } of walkValues(alpha.chi, alpha)) {
14671
+ if (value.typ === exports.EnumToken.IdenTokenType) {
14672
+ if (equalsIgnoreCase(value.val, "alpha")) {
14673
+ Object.assign(value, components?.[3]
14674
+ ? cloneNode(components[3], true)
14675
+ : {
14676
+ typ: exports.EnumToken.NumberTokenType,
14677
+ val: 1,
14678
+ });
14679
+ // continue;
14680
+ }
14681
+ else if (equalsIgnoreCase(value.val, "none")) {
14682
+ Object.assign(value, {
14683
+ typ: exports.EnumToken.NumberTokenType,
14684
+ val: 0,
14685
+ });
14686
+ }
14687
+ }
14688
+ }
14689
+ const result = evaluate([alpha]);
14690
+ if (result.length == 1) {
14691
+ alpha = result[0];
14692
+ }
14693
+ else {
14694
+ // @ts-expect-error
14695
+ alpha = originalAlpha;
14696
+ }
14697
+ }
14698
+ // console.error({ alpha });
14699
+ if (alpha.typ !== exports.EnumToken.IdenTokenType &&
14700
+ alpha.typ !== exports.EnumToken.NumberTokenType &&
14701
+ alpha.typ !== exports.EnumToken.PercentageTokenType) {
14702
+ return null;
14703
+ }
14704
+ if (alpha.typ === exports.EnumToken.IdenTokenType) {
14705
+ if (equalsIgnoreCase(alpha.val, "NaN") ||
14706
+ equalsIgnoreCase(alpha.val, "Infinity") ||
14707
+ equalsIgnoreCase(alpha.val, "-Infinity")) {
14708
+ return null;
14709
+ }
14710
+ }
14492
14711
  if (color.kin === exports.ColorType.COLOR_MIX || color.cal === "rel") {
14493
14712
  color = convertColor(color, getColorType(color));
14494
14713
  if (color == null) {
14495
14714
  return null;
14496
14715
  }
14716
+ components = getColorComponents(color);
14497
14717
  }
14498
- const components = getColorComponents(color);
14499
14718
  if (components == null) {
14500
14719
  return null;
14501
14720
  }
14502
- if (alpha?.typ === exports.EnumToken.IdenTokenType && equalsIgnoreCase(alpha.val, "alpha")) {
14503
- alpha = components[3] ?? {
14504
- typ: exports.EnumToken.NumberTokenType,
14505
- val: 1,
14506
- };
14507
- }
14508
- else if (alpha.typ === exports.EnumToken.MathFunctionTokenType &&
14509
- equalsIgnoreCase(alpha.val, "calc")) {
14510
- alpha = cloneNode(alpha, true);
14511
- const alphaValue = components[3] ?? {
14512
- typ: exports.EnumToken.NumberTokenType,
14513
- val: 1,
14514
- };
14515
- for (const { value, parent } of walkValues(alpha.chi, alpha)) {
14516
- if (value.typ === exports.EnumToken.IdenTokenType && equalsIgnoreCase(value.val, "alpha")) {
14517
- replaceNodeOrValue(parent, value, alphaValue);
14518
- }
14721
+ if (alpha?.typ === exports.EnumToken.IdenTokenType) {
14722
+ if (equalsIgnoreCase(alpha.val, "alpha")) {
14723
+ alpha = components[3] ?? {
14724
+ typ: exports.EnumToken.NumberTokenType,
14725
+ val: 1,
14726
+ };
14519
14727
  }
14520
- const result = evaluate([alpha]);
14521
- if (result.length == 1) {
14522
- alpha = result[0];
14728
+ else if (equalsIgnoreCase(alpha.val, "node")) {
14729
+ alpha = {
14730
+ typ: exports.EnumToken.NumberTokenType,
14731
+ val: 0,
14732
+ };
14523
14733
  }
14524
14734
  }
14525
14735
  return makeColor(color.kin, components, alpha);
@@ -15089,11 +15299,11 @@ function getAngle(token) {
15089
15299
 
15090
15300
  /**
15091
15301
  * Calculate the distance between two okLab colors.
15092
- * @param okLab1
15093
- * @param okLab2
15094
15302
  *
15095
15303
  * @private
15096
15304
  * {@link https://drafts.csswg.org/css-color-4/#comparing-color-values}
15305
+ * @param color1
15306
+ * @param color2
15097
15307
  */
15098
15308
  function okLabDistance(color1, color2) {
15099
15309
  color1 = convertColor(color1, exports.ColorType.OKLAB);
@@ -15422,6 +15632,300 @@ const pseudoAliasMap = {
15422
15632
  ":-moz-ui-valid": ":user-valid",
15423
15633
  "::-moz-selection": "::selection",
15424
15634
  };
15635
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions
15636
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-scrollbar
15637
+ // export const webkitExtensions = new Set([
15638
+ // "-webkit-app-region",
15639
+ // "-webkit-border-horizontal-spacing",
15640
+ // "-webkit-border-vertical-spacing",
15641
+ // "-webkit-box-reflect",
15642
+ // "-webkit-column-axis",
15643
+ // "-webkit-column-progression",
15644
+ // "-webkit-cursor-visibility",
15645
+ // "-webkit-font-smoothing",
15646
+ // "-webkit-hyphenate-limit-after",
15647
+ // "-webkit-hyphenate-limit-before",
15648
+ // "-webkit-hyphenate-limit-lines",
15649
+ // "-webkit-line-align",
15650
+ // "-webkit-line-box-contain",
15651
+ // "-webkit-line-clamp",
15652
+ // "-webkit-line-grid",
15653
+ // "-webkit-line-snap",
15654
+ // "-webkit-locale",
15655
+ // "-webkit-logical-height",
15656
+ // "-webkit-logical-width",
15657
+ // "-webkit-margin-after",
15658
+ // "-webkit-margin-before",
15659
+ // "-webkit-mask-box-image-outset",
15660
+ // "-webkit-mask-box-image-repeat",
15661
+ // "-webkit-mask-box-image-slice",
15662
+ // "-webkit-mask-box-image-source",
15663
+ // "-webkit-mask-box-image-width",
15664
+ // "-webkit-mask-box-image",
15665
+ // "-webkit-mask-composite",
15666
+ // "-webkit-mask-position-x",
15667
+ // "-webkit-mask-position-y",
15668
+ // "-webkit-mask-repeat-x",
15669
+ // "-webkit-mask-repeat-y",
15670
+ // "-webkit-mask-source-type",
15671
+ // "-webkit-max-logical-height",
15672
+ // "-webkit-max-logical-width",
15673
+ // "-webkit-min-logical-height",
15674
+ // "-webkit-min-logical-width",
15675
+ // "-webkit-nbsp-mode",
15676
+ // "-webkit-match-parent",
15677
+ // "-webkit-perspective-origin-x",
15678
+ // "-webkit-perspective-origin-y",
15679
+ // "-webkit-rtl-ordering",
15680
+ // "-webkit-tap-highlight-color",
15681
+ // "-webkit-text-decoration-skip",
15682
+ // "-webkit-text-decorations-in-effect",
15683
+ // "-webkit-text-fill-color",
15684
+ // "-webkit-text-security",
15685
+ // "-webkit-text-stroke-color",
15686
+ // "-webkit-text-stroke-width",
15687
+ // "-webkit-text-stroke",
15688
+ // "-webkit-text-zoom",
15689
+ // "-webkit-touch-callout",
15690
+ // "-webkit-transform-origin-x",
15691
+ // "-webkit-transform-origin-y",
15692
+ // "-webkit-transform-origin-z",
15693
+ // "-webkit-user-drag",
15694
+ // "-webkit-user-modify",
15695
+ // "-webkit-border-after",
15696
+ // "-webkit-border-after-color",
15697
+ // "-webkit-border-after-style",
15698
+ // "-webkit-border-after-width",
15699
+ // "-webkit-border-before",
15700
+ // "-webkit-border-before-color",
15701
+ // "-webkit-border-before-style",
15702
+ // "-webkit-border-before-width",
15703
+ // "-webkit-border-end",
15704
+ // "-webkit-border-end-color",
15705
+ // "-webkit-border-end-style",
15706
+ // "-webkit-border-end-width",
15707
+ // "-webkit-border-start",
15708
+ // "-webkit-border-start-color",
15709
+ // "-webkit-border-start-style",
15710
+ // "-webkit-border-start-width",
15711
+ // "-webkit-box-align",
15712
+ // "-webkit-box-direction",
15713
+ // "-webkit-box-flex-group",
15714
+ // "-webkit-box-flex",
15715
+ // "-webkit-box-lines",
15716
+ // "-webkit-box-ordinal-group",
15717
+ // "-webkit-box-orient",
15718
+ // "-webkit-box-pack",
15719
+ // "-webkit-column-break-after",
15720
+ // "-webkit-column-break-before",
15721
+ // "-webkit-column-break-inside",
15722
+ // "-webkit-font-feature-settings",
15723
+ // "-webkit-hyphenate-character",
15724
+ // "-webkit-initial-letter",
15725
+ // "-webkit-margin-end",
15726
+ // "-webkit-margin-start",
15727
+ // "-webkit-padding-after",
15728
+ // "-webkit-padding-before",
15729
+ // "-webkit-padding-end",
15730
+ // "-webkit-padding-start",
15731
+ // "-webkit-fill-available",
15732
+ // ":-webkit-animating-full-screen-transition",
15733
+ // ":-webkit-any",
15734
+ // ":-webkit-any-link",
15735
+ // ":-webkit-autofill",
15736
+ // ":-webkit-autofill-strong-password",
15737
+ // ":-webkit-drag",
15738
+ // ":-webkit-full-page-media",
15739
+ // ":-webkit-full-screen*",
15740
+ // ":-webkit-full-screen-ancestor",
15741
+ // ":-webkit-full-screen-document",
15742
+ // ":-webkit-full-screen-controls-hidden",
15743
+ // "::-webkit-file-upload-button*",
15744
+ // "::-webkit-inner-spin-button",
15745
+ // "::-webkit-input-placeholder",
15746
+ // "::-webkit-meter-bar",
15747
+ // "::-webkit-meter-even-less-good-value",
15748
+ // "::-webkit-meter-inner-element",
15749
+ // "::-webkit-meter-optimum-value",
15750
+ // "::-webkit-meter-suboptimum-value",
15751
+ // "::-webkit-progress-bar",
15752
+ // "::-webkit-progress-inner-element",
15753
+ // "::-webkit-progress-value",
15754
+ // "::-webkit-search-cancel-button",
15755
+ // "::-webkit-search-results-button",
15756
+ // "::-webkit-slider-runnable-track",
15757
+ // "::-webkit-slider-thumb",
15758
+ // "-webkit-animation",
15759
+ // "-webkit-device-pixel-ratio",
15760
+ // "-webkit-transform-2d",
15761
+ // "-webkit-transform-3d",
15762
+ // "-webkit-transition",
15763
+ // "::-webkit-scrollbar",
15764
+ // "::-webkit-scrollbar-button",
15765
+ // "::-webkit-scrollbar",
15766
+ // "::-webkit-scrollbar-thumb",
15767
+ // "::-webkit-scrollbar-track",
15768
+ // "::-webkit-scrollbar-track-piece",
15769
+ // "::-webkit-scrollbar:vertical",
15770
+ // "::-webkit-scrollbar-corner ",
15771
+ // "::-webkit-resizer",
15772
+ // ":vertical",
15773
+ // ":horizontal",
15774
+ // ]);
15775
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions
15776
+ // export const mozExtensions = new Set([
15777
+ // "-moz-box-align",
15778
+ // "-moz-box-direction",
15779
+ // "-moz-box-flex",
15780
+ // "-moz-box-ordinal-group",
15781
+ // "-moz-box-orient",
15782
+ // "-moz-box-pack",
15783
+ // "-moz-float-edge",
15784
+ // "-moz-force-broken-image-icon",
15785
+ // "-moz-image-region",
15786
+ // "-moz-orient",
15787
+ // "-moz-osx-font-smoothing",
15788
+ // "-moz-user-focus",
15789
+ // "-moz-user-input",
15790
+ // "-moz-user-modify",
15791
+ // "-moz-animation",
15792
+ // "-moz-animation-delay",
15793
+ // "-moz-animation-direction",
15794
+ // "-moz-animation-duration",
15795
+ // "-moz-animation-fill-mode",
15796
+ // "-moz-animation-iteration-count",
15797
+ // "-moz-animation-name",
15798
+ // "-moz-animation-play-state",
15799
+ // "-moz-animation-timing-function",
15800
+ // "-moz-appearance",
15801
+ // "-moz-backface-visibility",
15802
+ // "-moz-background-clip",
15803
+ // "-moz-background-origin",
15804
+ // "-moz-background-inline-policy",
15805
+ // "-moz-background-size",
15806
+ // "-moz-border-end",
15807
+ // "-moz-border-end-color",
15808
+ // "-moz-border-end-style",
15809
+ // "-moz-border-end-width",
15810
+ // "-moz-border-image",
15811
+ // "-moz-border-start",
15812
+ // "-moz-border-start-color",
15813
+ // "-moz-border-start-style",
15814
+ // "-moz-border-start-width",
15815
+ // "-moz-box-sizing",
15816
+ // "clip-path",
15817
+ // "-moz-column-count",
15818
+ // "-moz-column-fill",
15819
+ // "-moz-column-gap",
15820
+ // "-moz-column-width",
15821
+ // "-moz-column-rule",
15822
+ // "-moz-column-rule-width",
15823
+ // "-moz-column-rule-style",
15824
+ // "-moz-column-rule-color",
15825
+ // "filter",
15826
+ // "-moz-font-feature-settings",
15827
+ // "-moz-font-language-override",
15828
+ // "-moz-hyphens",
15829
+ // "-moz-margin-end",
15830
+ // "-moz-margin-start",
15831
+ // "mask",
15832
+ // "-moz-opacity",
15833
+ // "-moz-outline",
15834
+ // "-moz-outline-color",
15835
+ // "-moz-outline-offset",
15836
+ // "-moz-outline-style",
15837
+ // "-moz-outline-width",
15838
+ // "-moz-padding-end",
15839
+ // "-moz-padding-start",
15840
+ // "-moz-perspective",
15841
+ // "-moz-perspective-origin",
15842
+ // "pointer-events",
15843
+ // "-moz-tab-size",
15844
+ // "-moz-text-align-last",
15845
+ // "-moz-text-decoration-color",
15846
+ // "-moz-text-decoration-line",
15847
+ // "-moz-text-decoration-style",
15848
+ // "-moz-text-size-adjust",
15849
+ // "-moz-transform",
15850
+ // "-moz-transform-origin",
15851
+ // "-moz-transform-style",
15852
+ // "-moz-transition",
15853
+ // "-moz-transition-delay",
15854
+ // "-moz-transition-duration",
15855
+ // "-moz-transition-property",
15856
+ // "-moz-transition-timing-function",
15857
+ // "-moz-user-select",
15858
+ // "-moz-initial",
15859
+ // "-moz-appearance",
15860
+ // "-moz-linear-gradient",
15861
+ // "-moz-radial-gradient",
15862
+ // "-moz-element",
15863
+ // "-moz-image-rect",
15864
+ // "::-moz-anonymous-block",
15865
+ // "::-moz-anonymous-positioned-block",
15866
+ // ":-moz-any",
15867
+ // ":-moz-any-link",
15868
+ // ":-moz-broken",
15869
+ // "::-moz-canvas",
15870
+ // "::-moz-color-swatch",
15871
+ // "::-moz-cell-content",
15872
+ // ":-moz-drag-over",
15873
+ // ":-moz-first-node",
15874
+ // "::-moz-focus-inner",
15875
+ // "::-moz-focus-outer",
15876
+ // ":-moz-full-screen",
15877
+ // ":-moz-full-screen-ancestor",
15878
+ // ":-moz-handler-blocked",
15879
+ // ":-moz-handler-crashed",
15880
+ // ":-moz-handler-disabled",
15881
+ // "::-moz-inline-table",
15882
+ // ":-moz-last-node",
15883
+ // "::-moz-list-bullet",
15884
+ // "::-moz-list-number",
15885
+ // ":-moz-loading",
15886
+ // ":-moz-locale-dir",
15887
+ // ":-moz-locale-dir",
15888
+ // ":-moz-lwtheme",
15889
+ // ":-moz-lwtheme-brighttext",
15890
+ // ":-moz-lwtheme-darktext",
15891
+ // "::-moz-meter-bar",
15892
+ // ":-moz-native-anonymous",
15893
+ // ":-moz-only-whitespace",
15894
+ // "::-moz-pagebreak",
15895
+ // "::-moz-pagecontent",
15896
+ // ":-moz-placeholder",
15897
+ // "::-moz-placeholder",
15898
+ // "::-moz-progress-bar",
15899
+ // "::-moz-range-progress",
15900
+ // "::-moz-range-thumb",
15901
+ // "::-moz-range-track",
15902
+ // ":-moz-read-only",
15903
+ // ":-moz-read-write",
15904
+ // "::-moz-scrolled-canvas",
15905
+ // "::-moz-scrolled-content",
15906
+ // "::-moz-selection",
15907
+ // ":-moz-submit-invalid",
15908
+ // ":-moz-suppressed",
15909
+ // "::-moz-svg-foreign-content",
15910
+ // "::-moz-table",
15911
+ // "::-moz-table-cell",
15912
+ // "::-moz-table-column",
15913
+ // "::-moz-table-column-group",
15914
+ // "::-moz-table-outer",
15915
+ // "::-moz-table-row",
15916
+ // "::-moz-table-row-group",
15917
+ // ":-moz-ui-invalid",
15918
+ // ":-moz-ui-valid",
15919
+ // ":-moz-user-disabled",
15920
+ // "::-moz-viewport",
15921
+ // "::-moz-viewport-scroll",
15922
+ // ":-moz-window-inactive",
15923
+ // "-moz-device-pixel-ratio",
15924
+ // "-moz-os-version",
15925
+ // "-moz-touch-enabled",
15926
+ // "-moz-windows-glass",
15927
+ // "-moz-alt-content",
15928
+ // ]);
15425
15929
  // renamed standard properties
15426
15930
  const renamedStandardProperties = new Map([["color-adjust", "print-color-adjust"]]);
15427
15931
  function isLength(dimension) {
@@ -15440,8 +15944,36 @@ function isFrequency(dimension) {
15440
15944
  return "unit" in dimension && frequencyUnits.includes(dimension.unit.toLowerCase());
15441
15945
  }
15442
15946
  /**
15443
- * Reduce color stops
15444
- * @param stops
15947
+ * Is color space
15948
+ * @param token
15949
+ * @returns
15950
+ */
15951
+ // export function isColorspace(token: Token): boolean {
15952
+ // return (
15953
+ // token.typ === EnumToken.IdenTokenType &&
15954
+ // [
15955
+ // "srgb",
15956
+ // "srgb-linear",
15957
+ // "lab",
15958
+ // "oklab",
15959
+ // "lch",
15960
+ // "oklch",
15961
+ // "xyz",
15962
+ // "xyz-d50",
15963
+ // "xyz-d65",
15964
+ // "display-p3",
15965
+ // "a98-rgb",
15966
+ // "prophoto-rgb",
15967
+ // "rec2020",
15968
+ // "rgb",
15969
+ // "hsl",
15970
+ // "hwb",
15971
+ // ].includes((token as IdentToken).val.toLowerCase())
15972
+ // );
15973
+ // }
15974
+ /**
15975
+ * Reduce color stops
15976
+ * @param stops
15445
15977
  * @returns
15446
15978
  */
15447
15979
  function reduceColorStops(stops) {
@@ -15636,6 +16168,26 @@ function isPolarColorspace(token) {
15636
16168
  return (token.typ === exports.EnumToken.IdenTokenType &&
15637
16169
  ["hsl", "hwb", "lch", "oklch"].some((t) => equalsIgnoreCase(t, token.val)));
15638
16170
  }
16171
+ /**
16172
+ * Is hue interpolation method
16173
+ * @param token
16174
+ * @returns
16175
+ */
16176
+ // export function isHueInterpolationMethod(token: Token | Token[]): boolean {
16177
+ // if (!Array.isArray(token)) {
16178
+ // return token.typ == EnumToken.IdenTokenType && "hue" === (token as IdentToken).val?.toLowerCase?.();
16179
+ // }
16180
+ //
16181
+ // if (token.length != 2 || token[0].typ != EnumToken.IdenTokenType || token[1].typ != EnumToken.IdenTokenType) {
16182
+ // return false;
16183
+ // }
16184
+ //
16185
+ // return (
16186
+ // ["shorter", "longer", "increasing", "decreasing"].some((t) =>
16187
+ // equalsIgnoreCase(t, (token[0] as IdentToken).val ?? ""),
16188
+ // ) && "hue" === (token[1] as IdentToken).val?.toLowerCase?.()
16189
+ // );
16190
+ // }
15639
16191
  /**
15640
16192
  * Is ident color
15641
16193
  * @param token
@@ -15646,6 +16198,12 @@ function isIdentColor(token) {
15646
16198
  [exports.ColorType.SYS, exports.ColorType.DPSYS, exports.ColorType.LIT].includes(token.kin) &&
15647
16199
  isIdent(token.val));
15648
16200
  }
16201
+ // export function isPercentageToken(token: Token): boolean {
16202
+ // return (
16203
+ // token.typ == EnumToken.PercentageTokenType ||
16204
+ // (token.typ == EnumToken.NumberTokenType && (token as NumberToken).val == 0)
16205
+ // );
16206
+ // }
15649
16207
  function isColor(token, errors) {
15650
16208
  if (token.typ == exports.EnumToken.WildCardFunctionTokenType) {
15651
16209
  return true;
@@ -15909,21 +16467,33 @@ function isColor(token, errors) {
15909
16467
  return true;
15910
16468
  }
15911
16469
  else {
15912
- // @ts-ignore
15913
- if (["rgb", "hsl", "hwb", "lab", "lch", "oklab", "oklch"].some((t) => equalsIgnoreCase(t, token.val))) {
15914
- for (const keyword of token.val.slice(-3).split("")) {
15915
- }
15916
- }
16470
+ // const keywords: string[] = ["from", "none"];
16471
+ //
16472
+ // // @ts-ignore
16473
+ // if (
16474
+ // ["rgb", "hsl", "hwb", "lab", "lch", "oklab", "oklch"].some((t) =>
16475
+ // equalsIgnoreCase(t, (token as ColorToken).val),
16476
+ // )
16477
+ // ) {
16478
+ // // @ts-ignore
16479
+ // keywords.push("alpha");
16480
+ //
16481
+ // for (const keyword of (token as ColorToken).val.slice(-3).split("")) {
16482
+ // keywords.push(keyword);
16483
+ // }
16484
+ // }
15917
16485
  // @ts-ignore
15918
16486
  for (const v of token.chi) {
15919
- if (v.typ == exports.EnumToken.IdenTokenType) {
15920
- continue;
15921
- }
15922
- if (v.typ === exports.EnumToken.MathFunctionTokenType ||
15923
- v.typ === exports.EnumToken.WildCardFunctionTokenType ||
15924
- colorsFunc.includes(v.val)) {
15925
- continue;
15926
- }
16487
+ // if (v.typ == EnumToken.IdenTokenType) {
16488
+ // continue;
16489
+ // }
16490
+ // if (
16491
+ // v.typ === EnumToken.MathFunctionTokenType ||
16492
+ // v.typ === EnumToken.WildCardFunctionTokenType ||
16493
+ // colorsFunc.includes(v.val)
16494
+ // ) {
16495
+ // continue;
16496
+ // }
15927
16497
  }
15928
16498
  }
15929
16499
  return true;
@@ -16069,6 +16639,44 @@ function isNonPrintable(codepoint) {
16069
16639
  codepoint == 0x7f ||
16070
16640
  (codepoint >= 0xe && codepoint <= 0x1f));
16071
16641
  }
16642
+ // export function isURLToken(str: string): boolean {
16643
+ // let i: number = -1;
16644
+ // let c: number;
16645
+ //
16646
+ // while (++i < str.length) {
16647
+ // c = str.charCodeAt(i) as number;
16648
+ //
16649
+ // // single quote or double quote or start parenthesis or close parenthesis
16650
+ // if (isNonPrintable(c) || c == 0x27 || c == 0x22 || c == 0x28 || c == 0x29) {
16651
+ // return false;
16652
+ // }
16653
+ //
16654
+ // // valid escape
16655
+ // if (c == REVERSE_SOLIDUS) {
16656
+ // i++;
16657
+ //
16658
+ // if (i >= str.length) {
16659
+ // return false;
16660
+ // }
16661
+ //
16662
+ // c = str.charCodeAt(i) as number;
16663
+ //
16664
+ // // c is not '\n' or '\r' or '\f'
16665
+ // if (c == 0x6e || c == 0x72 || c == 0x66) {
16666
+ // return false;
16667
+ // }
16668
+ //
16669
+ // continue;
16670
+ // }
16671
+ //
16672
+ // // is white space
16673
+ // if (c == 0x20 || c == 0x09) {
16674
+ // break;
16675
+ // }
16676
+ // }
16677
+ //
16678
+ // return i == str.length;
16679
+ // }
16072
16680
  function isPseudo(name) {
16073
16681
  return (name.charAt(0) == ":" &&
16074
16682
  ((name.endsWith("(") && isIdent(name.charAt(1) == ":" ? name.slice(2, -1) : name.slice(1, -1))) ||
@@ -16077,6 +16685,94 @@ function isPseudo(name) {
16077
16685
  function isHash(name) {
16078
16686
  return name.charAt(0) == "#" && isIdentStart(name.charCodeAt(1));
16079
16687
  }
16688
+ // export const isNumber = memoize(function (name: string): boolean {
16689
+ // let codepoint: number = name.charCodeAt(0) as number;
16690
+ // let i: number = 0;
16691
+ // const j: number = name.length;
16692
+ //
16693
+ // if (j == 1 && !isDigit(codepoint)) {
16694
+ // return false;
16695
+ // }
16696
+ //
16697
+ // // '+' '-'
16698
+ // if ([0x2b, 0x2d].includes(codepoint)) {
16699
+ // i++;
16700
+ // }
16701
+ //
16702
+ // // consume digits
16703
+ // while (i < j) {
16704
+ // codepoint = name.charCodeAt(i) as number;
16705
+ //
16706
+ // if (isDigit(codepoint)) {
16707
+ // i++;
16708
+ // continue;
16709
+ // }
16710
+ //
16711
+ // // '.' 'E' 'e'
16712
+ // if (codepoint == 0x2e || codepoint == 0x45 || codepoint == 0x65) {
16713
+ // break;
16714
+ // }
16715
+ //
16716
+ // return false;
16717
+ // }
16718
+ //
16719
+ // // '.'
16720
+ // if (codepoint == 0x2e) {
16721
+ // if (!isDigit(name.charCodeAt(++i) as number)) {
16722
+ // return false;
16723
+ // }
16724
+ // }
16725
+ //
16726
+ // while (i < j) {
16727
+ // codepoint = name.charCodeAt(i) as number;
16728
+ //
16729
+ // if (isDigit(codepoint)) {
16730
+ // i++;
16731
+ // continue;
16732
+ // }
16733
+ //
16734
+ // // 'E' 'e'
16735
+ // if (codepoint == 0x45 || codepoint == 0x65) {
16736
+ // i++;
16737
+ // break;
16738
+ // }
16739
+ //
16740
+ // return false;
16741
+ // }
16742
+ //
16743
+ // // 'E' 'e'
16744
+ // if (codepoint == 0x45 || codepoint == 0x65) {
16745
+ // // if (i == j) {
16746
+ // // return false;
16747
+ // // }
16748
+ //
16749
+ // codepoint = name.charCodeAt(i + 1) as number;
16750
+ //
16751
+ // // '+' '-'
16752
+ // // if ([0x2b, 0x2d].includes(codepoint)) {
16753
+ // // i++;
16754
+ // // }
16755
+ //
16756
+ // codepoint = name.charCodeAt(i + 1) as number;
16757
+ //
16758
+ // if (!isDigit(codepoint)) {
16759
+ // return false;
16760
+ // }
16761
+ // }
16762
+ //
16763
+ // // while (++i < j) {
16764
+ // // codepoint = name.charCodeAt(i) as number;
16765
+ //
16766
+ // // if (!isDigit(codepoint)) {
16767
+ // // return false;
16768
+ // // }
16769
+ // // }
16770
+ //
16771
+ // return true;
16772
+ // }) as (name: string) => boolean;
16773
+ // export function isPercentage(name: string) {
16774
+ // return name.endsWith("%") && isNumber(name.slice(0, -1));
16775
+ // }
16080
16776
  function isFlex(dimension) {
16081
16777
  return "unit" in dimension && "fr" == dimension.unit.toLowerCase();
16082
16778
  }
@@ -16131,9 +16827,33 @@ function parseDimension(name) {
16131
16827
  }
16132
16828
  return dimension;
16133
16829
  }
16830
+ // export function isHexColor(name: string): boolean {
16831
+ // if (name.charAt(0) != "#" || ![4, 5, 7, 9].includes(name.length)) {
16832
+ // return false;
16833
+ // }
16834
+ //
16835
+ // for (let chr of name.slice(1)) {
16836
+ // let codepoint: number = chr.charCodeAt(0) as number;
16837
+ //
16838
+ // if (
16839
+ // !isDigit(codepoint) &&
16840
+ // // A-F
16841
+ // !(codepoint >= 0x41 && codepoint <= 0x46) &&
16842
+ // // a-f
16843
+ // !(codepoint >= 0x61 && codepoint <= 0x66)
16844
+ // ) {
16845
+ // return false;
16846
+ // }
16847
+ // }
16848
+ //
16849
+ // return true;
16850
+ // }
16134
16851
  function isFunction(name) {
16135
16852
  return name.endsWith("(") && isIdent(name.slice(0, -1));
16136
16853
  }
16854
+ // export function isAtKeyword(name: string): boolean {
16855
+ // return name.charCodeAt(0) == 0x40 && isIdent(name.slice(1));
16856
+ // }
16137
16857
  function isNewLine(codepoint) {
16138
16858
  // \n \r \f \v
16139
16859
  return (codepoint == 0xa ||
@@ -16154,6 +16874,32 @@ function isWhiteSpace(codepoint) {
16154
16874
  codepoint == 0x2028 ||
16155
16875
  codepoint == 0x2029);
16156
16876
  }
16877
+ // export function isValue(token: Token) {
16878
+ // if (token == null) {
16879
+ // return false;
16880
+ // }
16881
+ //
16882
+ // return (
16883
+ // token.typ === EnumToken.IdenTokenType ||
16884
+ // token.typ === EnumToken.DimensionTokenType ||
16885
+ // token.typ === EnumToken.LengthTokenType ||
16886
+ // token.typ === EnumToken.AngleTokenType ||
16887
+ // token.typ === EnumToken.FlexTokenType ||
16888
+ // token.typ === EnumToken.TimeTokenType ||
16889
+ // token.typ === EnumToken.ResolutionTokenType ||
16890
+ // token.typ === EnumToken.FrequencyTokenType ||
16891
+ // token.typ === EnumToken.NumberTokenType ||
16892
+ // token.typ === EnumToken.ColorTokenType ||
16893
+ // token.typ === EnumToken.FunctionTokenType ||
16894
+ // token.typ === EnumToken.UrlFunctionTokenType ||
16895
+ // token.typ === EnumToken.GridTemplateFuncTokenType ||
16896
+ // token.typ === EnumToken.ImageFunctionTokenType ||
16897
+ // token.typ === EnumToken.TimelineFunctionTokenType ||
16898
+ // token.typ === EnumToken.TimingFunctionTokenType ||
16899
+ // token.typ === EnumToken.MathFunctionTokenType ||
16900
+ // token.typ === EnumToken.TransformFunctionTokenType
16901
+ // );
16902
+ // }
16157
16903
  // https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Values_and_units#absolute_length_units
16158
16904
  /**
16159
16905
  * Convert length to px
@@ -16236,6 +16982,12 @@ function toPrecisionAngle(angle, precision = anglePrecision, correctValue = true
16236
16982
  return angle;
16237
16983
  }
16238
16984
 
16985
+ /**
16986
+ *
16987
+ * @param a
16988
+ * @param b
16989
+ * @returns
16990
+ */
16239
16991
  function eq(a, b) {
16240
16992
  if (a == null || b == null) {
16241
16993
  return a == b;
@@ -16315,7 +17067,6 @@ function replaceAstNodes(tokens, root) {
16315
17067
  token.val = pseudoAliasMap[token.val];
16316
17068
  if ((equalsIgnoreCase(token.val, "min-resolution") ||
16317
17069
  equalsIgnoreCase(token.val, "max-resolution")) &&
16318
- // ["min-resolution", "max-resolution"].includes((token as IdentToken).val) &&
16319
17070
  value.r?.[0]?.typ == exports.EnumToken.NumberTokenType) {
16320
17071
  Object.assign(value.r?.[0], {
16321
17072
  typ: exports.EnumToken.ResolutionTokenType,
@@ -16323,6 +17074,14 @@ function replaceAstNodes(tokens, root) {
16323
17074
  });
16324
17075
  result = true;
16325
17076
  }
17077
+ let isMin = token.val.startsWith("min-");
17078
+ let isMax = token.val.startsWith("max-");
17079
+ if (isMin || isMax) {
17080
+ token.val = token.val.slice(4);
17081
+ value.op.typ = isMax
17082
+ ? exports.EnumToken.LteTokenType
17083
+ : exports.EnumToken.GteTokenType;
17084
+ }
16326
17085
  }
16327
17086
  }
16328
17087
  }
@@ -16355,6 +17114,7 @@ function replaceAstNodes(tokens, root) {
16355
17114
  }
16356
17115
  }
16357
17116
  }
17117
+ // remove duplicate tokens
16358
17118
  if (tokens.find((t) => t.typ == exports.EnumToken.CommaTokenType) != null) {
16359
17119
  const set = new Set();
16360
17120
  const split = splitTokenList(tokens, [exports.EnumToken.CommaTokenType]);
@@ -17215,6 +17975,65 @@ var properties = {
17215
17975
  "padding-left": {
17216
17976
  shorthand: "padding"
17217
17977
  },
17978
+ "scroll-margin": {
17979
+ shorthand: "scroll-margin",
17980
+ properties: [
17981
+ "scroll-margin-top",
17982
+ "scroll-margin-right",
17983
+ "scroll-margin-bottom",
17984
+ "scroll-margin-left"
17985
+ ],
17986
+ types: [
17987
+ "Length",
17988
+ "Perc"
17989
+ ],
17990
+ "default": [
17991
+ "0"
17992
+ ],
17993
+ keywords: [
17994
+ "auto"
17995
+ ]
17996
+ },
17997
+ "scroll-margin-top": {
17998
+ shorthand: "scroll-margin"
17999
+ },
18000
+ "scroll-margin-right": {
18001
+ shorthand: "scroll-margin"
18002
+ },
18003
+ "scroll-margin-bottom": {
18004
+ shorthand: "scroll-margin"
18005
+ },
18006
+ "scroll-margin-left": {
18007
+ shorthand: "scroll-margin"
18008
+ },
18009
+ "scroll-padding": {
18010
+ shorthand: "scroll-padding",
18011
+ properties: [
18012
+ "scroll-padding-top",
18013
+ "scroll-padding-right",
18014
+ "scroll-padding-bottom",
18015
+ "scroll-padding-left"
18016
+ ],
18017
+ types: [
18018
+ "Length",
18019
+ "Perc"
18020
+ ],
18021
+ keywords: [
18022
+ "auto"
18023
+ ]
18024
+ },
18025
+ "scroll-padding-top": {
18026
+ shorthand: "scroll-padding"
18027
+ },
18028
+ "scroll-padding-right": {
18029
+ shorthand: "scroll-padding"
18030
+ },
18031
+ "scroll-padding-bottom": {
18032
+ shorthand: "scroll-padding"
18033
+ },
18034
+ "scroll-padding-left": {
18035
+ shorthand: "scroll-padding"
18036
+ },
17218
18037
  "border-radius": {
17219
18038
  shorthand: "border-radius",
17220
18039
  properties: [
@@ -17436,6 +18255,53 @@ var map = {
17436
18255
  "flex-wrap": {
17437
18256
  shorthand: "flex-flow"
17438
18257
  },
18258
+ "scroll-timeline": {
18259
+ shorthand: "scroll-timeline",
18260
+ pattern: "scroll-timeline-name scroll-timeline-axis",
18261
+ keywords: [
18262
+ "none",
18263
+ "block",
18264
+ "inline",
18265
+ "x",
18266
+ "y"
18267
+ ],
18268
+ "default": [
18269
+ "none",
18270
+ "block"
18271
+ ],
18272
+ properties: {
18273
+ "scroll-timeline-name": {
18274
+ keywords: [
18275
+ "none"
18276
+ ],
18277
+ "default": [
18278
+ "none"
18279
+ ],
18280
+ types: [
18281
+ "DashedIden"
18282
+ ]
18283
+ },
18284
+ "scroll-timeline-axis": {
18285
+ keywords: [
18286
+ "block",
18287
+ "inline",
18288
+ "x",
18289
+ "y"
18290
+ ],
18291
+ "default": [
18292
+ "block"
18293
+ ],
18294
+ types: [
18295
+ ]
18296
+ }
18297
+ }
18298
+ },
18299
+ "scroll-timeline-name": {
18300
+ shorthand: "scroll-timeline"
18301
+ },
18302
+ "scroll-timeline-axis": {
18303
+ shorthand: "scroll-timeline"
18304
+ },
17439
18305
  container: {
17440
18306
  shorthand: "container",
17441
18307
  pattern: "container-name container-type",
@@ -19454,6 +20320,7 @@ function objectHash(object) {
19454
20320
  /**
19455
20321
  * convert input to hex
19456
20322
  * @param input
20323
+ * @param length
19457
20324
  */
19458
20325
  function toHex(input, length) {
19459
20326
  let result = "";
@@ -19529,18 +20396,17 @@ const config = getConfig();
19529
20396
  class PropertyList {
19530
20397
  options = { removeDuplicateDeclarations: true, computeShorthand: true };
19531
20398
  declarations;
19532
- // ketsey = new Map;
19533
20399
  constructor(options = {}) {
19534
20400
  this.options = options;
19535
20401
  this.declarations = new Map();
19536
20402
  }
19537
- set(nam, value) {
19538
- return this.add({
19539
- typ: exports.EnumToken.DeclarationNodeType,
19540
- nam,
19541
- val: Array.isArray(value) ? value : parseString(String(value)),
19542
- });
19543
- }
20403
+ // set(nam: string, value: string | Token[]) {
20404
+ // return this.add({
20405
+ // typ: EnumToken.DeclarationNodeType,
20406
+ // nam,
20407
+ // val: Array.isArray(value) ? value : parseString(String(value)),
20408
+ // });
20409
+ // }
19544
20410
  add(...declarations) {
19545
20411
  let name;
19546
20412
  let syntaxRules = null;
@@ -19759,7 +20625,7 @@ class ComputeShorthandFeature {
19759
20625
  }
19760
20626
  }
19761
20627
  run(ast, options) {
19762
- if (!("chi" in ast)) {
20628
+ if (!("chi" in ast || ast.chi?.length == 0)) {
19763
20629
  return null;
19764
20630
  }
19765
20631
  // @ts-ignore
@@ -19802,6 +20668,104 @@ class ComputeShorthandFeature {
19802
20668
  }
19803
20669
  }
19804
20670
 
20671
+ const trimTokenSpace = new Set([
20672
+ exports.EnumToken.CommaTokenType,
20673
+ exports.EnumToken.DelimTokenType,
20674
+ exports.EnumToken.GtTokenType,
20675
+ exports.EnumToken.GteTokenType,
20676
+ exports.EnumToken.LtTokenType,
20677
+ exports.EnumToken.LteTokenType,
20678
+ exports.EnumToken.ChildCombinatorTokenType,
20679
+ ]);
20680
+ const trimSpaceAfter = new Set([
20681
+ ...tokensfuncSet.values(),
20682
+ exports.EnumToken.ChildCombinatorTokenType,
20683
+ exports.EnumToken.SupportsQueryConditionTokenType,
20684
+ exports.EnumToken.SupportsQueryUnaryConditionTokenType,
20685
+ ]);
20686
+ /**
20687
+ * Replace token in its parent node
20688
+ * @param parent
20689
+ * @param node
20690
+ * @param replacement
20691
+ * @throws TypeError replacement is null
20692
+ * @throws ReferenceError node not found in parent
20693
+ */
20694
+ function replaceNodeOrValue(parent, node, replacement) {
20695
+ if (replacement == null || (Array.isArray(replacement) && replacement.length === 0)) {
20696
+ throw new TypeError(`replacement is null`);
20697
+ }
20698
+ for (const newNode of Array.isArray(replacement) ? replacement : [replacement]) {
20699
+ if (newNode[PARENT] != node[PARENT]) {
20700
+ newNode[PARENT] = node[PARENT];
20701
+ }
20702
+ }
20703
+ if (parent.typ == exports.EnumToken.BinaryExpressionTokenType) {
20704
+ if (parent.l == node) {
20705
+ parent.l = replacement;
20706
+ }
20707
+ else if (parent.r == node) {
20708
+ parent.r = replacement;
20709
+ }
20710
+ else {
20711
+ throw new ReferenceError("Node not found");
20712
+ }
20713
+ }
20714
+ else {
20715
+ const target = "val" in parent && Array.isArray(parent.val)
20716
+ ? parent.val
20717
+ : (parent.chi ?? parent);
20718
+ if (Array.isArray(target)) {
20719
+ // @ts-ignore
20720
+ const index = target.indexOf(node);
20721
+ if (index == -1) {
20722
+ throw new ReferenceError("Node not found");
20723
+ }
20724
+ target.splice(index, 1, ...(Array.isArray(replacement) ? replacement : [replacement]));
20725
+ }
20726
+ else if ("l" in target && target.l == node) {
20727
+ target.l = replacement;
20728
+ }
20729
+ else if ("r" in target && target.r == node) {
20730
+ target.r = replacement;
20731
+ }
20732
+ else {
20733
+ throw new ReferenceError("Node not found");
20734
+ }
20735
+ }
20736
+ node[PARENT] = null;
20737
+ return true;
20738
+ }
20739
+ function trimWhiteSpaceTokens(tokens) {
20740
+ let i = 0;
20741
+ if (tokens[0]?.typ === exports.EnumToken.WhitespaceTokenType) {
20742
+ tokens.shift();
20743
+ }
20744
+ if (tokens[tokens.length - 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
20745
+ tokens.pop();
20746
+ }
20747
+ if (tokens.length === 1) {
20748
+ if (tokens[0].typ === exports.EnumToken.WhitespaceTokenType) {
20749
+ tokens.length = 0;
20750
+ }
20751
+ return tokens;
20752
+ }
20753
+ for (; i < tokens.length; i++) {
20754
+ if (trimSpaceAfter.has(tokens[i].typ) && tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
20755
+ tokens.splice(i + 1, 1);
20756
+ }
20757
+ else if (trimTokenSpace.has(tokens[i].typ)) {
20758
+ if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
20759
+ tokens.splice(i + 1, 1);
20760
+ }
20761
+ if (i > 0 && tokens[i - 1].typ === exports.EnumToken.Whitespace) {
20762
+ tokens.splice(--i, 1);
20763
+ }
20764
+ }
20765
+ }
20766
+ return tokens;
20767
+ }
20768
+
19805
20769
  class ComputeCalcExpressionFeature {
19806
20770
  accept = new Set([exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType]);
19807
20771
  get ordering() {
@@ -20640,7 +21604,7 @@ function eqMatrix(a, b) {
20640
21604
  return true;
20641
21605
  }
20642
21606
  function minifyTransformFunctions(transform) {
20643
- const name = transform.val.toLowerCase();
21607
+ const name = transform.val;
20644
21608
  if ("skewX" == name) {
20645
21609
  transform.val = "skew";
20646
21610
  return transform;
@@ -20776,6 +21740,29 @@ function compute(transformLists) {
20776
21740
  let mat;
20777
21741
  let transforms;
20778
21742
  const cumulative = [];
21743
+ // all transform function arguments must be 0 or scale(1)
21744
+ for (const transform of transformLists) {
21745
+ switch (transform.val) {
21746
+ case "rotate":
21747
+ case "rotateX":
21748
+ case "rotateY":
21749
+ case "rotateZ":
21750
+ case "rotate3d":
21751
+ for (const child of transform.chi) {
21752
+ if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) {
21753
+ continue;
21754
+ }
21755
+ if ((child.typ != exports.EnumToken.AngleTokenType &&
21756
+ child.typ != exports.EnumToken.NumberTokenType &&
21757
+ child.typ != exports.EnumToken.PercentageTokenType) ||
21758
+ // angle >= 360deg, do not transform
21759
+ Math.abs(getAngle(child)) >= 1) {
21760
+ return null;
21761
+ }
21762
+ }
21763
+ // break;
21764
+ }
21765
+ }
20779
21766
  for (const transformList of splitTransformList(transformLists)) {
20780
21767
  mat = computeMatrix(transformList, identity());
20781
21768
  if (mat == null) {
@@ -20806,60 +21793,6 @@ function compute(transformLists) {
20806
21793
  cumulative,
20807
21794
  minified: minify$1(matrix) ?? [serialized],
20808
21795
  };
20809
- // valid identity matrix
20810
- if ((result.minified.length == 1 &&
20811
- result.minified[0].typ == exports.EnumToken.IdenTokenType &&
20812
- result.minified[0].val == "none") ||
20813
- (result.cumulative.length == 1 &&
20814
- result.cumulative[0].typ == exports.EnumToken.IdenTokenType &&
20815
- result.cumulative[0].val == "none") ||
20816
- (result.matrix?.typ == exports.EnumToken.IdenTokenType && result.matrix.val == "none")) {
20817
- // all transform function arguments must be 0 or scale(1)
20818
- for (const transform of transformLists) {
20819
- switch (transform.val) {
20820
- case "translate":
20821
- case "translateX":
20822
- case "translateY":
20823
- case "translateZ":
20824
- case "translate3d":
20825
- case "rotate":
20826
- case "rotateX":
20827
- case "rotateY":
20828
- case "rotateZ":
20829
- case "rotate3d":
20830
- case "skew":
20831
- case "skewX":
20832
- case "skewY":
20833
- for (const child of transform.chi) {
20834
- if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) {
20835
- continue;
20836
- }
20837
- if ((child.typ != exports.EnumToken.AngleTokenType &&
20838
- child.typ != exports.EnumToken.NumberTokenType &&
20839
- child.typ != exports.EnumToken.PercentageTokenType) ||
20840
- getNumber(child) != 0) {
20841
- return null;
20842
- }
20843
- }
20844
- break;
20845
- case "scale":
20846
- case "scaleX":
20847
- case "scaleY":
20848
- case "scaleZ":
20849
- case "scale3d":
20850
- for (const child of transform.chi) {
20851
- if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) {
20852
- continue;
20853
- }
20854
- if ((child.typ != exports.EnumToken.NumberTokenType && child.typ != exports.EnumToken.PercentageTokenType) ||
20855
- getNumber(child) != 1) {
20856
- return null;
20857
- }
20858
- }
20859
- break;
20860
- }
20861
- }
20862
- }
20863
21796
  return result;
20864
21797
  }
20865
21798
  function computeMatrix(transformList, matrixVar) {
@@ -21187,7 +22120,7 @@ class TransformCssFeature {
21187
22120
  minified: null,
21188
22121
  };
21189
22122
  if (matrix == null || cumulative == null || minified == null) {
21190
- node.val = children;
22123
+ node.val = children.map((t) => t.typ == exports.EnumToken.TransformFunctionTokenType ? minifyTransformFunctions(t) : t);
21191
22124
  continue;
21192
22125
  }
21193
22126
  let r = [filterValues(children)];
@@ -21871,7 +22804,15 @@ function reduce(acc, curr) {
21871
22804
  // trim :is()
21872
22805
  if (curr[0] == "&") {
21873
22806
  if (curr[1] == " " && !isIdent(curr[2]) && !isFunction(curr[2])) {
21874
- curr.splice(0, 2);
22807
+ const all = new Array(Math.max(curr.length - 2, 0));
22808
+ let write = 0;
22809
+ for (let read = 2; read < curr.length; read++) {
22810
+ all[write++] = curr[read];
22811
+ }
22812
+ curr.length = 0;
22813
+ for (let index = 0; index < write; index++) {
22814
+ curr[index] = all[index];
22815
+ }
21875
22816
  }
21876
22817
  }
21877
22818
  acc.push(curr.join(""));
@@ -22149,19 +23090,40 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
22149
23090
  if (optimized.length > 1) {
22150
23091
  const check = optimized.at(-2);
22151
23092
  if (!combinators.includes(check)) {
22152
- let last = optimized.pop();
23093
+ const last = optimized[optimized.length - 1];
23094
+ const all = new Array(Math.max(optimized.length - 1, 0));
23095
+ let write = 0;
23096
+ for (let read = 0; read < optimized.length - 1; read++) {
23097
+ all[write++] = optimized[read];
23098
+ }
23099
+ optimized.length = 0;
23100
+ for (let index = 0; index < write; index++) {
23101
+ optimized[index] = all[index];
23102
+ }
22153
23103
  wrap = false;
22154
23104
  rule =
22155
23105
  optimized.join("") +
22156
23106
  `:is(${selector
22157
23107
  .map((s) => {
23108
+ const next = s[0] == "&" ? new Array(s.length) : new Array(s.length + 1);
23109
+ let write = 0;
22158
23110
  if (s[0] == "&") {
22159
- s.splice(0, 1, last);
23111
+ next[write++] = last;
23112
+ for (let read = 1; read < s.length; read++) {
23113
+ next[write++] = s[read];
23114
+ }
22160
23115
  }
22161
23116
  else {
22162
- s.unshift(last);
23117
+ next[write++] = last;
23118
+ for (let read = 0; read < s.length; read++) {
23119
+ next[write++] = s[read];
23120
+ }
23121
+ }
23122
+ const rebuilt = new Array(write);
23123
+ for (let index = 0; index < write; index++) {
23124
+ rebuilt[index] = next[index];
22163
23125
  }
22164
- return s.join("");
23126
+ return rebuilt.join("");
22165
23127
  })
22166
23128
  .join(",")})`;
22167
23129
  }
@@ -22170,7 +23132,20 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
22170
23132
  rule = selector
22171
23133
  .map((s) => {
22172
23134
  if (s[0] == "&") {
22173
- s.splice(0, 1, ...node[OPTIMIZED].optimized);
23135
+ const replacement = node[OPTIMIZED].optimized;
23136
+ const all = new Array(Math.max(s.length - 1 + replacement.length, 0));
23137
+ let write = 0;
23138
+ for (let read = 0; read < replacement.length; read++) {
23139
+ all[write++] = replacement[read];
23140
+ }
23141
+ for (let read = 1; read < s.length; read++) {
23142
+ all[write++] = s[read];
23143
+ }
23144
+ const rebuilt = new Array(write);
23145
+ for (let index = 0; index < write; index++) {
23146
+ rebuilt[index] = all[index];
23147
+ }
23148
+ return rebuilt.join("");
22174
23149
  }
22175
23150
  return s.join("");
22176
23151
  })
@@ -22402,18 +23377,42 @@ function optimizeSelector(selector) {
22402
23377
  while (optimized.length > 0) {
22403
23378
  const last = optimized.at(-1);
22404
23379
  if (last == " " || combinators.includes(last)) {
22405
- optimized.pop();
23380
+ const all = new Array(Math.max(optimized.length - 1, 0));
23381
+ let write = 0;
23382
+ for (let read = 0; read < optimized.length - 1; read++) {
23383
+ all[write++] = optimized[read];
23384
+ }
23385
+ optimized.length = 0;
23386
+ for (let index = 0; index < write; index++) {
23387
+ optimized[index] = all[index];
23388
+ }
22406
23389
  continue;
22407
23390
  }
22408
23391
  break;
22409
23392
  }
22410
23393
  for (let i1 = 0; i1 < selector.length; i1++) {
22411
- selector[i1].splice(0, optimized.length);
23394
+ const all = new Array(Math.max(selector[i1].length - optimized.length, 0));
23395
+ let write = 0;
23396
+ for (let read = optimized.length; read < selector[i1].length; read++) {
23397
+ all[write++] = selector[i1][read];
23398
+ }
23399
+ selector[i1].length = 0;
23400
+ for (let index = 0; index < write; index++) {
23401
+ selector[i1][index] = all[index];
23402
+ }
22412
23403
  }
22413
23404
  let reducible = optimized.length == 1;
22414
23405
  if (optimized[0] == "&") {
22415
23406
  if (optimized[1] == " ") {
22416
- optimized.splice(0, 2);
23407
+ const all = new Array(Math.max(optimized.length - 2, 0));
23408
+ let write = 0;
23409
+ for (let read = 2; read < optimized.length; read++) {
23410
+ all[write++] = optimized[read];
23411
+ }
23412
+ optimized.length = 0;
23413
+ for (let index = 0; index < write; index++) {
23414
+ optimized[index] = all[index];
23415
+ }
22417
23416
  }
22418
23417
  }
22419
23418
  if (optimized.length == 0 || optimized[0].charAt(0) == "&" || selector.length == 1) {
@@ -23000,7 +23999,15 @@ function reduceRuleSelector(node) {
23000
23999
  if (selector.length > 1 &&
23001
24000
  selector[0] == "&" &&
23002
24001
  (combinators.includes(selector[1]) || !/^[a-zA-Z:]/.test(selector[1]))) {
23003
- selector.shift();
24002
+ const all = new Array(Math.max(selector.length - 1, 0));
24003
+ let write = 0;
24004
+ for (let read = 1; read < selector.length; read++) {
24005
+ all[write++] = selector[read];
24006
+ }
24007
+ selector.length = 0;
24008
+ for (let index = 0; index < write; index++) {
24009
+ selector[index] = all[index];
24010
+ }
23004
24011
  }
23005
24012
  }
23006
24013
  const unique = new Set();
@@ -23322,6 +24329,19 @@ function replaceCompoundLiteral(selector, replace) {
23322
24329
  .reduce((acc, curr) => acc + (curr == "&" ? replace : curr), "");
23323
24330
  }
23324
24331
 
24332
+ /**
24333
+ *
24334
+ * @param value
24335
+ * @returns
24336
+ */
24337
+ function toBase64(value) {
24338
+ let result = '';
24339
+ for (const c of new TextEncoder().encode(value)) {
24340
+ result += String.fromCharCode(c);
24341
+ }
24342
+ return btoa(result);
24343
+ }
24344
+
23325
24345
  // from https://github.com/Rich-Harris/vlq/tree/master
23326
24346
  // credit: Rich Harris
23327
24347
  const integer_to_char = {};
@@ -23371,15 +24391,20 @@ function decode(str) {
23371
24391
  * @returns
23372
24392
  */
23373
24393
  function encode(value) {
23374
- if (typeof value === 'number') {
23375
- return encode_integer(value);
23376
- }
24394
+ // if (typeof value === 'number') {
24395
+ // return encode_integer(value);
24396
+ // }
23377
24397
  let result = '';
23378
24398
  for (let i = 0; i < value.length; i += 1) {
23379
24399
  result += encode_integer(value[i]);
23380
24400
  }
23381
24401
  return result;
23382
24402
  }
24403
+ /**
24404
+ *
24405
+ * @param num
24406
+ * @returns
24407
+ */
23383
24408
  function encode_integer(num) {
23384
24409
  let result = '';
23385
24410
  if (num < 0) {
@@ -23401,6 +24426,35 @@ function encode_integer(num) {
23401
24426
 
23402
24427
  /**
23403
24428
  * Generate and parse source map
24429
+ *
24430
+ * ```ts
24431
+ * const sourcemap = new SourceMap();
24432
+ *
24433
+ * // you can also pass an input sourcemap
24434
+ * // const sourcemap = new SourceMap(sourcemapObjectOrJSONString);
24435
+ *
24436
+ * sourcemap.addSourceContent(0, '/css/styles.css', null);
24437
+ * sourcemap.addSourceContent(1, '/css/typography.css', null);
24438
+ *
24439
+ * const maps = [];
24440
+ *
24441
+ * maps.add([
24442
+ 1, 1, 0, 1, 1]);
24443
+ * maps.add([
24444
+ 2, 1, 1, 1, 1
24445
+ ]);
24446
+
24447
+ sourcemap.add(maps);
24448
+
24449
+ // convert to inline sourcemap
24450
+ sourcemap.toUrl();
24451
+
24452
+ // convert to JSON
24453
+ sourcemap.toJSON();
24454
+
24455
+ // find the original file, line and column
24456
+ sourcemap.find(2, 1);
24457
+ ```
23404
24458
  */
23405
24459
  class SourceMap {
23406
24460
  /**
@@ -23451,7 +24505,7 @@ class SourceMap {
23451
24505
  line = -1;
23452
24506
  /**
23453
24507
  *
23454
- * @param sourcemaps
24508
+ * @param sourcemaps input sourcemap
23455
24509
  */
23456
24510
  constructor(sourcemaps) {
23457
24511
  if (typeof sourcemaps === "string") {
@@ -23492,9 +24546,9 @@ class SourceMap {
23492
24546
  }
23493
24547
  /**
23494
24548
  * add source
23495
- * @param id
23496
- * @param fileName
23497
- * @param content
24549
+ * @param id source id
24550
+ * @param fileName source file
24551
+ * @param content source content
23498
24552
  * @returns
23499
24553
  */
23500
24554
  addSourceContent(id, fileName, content) {
@@ -23630,7 +24684,7 @@ class SourceMap {
23630
24684
  */
23631
24685
  toUrl() {
23632
24686
  // /*# sourceMappingURL = ${url} */
23633
- return `data:application/json;charset=utf-8;base64,${btoa(JSON.stringify(this.toJSON()))}`;
24687
+ return `data:application/json;charset=utf-8;base64,${toBase64(JSON.stringify(this.toJSON()))}`;
23634
24688
  }
23635
24689
  /**
23636
24690
  * Convert to JSON object
@@ -24070,11 +25124,13 @@ function doRender(data, options = {}, mapping) {
24070
25124
  ...options,
24071
25125
  };
24072
25126
  if (options.withParents) {
24073
- // @ts-ignore
24074
- let parent = data[PARENT];
25127
+ let parent;
24075
25128
  while (data[PARENT] != null) {
24076
25129
  // @ts-ignore
24077
- parent = { ...data[PARENT], chi: [{ ...data }] };
25130
+ // parent = { ...data[PARENT], chi: [data] };
25131
+ parent = cloneNode(data[PARENT]);
25132
+ // @ts-ignore
25133
+ parent.chi = [data];
24078
25134
  // @ts-ignore
24079
25135
  parent[PARENT] = data[PARENT][PARENT];
24080
25136
  // @ts-ignore
@@ -24244,6 +25300,8 @@ function updateSourceMap(node, options, cache, sourcemaps, sourceLocation, lines
24244
25300
  * @param sourceLocation
24245
25301
  * @param linesMap
24246
25302
  * @param str
25303
+ * @param start
25304
+ * @param end
24247
25305
  */
24248
25306
  function move(sourceLocation, linesMap, str, start, end) {
24249
25307
  let i = start ?? 0;
@@ -24436,8 +25494,8 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
24436
25494
  };
24437
25495
  }
24438
25496
  switch (token.typ) {
24439
- case exports.EnumToken.FunctionTokenDefType:
24440
25497
  case exports.EnumToken.UrlFunctionTokenDefType:
25498
+ case exports.EnumToken.FunctionTokenDefType:
24441
25499
  case exports.EnumToken.MathFunctionTokenDefType:
24442
25500
  case exports.EnumToken.ImageFunctionTokenDefType:
24443
25501
  case exports.EnumToken.ColorFunctionTokenDefType:
@@ -24537,8 +25595,8 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
24537
25595
  return token.val;
24538
25596
  }
24539
25597
  if (Array.isArray(token.chi)) {
24540
- const fnName = token.val.toLowerCase();
24541
- const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val.toLowerCase());
25598
+ const fnName = token.val;
25599
+ const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val);
24542
25600
  const hasAlpha = [
24543
25601
  "rgb",
24544
25602
  "rgba",
@@ -24581,6 +25639,9 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
24581
25639
  }
24582
25640
  case exports.EnumToken.UrlFunctionTokenType:
24583
25641
  if (options.minify && token.typ === exports.EnumToken.UrlFunctionTokenType) {
25642
+ if (token.chi[0]?.typ === exports.EnumToken.BadUrlTokenType) {
25643
+ return "url()";
25644
+ }
24584
25645
  for (const child of token.chi) {
24585
25646
  if (child.typ === exports.EnumToken.StringTokenType) {
24586
25647
  if (child.val.slice(1, 5) !== "data:" &&
@@ -25268,6 +26329,12 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
25268
26329
  return token.val.typ == exports.EnumToken.FractionTokenType
25269
26330
  ? renderValue(token.val, options, cache)
25270
26331
  : minifyNumber(token.val);
26332
+ case exports.EnumToken.InfinityTokenType:
26333
+ return "0/0";
26334
+ case exports.EnumToken.NegativeInfinityTokenType:
26335
+ return "-0/0";
26336
+ case exports.EnumToken.NaNTokenType:
26337
+ return "NaN";
25271
26338
  case exports.EnumToken.AtRuleTokenType:
25272
26339
  return "@" + token.nam;
25273
26340
  case exports.EnumToken.CommentTokenType:
@@ -25397,9 +26464,19 @@ function filterValues(values) {
25397
26464
 
25398
26465
  const SymbolsMapTokens = Object.create(null);
25399
26466
  // Regex for escape sequence decoding - compile once, reuse many times
25400
- const ESCAPE_SEQUENCE_REGEX = /\\([0-9a-fA-F]{1,6})(?:\s)?/g;
26467
+ const ESCAPE_SEQUENCE_REGEX = /\\((\n|\r|\f|\v|\u2028|\u2029|([0-9a-fA-F]{1,6})) ?)/gms;
25401
26468
  function decodeEscapeSequences(value) {
25402
26469
  return value.replace(ESCAPE_SEQUENCE_REGEX, (_, sequence) => {
26470
+ // \n \r \f \v
26471
+ switch (sequence.charCodeAt(0)) {
26472
+ case 0xa:
26473
+ case 0xb:
26474
+ case 0xc:
26475
+ case 0xd:
26476
+ case 0x2028:
26477
+ case 0x2029:
26478
+ return "";
26479
+ }
25403
26480
  const codepoint = parseInt(sequence, 16);
25404
26481
  if (codepoint == 0 ||
25405
26482
  // leading surrogate
@@ -25637,18 +26714,17 @@ class Tokenizer {
25637
26714
  constructor(parseInfo, input = null) {
25638
26715
  this.parseInfo = parseInfo;
25639
26716
  this.input = input;
25640
- if (typeof this.parseInfo == "string") {
25641
- if (typeof parseInfo == "string") {
25642
- this.parseInfo = {
26717
+ this.parseInfo =
26718
+ typeof parseInfo == "string"
26719
+ ? {
25643
26720
  stream: parseInfo,
25644
26721
  source: new SourceFile(parseInfo, [], ""),
25645
26722
  offset: 0,
25646
26723
  time: 0,
25647
26724
  position: 0,
25648
26725
  currentPosition: 0,
25649
- };
25650
- }
25651
- }
26726
+ }
26727
+ : parseInfo;
25652
26728
  }
25653
26729
  /**
25654
26730
  *
@@ -25665,6 +26741,18 @@ class Tokenizer {
25665
26741
  this.advance(parseInfo, 2);
25666
26742
  continue;
25667
26743
  }
26744
+ charCode = parseInfo.stream.charCodeAt(parseInfo.currentPosition - parseInfo.offset + 1);
26745
+ // \n \r \f \v
26746
+ if (charCode == 0xa ||
26747
+ charCode == 0xb ||
26748
+ charCode == 0xc ||
26749
+ charCode == 0xd ||
26750
+ charCode == 0x2028 ||
26751
+ charCode == 0x2029) {
26752
+ this.advance(parseInfo, 2);
26753
+ decodeSegments = true;
26754
+ continue;
26755
+ }
25668
26756
  const sequence = this.peek(parseInfo, 7);
25669
26757
  let escapeSequence = "";
25670
26758
  let codepoint;
@@ -25708,7 +26796,7 @@ class Tokenizer {
25708
26796
  this.advance(parseInfo);
25709
26797
  }
25710
26798
  // EOF - 'Unclosed-string' fixed
25711
- return this.makeToken(parseInfo, exports.EnumToken.StringTokenType);
26799
+ return this.makeToken(parseInfo, exports.EnumToken.StringTokenType, decodeSegments ? { decodeSegments } : null);
25712
26800
  // return result;
25713
26801
  }
25714
26802
  /**
@@ -25716,7 +26804,7 @@ class Tokenizer {
25716
26804
  * @param parseInfo
25717
26805
  * @returns
25718
26806
  */
25719
- consumeURLToken(parseInfo) {
26807
+ consumeStringAsURLToken(parseInfo) {
25720
26808
  const quote = this.advance(parseInfo).charCodeAt(0);
25721
26809
  let charCode;
25722
26810
  let decodeSegments = false;
@@ -25770,7 +26858,7 @@ class Tokenizer {
25770
26858
  return this.makeToken(parseInfo, exports.EnumToken.BadUrlTokenType);
25771
26859
  }
25772
26860
  if (isWhiteSpace(charCode)) {
25773
- this.advance(parseInfo, k);
26861
+ // this.advance(parseInfo, k);
25774
26862
  k++;
25775
26863
  continue;
25776
26864
  }
@@ -26158,7 +27246,7 @@ class Tokenizer {
26158
27246
  }
26159
27247
  return 0;
26160
27248
  }
26161
- parseURLToken(parseInfo, endPosition) {
27249
+ consumeURLToken(parseInfo, endPosition) {
26162
27250
  let charCode;
26163
27251
  // consume an <url>
26164
27252
  while (isWhiteSpace(this.peekCharCode(parseInfo))) {
@@ -26166,7 +27254,7 @@ class Tokenizer {
26166
27254
  }
26167
27255
  charCode = this.peekCharCode(parseInfo);
26168
27256
  if (charCode == 34 /* TokenMap.DOUBLE_QUOTE */ || charCode == 39 /* TokenMap.SINGLE_QUOTE */) {
26169
- return this.consumeURLToken(parseInfo);
27257
+ return this.consumeStringAsURLToken(parseInfo);
26170
27258
  }
26171
27259
  do {
26172
27260
  this.advance(parseInfo);
@@ -26174,14 +27262,28 @@ class Tokenizer {
26174
27262
  } while (
26175
27263
  // !(value === "/" && this.match(parseInfo, "/*") &&
26176
27264
  charCode !== 41 /* TokenMap.RIGHT_PARENTHESIS */ &&
27265
+ !isWhiteSpace(charCode) &&
26177
27266
  parseInfo.currentPosition < endPosition);
26178
- // if (parseInfo.position < parseInfo.currentPosition) {
27267
+ if (charCode !== 41 /* TokenMap.RIGHT_PARENTHESIS */) {
27268
+ let k = 1;
27269
+ while (k < endPosition) {
27270
+ charCode = parseInfo.stream.charCodeAt(parseInfo.currentPosition - parseInfo.offset + k);
27271
+ if (isWhiteSpace(charCode)) {
27272
+ k++;
27273
+ continue;
27274
+ }
27275
+ break;
27276
+ }
27277
+ if (charCode != charCode || (charCode != 41 /* TokenMap.RIGHT_PARENTHESIS */ && !isIdentStart(charCode))) {
27278
+ this.advance(parseInfo, k);
27279
+ return this.makeToken(parseInfo, exports.EnumToken.BadUrlTokenType);
27280
+ }
27281
+ }
26179
27282
  return this.makeToken(parseInfo,
26180
27283
  // parseInfo.position < parseInfo.currentPosition
26181
27284
  (charCode = this.peekCharCode(parseInfo)) != charCode || !this.isURLToken(parseInfo)
26182
27285
  ? exports.EnumToken.BadUrlTokenType
26183
27286
  : exports.EnumToken.UrlTokenTokenType);
26184
- // }
26185
27287
  }
26186
27288
  /**
26187
27289
  *
@@ -26426,31 +27528,26 @@ class Tokenizer {
26426
27528
  /**
26427
27529
  *
26428
27530
  * @param parseInfo
26429
- * @param start
26430
- * @param end
26431
27531
  * @returns
26432
27532
  */
26433
- isIdentToken(parseInfo, start, end) {
27533
+ isIdentToken(parseInfo /* , start?: number, end?: number */) {
26434
27534
  let j = parseInfo.currentPosition - parseInfo.offset;
26435
27535
  let i = parseInfo.position - parseInfo.offset;
26436
- if (start != null) {
26437
- if (end == null) {
26438
- if (start < 0) {
26439
- j += start;
26440
- }
26441
- else {
26442
- i += start;
26443
- }
26444
- }
26445
- else {
26446
- if (end < 0) {
26447
- j += end;
26448
- }
26449
- else {
26450
- j = parseInfo.position + end;
26451
- }
26452
- }
26453
- }
27536
+ // if (start != null) {
27537
+ // if (end == null) {
27538
+ // if (start < 0) {
27539
+ // j += start;
27540
+ // } else {
27541
+ // i += start;
27542
+ // }
27543
+ // } else {
27544
+ // if (end < 0) {
27545
+ // j += end;
27546
+ // } else {
27547
+ // j = parseInfo.position + end;
27548
+ // }
27549
+ // }
27550
+ // }
26454
27551
  j--;
26455
27552
  let codepoint = parseInfo.stream.charCodeAt(i);
26456
27553
  // -
@@ -26493,18 +27590,18 @@ class Tokenizer {
26493
27590
  * @param parseInfo
26494
27591
  * @returns
26495
27592
  */
26496
- isPseudo(parseInfo) {
26497
- let position = parseInfo.currentPosition - parseInfo.offset;
26498
- let endPosition = parseInfo.currentPosition - parseInfo.offset;
26499
- return (parseInfo.stream.charAt(position) == ":" &&
26500
- parseInfo.stream.charAt(endPosition - 1) == "(" &&
26501
- (parseInfo.stream.charAt(position + 1) == ":"
26502
- ? this.isIdentToken(parseInfo, 2, -1)
26503
- : this.isIdentToken(parseInfo, 1, -1))) ||
26504
- parseInfo.stream.charAt(position + 1) == ":"
26505
- ? this.isIdentToken(parseInfo, 2)
26506
- : this.isIdentToken(parseInfo, 1);
26507
- }
27593
+ // isPseudo(parseInfo: ParseInfo): boolean {
27594
+ // let position: number = parseInfo.currentPosition - parseInfo.offset;
27595
+ // let endPosition: number = parseInfo.currentPosition - parseInfo.offset;
27596
+ // return (parseInfo.stream.charAt(position) == ":" &&
27597
+ // parseInfo.stream.charAt(endPosition - 1) == "(" &&
27598
+ // (parseInfo.stream.charAt(position + 1) == ":"
27599
+ // ? this.isIdentToken(parseInfo, 2, -1)
27600
+ // : this.isIdentToken(parseInfo, 1, -1))) ||
27601
+ // parseInfo.stream.charAt(position + 1) == ":"
27602
+ // ? this.isIdentToken(parseInfo, 2)
27603
+ // : this.isIdentToken(parseInfo, 1);
27604
+ // }
26508
27605
  /**
26509
27606
  *
26510
27607
  * @param parseInfo
@@ -26561,8 +27658,6 @@ class Tokenizer {
26561
27658
  }
26562
27659
  /**
26563
27660
  * Tokenize CSS string
26564
- * @param parseInfo
26565
- * @param yieldEOFToken
26566
27661
  */
26567
27662
  next( /* parseInfo: ParseInfo | string, yieldEOFToken: boolean = true */) {
26568
27663
  const parseInfo = this.parseInfo;
@@ -26577,7 +27672,7 @@ class Tokenizer {
26577
27672
  while ((charCode = this.peekCharCode(parseInfo)) == charCode) {
26578
27673
  if (this.state === exports.EnumToken.UrlFunctionTokenDefType) {
26579
27674
  this.state = null;
26580
- return this.parseURLToken(parseInfo, endPosition);
27675
+ return this.consumeURLToken(parseInfo, endPosition);
26581
27676
  }
26582
27677
  if (parseInfo.position == parseInfo.currentPosition) {
26583
27678
  if (charCode == 45 /* TokenMap.MINUS */ ||
@@ -26697,12 +27792,14 @@ class Tokenizer {
26697
27792
  // '('
26698
27793
  case 40 /* TokenMap.LEFT_PARENTHESIS */:
26699
27794
  if (parseInfo.position < parseInfo.currentPosition) {
26700
- if (parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" &&
26701
- this.isPseudo(parseInfo)) {
26702
- this.advance(parseInfo);
26703
- return this.makeToken(parseInfo, exports.EnumToken.PseudoClassFunctionTokenDefType);
26704
- }
26705
- else if (this.isIdentToken(parseInfo)) {
27795
+ // if (
27796
+ // parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" &&
27797
+ // this.isPseudo(parseInfo)
27798
+ // ) {
27799
+ // this.advance(parseInfo);
27800
+ // return this.makeToken(parseInfo, EnumToken.PseudoClassFunctionTokenDefType);
27801
+ // } else
27802
+ if (this.isIdentToken(parseInfo)) {
26706
27803
  const hint = this.startsWith(parseInfo, "--")
26707
27804
  ? exports.EnumToken.CustomFunctionTokenDefType
26708
27805
  : (getSymbolHint(parseInfo, parseInfo.position - parseInfo.offset, parseInfo.currentPosition - parseInfo.offset + 1) ?? exports.EnumToken.FunctionTokenDefType);
@@ -26946,6 +28043,9 @@ class Tokenizer {
26946
28043
  case 46 /* TokenMap.DOT */:
26947
28044
  const codepoint = parseInfo.stream.charCodeAt(parseInfo.currentPosition - parseInfo.offset + 1);
26948
28045
  if (isIdentStart(codepoint) || codepoint == 45 /* TokenMap.MINUS */) {
28046
+ if (parseInfo.position < parseInfo.currentPosition) {
28047
+ return this.makeToken(parseInfo);
28048
+ }
26949
28049
  this.advance(parseInfo);
26950
28050
  let tokensCount = this.consumeIdentToken(parseInfo);
26951
28051
  if (tokensCount > 0) {
@@ -26977,8 +28077,6 @@ class Tokenizer {
26977
28077
  }
26978
28078
  /**
26979
28079
  * tokenize readable stream
26980
- * @param input
26981
- * @param parseInfo
26982
28080
  */
26983
28081
  async tokenizeStream() {
26984
28082
  const decoder = new TextDecoder("utf-8");
@@ -27065,7 +28163,6 @@ function parseSelector(tokens, context, options, errors) {
27065
28163
  const stack = [];
27066
28164
  const uniq = new Map();
27067
28165
  let allowed = true;
27068
- let i = 0;
27069
28166
  let index;
27070
28167
  let parent = context;
27071
28168
  let nested = false;
@@ -27099,121 +28196,132 @@ function parseSelector(tokens, context, options, errors) {
27099
28196
  nested = parent?.typ == exports.EnumToken.RuleNodeType;
27100
28197
  parent = parent?.[PARENT];
27101
28198
  } while (!nested && parent != null);
27102
- for (; i < tokens.length; i++) {
27103
- if (tokens[i].typ == exports.EnumToken.ColonTokenType) {
27104
- if (tokens[i + 1]?.typ == exports.EnumToken.IdenTokenType) {
27105
- Object.assign(tokens[i], {
28199
+ const all = new Array(tokens.length);
28200
+ let write = 0;
28201
+ for (let read = 0; read < tokens.length; read++) {
28202
+ let token = tokens[read];
28203
+ if (token.typ == exports.EnumToken.ColonTokenType) {
28204
+ const next = tokens[read + 1];
28205
+ if (next?.typ == exports.EnumToken.IdenTokenType) {
28206
+ all[write++] = {
28207
+ ...token,
27106
28208
  typ: exports.EnumToken.PseudoElementTokenType,
27107
- val: ":" + tokens[i + 1].val,
27108
- });
27109
- tokens[i][LOCEND] = tokens[i + 1][LOCEND];
27110
- tokens.splice(i + 1, 1);
28209
+ val: ":" + next.val,
28210
+ [LOCEND]: next[LOCEND],
28211
+ };
28212
+ read++;
27111
28213
  continue;
27112
28214
  }
27113
- if (tokens[i + 1]?.typ == exports.EnumToken.FunctionTokenDefType) {
27114
- val = ":" + tokens[i + 1].val;
27115
- Object.assign(tokens[i], {
28215
+ if (next?.typ == exports.EnumToken.FunctionTokenDefType) {
28216
+ val = ":" + next.val;
28217
+ all[write++] = {
28218
+ ...token,
27116
28219
  typ: val + "()" in getSyntaxConfig().selectors
27117
28220
  ? exports.EnumToken.PseudoClassFunctionTokenDefType
27118
- : tokens[i + 1].typ,
28221
+ : next.typ,
27119
28222
  val,
27120
- });
27121
- tokens[i][LOCEND] = tokens[i + 1][LOCEND];
27122
- tokens.splice(i + 1, 1);
28223
+ [LOCEND]: next[LOCEND],
28224
+ };
28225
+ read++;
27123
28226
  continue;
27124
28227
  }
27125
28228
  }
27126
- if (tokens[i].typ == exports.EnumToken.DoubleColonTokenType) {
27127
- val = ":" + tokens[i + 1].val;
27128
- if (tokens[i + 1]?.typ == exports.EnumToken.IdenTokenType) {
27129
- Object.assign(tokens[i], {
28229
+ if (token.typ == exports.EnumToken.DoubleColonTokenType) {
28230
+ const next = tokens[read + 1];
28231
+ val = ":" + next.val;
28232
+ if (next?.typ == exports.EnumToken.IdenTokenType) {
28233
+ all[write++] = {
28234
+ ...token,
27130
28235
  typ: exports.EnumToken.PseudoClassTokenType,
27131
28236
  val: (pseudoElements.includes(val) ? "" : ":") + val,
27132
- });
27133
- tokens[i][LOCEND] = tokens[i + 1][LOCEND];
27134
- tokens.splice(i + 1, 1);
28237
+ [LOCEND]: next[LOCEND],
28238
+ };
28239
+ read++;
27135
28240
  continue;
27136
28241
  }
27137
- if (tokens[i + 1]?.typ == exports.EnumToken.FunctionTokenDefType) {
27138
- val = "::" + tokens[i + 1].val;
27139
- Object.assign(tokens[i], {
28242
+ if (next?.typ == exports.EnumToken.FunctionTokenDefType) {
28243
+ val = "::" + next.val;
28244
+ all[write++] = {
28245
+ ...token,
27140
28246
  typ: val + "()" in getSyntaxConfig().selectors
27141
28247
  ? exports.EnumToken.PseudoClassFunctionTokenDefType
27142
28248
  : exports.EnumToken.FunctionTokenDefType,
27143
28249
  val,
27144
- });
27145
- tokens[i][LOCEND] = tokens[i + 1][LOCEND];
27146
- tokens.splice(i + 1, 1);
28250
+ [LOCEND]: next[LOCEND],
28251
+ };
28252
+ read++;
27147
28253
  continue;
27148
28254
  }
27149
28255
  }
27150
- if (tokens[i].typ == exports.EnumToken.ColorTokenType) {
27151
- if (isHash(tokens[i].val)) {
27152
- Object.assign(tokens[i], {
27153
- typ: exports.EnumToken.HashTokenType,
27154
- });
28256
+ if (token.typ == exports.EnumToken.ColorTokenType) {
28257
+ if (isHash(token.val)) {
28258
+ token.typ = exports.EnumToken.HashTokenType;
28259
+ all[write++] = token;
28260
+ continue;
27155
28261
  }
27156
- else {
27157
- return {
27158
- typ: exports.EnumToken.RuleNodeType,
27159
- sel: [
27160
- ...tokens
27161
- .reduce((acc, curr, index, array) => {
27162
- // if (curr.typ == EnumToken.CommentTokenType) {
27163
- // return acc;
27164
- // }
27165
- if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
27166
- if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
27167
- trimWhiteSpace.includes(array[index + 1]?.typ) ||
27168
- combinators.includes(array[index - 1]?.val) ||
27169
- combinators.includes(array[index + 1]?.val)) {
27170
- return acc;
27171
- }
27172
- }
27173
- let t = renderValue(curr, { minify: false });
27174
- if (t == ",") {
27175
- acc.push([]);
27176
- }
27177
- else {
27178
- acc[acc.length - 1].push(t);
28262
+ return {
28263
+ typ: exports.EnumToken.RuleNodeType,
28264
+ sel: [
28265
+ ...tokens
28266
+ .reduce((acc, curr, index, array) => {
28267
+ if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
28268
+ if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
28269
+ trimWhiteSpace.includes(array[index + 1]?.typ) ||
28270
+ combinators.includes(array[index - 1]?.val) ||
28271
+ combinators.includes(array[index + 1]?.val)) {
28272
+ return acc;
27179
28273
  }
27180
- return acc;
27181
- }, [[]])
27182
- .reduce((acc, curr) => {
27183
- let i = 0;
27184
- for (; i < curr.length; i++) {
27185
- if (i + 1 < curr.length && curr[i] == "*") {
27186
- if (curr[i] == "*") {
27187
- let index = curr[i + 1] == " " ? 2 : 1;
27188
- if (![">", "~", "+"].includes(curr[index])) {
27189
- curr.splice(i, index);
27190
- }
28274
+ }
28275
+ let t = renderValue(curr, { minify: false });
28276
+ if (t == ",") {
28277
+ acc.push([]);
28278
+ }
28279
+ else {
28280
+ acc[acc.length - 1].push(t);
28281
+ }
28282
+ return acc;
28283
+ }, [[]])
28284
+ .reduce((acc, curr) => {
28285
+ let i = 0;
28286
+ for (; i < curr.length; i++) {
28287
+ if (i + 1 < curr.length && curr[i] == "*") {
28288
+ if (curr[i] == "*") {
28289
+ let index = curr[i + 1] == " " ? 2 : 1;
28290
+ if (![">", "~", "+"].includes(curr[index])) {
28291
+ curr.splice(i, index);
27191
28292
  }
27192
28293
  }
27193
28294
  }
27194
- acc.set(curr.join(""), curr);
27195
- return acc;
27196
- }, uniq)
27197
- .keys(),
27198
- ].join(","),
27199
- chi: [],
27200
- [LOCSRCID]: tokens[0][LOCSRCID],
27201
- [LOCSTA]: tokens[0][LOCSTA],
27202
- [LOCEND]: tokens[tokens.length - 1][LOCEND],
27203
- [TOKENS]: tokens,
27204
- [STATE]: exports.EnumAstNodeStatus.Invalid,
27205
- [ERRORS]: [
27206
- {
27207
- action: "drop",
27208
- node: tokens[i],
27209
- message: "invalid hash id",
27210
- },
27211
- ],
27212
- };
27213
- }
28295
+ }
28296
+ acc.set(curr.join(""), curr);
28297
+ return acc;
28298
+ }, uniq)
28299
+ .keys(),
28300
+ ].join(","),
28301
+ chi: [],
28302
+ [LOCSRCID]: tokens[0][LOCSRCID],
28303
+ [LOCSTA]: tokens[0][LOCSTA],
28304
+ [LOCEND]: tokens[tokens.length - 1][LOCEND],
28305
+ [TOKENS]: tokens,
28306
+ [STATE]: exports.EnumAstNodeStatus.Invalid,
28307
+ [ERRORS]: [
28308
+ {
28309
+ action: "drop",
28310
+ node: token,
28311
+ message: "invalid hash id",
28312
+ },
28313
+ ],
28314
+ };
27214
28315
  }
28316
+ all[write++] = token;
27215
28317
  }
27216
- const result = matchSelectorSyntax(tokens, errors, options, nested === true);
28318
+ if (write !== tokens.length) {
28319
+ for (let index = 0; index < write; index++) {
28320
+ tokens[index] = all[index];
28321
+ }
28322
+ tokens.length = write;
28323
+ }
28324
+ const result = matchSelectorSyntax(tokens, errors, options, nested);
27217
28325
  trimArray(tokens);
27218
28326
  if (result.success) {
27219
28327
  for (let i = 0; i < tokens.length; i++) {
@@ -27530,7 +28638,6 @@ function parseGridTemplate(template) {
27530
28638
  * @param errors
27531
28639
  */
27532
28640
  function parseDeclaration(tokens, parent, options, errors) {
27533
- // console.error(tokens);
27534
28641
  const name = tokens.shift();
27535
28642
  let i;
27536
28643
  let rules = null;
@@ -27645,7 +28752,7 @@ function parseDeclaration(tokens, parent, options, errors) {
27645
28752
  let token;
27646
28753
  let index;
27647
28754
  if (syntaxRules != null) {
27648
- const doNotValidate = options.validation === false || options.validation === exports.ValidationLevel.None;
28755
+ const doNotValidate = options.validation === false;
27649
28756
  result = doNotValidate ? null : matchAllSyntaxes(syntaxRules, createValidationContext(tokens), options);
27650
28757
  if (doNotValidate || result != null) {
27651
28758
  success = doNotValidate || result?.success;
@@ -27676,17 +28783,11 @@ function parseDeclaration(tokens, parent, options, errors) {
27676
28783
  stack.push(token);
27677
28784
  continue;
27678
28785
  }
28786
+ if (token.typ === exports.EnumToken.ColonTokenType && stack.length == 0) {
28787
+ stack.push(token);
28788
+ continue;
28789
+ }
27679
28790
  switch (token.typ) {
27680
- // case EnumToken.IdenTokenType:
27681
- // if (tokens[i + 1]?.typ == EnumToken.StartParensTokenType) {
27682
- // Object.assign(token, {
27683
- // typ: EnumToken.FunctionTokenDefType,
27684
- // });
27685
- // token[LOCEND] = tokens[i + 1][LOCEND];
27686
- // tokens.splice(i + 1, 1);
27687
- // stack.push(token);
27688
- // }
27689
- // break;
27690
28791
  case exports.EnumToken.Literal:
27691
28792
  if (token.val === "/" && stack.at(-1)?.typ == exports.EnumToken.MathFunctionTokenDefType) {
27692
28793
  Object.assign(token, {
@@ -27864,10 +28965,19 @@ function parseDeclaration(tokens, parent, options, errors) {
27864
28965
  }
27865
28966
  if (trimTokenSpace$1.has(token.typ)) {
27866
28967
  if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
27867
- tokens.splice(i + 1, 1);
28968
+ for (let index = i + 1; index < tokens.length - 1; index++) {
28969
+ tokens[index] = tokens[index + 1];
28970
+ }
28971
+ tokens.length--;
28972
+ i--;
28973
+ continue;
27868
28974
  }
27869
28975
  if (tokens[i - 1]?.typ == exports.EnumToken.WhitespaceTokenType) {
27870
- tokens.splice(--i, 1);
28976
+ for (let index = i - 1; index < tokens.length - 1; index++) {
28977
+ tokens[index] = tokens[index + 1];
28978
+ }
28979
+ tokens.length--;
28980
+ i--;
27871
28981
  }
27872
28982
  }
27873
28983
  }
@@ -27919,12 +29029,11 @@ function parseDeclaration(tokens, parent, options, errors) {
27919
29029
  name[STATE] = exports.EnumAstNodeStatus.Unknown;
27920
29030
  name[ERRORS] = result?.errors ?? [];
27921
29031
  // @ts-expect-error
27922
- const node = Object.assign(name, {
29032
+ return Object.assign(name, {
27923
29033
  typ: exports.EnumToken.DeclarationNodeType,
27924
29034
  nam: name.val,
27925
29035
  val: tokens,
27926
29036
  });
27927
- return node;
27928
29037
  }
27929
29038
  if (equalsIgnoreCase("composes", name.val)) {
27930
29039
  let index = -1;
@@ -28243,6 +29352,16 @@ function parseMediaqueryList(stream, options) {
28243
29352
  val.splice(0, val.length, ...filteredValues);
28244
29353
  }
28245
29354
  }
29355
+ if (stack.at(-1)?.typ === exports.EnumToken.ColonTokenType) {
29356
+ if (name.startsWith("min-")) {
29357
+ filteredNames[0].val = name.substring(4);
29358
+ stack.at(-1).typ = exports.EnumToken.GteTokenType;
29359
+ }
29360
+ else if (name.startsWith("max-")) {
29361
+ filteredNames[0].val = name.substring(4);
29362
+ stack.at(-1).typ = exports.EnumToken.LteTokenType;
29363
+ }
29364
+ }
28246
29365
  // @ts-expect-error
28247
29366
  tokens.splice(index3 + 1, tokens.length - index3 - 2, {
28248
29367
  typ: exports.EnumToken.MediaQueryConditionTokenType,
@@ -28298,6 +29417,61 @@ function parseMediaqueryList(stream, options) {
28298
29417
  [LOCEND]: right.at(-1)[LOCEND],
28299
29418
  };
28300
29419
  tokens.length = l + 1;
29420
+ // media range query
29421
+ if (options.minify &&
29422
+ tokens[l].op.typ === exports.EnumToken.AndTokenType) {
29423
+ if (left.length === 1 &&
29424
+ left[0].typ == exports.EnumToken.ParensTokenType &&
29425
+ left[0].chi.length == 1 &&
29426
+ left[0].chi[0].typ == exports.EnumToken.MediaQueryConditionTokenType &&
29427
+ left[0].chi[0].l.length == 1 &&
29428
+ left[0].chi[0].l[0].typ ==
29429
+ exports.EnumToken.IdenTokenType &&
29430
+ (left[0].chi[0].op.typ ==
29431
+ exports.EnumToken.GtTokenType ||
29432
+ left[0].chi[0].op.typ ==
29433
+ exports.EnumToken.GteTokenType) &&
29434
+ right.length === 1 &&
29435
+ left[0].typ == exports.EnumToken.ParensTokenType &&
29436
+ right[0].chi.length == 1 &&
29437
+ right[0].chi[0].typ ==
29438
+ exports.EnumToken.MediaQueryConditionTokenType &&
29439
+ right[0].chi[0].l.length == 1 &&
29440
+ right[0].chi[0].l[0].typ ==
29441
+ exports.EnumToken.IdenTokenType &&
29442
+ (right[0].chi[0].op.typ ==
29443
+ exports.EnumToken.LtTokenType ||
29444
+ right[0].chi[0].op.typ ==
29445
+ exports.EnumToken.LteTokenType) &&
29446
+ equalsIgnoreCase(left[0].chi[0]
29447
+ .l[0].val, right[0].chi[0]
29448
+ .l[0].val)) {
29449
+ tokens[l] = {
29450
+ typ: exports.EnumToken.ParensTokenType,
29451
+ chi: [
29452
+ {
29453
+ typ: exports.EnumToken.MediaRangeQueryTokenType,
29454
+ op1: Object.assign(left[0].chi[0]
29455
+ .op, {
29456
+ typ: left[0]
29457
+ .chi[0].op.typ == exports.EnumToken.GteTokenType
29458
+ ? exports.EnumToken.LteTokenType
29459
+ : exports.EnumToken.LtTokenType,
29460
+ }),
29461
+ op2: right[0].chi[0]
29462
+ .op,
29463
+ l: left[0].chi[0].r,
29464
+ val: left[0].chi[0]
29465
+ .l,
29466
+ r: right[0].chi[0].r,
29467
+ [LOCSRCID]: left[0][LOCSRCID],
29468
+ [LOCSTA]: left[0][LOCSTA],
29469
+ [LOCEND]: right.at(-1)[LOCEND],
29470
+ },
29471
+ ],
29472
+ };
29473
+ }
29474
+ }
28301
29475
  expectAndOrComma = true;
28302
29476
  }
28303
29477
  }
@@ -28736,7 +29910,7 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
28736
29910
  let i = 0;
28737
29911
  let success = true;
28738
29912
  let expectAndOr = false;
28739
- let scope = new Set();
29913
+ // let scope: Set<EnumToken> = new Set();
28740
29914
  const errors = [];
28741
29915
  // const scopes: Array<Set<EnumToken>> = [scope];
28742
29916
  for (; i < stream.length; i++) {
@@ -28758,7 +29932,7 @@ function matchAtRuleWhenElseSyntax(stream, context, options = {}) {
28758
29932
  Object.assign(stream[i], {
28759
29933
  typ: "or" === val ? exports.EnumToken.OrTokenType : exports.EnumToken.AndTokenType,
28760
29934
  });
28761
- scope.add(stream[i].typ);
29935
+ // scope.add(stream[i].typ);
28762
29936
  stack.push(stream[i]);
28763
29937
  // break;
28764
29938
  }
@@ -29138,7 +30312,7 @@ function parseAtRuleFontFeatureValues(stream, context, options = {}) {
29138
30312
  const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + context.nam);
29139
30313
  const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
29140
30314
  trimArray(stream);
29141
- const { success, errors} = matchAllSyntaxes(syntax, createValidationContext(stream), options);
30315
+ const { success, errors /* , ...all */ } = matchAllSyntaxes(syntax, createValidationContext(stream), options);
29142
30316
  return { success, errors };
29143
30317
  }
29144
30318
 
@@ -29650,7 +30824,7 @@ function parseVisitors(visitorsDef, errors) {
29650
30824
  }
29651
30825
  /**
29652
30826
  * Parse css string
29653
- * @param iter
30827
+ * @param tokenizer
29654
30828
  * @param options
29655
30829
  *
29656
30830
  * @throws Error
@@ -30647,6 +31821,7 @@ async function doParse(iter, options = {}) {
30647
31821
  const imports = [];
30648
31822
  let item;
30649
31823
  let node;
31824
+ // @ts-ignore ignore error
30650
31825
  let parensMatch = 0;
30651
31826
  let curlyBracketMatch = 0;
30652
31827
  let tokenizer = iter instanceof Promise ? await iter : iter;
@@ -32609,17 +33784,18 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
32609
33784
  * console.log(declarations);
32610
33785
  * ```
32611
33786
  */
32612
- async function parseDeclarations(declaration) {
33787
+ function parseDeclarations(declaration) {
32613
33788
  const stream = `.x{${declaration}}`;
32614
- return doParse(new Tokenizer({
33789
+ const result = doParseSync(new Tokenizer({
32615
33790
  stream,
32616
33791
  offset: 0,
32617
33792
  position: 0,
32618
33793
  source: new SourceFile(stream, [], ""),
32619
33794
  currentPosition: 0,
32620
- }), { setParent: false, minify: false, validation: false }).then((result) => {
32621
- return result.ast.chi[0].chi.filter((t) => t.typ == exports.EnumToken.DeclarationNodeType || t.typ == exports.EnumToken.CommentNodeType);
32622
- });
33795
+ }), { setParent: false, minify: false, validation: false });
33796
+ // .then((result) => {
33797
+ return result.ast.chi[0].chi.filter((t) => t.typ == exports.EnumToken.DeclarationNodeType || t.typ == exports.EnumToken.CommentNodeType);
33798
+ // });
32623
33799
  }
32624
33800
  /**
32625
33801
  * Parse css string and return an array of tokens
@@ -32644,14 +33820,6 @@ async function parseDeclarations(declaration) {
32644
33820
  * ```
32645
33821
  */
32646
33822
  function parseString(src, options = { parseColor: true }, errors) {
32647
- // const parseInfo: ParseInfo = {
32648
- // stream: src,
32649
- // offset: 0,
32650
- // time: 0,
32651
- // source: new SourceFile(src, [], ""),
32652
- // position: 0,
32653
- // currentPosition: 0,
32654
- // };
32655
33823
  const tokenizer = new Tokenizer({
32656
33824
  stream: src,
32657
33825
  buffer: "",
@@ -33265,13 +34433,10 @@ function transformSync(...args) {
33265
34433
  const parseResult = parseSync(stream, options);
33266
34434
  let mapping = null;
33267
34435
  let importMapping = null;
33268
- if (typeof options.module == "number" && options.module & exports.ModuleScopeEnumOptions.ICSS) {
33269
- mapping = parseResult.mapping;
33270
- importMapping = parseResult.importMapping;
33271
- }
33272
- else if (typeof options.module == "object" &&
33273
- typeof options.module.scoped == "number" &&
33274
- options.module.scoped & exports.ModuleScopeEnumOptions.ICSS) {
34436
+ if ((typeof options.module == "number" && options.module & exports.ModuleScopeEnumOptions.ICSS) ||
34437
+ (typeof options.module == "object" &&
34438
+ typeof options.module.scoped == "number" &&
34439
+ options.module.scoped & exports.ModuleScopeEnumOptions.ICSS)) {
33275
34440
  mapping = parseResult.mapping;
33276
34441
  importMapping = parseResult.importMapping;
33277
34442
  }
@@ -33488,13 +34653,10 @@ async function transform(...args) {
33488
34653
  return parse(stream, options).then((parseResult) => {
33489
34654
  let mapping = null;
33490
34655
  let importMapping = null;
33491
- if (typeof options.module == "number" && options.module & exports.ModuleScopeEnumOptions.ICSS) {
33492
- mapping = parseResult.mapping;
33493
- importMapping = parseResult.importMapping;
33494
- }
33495
- else if (typeof options.module == "object" &&
33496
- typeof options.module.scoped == "number" &&
33497
- options.module.scoped & exports.ModuleScopeEnumOptions.ICSS) {
34656
+ if ((typeof options.module == "number" && options.module & exports.ModuleScopeEnumOptions.ICSS) ||
34657
+ (typeof options.module == "object" &&
34658
+ typeof options.module.scoped == "number" &&
34659
+ options.module.scoped & exports.ModuleScopeEnumOptions.ICSS)) {
33498
34660
  mapping = parseResult.mapping;
33499
34661
  importMapping = parseResult.importMapping;
33500
34662
  }