@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
@@ -266,7 +266,7 @@ function eqMatrix(a, b) {
266
266
  return true;
267
267
  }
268
268
  function minifyTransformFunctions(transform) {
269
- const name = transform.val.toLowerCase();
269
+ const name = transform.val;
270
270
  if ("skewX" == name) {
271
271
  transform.val = "skew";
272
272
  return transform;
@@ -660,6 +660,18 @@ var EnumToken;
660
660
  * wrapped values token type like {Arial, sans-serif}
661
661
  */
662
662
  EnumToken[EnumToken["WrappedValuesTokenType"] = 140] = "WrappedValuesTokenType";
663
+ /**
664
+ * infinity token
665
+ */
666
+ EnumToken[EnumToken["NaNTokenType"] = 141] = "NaNTokenType";
667
+ /**
668
+ * infinity token
669
+ */
670
+ EnumToken[EnumToken["InfinityTokenType"] = 142] = "InfinityTokenType";
671
+ /**
672
+ * negative infinity token
673
+ */
674
+ EnumToken[EnumToken["NegativeInfinityTokenType"] = 143] = "NegativeInfinityTokenType";
663
675
  /* aliases */
664
676
  /**
665
677
  * alias for time token type
@@ -108,6 +108,65 @@ var properties = {
108
108
  "padding-left": {
109
109
  shorthand: "padding"
110
110
  },
111
+ "scroll-margin": {
112
+ shorthand: "scroll-margin",
113
+ properties: [
114
+ "scroll-margin-top",
115
+ "scroll-margin-right",
116
+ "scroll-margin-bottom",
117
+ "scroll-margin-left"
118
+ ],
119
+ types: [
120
+ "Length",
121
+ "Perc"
122
+ ],
123
+ "default": [
124
+ "0"
125
+ ],
126
+ keywords: [
127
+ "auto"
128
+ ]
129
+ },
130
+ "scroll-margin-top": {
131
+ shorthand: "scroll-margin"
132
+ },
133
+ "scroll-margin-right": {
134
+ shorthand: "scroll-margin"
135
+ },
136
+ "scroll-margin-bottom": {
137
+ shorthand: "scroll-margin"
138
+ },
139
+ "scroll-margin-left": {
140
+ shorthand: "scroll-margin"
141
+ },
142
+ "scroll-padding": {
143
+ shorthand: "scroll-padding",
144
+ properties: [
145
+ "scroll-padding-top",
146
+ "scroll-padding-right",
147
+ "scroll-padding-bottom",
148
+ "scroll-padding-left"
149
+ ],
150
+ types: [
151
+ "Length",
152
+ "Perc"
153
+ ],
154
+ keywords: [
155
+ "auto"
156
+ ]
157
+ },
158
+ "scroll-padding-top": {
159
+ shorthand: "scroll-padding"
160
+ },
161
+ "scroll-padding-right": {
162
+ shorthand: "scroll-padding"
163
+ },
164
+ "scroll-padding-bottom": {
165
+ shorthand: "scroll-padding"
166
+ },
167
+ "scroll-padding-left": {
168
+ shorthand: "scroll-padding"
169
+ },
111
170
  "border-radius": {
112
171
  shorthand: "border-radius",
113
172
  properties: [
@@ -329,6 +388,53 @@ var map = {
329
388
  "flex-wrap": {
330
389
  shorthand: "flex-flow"
331
390
  },
391
+ "scroll-timeline": {
392
+ shorthand: "scroll-timeline",
393
+ pattern: "scroll-timeline-name scroll-timeline-axis",
394
+ keywords: [
395
+ "none",
396
+ "block",
397
+ "inline",
398
+ "x",
399
+ "y"
400
+ ],
401
+ "default": [
402
+ "none",
403
+ "block"
404
+ ],
405
+ properties: {
406
+ "scroll-timeline-name": {
407
+ keywords: [
408
+ "none"
409
+ ],
410
+ "default": [
411
+ "none"
412
+ ],
413
+ types: [
414
+ "DashedIden"
415
+ ]
416
+ },
417
+ "scroll-timeline-axis": {
418
+ keywords: [
419
+ "block",
420
+ "inline",
421
+ "x",
422
+ "y"
423
+ ],
424
+ "default": [
425
+ "block"
426
+ ],
427
+ types: [
428
+ ]
429
+ }
430
+ }
431
+ },
432
+ "scroll-timeline-name": {
433
+ shorthand: "scroll-timeline"
434
+ },
435
+ "scroll-timeline-axis": {
436
+ shorthand: "scroll-timeline"
437
+ },
332
438
  container: {
333
439
  shorthand: "container",
334
440
  pattern: "container-name container-type",
@@ -1584,7 +1584,7 @@ var declarations = {
1584
1584
  syntax: "none | nearest"
1585
1585
  },
1586
1586
  "scroll-margin": {
1587
- syntax: "<length>{1,4}"
1587
+ syntax: " <length>{1,4}"
1588
1588
  },
1589
1589
  "scroll-margin-block": {
1590
1590
  syntax: "<length>{1,2}"
@@ -1596,7 +1596,7 @@ var declarations = {
1596
1596
  syntax: "<length>"
1597
1597
  },
1598
1598
  "scroll-margin-bottom": {
1599
- syntax: "<length>"
1599
+ syntax: " auto | <length-percentage [0,∞]>"
1600
1600
  },
1601
1601
  "scroll-margin-inline": {
1602
1602
  syntax: "<length>{1,2}"
@@ -1608,13 +1608,13 @@ var declarations = {
1608
1608
  syntax: "<length>"
1609
1609
  },
1610
1610
  "scroll-margin-left": {
1611
- syntax: "<length>"
1611
+ syntax: " auto | <length-percentage [0,∞]>"
1612
1612
  },
1613
1613
  "scroll-margin-right": {
1614
- syntax: "<length>"
1614
+ syntax: " auto | <length-percentage [0,∞]>"
1615
1615
  },
1616
1616
  "scroll-margin-top": {
1617
- syntax: "<length>"
1617
+ syntax: " auto | <length-percentage [0,∞]>"
1618
1618
  },
1619
1619
  "scroll-marker-group": {
1620
1620
  syntax: "none | before | after"
@@ -1683,13 +1683,13 @@ var declarations = {
1683
1683
  syntax: "none | auto"
1684
1684
  },
1685
1685
  "scroll-timeline": {
1686
- syntax: "[ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#"
1686
+ syntax: " [ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#"
1687
1687
  },
1688
1688
  "scroll-timeline-axis": {
1689
- syntax: "[ block | inline | x | y ]#"
1689
+ syntax: " [ block | inline | x | y ]#"
1690
1690
  },
1691
1691
  "scroll-timeline-name": {
1692
- syntax: "[ none | <dashed-ident> ]#"
1692
+ syntax: " [ none | <dashed-ident> ]#"
1693
1693
  },
1694
1694
  "scrollbar-color": {
1695
1695
  syntax: "auto | <color>{2}"
@@ -2182,6 +2182,9 @@ var functions = {
2182
2182
  acos: {
2183
2183
  syntax: "acos( <calc-sum> )"
2184
2184
  },
2185
+ alpha: {
2186
+ syntax: "alpha( from <color> / [ <alpha-value> | none ] )"
2187
+ },
2185
2188
  anchor: {
2186
2189
  syntax: "anchor( <anchor-name>? && <anchor-side>, <length-percentage>? )"
2187
2190
  },
@@ -1,8 +1,7 @@
1
1
  import { PropertySet } from './set.js';
2
2
  import { getConfig } from '../utils/config.js';
3
3
  import { PropertyMap } from './map.js';
4
- import { parseString } from '../parse.js';
5
- import { EnumToken, EnumAstNodeStatus } from '../../ast/types.js';
4
+ import { EnumAstNodeStatus, EnumToken } from '../../ast/types.js';
6
5
  import { getParsedSyntax } from '../../validation/config.js';
7
6
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
8
7
  import { matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
@@ -14,18 +13,17 @@ const config = getConfig();
14
13
  class PropertyList {
15
14
  options = { removeDuplicateDeclarations: true, computeShorthand: true };
16
15
  declarations;
17
- // ketsey = new Map;
18
16
  constructor(options = {}) {
19
17
  this.options = options;
20
18
  this.declarations = new Map();
21
19
  }
22
- set(nam, value) {
23
- return this.add({
24
- typ: EnumToken.DeclarationNodeType,
25
- nam,
26
- val: Array.isArray(value) ? value : parseString(String(value)),
27
- });
28
- }
20
+ // set(nam: string, value: string | Token[]) {
21
+ // return this.add({
22
+ // typ: EnumToken.DeclarationNodeType,
23
+ // nam,
24
+ // val: Array.isArray(value) ? value : parseString(String(value)),
25
+ // });
26
+ // }
29
27
  add(...declarations) {
30
28
  let name;
31
29
  let syntaxRules = null;
@@ -434,7 +434,7 @@ function parseVisitors(visitorsDef, errors) {
434
434
  }
435
435
  /**
436
436
  * Parse css string
437
- * @param iter
437
+ * @param tokenizer
438
438
  * @param options
439
439
  *
440
440
  * @throws Error
@@ -1431,6 +1431,7 @@ async function doParse(iter, options = {}) {
1431
1431
  const imports = [];
1432
1432
  let item;
1433
1433
  let node;
1434
+ // @ts-ignore ignore error
1434
1435
  let parensMatch = 0;
1435
1436
  let curlyBracketMatch = 0;
1436
1437
  let tokenizer = iter instanceof Promise ? await iter : iter;
@@ -3393,17 +3394,18 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
3393
3394
  * console.log(declarations);
3394
3395
  * ```
3395
3396
  */
3396
- async function parseDeclarations(declaration) {
3397
+ function parseDeclarations(declaration) {
3397
3398
  const stream = `.x{${declaration}}`;
3398
- return doParse(new Tokenizer({
3399
+ const result = doParseSync(new Tokenizer({
3399
3400
  stream,
3400
3401
  offset: 0,
3401
3402
  position: 0,
3402
3403
  source: new SourceFile(stream, [], ""),
3403
3404
  currentPosition: 0,
3404
- }), { setParent: false, minify: false, validation: false }).then((result) => {
3405
- return result.ast.chi[0].chi.filter((t) => t.typ == EnumToken.DeclarationNodeType || t.typ == EnumToken.CommentNodeType);
3406
- });
3405
+ }), { setParent: false, minify: false, validation: false });
3406
+ // .then((result) => {
3407
+ return result.ast.chi[0].chi.filter((t) => t.typ == EnumToken.DeclarationNodeType || t.typ == EnumToken.CommentNodeType);
3408
+ // });
3407
3409
  }
3408
3410
  /**
3409
3411
  * Parse css string and return an array of tokens
@@ -3428,14 +3430,6 @@ async function parseDeclarations(declaration) {
3428
3430
  * ```
3429
3431
  */
3430
3432
  function parseString(src, options = { parseColor: true }, errors) {
3431
- // const parseInfo: ParseInfo = {
3432
- // stream: src,
3433
- // offset: 0,
3434
- // time: 0,
3435
- // source: new SourceFile(src, [], ""),
3436
- // position: 0,
3437
- // currentPosition: 0,
3438
- // };
3439
3433
  const tokenizer = new Tokenizer({
3440
3434
  stream: src,
3441
3435
  buffer: "",
@@ -5,9 +5,19 @@ import { SourceFile } from './source.js';
5
5
 
6
6
  const SymbolsMapTokens = Object.create(null);
7
7
  // Regex for escape sequence decoding - compile once, reuse many times
8
- const ESCAPE_SEQUENCE_REGEX = /\\([0-9a-fA-F]{1,6})(?:\s)?/g;
8
+ const ESCAPE_SEQUENCE_REGEX = /\\((\n|\r|\f|\v|\u2028|\u2029|([0-9a-fA-F]{1,6})) ?)/gms;
9
9
  function decodeEscapeSequences(value) {
10
10
  return value.replace(ESCAPE_SEQUENCE_REGEX, (_, sequence) => {
11
+ // \n \r \f \v
12
+ switch (sequence.charCodeAt(0)) {
13
+ case 0xa:
14
+ case 0xb:
15
+ case 0xc:
16
+ case 0xd:
17
+ case 0x2028:
18
+ case 0x2029:
19
+ return "";
20
+ }
11
21
  const codepoint = parseInt(sequence, 16);
12
22
  if (codepoint == 0 ||
13
23
  // leading surrogate
@@ -245,18 +255,17 @@ class Tokenizer {
245
255
  constructor(parseInfo, input = null) {
246
256
  this.parseInfo = parseInfo;
247
257
  this.input = input;
248
- if (typeof this.parseInfo == "string") {
249
- if (typeof parseInfo == "string") {
250
- this.parseInfo = {
258
+ this.parseInfo =
259
+ typeof parseInfo == "string"
260
+ ? {
251
261
  stream: parseInfo,
252
262
  source: new SourceFile(parseInfo, [], ""),
253
263
  offset: 0,
254
264
  time: 0,
255
265
  position: 0,
256
266
  currentPosition: 0,
257
- };
258
- }
259
- }
267
+ }
268
+ : parseInfo;
260
269
  }
261
270
  /**
262
271
  *
@@ -273,6 +282,18 @@ class Tokenizer {
273
282
  this.advance(parseInfo, 2);
274
283
  continue;
275
284
  }
285
+ charCode = parseInfo.stream.charCodeAt(parseInfo.currentPosition - parseInfo.offset + 1);
286
+ // \n \r \f \v
287
+ if (charCode == 0xa ||
288
+ charCode == 0xb ||
289
+ charCode == 0xc ||
290
+ charCode == 0xd ||
291
+ charCode == 0x2028 ||
292
+ charCode == 0x2029) {
293
+ this.advance(parseInfo, 2);
294
+ decodeSegments = true;
295
+ continue;
296
+ }
276
297
  const sequence = this.peek(parseInfo, 7);
277
298
  let escapeSequence = "";
278
299
  let codepoint;
@@ -316,7 +337,7 @@ class Tokenizer {
316
337
  this.advance(parseInfo);
317
338
  }
318
339
  // EOF - 'Unclosed-string' fixed
319
- return this.makeToken(parseInfo, EnumToken.StringTokenType);
340
+ return this.makeToken(parseInfo, EnumToken.StringTokenType, decodeSegments ? { decodeSegments } : null);
320
341
  // return result;
321
342
  }
322
343
  /**
@@ -324,7 +345,7 @@ class Tokenizer {
324
345
  * @param parseInfo
325
346
  * @returns
326
347
  */
327
- consumeURLToken(parseInfo) {
348
+ consumeStringAsURLToken(parseInfo) {
328
349
  const quote = this.advance(parseInfo).charCodeAt(0);
329
350
  let charCode;
330
351
  let decodeSegments = false;
@@ -378,7 +399,7 @@ class Tokenizer {
378
399
  return this.makeToken(parseInfo, EnumToken.BadUrlTokenType);
379
400
  }
380
401
  if (isWhiteSpace(charCode)) {
381
- this.advance(parseInfo, k);
402
+ // this.advance(parseInfo, k);
382
403
  k++;
383
404
  continue;
384
405
  }
@@ -766,7 +787,7 @@ class Tokenizer {
766
787
  }
767
788
  return 0;
768
789
  }
769
- parseURLToken(parseInfo, endPosition) {
790
+ consumeURLToken(parseInfo, endPosition) {
770
791
  let charCode;
771
792
  // consume an <url>
772
793
  while (isWhiteSpace(this.peekCharCode(parseInfo))) {
@@ -774,7 +795,7 @@ class Tokenizer {
774
795
  }
775
796
  charCode = this.peekCharCode(parseInfo);
776
797
  if (charCode == 34 /* TokenMap.DOUBLE_QUOTE */ || charCode == 39 /* TokenMap.SINGLE_QUOTE */) {
777
- return this.consumeURLToken(parseInfo);
798
+ return this.consumeStringAsURLToken(parseInfo);
778
799
  }
779
800
  do {
780
801
  this.advance(parseInfo);
@@ -782,14 +803,28 @@ class Tokenizer {
782
803
  } while (
783
804
  // !(value === "/" && this.match(parseInfo, "/*") &&
784
805
  charCode !== 41 /* TokenMap.RIGHT_PARENTHESIS */ &&
806
+ !isWhiteSpace(charCode) &&
785
807
  parseInfo.currentPosition < endPosition);
786
- // if (parseInfo.position < parseInfo.currentPosition) {
808
+ if (charCode !== 41 /* TokenMap.RIGHT_PARENTHESIS */) {
809
+ let k = 1;
810
+ while (k < endPosition) {
811
+ charCode = parseInfo.stream.charCodeAt(parseInfo.currentPosition - parseInfo.offset + k);
812
+ if (isWhiteSpace(charCode)) {
813
+ k++;
814
+ continue;
815
+ }
816
+ break;
817
+ }
818
+ if (charCode != charCode || (charCode != 41 /* TokenMap.RIGHT_PARENTHESIS */ && !isIdentStart(charCode))) {
819
+ this.advance(parseInfo, k);
820
+ return this.makeToken(parseInfo, EnumToken.BadUrlTokenType);
821
+ }
822
+ }
787
823
  return this.makeToken(parseInfo,
788
824
  // parseInfo.position < parseInfo.currentPosition
789
825
  (charCode = this.peekCharCode(parseInfo)) != charCode || !this.isURLToken(parseInfo)
790
826
  ? EnumToken.BadUrlTokenType
791
827
  : EnumToken.UrlTokenTokenType);
792
- // }
793
828
  }
794
829
  /**
795
830
  *
@@ -1034,31 +1069,26 @@ class Tokenizer {
1034
1069
  /**
1035
1070
  *
1036
1071
  * @param parseInfo
1037
- * @param start
1038
- * @param end
1039
1072
  * @returns
1040
1073
  */
1041
- isIdentToken(parseInfo, start, end) {
1074
+ isIdentToken(parseInfo /* , start?: number, end?: number */) {
1042
1075
  let j = parseInfo.currentPosition - parseInfo.offset;
1043
1076
  let i = parseInfo.position - parseInfo.offset;
1044
- if (start != null) {
1045
- if (end == null) {
1046
- if (start < 0) {
1047
- j += start;
1048
- }
1049
- else {
1050
- i += start;
1051
- }
1052
- }
1053
- else {
1054
- if (end < 0) {
1055
- j += end;
1056
- }
1057
- else {
1058
- j = parseInfo.position + end;
1059
- }
1060
- }
1061
- }
1077
+ // if (start != null) {
1078
+ // if (end == null) {
1079
+ // if (start < 0) {
1080
+ // j += start;
1081
+ // } else {
1082
+ // i += start;
1083
+ // }
1084
+ // } else {
1085
+ // if (end < 0) {
1086
+ // j += end;
1087
+ // } else {
1088
+ // j = parseInfo.position + end;
1089
+ // }
1090
+ // }
1091
+ // }
1062
1092
  j--;
1063
1093
  let codepoint = parseInfo.stream.charCodeAt(i);
1064
1094
  // -
@@ -1101,18 +1131,18 @@ class Tokenizer {
1101
1131
  * @param parseInfo
1102
1132
  * @returns
1103
1133
  */
1104
- isPseudo(parseInfo) {
1105
- let position = parseInfo.currentPosition - parseInfo.offset;
1106
- let endPosition = parseInfo.currentPosition - parseInfo.offset;
1107
- return (parseInfo.stream.charAt(position) == ":" &&
1108
- parseInfo.stream.charAt(endPosition - 1) == "(" &&
1109
- (parseInfo.stream.charAt(position + 1) == ":"
1110
- ? this.isIdentToken(parseInfo, 2, -1)
1111
- : this.isIdentToken(parseInfo, 1, -1))) ||
1112
- parseInfo.stream.charAt(position + 1) == ":"
1113
- ? this.isIdentToken(parseInfo, 2)
1114
- : this.isIdentToken(parseInfo, 1);
1115
- }
1134
+ // isPseudo(parseInfo: ParseInfo): boolean {
1135
+ // let position: number = parseInfo.currentPosition - parseInfo.offset;
1136
+ // let endPosition: number = parseInfo.currentPosition - parseInfo.offset;
1137
+ // return (parseInfo.stream.charAt(position) == ":" &&
1138
+ // parseInfo.stream.charAt(endPosition - 1) == "(" &&
1139
+ // (parseInfo.stream.charAt(position + 1) == ":"
1140
+ // ? this.isIdentToken(parseInfo, 2, -1)
1141
+ // : this.isIdentToken(parseInfo, 1, -1))) ||
1142
+ // parseInfo.stream.charAt(position + 1) == ":"
1143
+ // ? this.isIdentToken(parseInfo, 2)
1144
+ // : this.isIdentToken(parseInfo, 1);
1145
+ // }
1116
1146
  /**
1117
1147
  *
1118
1148
  * @param parseInfo
@@ -1169,8 +1199,6 @@ class Tokenizer {
1169
1199
  }
1170
1200
  /**
1171
1201
  * Tokenize CSS string
1172
- * @param parseInfo
1173
- * @param yieldEOFToken
1174
1202
  */
1175
1203
  next( /* parseInfo: ParseInfo | string, yieldEOFToken: boolean = true */) {
1176
1204
  const parseInfo = this.parseInfo;
@@ -1185,7 +1213,7 @@ class Tokenizer {
1185
1213
  while ((charCode = this.peekCharCode(parseInfo)) == charCode) {
1186
1214
  if (this.state === EnumToken.UrlFunctionTokenDefType) {
1187
1215
  this.state = null;
1188
- return this.parseURLToken(parseInfo, endPosition);
1216
+ return this.consumeURLToken(parseInfo, endPosition);
1189
1217
  }
1190
1218
  if (parseInfo.position == parseInfo.currentPosition) {
1191
1219
  if (charCode == 45 /* TokenMap.MINUS */ ||
@@ -1305,12 +1333,14 @@ class Tokenizer {
1305
1333
  // '('
1306
1334
  case 40 /* TokenMap.LEFT_PARENTHESIS */:
1307
1335
  if (parseInfo.position < parseInfo.currentPosition) {
1308
- if (parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" &&
1309
- this.isPseudo(parseInfo)) {
1310
- this.advance(parseInfo);
1311
- return this.makeToken(parseInfo, EnumToken.PseudoClassFunctionTokenDefType);
1312
- }
1313
- else if (this.isIdentToken(parseInfo)) {
1336
+ // if (
1337
+ // parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" &&
1338
+ // this.isPseudo(parseInfo)
1339
+ // ) {
1340
+ // this.advance(parseInfo);
1341
+ // return this.makeToken(parseInfo, EnumToken.PseudoClassFunctionTokenDefType);
1342
+ // } else
1343
+ if (this.isIdentToken(parseInfo)) {
1314
1344
  const hint = this.startsWith(parseInfo, "--")
1315
1345
  ? EnumToken.CustomFunctionTokenDefType
1316
1346
  : (getSymbolHint(parseInfo, parseInfo.position - parseInfo.offset, parseInfo.currentPosition - parseInfo.offset + 1) ?? EnumToken.FunctionTokenDefType);
@@ -1554,6 +1584,9 @@ class Tokenizer {
1554
1584
  case 46 /* TokenMap.DOT */:
1555
1585
  const codepoint = parseInfo.stream.charCodeAt(parseInfo.currentPosition - parseInfo.offset + 1);
1556
1586
  if (isIdentStart(codepoint) || codepoint == 45 /* TokenMap.MINUS */) {
1587
+ if (parseInfo.position < parseInfo.currentPosition) {
1588
+ return this.makeToken(parseInfo);
1589
+ }
1557
1590
  this.advance(parseInfo);
1558
1591
  let tokensCount = this.consumeIdentToken(parseInfo);
1559
1592
  if (tokensCount > 0) {
@@ -1585,8 +1618,6 @@ class Tokenizer {
1585
1618
  }
1586
1619
  /**
1587
1620
  * tokenize readable stream
1588
- * @param input
1589
- * @param parseInfo
1590
1621
  */
1591
1622
  async tokenizeStream() {
1592
1623
  const decoder = new TextDecoder("utf-8");
@@ -6,7 +6,7 @@ function parseAtRuleFontFeatureValues(stream, context, options = {}) {
6
6
  const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + context.nam);
7
7
  const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
8
8
  trimArray(stream);
9
- const { success, errors} = matchAllSyntaxes(syntax, createValidationContext(stream), options);
9
+ const { success, errors /* , ...all */ } = matchAllSyntaxes(syntax, createValidationContext(stream), options);
10
10
  return { success, errors };
11
11
  }
12
12
 
@@ -5,6 +5,7 @@ import { tokensfuncDefMap, mediaTypes, LOCSTA, LOCEND, mFLT, mFGT, LOCSRCID } fr
5
5
  import { trimArray, matchAllSyntaxes, createValidationContext, getMFInfo, isMFValue } from '../../validation/match.js';
6
6
  import { ValidationSyntaxGroupEnum, MediaFeatureType } from '../../validation/parser/typedef.js';
7
7
  import { getParsedSyntax } from '../../validation/config.js';
8
+ import { equalsIgnoreCase } from './text.js';
8
9
 
9
10
  // https://drafts.csswg.org/mediaqueries/#media-descriptor-table:~:text=It%20is%20invalid%20to%20mix%20and%20and%20or%20and%20not%20at%20the%20same%20%E2%80%9Clevel%E2%80%9D%20of%20a%20media%20query%2E
10
11
  // 'or' is not allowed at the same level as 'and' and 'not'
@@ -285,6 +286,16 @@ function parseMediaqueryList(stream, options) {
285
286
  val.splice(0, val.length, ...filteredValues);
286
287
  }
287
288
  }
289
+ if (stack.at(-1)?.typ === EnumToken.ColonTokenType) {
290
+ if (name.startsWith("min-")) {
291
+ filteredNames[0].val = name.substring(4);
292
+ stack.at(-1).typ = EnumToken.GteTokenType;
293
+ }
294
+ else if (name.startsWith("max-")) {
295
+ filteredNames[0].val = name.substring(4);
296
+ stack.at(-1).typ = EnumToken.LteTokenType;
297
+ }
298
+ }
288
299
  // @ts-expect-error
289
300
  tokens.splice(index3 + 1, tokens.length - index3 - 2, {
290
301
  typ: EnumToken.MediaQueryConditionTokenType,
@@ -340,6 +351,61 @@ function parseMediaqueryList(stream, options) {
340
351
  [LOCEND]: right.at(-1)[LOCEND],
341
352
  };
342
353
  tokens.length = l + 1;
354
+ // media range query
355
+ if (options.minify &&
356
+ tokens[l].op.typ === EnumToken.AndTokenType) {
357
+ if (left.length === 1 &&
358
+ left[0].typ == EnumToken.ParensTokenType &&
359
+ left[0].chi.length == 1 &&
360
+ left[0].chi[0].typ == EnumToken.MediaQueryConditionTokenType &&
361
+ left[0].chi[0].l.length == 1 &&
362
+ left[0].chi[0].l[0].typ ==
363
+ EnumToken.IdenTokenType &&
364
+ (left[0].chi[0].op.typ ==
365
+ EnumToken.GtTokenType ||
366
+ left[0].chi[0].op.typ ==
367
+ EnumToken.GteTokenType) &&
368
+ right.length === 1 &&
369
+ left[0].typ == EnumToken.ParensTokenType &&
370
+ right[0].chi.length == 1 &&
371
+ right[0].chi[0].typ ==
372
+ EnumToken.MediaQueryConditionTokenType &&
373
+ right[0].chi[0].l.length == 1 &&
374
+ right[0].chi[0].l[0].typ ==
375
+ EnumToken.IdenTokenType &&
376
+ (right[0].chi[0].op.typ ==
377
+ EnumToken.LtTokenType ||
378
+ right[0].chi[0].op.typ ==
379
+ EnumToken.LteTokenType) &&
380
+ equalsIgnoreCase(left[0].chi[0]
381
+ .l[0].val, right[0].chi[0]
382
+ .l[0].val)) {
383
+ tokens[l] = {
384
+ typ: EnumToken.ParensTokenType,
385
+ chi: [
386
+ {
387
+ typ: EnumToken.MediaRangeQueryTokenType,
388
+ op1: Object.assign(left[0].chi[0]
389
+ .op, {
390
+ typ: left[0]
391
+ .chi[0].op.typ == EnumToken.GteTokenType
392
+ ? EnumToken.LteTokenType
393
+ : EnumToken.LtTokenType,
394
+ }),
395
+ op2: right[0].chi[0]
396
+ .op,
397
+ l: left[0].chi[0].r,
398
+ val: left[0].chi[0]
399
+ .l,
400
+ r: right[0].chi[0].r,
401
+ [LOCSRCID]: left[0][LOCSRCID],
402
+ [LOCSTA]: left[0][LOCSTA],
403
+ [LOCEND]: right.at(-1)[LOCEND],
404
+ },
405
+ ],
406
+ };
407
+ }
408
+ }
343
409
  expectAndOrComma = true;
344
410
  }
345
411
  }