@tbela99/css-parser 1.6.5 → 1.6.6

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,108 @@
1
1
  # Changelog
2
2
 
3
+ # v1.6.6
4
+
5
+ ## Fixes
6
+
7
+ - [x] parsing aspect ratio using a single number
8
+ - [x] bugs in calc()
9
+ - [x] computing media range in container at-rule
10
+
11
+ ```css
12
+
13
+ @media (aspect-ratio: 1.77) {
14
+ html {
15
+ background-color: cyan;
16
+ }
17
+ }
18
+
19
+ body {
20
+ left: sin(45deg);
21
+ left: cos(45deg);
22
+ left: tan(45deg);
23
+ left: asin(0.5);
24
+ left: acos(0.5);
25
+ left: atan(10);
26
+ left: atan2(-1, 1);
27
+ }
28
+
29
+ p {
30
+ font-size: calc(pow(10, 12) * 1rem);
31
+ font-size: calc(sqrt(100) * 1rem);
32
+ font-size: calc(hypot(3, 4) * 1rem);
33
+ font-size: calc(log(10) * 1rem);
34
+ font-size: calc(exp(10) * 1rem);
35
+ }
36
+
37
+
38
+ p {
39
+ color: alpha(from red / calc(alpha * 0.5));
40
+ }
41
+ p {
42
+ font-size: calc(pow(e, pi) * 1rem);
43
+ }
44
+
45
+ @container (min-width: 700px) {
46
+ .container {
47
+
48
+ display: grid;
49
+ }
50
+ }
51
+
52
+ @container (max-width: 1400px) {
53
+ .container {
54
+
55
+ display: grid;
56
+ }
57
+ }
58
+
59
+ @container (min-width: 700px) and (max-width: 1400px) {
60
+ .container {
61
+
62
+ display: grid;
63
+ /* styles applied when a container is at least 700px */
64
+ }
65
+ }
66
+
67
+ ```
68
+ is now computed as
69
+
70
+ ```css
71
+ @media (aspect-ratio:1.77) {
72
+ html {
73
+ background-color: cyan
74
+ }
75
+ }
76
+ body {
77
+ left: .707107;
78
+ left: .707107;
79
+ left: 1;
80
+ left: 30deg;
81
+ left: 60deg;
82
+ left: .234turn;
83
+ left: -45deg
84
+ }
85
+ p {
86
+ font-size: 23.140693rem;
87
+ color: #ff000080
88
+ }
89
+ @container (width>=700px) {
90
+ .container {
91
+ display: grid
92
+ }
93
+ }
94
+ @container (width<=1400px) {
95
+ .container {
96
+ display: grid
97
+ }
98
+ }
99
+ @container (700px<=width<=1400px) {
100
+ .container {
101
+ display: grid
102
+ }
103
+ }
104
+ ```
105
+
3
106
  # v1.6.5
4
107
 
5
108
  ## New
@@ -0,0 +1,119 @@
1
+ # Contributing
2
+
3
+ Thanks for your interest in contributing to CSS Parser. This guide explains how to get the project running locally, update its generated configuration data, run the checks, and submit a change. It is intended to help new contributors get started and make contributions easier to review.
4
+
5
+ ## Get the source
6
+
7
+ 1. Fork the repository on GitHub.
8
+ 2. Clone your fork and enter the project directory:
9
+
10
+ ```sh
11
+ git clone https://github.com/<your-user-name>/css-parser.git
12
+ cd css-parser
13
+ ```
14
+
15
+ 3. Add the upstream repository and install the root project dependencies:
16
+
17
+ ```sh
18
+ git remote add upstream https://github.com/tbela99/css-parser.git
19
+ npm install
20
+ ```
21
+
22
+ 4. Create a branch for your change:
23
+
24
+ ```sh
25
+ git switch -c descriptive-branch-name
26
+ ```
27
+
28
+ Use a current Node.js release compatible with the project dependencies.
29
+
30
+ ## Update generated configuration
31
+
32
+ The repository includes scripts for refreshing generated CSS property and syntax data. Run them from the project root:
33
+
34
+ ```sh
35
+ npm run config-update
36
+ npm run syntax-update
37
+ ```
38
+
39
+ `config-update` regenerates `src/data/properties.json`. `syntax-update` regenerates `src/data/validation.json` from upstream CSS data and therefore requires an internet connection. Review the generated changes and include them when they are relevant to your contribution.
40
+
41
+ ## Building
42
+
43
+ Run the build command:
44
+
45
+ ```sh
46
+ npm run build
47
+ ```
48
+
49
+ Validate your changes before committing using deno:
50
+
51
+ ```sh
52
+ deno publish --dry-run
53
+ ```
54
+
55
+ ## Run tests
56
+
57
+ Run the complete Node.js and browser test suites before submitting a change:
58
+
59
+ ```sh
60
+ npm test
61
+ ```
62
+
63
+ For a quicker, focused check, run either suite:
64
+
65
+ ```sh
66
+ npm run test:node
67
+ npm run test:web
68
+ ```
69
+
70
+ The browser tests use Playwright with Chromium, Firefox, and WebKit. Install the required browsers if Playwright reports that they are missing.
71
+
72
+ For debugging, run either suite:
73
+
74
+ ```sh
75
+ npm run debug:node
76
+ npm run debug:web
77
+ ```
78
+ ## Check code coverage
79
+
80
+ Generate Node.js coverage reports with:
81
+
82
+ ```sh
83
+ npm run test:cov
84
+ ```
85
+
86
+ The command prints a text summary and writes an HTML report under `coverage/`. Browser coverage can be collected separately with:
87
+
88
+ ```sh
89
+ npm run test:web-cov
90
+ ```
91
+
92
+ When changing behavior, add or update tests that exercise it and use the coverage reports to spot untested paths.
93
+
94
+ ## Run the benchmark
95
+
96
+ The benchmark has its own dependencies and must be run from the `benchmark/` directory:
97
+
98
+ ```sh
99
+ cd benchmark
100
+ npm install
101
+ npm run all
102
+ ```
103
+
104
+ This computes output sizes, runs the timing benchmarks, and generates `benchmark/results/benchmark.html`. Open that report to inspect the results. To run individual stages, use `npm run sizes`, `npm run bench`, or `npm run report` from `benchmark/`.
105
+
106
+ ## Open a pull request
107
+
108
+ 1. Review your changes and make sure no unrelated generated files or benchmark results are included.
109
+ 2. Run the relevant tests; include coverage or benchmark results when they help explain the change.
110
+ 3. Push your branch to your fork:
111
+
112
+ ```sh
113
+ git push -u origin descriptive-branch-name
114
+ ```
115
+
116
+ 4. Open a pull request on GitHub against `tbela99/css-parser`'s `master` branch.
117
+ 5. In the pull request description, explain the problem and the proposed change, link any related issue, and list the checks you ran. Include before-and-after benchmark results for performance-related changes.
118
+
119
+ Keep each pull request focused, and be ready to discuss or revise the change during review.
@@ -2518,7 +2518,7 @@ var syntaxes = {
2518
2518
  syntax: "<number> | <percentage> | none"
2519
2519
  },
2520
2520
  "an+b": {
2521
- syntax: "odd | even | <integer> | <n-dimension> | '+'?† n | -n | <ndashdigit-dimension> | '+'?† <ndashdigit-ident> | <dashndashdigit-ident> | <n-dimension> <signed-integer> | '+'?† n <signed-integer> | -n <signed-integer> | <ndash-dimension> <signless-integer> | '+'?† n- <signless-integer> | -n- <signless-integer> | <n-dimension> ['+' | '-'] <signless-integer> | '+'?† n ['+' | '-'] <signless-integer> | -n ['+' | '-'] <signless-integer>"
2521
+ syntax: "odd | even | <integer> | <n-dimension> | '+'? n | -n | <ndashdigit-dimension> | '+'? <ndashdigit-ident> | <dashndashdigit-ident> | <n-dimension> <signed-integer> | '+'? n <signed-integer> | -n <signed-integer> | <ndash-dimension> <signless-integer> | '+'? n- <signless-integer> | -n- <signless-integer> | <n-dimension> ['+' | '-'] <signless-integer> | '+'? n ['+' | '-'] <signless-integer> | -n ['+' | '-'] <signless-integer>"
2522
2522
  },
2523
2523
  "anchor()": {
2524
2524
  syntax: "anchor( <anchor-name>? && <anchor-side>, <length-percentage>? )"
@@ -4551,6 +4551,9 @@ var atRules = {
4551
4551
  marks: {
4552
4552
  syntax: "none | [ crop || cross ]"
4553
4553
  },
4554
+ "page-margin-safety": {
4555
+ syntax: "none | clamp | add"
4556
+ },
4554
4557
  "page-orientation": {
4555
4558
  syntax: "upright | rotate-left | rotate-right"
4556
4559
  },
@@ -3515,7 +3515,7 @@
3515
3515
  syntax: "<number> | <percentage> | none"
3516
3516
  },
3517
3517
  "an+b": {
3518
- syntax: "odd | even | <integer> | <n-dimension> | '+'?† n | -n | <ndashdigit-dimension> | '+'?† <ndashdigit-ident> | <dashndashdigit-ident> | <n-dimension> <signed-integer> | '+'?† n <signed-integer> | -n <signed-integer> | <ndash-dimension> <signless-integer> | '+'?† n- <signless-integer> | -n- <signless-integer> | <n-dimension> ['+' | '-'] <signless-integer> | '+'?† n ['+' | '-'] <signless-integer> | -n ['+' | '-'] <signless-integer>"
3518
+ syntax: "odd | even | <integer> | <n-dimension> | '+'? n | -n | <ndashdigit-dimension> | '+'? <ndashdigit-ident> | <dashndashdigit-ident> | <n-dimension> <signed-integer> | '+'? n <signed-integer> | -n <signed-integer> | <ndash-dimension> <signless-integer> | '+'? n- <signless-integer> | -n- <signless-integer> | <n-dimension> ['+' | '-'] <signless-integer> | '+'? n ['+' | '-'] <signless-integer> | -n ['+' | '-'] <signless-integer>"
3519
3519
  },
3520
3520
  "anchor()": {
3521
3521
  syntax: "anchor( <anchor-name>? && <anchor-side>, <length-percentage>? )"
@@ -5548,6 +5548,9 @@
5548
5548
  marks: {
5549
5549
  syntax: "none | [ crop || cross ]"
5550
5550
  },
5551
+ "page-margin-safety": {
5552
+ syntax: "none | clamp | add"
5553
+ },
5551
5554
  "page-orientation": {
5552
5555
  syntax: "upright | rotate-left | rotate-right"
5553
5556
  },
@@ -10027,6 +10030,7 @@
10027
10030
  return g > 1 ? [a / g, b / g] : [a, b];
10028
10031
  }
10029
10032
 
10033
+ const numbers = new Set(["sin", "cos", "asin", "acos", "sign", "tan"]);
10030
10034
  /**
10031
10035
  * evaluate an array of tokens
10032
10036
  * @param tokens
@@ -10216,9 +10220,22 @@
10216
10220
  r.typ == exports.EnumToken.NegativeInfinityTokenType) {
10217
10221
  return computeInfinity(l, r, op, defaultReturn);
10218
10222
  }
10223
+ if (l.typ == exports.EnumToken.FunctionTokenType || l.typ == exports.EnumToken.MathFunctionTokenType) {
10224
+ const val = evaluateFunc(l);
10225
+ if (val == null ||
10226
+ (val.length == 1 &&
10227
+ (val[0].typ == exports.EnumToken.MathFunctionTokenType || val[0].typ == exports.EnumToken.FunctionTokenType))) {
10228
+ return defaultReturn;
10229
+ }
10230
+ if (val.length == 1) {
10231
+ l = val[0];
10232
+ }
10233
+ }
10219
10234
  if (r.typ == exports.EnumToken.FunctionTokenType || r.typ == exports.EnumToken.MathFunctionTokenType) {
10220
10235
  const val = evaluateFunc(r);
10221
- if (val == null) {
10236
+ if (val == null ||
10237
+ (val.length == 1 &&
10238
+ (val[0].typ == exports.EnumToken.MathFunctionTokenType || val[0].typ == exports.EnumToken.FunctionTokenType))) {
10222
10239
  return defaultReturn;
10223
10240
  }
10224
10241
  if (val.length == 1) {
@@ -10436,45 +10453,43 @@
10436
10453
  function evaluateFunc(token) {
10437
10454
  const values = token.chi.slice();
10438
10455
  switch (token.val) {
10439
- case "abs":
10440
10456
  case "sin":
10441
10457
  case "cos":
10442
10458
  case "tan":
10459
+ for (let i = 0; i < values.length; i++) {
10460
+ if (values[i].typ == exports.EnumToken.NumberTokenType) {
10461
+ values[i] = Object.assign(values[i], { typ: exports.EnumToken.AngleTokenType, unit: "rad" });
10462
+ }
10463
+ else if (values[i].typ == exports.EnumToken.AngleTokenType && values[i].unit != "rad") {
10464
+ switch (values[i].unit) {
10465
+ case "deg":
10466
+ Object.assign(values[i], {
10467
+ unit: "rad",
10468
+ val: values[i].val * (Math.PI / 180),
10469
+ });
10470
+ break;
10471
+ case "grad":
10472
+ Object.assign(values[i], {
10473
+ unit: "rad",
10474
+ val: values[i].val * (Math.PI / 200),
10475
+ });
10476
+ break;
10477
+ case "turn":
10478
+ Object.assign(values[i], {
10479
+ unit: "rad",
10480
+ val: values[i].val * (2 * Math.PI),
10481
+ });
10482
+ break;
10483
+ }
10484
+ }
10485
+ }
10443
10486
  case "asin":
10444
10487
  case "acos":
10445
10488
  case "atan":
10489
+ case "abs":
10446
10490
  case "sign":
10447
10491
  case "sqrt":
10448
- case "exp": {
10449
- if (token.val == "tan" || token.val == "atan") {
10450
- for (let i = 0; i < values.length; i++) {
10451
- if (values[i].typ == exports.EnumToken.NumberTokenType) {
10452
- values[i] = Object.assign(values[i], { typ: exports.EnumToken.AngleTokenType, unit: "rad" });
10453
- }
10454
- else if (values[i].typ == exports.EnumToken.AngleTokenType && values[i].unit != "rad") {
10455
- switch (values[i].unit) {
10456
- case "deg":
10457
- Object.assign(values[i], {
10458
- unit: "rad",
10459
- val: values[i].val * (Math.PI / 180),
10460
- });
10461
- break;
10462
- case "grad":
10463
- Object.assign(values[i], {
10464
- unit: "rad",
10465
- val: values[i].val * (Math.PI / 200),
10466
- });
10467
- break;
10468
- case "turn":
10469
- Object.assign(values[i], {
10470
- unit: "rad",
10471
- val: values[i].val * (2 * Math.PI),
10472
- });
10473
- break;
10474
- }
10475
- }
10476
- }
10477
- }
10492
+ case "exp":
10478
10493
  const value = evaluate(values);
10479
10494
  // @ts-ignore
10480
10495
  let val = value[0].typ == exports.EnumToken.NumberTokenType ||
@@ -10484,7 +10499,7 @@
10484
10499
  : // @ts-expect-error
10485
10500
  value[0].l.val / value[0].r.val;
10486
10501
  return [
10487
- token.val == "tan" || token.val == "atan"
10502
+ token.val == "asin" || token.val == "acos" || token.val == "atan"
10488
10503
  ? {
10489
10504
  typ: exports.EnumToken.AngleTokenType,
10490
10505
  val: Math[token.val](val),
@@ -10495,7 +10510,7 @@
10495
10510
  [PARENT]: value[0][PARENT],
10496
10511
  }
10497
10512
  : {
10498
- typ: token.val == "sign" ? exports.EnumToken.NumberTokenType : value[0].typ,
10513
+ typ: numbers.has(token.val) ? exports.EnumToken.NumberTokenType : value[0].typ,
10499
10514
  val: Math[token.val](val),
10500
10515
  [LOCSRCID]: value[0][LOCSRCID],
10501
10516
  [LOCSTA]: value[0][LOCSTA],
@@ -10503,7 +10518,6 @@
10503
10518
  [PARENT]: value[0][PARENT],
10504
10519
  },
10505
10520
  ];
10506
- }
10507
10521
  case "hypot": {
10508
10522
  const chi = values.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType, exports.EnumToken.CommaTokenType].includes(t.typ));
10509
10523
  let all = [];
@@ -12258,7 +12272,8 @@
12258
12272
  return { valid: true, success: false, isValueAllowed: false };
12259
12273
  }
12260
12274
  featureName = featureName.toLowerCase();
12261
- if (!(featureName in config$3.mediaFeatures)) {
12275
+ // @ts-expect-error
12276
+ if (config$3.mediaFeatures[featureName] == null) {
12262
12277
  return { valid: false, success: false };
12263
12278
  }
12264
12279
  // @ts-expect-error
@@ -12302,8 +12317,7 @@
12302
12317
  return {
12303
12318
  valid: true,
12304
12319
  success: (tokens.length == 1 &&
12305
- tokens[0].typ == exports.EnumToken.NumberTokenType &&
12306
- tokens[0].val.typ == exports.EnumToken.FractionTokenType) ||
12320
+ tokens[0].typ == exports.EnumToken.NumberTokenType) ||
12307
12321
  (tokens.length === 3 &&
12308
12322
  tokens[0].typ == exports.EnumToken.NumberTokenType &&
12309
12323
  typeof tokens[0].val === "number" &&
@@ -21047,7 +21061,8 @@
21047
21061
  }
21048
21062
  }
21049
21063
  run(ast) {
21050
- if (!("chi" in ast)) {
21064
+ // @ts-ignore
21065
+ if (ast.chi == null) {
21051
21066
  return null;
21052
21067
  }
21053
21068
  for (const node of ast.chi) {
@@ -21065,15 +21080,7 @@
21065
21080
  // @ts-ignore
21066
21081
  replaceNodeOrValue(parent, value, result);
21067
21082
  }
21068
- catch (e) {
21069
- // @ts-ignore
21070
- if (Array.isArray(parent.chi)) {
21071
- // @ts-ignore
21072
- parent.chi.length = 0;
21073
- // @ts-ignore
21074
- parent.chi.push(...result);
21075
- }
21076
- }
21083
+ catch (e) { }
21077
21084
  continue;
21078
21085
  }
21079
21086
  if (value != null && tokensfuncSet.has(value.typ)) {
@@ -29468,8 +29475,6 @@
29468
29475
  }
29469
29476
  }
29470
29477
  }
29471
- // let isValidMFValue = isMFValue(name, left, true);
29472
- // isValidMFValue = isMFValue(name, right, true);
29473
29478
  for (const val of [left, right]) {
29474
29479
  if (mfInfo?.type === MediaFeatureType.RatioType) {
29475
29480
  const filteredValues = val.filter((n) => n.typ !== exports.EnumToken.WhitespaceTokenType &&
@@ -30265,7 +30270,7 @@
30265
30270
  };
30266
30271
  }
30267
30272
  {
30268
- for (const stream of parts.slice()) {
30273
+ for (const stream of parts) {
30269
30274
  let success = true;
30270
30275
  let i;
30271
30276
  let currentScope = new Set();
@@ -30384,6 +30389,22 @@
30384
30389
  [LOCSTA]: names[0][LOCSTA],
30385
30390
  [LOCEND]: values.at(-1)[LOCEND],
30386
30391
  });
30392
+ const token = tokens[index3 + 1];
30393
+ if (token.op.typ === exports.EnumToken.ColonTokenType) {
30394
+ let name = token.l.find((t) => t.typ === exports.EnumToken.IdenTokenType);
30395
+ if (name != null) {
30396
+ if (name.val.startsWith("min-")) {
30397
+ name.val = name.val.substring(4);
30398
+ // @ts-ignore
30399
+ token.op.typ = exports.EnumToken.GteTokenType;
30400
+ }
30401
+ else if (name.val.startsWith("max-")) {
30402
+ name.val = name.val.substring(4);
30403
+ // @ts-ignore
30404
+ token.op.typ = exports.EnumToken.LteTokenType;
30405
+ }
30406
+ }
30407
+ }
30387
30408
  // check <style()> or <scroll-state()>
30388
30409
  }
30389
30410
  if (tokensfuncDefMap.has(stack.at(-1)?.typ)) {
@@ -30475,6 +30496,58 @@
30475
30496
  };
30476
30497
  tokens.length = l + 1;
30477
30498
  expectAndOr = true;
30499
+ if (tokens[l].op.typ === exports.EnumToken.AndTokenType) {
30500
+ let left = tokens[l].l.find((t) => t.typ != exports.EnumToken.WhitespaceTokenType && t.typ != exports.EnumToken.IdenTokenType);
30501
+ let right = tokens[l].r.find((t) => t.typ != exports.EnumToken.WhitespaceTokenType && t.typ != exports.EnumToken.IdenTokenType);
30502
+ if (left.typ == exports.EnumToken.ParensTokenType && right.typ == exports.EnumToken.ParensTokenType) {
30503
+ left = left.chi.find((t) => t.typ != exports.EnumToken.WhitespaceTokenType && t.typ != exports.EnumToken.IdenTokenType);
30504
+ right = right.chi.find((t) => t.typ != exports.EnumToken.WhitespaceTokenType && t.typ != exports.EnumToken.IdenTokenType);
30505
+ if (left.typ == exports.EnumToken.MediaQueryConditionTokenType &&
30506
+ (mFLT.has(left.op.typ) ||
30507
+ mFGT.has(left.op.typ)) &&
30508
+ right.typ == exports.EnumToken.MediaQueryConditionTokenType &&
30509
+ (mFLT.has(right.op.typ) ||
30510
+ mFGT.has(right.op.typ))) {
30511
+ const name = left.l.find((t) => t.typ == exports.EnumToken.IdenTokenType);
30512
+ const name2 = right.l.find((t) => t.typ == exports.EnumToken.IdenTokenType);
30513
+ if (equalsIgnoreCase(name.val, name2.val)) {
30514
+ switch (left.op.typ) {
30515
+ case exports.EnumToken.LtTokenType:
30516
+ left.op.typ = exports.EnumToken.GtTokenType;
30517
+ break;
30518
+ case exports.EnumToken.LteTokenType:
30519
+ left.op.typ = exports.EnumToken.GteTokenType;
30520
+ break;
30521
+ case exports.EnumToken.GtTokenType:
30522
+ left.op.typ = exports.EnumToken.LtTokenType;
30523
+ break;
30524
+ case exports.EnumToken.GteTokenType:
30525
+ left.op.typ = exports.EnumToken.LteTokenType;
30526
+ break;
30527
+ }
30528
+ tokens[l] = {
30529
+ typ: exports.EnumToken.ParensTokenType,
30530
+ chi: [
30531
+ {
30532
+ typ: exports.EnumToken.MediaRangeQueryTokenType,
30533
+ l: left.r,
30534
+ val: [name],
30535
+ op1: left.op,
30536
+ op2: right.op,
30537
+ r: right.r,
30538
+ [LOCSRCID]: name[LOCSRCID],
30539
+ [LOCSTA]: left[LOCSTA],
30540
+ [LOCEND]: right[LOCEND],
30541
+ },
30542
+ ],
30543
+ [LOCSRCID]: name[LOCSRCID],
30544
+ [LOCSTA]: left[LOCSTA],
30545
+ [LOCEND]: right[LOCEND],
30546
+ };
30547
+ }
30548
+ }
30549
+ }
30550
+ }
30478
30551
  }
30479
30552
  break;
30480
30553
  }
@@ -31108,7 +31181,6 @@
31108
31181
  // let currentItemIndex: number;
31109
31182
  ast[LOCSRCID] = options.source.id;
31110
31183
  ast[LOCSTA] = 0;
31111
- // let tokenizer: Tokenizer;
31112
31184
  while (!tokenizer.done()) {
31113
31185
  tokenizer.next();
31114
31186
  // item = (iter as Array<TokenizeResult>)[currentItemIndex];
package/dist/index.cjs CHANGED
@@ -3518,7 +3518,7 @@ var syntaxes = {
3518
3518
  syntax: "<number> | <percentage> | none"
3519
3519
  },
3520
3520
  "an+b": {
3521
- syntax: "odd | even | <integer> | <n-dimension> | '+'?† n | -n | <ndashdigit-dimension> | '+'?† <ndashdigit-ident> | <dashndashdigit-ident> | <n-dimension> <signed-integer> | '+'?† n <signed-integer> | -n <signed-integer> | <ndash-dimension> <signless-integer> | '+'?† n- <signless-integer> | -n- <signless-integer> | <n-dimension> ['+' | '-'] <signless-integer> | '+'?† n ['+' | '-'] <signless-integer> | -n ['+' | '-'] <signless-integer>"
3521
+ syntax: "odd | even | <integer> | <n-dimension> | '+'? n | -n | <ndashdigit-dimension> | '+'? <ndashdigit-ident> | <dashndashdigit-ident> | <n-dimension> <signed-integer> | '+'? n <signed-integer> | -n <signed-integer> | <ndash-dimension> <signless-integer> | '+'? n- <signless-integer> | -n- <signless-integer> | <n-dimension> ['+' | '-'] <signless-integer> | '+'? n ['+' | '-'] <signless-integer> | -n ['+' | '-'] <signless-integer>"
3522
3522
  },
3523
3523
  "anchor()": {
3524
3524
  syntax: "anchor( <anchor-name>? && <anchor-side>, <length-percentage>? )"
@@ -5551,6 +5551,9 @@ var atRules = {
5551
5551
  marks: {
5552
5552
  syntax: "none | [ crop || cross ]"
5553
5553
  },
5554
+ "page-margin-safety": {
5555
+ syntax: "none | clamp | add"
5556
+ },
5554
5557
  "page-orientation": {
5555
5558
  syntax: "upright | rotate-left | rotate-right"
5556
5559
  },
@@ -10030,6 +10033,7 @@ function simplify(a, b) {
10030
10033
  return g > 1 ? [a / g, b / g] : [a, b];
10031
10034
  }
10032
10035
 
10036
+ const numbers = new Set(["sin", "cos", "asin", "acos", "sign", "tan"]);
10033
10037
  /**
10034
10038
  * evaluate an array of tokens
10035
10039
  * @param tokens
@@ -10219,9 +10223,22 @@ function doEvaluate(l, r, op) {
10219
10223
  r.typ == exports.EnumToken.NegativeInfinityTokenType) {
10220
10224
  return computeInfinity(l, r, op, defaultReturn);
10221
10225
  }
10226
+ if (l.typ == exports.EnumToken.FunctionTokenType || l.typ == exports.EnumToken.MathFunctionTokenType) {
10227
+ const val = evaluateFunc(l);
10228
+ if (val == null ||
10229
+ (val.length == 1 &&
10230
+ (val[0].typ == exports.EnumToken.MathFunctionTokenType || val[0].typ == exports.EnumToken.FunctionTokenType))) {
10231
+ return defaultReturn;
10232
+ }
10233
+ if (val.length == 1) {
10234
+ l = val[0];
10235
+ }
10236
+ }
10222
10237
  if (r.typ == exports.EnumToken.FunctionTokenType || r.typ == exports.EnumToken.MathFunctionTokenType) {
10223
10238
  const val = evaluateFunc(r);
10224
- if (val == null) {
10239
+ if (val == null ||
10240
+ (val.length == 1 &&
10241
+ (val[0].typ == exports.EnumToken.MathFunctionTokenType || val[0].typ == exports.EnumToken.FunctionTokenType))) {
10225
10242
  return defaultReturn;
10226
10243
  }
10227
10244
  if (val.length == 1) {
@@ -10439,45 +10456,43 @@ function getValue$1(t) {
10439
10456
  function evaluateFunc(token) {
10440
10457
  const values = token.chi.slice();
10441
10458
  switch (token.val) {
10442
- case "abs":
10443
10459
  case "sin":
10444
10460
  case "cos":
10445
10461
  case "tan":
10462
+ for (let i = 0; i < values.length; i++) {
10463
+ if (values[i].typ == exports.EnumToken.NumberTokenType) {
10464
+ values[i] = Object.assign(values[i], { typ: exports.EnumToken.AngleTokenType, unit: "rad" });
10465
+ }
10466
+ else if (values[i].typ == exports.EnumToken.AngleTokenType && values[i].unit != "rad") {
10467
+ switch (values[i].unit) {
10468
+ case "deg":
10469
+ Object.assign(values[i], {
10470
+ unit: "rad",
10471
+ val: values[i].val * (Math.PI / 180),
10472
+ });
10473
+ break;
10474
+ case "grad":
10475
+ Object.assign(values[i], {
10476
+ unit: "rad",
10477
+ val: values[i].val * (Math.PI / 200),
10478
+ });
10479
+ break;
10480
+ case "turn":
10481
+ Object.assign(values[i], {
10482
+ unit: "rad",
10483
+ val: values[i].val * (2 * Math.PI),
10484
+ });
10485
+ break;
10486
+ }
10487
+ }
10488
+ }
10446
10489
  case "asin":
10447
10490
  case "acos":
10448
10491
  case "atan":
10492
+ case "abs":
10449
10493
  case "sign":
10450
10494
  case "sqrt":
10451
- case "exp": {
10452
- if (token.val == "tan" || token.val == "atan") {
10453
- for (let i = 0; i < values.length; i++) {
10454
- if (values[i].typ == exports.EnumToken.NumberTokenType) {
10455
- values[i] = Object.assign(values[i], { typ: exports.EnumToken.AngleTokenType, unit: "rad" });
10456
- }
10457
- else if (values[i].typ == exports.EnumToken.AngleTokenType && values[i].unit != "rad") {
10458
- switch (values[i].unit) {
10459
- case "deg":
10460
- Object.assign(values[i], {
10461
- unit: "rad",
10462
- val: values[i].val * (Math.PI / 180),
10463
- });
10464
- break;
10465
- case "grad":
10466
- Object.assign(values[i], {
10467
- unit: "rad",
10468
- val: values[i].val * (Math.PI / 200),
10469
- });
10470
- break;
10471
- case "turn":
10472
- Object.assign(values[i], {
10473
- unit: "rad",
10474
- val: values[i].val * (2 * Math.PI),
10475
- });
10476
- break;
10477
- }
10478
- }
10479
- }
10480
- }
10495
+ case "exp":
10481
10496
  const value = evaluate(values);
10482
10497
  // @ts-ignore
10483
10498
  let val = value[0].typ == exports.EnumToken.NumberTokenType ||
@@ -10487,7 +10502,7 @@ function evaluateFunc(token) {
10487
10502
  : // @ts-expect-error
10488
10503
  value[0].l.val / value[0].r.val;
10489
10504
  return [
10490
- token.val == "tan" || token.val == "atan"
10505
+ token.val == "asin" || token.val == "acos" || token.val == "atan"
10491
10506
  ? {
10492
10507
  typ: exports.EnumToken.AngleTokenType,
10493
10508
  val: Math[token.val](val),
@@ -10498,7 +10513,7 @@ function evaluateFunc(token) {
10498
10513
  [PARENT]: value[0][PARENT],
10499
10514
  }
10500
10515
  : {
10501
- typ: token.val == "sign" ? exports.EnumToken.NumberTokenType : value[0].typ,
10516
+ typ: numbers.has(token.val) ? exports.EnumToken.NumberTokenType : value[0].typ,
10502
10517
  val: Math[token.val](val),
10503
10518
  [LOCSRCID]: value[0][LOCSRCID],
10504
10519
  [LOCSTA]: value[0][LOCSTA],
@@ -10506,7 +10521,6 @@ function evaluateFunc(token) {
10506
10521
  [PARENT]: value[0][PARENT],
10507
10522
  },
10508
10523
  ];
10509
- }
10510
10524
  case "hypot": {
10511
10525
  const chi = values.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType, exports.EnumToken.CommaTokenType].includes(t.typ));
10512
10526
  let all = [];
@@ -12261,7 +12275,8 @@ function isMFValue(featureName, tokens, isMFRange) {
12261
12275
  return { valid: true, success: false, isValueAllowed: false };
12262
12276
  }
12263
12277
  featureName = featureName.toLowerCase();
12264
- if (!(featureName in config$3.mediaFeatures)) {
12278
+ // @ts-expect-error
12279
+ if (config$3.mediaFeatures[featureName] == null) {
12265
12280
  return { valid: false, success: false };
12266
12281
  }
12267
12282
  // @ts-expect-error
@@ -12305,8 +12320,7 @@ function isMFValue(featureName, tokens, isMFRange) {
12305
12320
  return {
12306
12321
  valid: true,
12307
12322
  success: (tokens.length == 1 &&
12308
- tokens[0].typ == exports.EnumToken.NumberTokenType &&
12309
- tokens[0].val.typ == exports.EnumToken.FractionTokenType) ||
12323
+ tokens[0].typ == exports.EnumToken.NumberTokenType) ||
12310
12324
  (tokens.length === 3 &&
12311
12325
  tokens[0].typ == exports.EnumToken.NumberTokenType &&
12312
12326
  typeof tokens[0].val === "number" &&
@@ -21050,7 +21064,8 @@ class ComputeCalcExpressionFeature {
21050
21064
  }
21051
21065
  }
21052
21066
  run(ast) {
21053
- if (!("chi" in ast)) {
21067
+ // @ts-ignore
21068
+ if (ast.chi == null) {
21054
21069
  return null;
21055
21070
  }
21056
21071
  for (const node of ast.chi) {
@@ -21068,15 +21083,7 @@ class ComputeCalcExpressionFeature {
21068
21083
  // @ts-ignore
21069
21084
  replaceNodeOrValue(parent, value, result);
21070
21085
  }
21071
- catch (e) {
21072
- // @ts-ignore
21073
- if (Array.isArray(parent.chi)) {
21074
- // @ts-ignore
21075
- parent.chi.length = 0;
21076
- // @ts-ignore
21077
- parent.chi.push(...result);
21078
- }
21079
- }
21086
+ catch (e) { }
21080
21087
  continue;
21081
21088
  }
21082
21089
  if (value != null && tokensfuncSet.has(value.typ)) {
@@ -29471,8 +29478,6 @@ function parseMediaqueryList(stream, options) {
29471
29478
  }
29472
29479
  }
29473
29480
  }
29474
- // let isValidMFValue = isMFValue(name, left, true);
29475
- // isValidMFValue = isMFValue(name, right, true);
29476
29481
  for (const val of [left, right]) {
29477
29482
  if (mfInfo?.type === MediaFeatureType.RatioType) {
29478
29483
  const filteredValues = val.filter((n) => n.typ !== exports.EnumToken.WhitespaceTokenType &&
@@ -30268,7 +30273,7 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
30268
30273
  };
30269
30274
  }
30270
30275
  {
30271
- for (const stream of parts.slice()) {
30276
+ for (const stream of parts) {
30272
30277
  let success = true;
30273
30278
  let i;
30274
30279
  let currentScope = new Set();
@@ -30387,6 +30392,22 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
30387
30392
  [LOCSTA]: names[0][LOCSTA],
30388
30393
  [LOCEND]: values.at(-1)[LOCEND],
30389
30394
  });
30395
+ const token = tokens[index3 + 1];
30396
+ if (token.op.typ === exports.EnumToken.ColonTokenType) {
30397
+ let name = token.l.find((t) => t.typ === exports.EnumToken.IdenTokenType);
30398
+ if (name != null) {
30399
+ if (name.val.startsWith("min-")) {
30400
+ name.val = name.val.substring(4);
30401
+ // @ts-ignore
30402
+ token.op.typ = exports.EnumToken.GteTokenType;
30403
+ }
30404
+ else if (name.val.startsWith("max-")) {
30405
+ name.val = name.val.substring(4);
30406
+ // @ts-ignore
30407
+ token.op.typ = exports.EnumToken.LteTokenType;
30408
+ }
30409
+ }
30410
+ }
30390
30411
  // check <style()> or <scroll-state()>
30391
30412
  }
30392
30413
  if (tokensfuncDefMap.has(stack.at(-1)?.typ)) {
@@ -30478,6 +30499,58 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
30478
30499
  };
30479
30500
  tokens.length = l + 1;
30480
30501
  expectAndOr = true;
30502
+ if (tokens[l].op.typ === exports.EnumToken.AndTokenType) {
30503
+ let left = tokens[l].l.find((t) => t.typ != exports.EnumToken.WhitespaceTokenType && t.typ != exports.EnumToken.IdenTokenType);
30504
+ let right = tokens[l].r.find((t) => t.typ != exports.EnumToken.WhitespaceTokenType && t.typ != exports.EnumToken.IdenTokenType);
30505
+ if (left.typ == exports.EnumToken.ParensTokenType && right.typ == exports.EnumToken.ParensTokenType) {
30506
+ left = left.chi.find((t) => t.typ != exports.EnumToken.WhitespaceTokenType && t.typ != exports.EnumToken.IdenTokenType);
30507
+ right = right.chi.find((t) => t.typ != exports.EnumToken.WhitespaceTokenType && t.typ != exports.EnumToken.IdenTokenType);
30508
+ if (left.typ == exports.EnumToken.MediaQueryConditionTokenType &&
30509
+ (mFLT.has(left.op.typ) ||
30510
+ mFGT.has(left.op.typ)) &&
30511
+ right.typ == exports.EnumToken.MediaQueryConditionTokenType &&
30512
+ (mFLT.has(right.op.typ) ||
30513
+ mFGT.has(right.op.typ))) {
30514
+ const name = left.l.find((t) => t.typ == exports.EnumToken.IdenTokenType);
30515
+ const name2 = right.l.find((t) => t.typ == exports.EnumToken.IdenTokenType);
30516
+ if (equalsIgnoreCase(name.val, name2.val)) {
30517
+ switch (left.op.typ) {
30518
+ case exports.EnumToken.LtTokenType:
30519
+ left.op.typ = exports.EnumToken.GtTokenType;
30520
+ break;
30521
+ case exports.EnumToken.LteTokenType:
30522
+ left.op.typ = exports.EnumToken.GteTokenType;
30523
+ break;
30524
+ case exports.EnumToken.GtTokenType:
30525
+ left.op.typ = exports.EnumToken.LtTokenType;
30526
+ break;
30527
+ case exports.EnumToken.GteTokenType:
30528
+ left.op.typ = exports.EnumToken.LteTokenType;
30529
+ break;
30530
+ }
30531
+ tokens[l] = {
30532
+ typ: exports.EnumToken.ParensTokenType,
30533
+ chi: [
30534
+ {
30535
+ typ: exports.EnumToken.MediaRangeQueryTokenType,
30536
+ l: left.r,
30537
+ val: [name],
30538
+ op1: left.op,
30539
+ op2: right.op,
30540
+ r: right.r,
30541
+ [LOCSRCID]: name[LOCSRCID],
30542
+ [LOCSTA]: left[LOCSTA],
30543
+ [LOCEND]: right[LOCEND],
30544
+ },
30545
+ ],
30546
+ [LOCSRCID]: name[LOCSRCID],
30547
+ [LOCSTA]: left[LOCSTA],
30548
+ [LOCEND]: right[LOCEND],
30549
+ };
30550
+ }
30551
+ }
30552
+ }
30553
+ }
30481
30554
  }
30482
30555
  break;
30483
30556
  }
@@ -31111,7 +31184,6 @@ function doParseSync(tokenizer, options = {}) {
31111
31184
  // let currentItemIndex: number;
31112
31185
  ast[LOCSRCID] = options.source.id;
31113
31186
  ast[LOCSTA] = 0;
31114
- // let tokenizer: Tokenizer;
31115
31187
  while (!tokenizer.done()) {
31116
31188
  tokenizer.next();
31117
31189
  // item = (iter as Array<TokenizeResult>)[currentItemIndex];
@@ -20,7 +20,8 @@ class ComputeCalcExpressionFeature {
20
20
  }
21
21
  }
22
22
  run(ast) {
23
- if (!("chi" in ast)) {
23
+ // @ts-ignore
24
+ if (ast.chi == null) {
24
25
  return null;
25
26
  }
26
27
  for (const node of ast.chi) {
@@ -38,15 +39,7 @@ class ComputeCalcExpressionFeature {
38
39
  // @ts-ignore
39
40
  replaceNodeOrValue(parent, value, result);
40
41
  }
41
- catch (e) {
42
- // @ts-ignore
43
- if (Array.isArray(parent.chi)) {
44
- // @ts-ignore
45
- parent.chi.length = 0;
46
- // @ts-ignore
47
- parent.chi.push(...result);
48
- }
49
- }
42
+ catch (e) { }
50
43
  continue;
51
44
  }
52
45
  if (value != null && tokensfuncSet.has(value.typ)) {
@@ -3,6 +3,7 @@ import { mathFuncs, PARENT, LOCEND, LOCSTA, LOCSRCID } from '../../syntax/consta
3
3
  import { EnumToken } from '../types.js';
4
4
  import { rem, compute } from './math.js';
5
5
 
6
+ const numbers = new Set(["sin", "cos", "asin", "acos", "sign", "tan"]);
6
7
  /**
7
8
  * evaluate an array of tokens
8
9
  * @param tokens
@@ -192,9 +193,22 @@ function doEvaluate(l, r, op) {
192
193
  r.typ == EnumToken.NegativeInfinityTokenType) {
193
194
  return computeInfinity(l, r, op, defaultReturn);
194
195
  }
196
+ if (l.typ == EnumToken.FunctionTokenType || l.typ == EnumToken.MathFunctionTokenType) {
197
+ const val = evaluateFunc(l);
198
+ if (val == null ||
199
+ (val.length == 1 &&
200
+ (val[0].typ == EnumToken.MathFunctionTokenType || val[0].typ == EnumToken.FunctionTokenType))) {
201
+ return defaultReturn;
202
+ }
203
+ if (val.length == 1) {
204
+ l = val[0];
205
+ }
206
+ }
195
207
  if (r.typ == EnumToken.FunctionTokenType || r.typ == EnumToken.MathFunctionTokenType) {
196
208
  const val = evaluateFunc(r);
197
- if (val == null) {
209
+ if (val == null ||
210
+ (val.length == 1 &&
211
+ (val[0].typ == EnumToken.MathFunctionTokenType || val[0].typ == EnumToken.FunctionTokenType))) {
198
212
  return defaultReturn;
199
213
  }
200
214
  if (val.length == 1) {
@@ -412,45 +426,43 @@ function getValue(t) {
412
426
  function evaluateFunc(token) {
413
427
  const values = token.chi.slice();
414
428
  switch (token.val) {
415
- case "abs":
416
429
  case "sin":
417
430
  case "cos":
418
431
  case "tan":
432
+ for (let i = 0; i < values.length; i++) {
433
+ if (values[i].typ == EnumToken.NumberTokenType) {
434
+ values[i] = Object.assign(values[i], { typ: EnumToken.AngleTokenType, unit: "rad" });
435
+ }
436
+ else if (values[i].typ == EnumToken.AngleTokenType && values[i].unit != "rad") {
437
+ switch (values[i].unit) {
438
+ case "deg":
439
+ Object.assign(values[i], {
440
+ unit: "rad",
441
+ val: values[i].val * (Math.PI / 180),
442
+ });
443
+ break;
444
+ case "grad":
445
+ Object.assign(values[i], {
446
+ unit: "rad",
447
+ val: values[i].val * (Math.PI / 200),
448
+ });
449
+ break;
450
+ case "turn":
451
+ Object.assign(values[i], {
452
+ unit: "rad",
453
+ val: values[i].val * (2 * Math.PI),
454
+ });
455
+ break;
456
+ }
457
+ }
458
+ }
419
459
  case "asin":
420
460
  case "acos":
421
461
  case "atan":
462
+ case "abs":
422
463
  case "sign":
423
464
  case "sqrt":
424
- case "exp": {
425
- if (token.val == "tan" || token.val == "atan") {
426
- for (let i = 0; i < values.length; i++) {
427
- if (values[i].typ == EnumToken.NumberTokenType) {
428
- values[i] = Object.assign(values[i], { typ: EnumToken.AngleTokenType, unit: "rad" });
429
- }
430
- else if (values[i].typ == EnumToken.AngleTokenType && values[i].unit != "rad") {
431
- switch (values[i].unit) {
432
- case "deg":
433
- Object.assign(values[i], {
434
- unit: "rad",
435
- val: values[i].val * (Math.PI / 180),
436
- });
437
- break;
438
- case "grad":
439
- Object.assign(values[i], {
440
- unit: "rad",
441
- val: values[i].val * (Math.PI / 200),
442
- });
443
- break;
444
- case "turn":
445
- Object.assign(values[i], {
446
- unit: "rad",
447
- val: values[i].val * (2 * Math.PI),
448
- });
449
- break;
450
- }
451
- }
452
- }
453
- }
465
+ case "exp":
454
466
  const value = evaluate(values);
455
467
  // @ts-ignore
456
468
  let val = value[0].typ == EnumToken.NumberTokenType ||
@@ -460,7 +472,7 @@ function evaluateFunc(token) {
460
472
  : // @ts-expect-error
461
473
  value[0].l.val / value[0].r.val;
462
474
  return [
463
- token.val == "tan" || token.val == "atan"
475
+ token.val == "asin" || token.val == "acos" || token.val == "atan"
464
476
  ? {
465
477
  typ: EnumToken.AngleTokenType,
466
478
  val: Math[token.val](val),
@@ -471,7 +483,7 @@ function evaluateFunc(token) {
471
483
  [PARENT]: value[0][PARENT],
472
484
  }
473
485
  : {
474
- typ: token.val == "sign" ? EnumToken.NumberTokenType : value[0].typ,
486
+ typ: numbers.has(token.val) ? EnumToken.NumberTokenType : value[0].typ,
475
487
  val: Math[token.val](val),
476
488
  [LOCSRCID]: value[0][LOCSRCID],
477
489
  [LOCSTA]: value[0][LOCSTA],
@@ -479,7 +491,6 @@ function evaluateFunc(token) {
479
491
  [PARENT]: value[0][PARENT],
480
492
  },
481
493
  ];
482
- }
483
494
  case "hypot": {
484
495
  const chi = values.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType, EnumToken.CommaTokenType].includes(t.typ));
485
496
  let all = [];
@@ -506,7 +506,6 @@ function doParseSync(tokenizer, options = {}) {
506
506
  // let currentItemIndex: number;
507
507
  ast[LOCSRCID] = options.source.id;
508
508
  ast[LOCSTA] = 0;
509
- // let tokenizer: Tokenizer;
510
509
  while (!tokenizer.done()) {
511
510
  tokenizer.next();
512
511
  // item = (iter as Array<TokenizeResult>)[currentItemIndex];
@@ -3,6 +3,7 @@ import { tokensfuncDefMap, LOCSTA, mFGT, mFLT, LOCEND, LOCSRCID } from '../../sy
3
3
  import { matchAllSyntaxes, createValidationContext, trimArray } from '../../validation/match.js';
4
4
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
5
5
  import { getSyntaxRule } from '../../validation/config.js';
6
+ import { equalsIgnoreCase } from './text.js';
6
7
 
7
8
  function parseAtRuleContainerQueryList(stream, context, options = {}) {
8
9
  let matchCount = 0;
@@ -37,7 +38,7 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
37
38
  };
38
39
  }
39
40
  {
40
- for (const stream of parts.slice()) {
41
+ for (const stream of parts) {
41
42
  let success = true;
42
43
  let i;
43
44
  let currentScope = new Set();
@@ -156,6 +157,22 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
156
157
  [LOCSTA]: names[0][LOCSTA],
157
158
  [LOCEND]: values.at(-1)[LOCEND],
158
159
  });
160
+ const token = tokens[index3 + 1];
161
+ if (token.op.typ === EnumToken.ColonTokenType) {
162
+ let name = token.l.find((t) => t.typ === EnumToken.IdenTokenType);
163
+ if (name != null) {
164
+ if (name.val.startsWith("min-")) {
165
+ name.val = name.val.substring(4);
166
+ // @ts-ignore
167
+ token.op.typ = EnumToken.GteTokenType;
168
+ }
169
+ else if (name.val.startsWith("max-")) {
170
+ name.val = name.val.substring(4);
171
+ // @ts-ignore
172
+ token.op.typ = EnumToken.LteTokenType;
173
+ }
174
+ }
175
+ }
159
176
  // check <style()> or <scroll-state()>
160
177
  }
161
178
  if (tokensfuncDefMap.has(stack.at(-1)?.typ)) {
@@ -247,6 +264,58 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
247
264
  };
248
265
  tokens.length = l + 1;
249
266
  expectAndOr = true;
267
+ if (tokens[l].op.typ === EnumToken.AndTokenType) {
268
+ let left = tokens[l].l.find((t) => t.typ != EnumToken.WhitespaceTokenType && t.typ != EnumToken.IdenTokenType);
269
+ let right = tokens[l].r.find((t) => t.typ != EnumToken.WhitespaceTokenType && t.typ != EnumToken.IdenTokenType);
270
+ if (left.typ == EnumToken.ParensTokenType && right.typ == EnumToken.ParensTokenType) {
271
+ left = left.chi.find((t) => t.typ != EnumToken.WhitespaceTokenType && t.typ != EnumToken.IdenTokenType);
272
+ right = right.chi.find((t) => t.typ != EnumToken.WhitespaceTokenType && t.typ != EnumToken.IdenTokenType);
273
+ if (left.typ == EnumToken.MediaQueryConditionTokenType &&
274
+ (mFLT.has(left.op.typ) ||
275
+ mFGT.has(left.op.typ)) &&
276
+ right.typ == EnumToken.MediaQueryConditionTokenType &&
277
+ (mFLT.has(right.op.typ) ||
278
+ mFGT.has(right.op.typ))) {
279
+ const name = left.l.find((t) => t.typ == EnumToken.IdenTokenType);
280
+ const name2 = right.l.find((t) => t.typ == EnumToken.IdenTokenType);
281
+ if (equalsIgnoreCase(name.val, name2.val)) {
282
+ switch (left.op.typ) {
283
+ case EnumToken.LtTokenType:
284
+ left.op.typ = EnumToken.GtTokenType;
285
+ break;
286
+ case EnumToken.LteTokenType:
287
+ left.op.typ = EnumToken.GteTokenType;
288
+ break;
289
+ case EnumToken.GtTokenType:
290
+ left.op.typ = EnumToken.LtTokenType;
291
+ break;
292
+ case EnumToken.GteTokenType:
293
+ left.op.typ = EnumToken.LteTokenType;
294
+ break;
295
+ }
296
+ tokens[l] = {
297
+ typ: EnumToken.ParensTokenType,
298
+ chi: [
299
+ {
300
+ typ: EnumToken.MediaRangeQueryTokenType,
301
+ l: left.r,
302
+ val: [name],
303
+ op1: left.op,
304
+ op2: right.op,
305
+ r: right.r,
306
+ [LOCSRCID]: name[LOCSRCID],
307
+ [LOCSTA]: left[LOCSTA],
308
+ [LOCEND]: right[LOCEND],
309
+ },
310
+ ],
311
+ [LOCSRCID]: name[LOCSRCID],
312
+ [LOCSTA]: left[LOCSTA],
313
+ [LOCEND]: right[LOCEND],
314
+ };
315
+ }
316
+ }
317
+ }
318
+ }
250
319
  }
251
320
  break;
252
321
  }
@@ -190,8 +190,6 @@ function parseMediaqueryList(stream, options) {
190
190
  }
191
191
  }
192
192
  }
193
- // let isValidMFValue = isMFValue(name, left, true);
194
- // isValidMFValue = isMFValue(name, right, true);
195
193
  for (const val of [left, right]) {
196
194
  if (mfInfo?.type === MediaFeatureType.RatioType) {
197
195
  const filteredValues = val.filter((n) => n.typ !== EnumToken.WhitespaceTokenType &&
@@ -82,7 +82,8 @@ function isMFValue(featureName, tokens, isMFRange) {
82
82
  return { valid: true, success: false, isValueAllowed: false };
83
83
  }
84
84
  featureName = featureName.toLowerCase();
85
- if (!(featureName in config.mediaFeatures)) {
85
+ // @ts-expect-error
86
+ if (config.mediaFeatures[featureName] == null) {
86
87
  return { valid: false, success: false };
87
88
  }
88
89
  // @ts-expect-error
@@ -126,8 +127,7 @@ function isMFValue(featureName, tokens, isMFRange) {
126
127
  return {
127
128
  valid: true,
128
129
  success: (tokens.length == 1 &&
129
- tokens[0].typ == EnumToken.NumberTokenType &&
130
- tokens[0].val.typ == EnumToken.FractionTokenType) ||
130
+ tokens[0].typ == EnumToken.NumberTokenType) ||
131
131
  (tokens.length === 3 &&
132
132
  tokens[0].typ == EnumToken.NumberTokenType &&
133
133
  typeof tokens[0].val === "number" &&
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tbela99/css-parser",
3
3
  "description": "CSS parser, minifier and validator for node and the browser",
4
- "version": "1.6.5",
4
+ "version": "1.6.6",
5
5
  "exports": {
6
6
  ".": "./dist/node.js",
7
7
  "./node": "./dist/node.js",
@@ -68,17 +68,17 @@
68
68
  "@types/chai": "^5.2.3",
69
69
  "@types/chai-as-promised": "^8.0.2",
70
70
  "@types/mocha": "^10.0.10",
71
- "@types/node": "^26.4.1",
72
- "@types/web": "^0.0.354",
71
+ "@types/node": "^26.6.4",
72
+ "@types/web": "^0.0.357",
73
73
  "@web/test-runner": "^1.0.0",
74
74
  "@web/test-runner-playwright": "^1.0.0",
75
- "chai": "^6.2.2",
75
+ "chai": "^6.3.0",
76
76
  "chai-as-promised": "^8.0.2",
77
77
  "esno": "^4.8.0",
78
78
  "markdown-it-task-lists": "^2.1.1",
79
- "mocha": "^12.0.0",
80
- "playwright": "^1.62.1",
81
- "rollup": "^4.63.1",
79
+ "mocha": "^12.0.3",
80
+ "playwright": "^1.63.0",
81
+ "rollup": "^4.63.6",
82
82
  "rollup-plugin-dts": "^6.5.1",
83
83
  "superc8": "^12.7.0",
84
84
  "tslib": "^2.8.1",
@@ -89,4 +89,4 @@
89
89
  "typedoc-unhoax-theme": "^0.5.3"
90
90
  },
91
91
  "sideEffects": false
92
- }
92
+ }