@tbela99/css-parser 0.9.0 → 0.9.1

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.
@@ -107,6 +107,7 @@
107
107
  EnumToken[EnumToken["MediaFeatureAndTokenType"] = 89] = "MediaFeatureAndTokenType";
108
108
  EnumToken[EnumToken["MediaFeatureOrTokenType"] = 90] = "MediaFeatureOrTokenType";
109
109
  EnumToken[EnumToken["PseudoPageTokenType"] = 91] = "PseudoPageTokenType";
110
+ EnumToken[EnumToken["PseudoElementTokenType"] = 92] = "PseudoElementTokenType";
110
111
  /* aliases */
111
112
  EnumToken[EnumToken["Time"] = 25] = "Time";
112
113
  EnumToken[EnumToken["Iden"] = 7] = "Iden";
@@ -465,22 +466,6 @@
465
466
  .filter((t) => ![exports.EnumToken.LiteralTokenType, exports.EnumToken.CommentTokenType, exports.EnumToken.CommaTokenType, exports.EnumToken.WhitespaceTokenType].includes(t.typ));
466
467
  }
467
468
 
468
- function xyzd502srgb(x, y, z) {
469
- // @ts-ignore
470
- return lsrgb2srgbvalues(
471
- /* r: */
472
- x * 3.1341359569958707 -
473
- y * 1.6173863321612538 -
474
- 0.4906619460083532 * z,
475
- /* g: */
476
- x * -0.978795502912089 +
477
- y * 1.916254567259524 +
478
- 0.03344273116131949 * z,
479
- /* b: */
480
- x * 0.07195537988411677 -
481
- y * 0.2289768264158322 +
482
- 1.405386058324125 * z);
483
- }
484
469
  function XYZ_to_lin_sRGB(x, y, z) {
485
470
  // convert XYZ to linear-light sRGB
486
471
  const M = [
@@ -749,6 +734,45 @@
749
734
  1.7076147009309444 * S);
750
735
  }
751
736
 
737
+ /*
738
+ */
739
+ function xyzd502lch(x, y, z, alpha) {
740
+ // @ts-ignore
741
+ const [l, a, b] = xyz2lab(...XYZ_D50_to_D65(x, y, z));
742
+ // L in range [0,100]. For use in CSS, add a percent
743
+ return lab2lchvalues(l, a, b, alpha);
744
+ }
745
+ function XYZ_D65_to_D50(x, y, z) {
746
+ // Bradford chromatic adaptation from D65 to D50
747
+ // The matrix below is the result of three operations:
748
+ // - convert from XYZ to retinal cone domain
749
+ // - scale components from one reference white to another
750
+ // - convert back to XYZ
751
+ // see https://github.com/LeaVerou/color.js/pull/354/files
752
+ var M = [
753
+ [1.0479297925449969, 0.022946870601609652, -0.05019226628920524],
754
+ [0.02962780877005599, 0.9904344267538799, -0.017073799063418826],
755
+ [-0.009243040646204504, 0.015055191490298152, 0.7518742814281371]
756
+ ];
757
+ return multiplyMatrices(M, [x, y, z]);
758
+ }
759
+ function xyzd502srgb(x, y, z) {
760
+ // @ts-ignore
761
+ return lsrgb2srgbvalues(
762
+ /* r: */
763
+ x * 3.1341359569958707 -
764
+ y * 1.6173863321612538 -
765
+ 0.4906619460083532 * z,
766
+ /* g: */
767
+ x * -0.978795502912089 +
768
+ y * 1.916254567259524 +
769
+ 0.03344273116131949 * z,
770
+ /* b: */
771
+ x * 0.07195537988411677 -
772
+ y * 0.2289768264158322 +
773
+ 1.405386058324125 * z);
774
+ }
775
+
752
776
  // L: 0% = 0.0, 100% = 100.0
753
777
  // for a and b: -100% = -125, 100% = 125
754
778
  function hex2lab(token) {
@@ -1361,28 +1385,6 @@
1361
1385
  return hsv2hwb(...hsl2hsv(h, s, l, a));
1362
1386
  }
1363
1387
 
1364
- function xyzd502lch(x, y, z, alpha) {
1365
- // @ts-ignore
1366
- const [l, a, b] = xyz2lab(...XYZ_D50_to_D65(x, y, z));
1367
- // L in range [0,100]. For use in CSS, add a percent
1368
- // @ts-ignore
1369
- return lab2lchvalues(l, a, b, alpha);
1370
- }
1371
- function XYZ_D65_to_D50(x, y, z) {
1372
- // Bradford chromatic adaptation from D65 to D50
1373
- // The matrix below is the result of three operations:
1374
- // - convert from XYZ to retinal cone domain
1375
- // - scale components from one reference white to another
1376
- // - convert back to XYZ
1377
- // see https://github.com/LeaVerou/color.js/pull/354/files
1378
- var M = [
1379
- [1.0479297925449969, 0.022946870601609652, -0.05019226628920524],
1380
- [0.02962780877005599, 0.9904344267538799, -0.017073799063418826],
1381
- [-0.009243040646204504, 0.015055191490298152, 0.7518742814281371]
1382
- ];
1383
- return multiplyMatrices(M, [x, y, z]);
1384
- }
1385
-
1386
1388
  function prophotorgb2srgbvalues(r, g, b, a = null) {
1387
1389
  // @ts-ignore
1388
1390
  return xyzd502srgb(...prophotorgb2xyz50(r, g, b, a));
@@ -3249,11 +3251,11 @@
3249
3251
  }
3250
3252
 
3251
3253
  class SourceMap {
3254
+ lastLocation = null;
3252
3255
  #version = 3;
3253
3256
  #sources = [];
3254
3257
  #map = new Map;
3255
3258
  #line = -1;
3256
- lastLocation = null;
3257
3259
  add(source, original) {
3258
3260
  if (original.src !== '') {
3259
3261
  if (!this.#sources.includes(original.src)) {
@@ -3881,8 +3883,9 @@
3881
3883
  return '';
3882
3884
  }
3883
3885
  case exports.EnumToken.PseudoClassTokenType:
3886
+ case exports.EnumToken.PseudoElementTokenType:
3884
3887
  // https://www.w3.org/TR/selectors-4/#single-colon-pseudos
3885
- if (token.typ == exports.EnumToken.PseudoClassTokenType && ['::before', '::after', '::first-line', '::first-letter'].includes(token.val)) {
3888
+ if (token.typ == exports.EnumToken.PseudoElementTokenType && pseudoElements.includes(token.val.slice(1))) {
3886
3889
  return token.val.slice(1);
3887
3890
  }
3888
3891
  case exports.EnumToken.UrlTokenTokenType:
@@ -3963,6 +3966,7 @@
3963
3966
  'aural', 'braille', 'embossed', 'handheld', 'projection', 'tty', 'tv', 'speech'];
3964
3967
  // https://www.w3.org/TR/css-values-4/#math-function
3965
3968
  const mathFuncs = ['calc', 'clamp', 'min', 'max', 'round', 'mod', 'rem', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2', 'pow', 'sqrt', 'hypot', 'log', 'exp', 'abs', 'sign'];
3969
+ const pseudoElements = [':before', ':after', ':first-line', ':first-letter'];
3966
3970
  const webkitPseudoAliasMap = {
3967
3971
  '-webkit-autofill': 'autofill',
3968
3972
  '-webkit-any': 'is',
@@ -6219,13 +6223,13 @@
6219
6223
  shorthand: "background"
6220
6224
  }
6221
6225
  };
6222
- var config$4 = {
6226
+ var config$3 = {
6223
6227
  properties: properties,
6224
6228
  map: map
6225
6229
  };
6226
6230
 
6227
- Object.freeze(config$4);
6228
- const getConfig = () => config$4;
6231
+ Object.freeze(config$3);
6232
+ const getConfig = () => config$3;
6229
6233
 
6230
6234
  function matchType(val, properties) {
6231
6235
  if (val.typ == exports.EnumToken.IdenTokenType && properties.keywords.includes(val.val) ||
@@ -7252,7 +7256,7 @@
7252
7256
  syntax: "auto || <ratio>"
7253
7257
  },
7254
7258
  "backdrop-filter": {
7255
- syntax: "none | <filter-function-list>"
7259
+ syntax: "none | <filter-value-list>"
7256
7260
  },
7257
7261
  "backface-visibility": {
7258
7262
  syntax: "visible | hidden"
@@ -7666,7 +7670,7 @@
7666
7670
  syntax: "nonzero | evenodd"
7667
7671
  },
7668
7672
  filter: {
7669
- syntax: "none | <filter-function-list>"
7673
+ syntax: "none | <filter-value-list>"
7670
7674
  },
7671
7675
  flex: {
7672
7676
  syntax: "none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]"
@@ -8122,7 +8126,7 @@
8122
8126
  syntax: "<integer>"
8123
8127
  },
8124
8128
  outline: {
8125
- syntax: "[ <'outline-width'> || <'outline-style'> || <'outline-color'> ]"
8129
+ syntax: "<'outline-width'> || <'outline-style'> || <'outline-color'>"
8126
8130
  },
8127
8131
  "outline-color": {
8128
8132
  syntax: "auto | <color>"
@@ -8551,7 +8555,7 @@
8551
8555
  syntax: "space-all | normal | space-first | trim-start"
8552
8556
  },
8553
8557
  "text-transform": {
8554
- syntax: "none | capitalize | uppercase | lowercase | full-width | full-size-kana"
8558
+ syntax: "none | [ capitalize | uppercase | lowercase ] || full-width || full-size-kana | math-auto"
8555
8559
  },
8556
8560
  "text-underline-offset": {
8557
8561
  syntax: "auto | <length> | <percentage> "
@@ -8641,7 +8645,7 @@
8641
8645
  syntax: "visible | hidden | collapse"
8642
8646
  },
8643
8647
  "white-space": {
8644
- syntax: "normal | pre | nowrap | pre-wrap | pre-line | break-spaces | [ <'white-space-collapse'> || <'text-wrap'> ]"
8648
+ syntax: "normal | pre | pre-wrap | pre-line | <'white-space-collapse'> || <'text-wrap-mode'>"
8645
8649
  },
8646
8650
  "white-space-collapse": {
8647
8651
  syntax: "collapse | preserve | preserve-breaks | preserve-spaces | break-spaces"
@@ -8677,7 +8681,7 @@
8677
8681
  syntax: "auto | <integer>"
8678
8682
  },
8679
8683
  zoom: {
8680
- syntax: "normal | reset | <number> | <percentage>"
8684
+ syntax: "normal | reset | <number [0,∞]> || <percentage [0,∞]>"
8681
8685
  }
8682
8686
  };
8683
8687
  var functions = {
@@ -8718,7 +8722,7 @@
8718
8722
  syntax: "calc-size( <calc-size-basis>, <calc-sum> )"
8719
8723
  },
8720
8724
  circle: {
8721
- syntax: "circle( [ <shape-radius> ]? [ at <position> ]? )"
8725
+ syntax: "circle( <radial-size>? [ at <position> ]? )"
8722
8726
  },
8723
8727
  clamp: {
8724
8728
  syntax: "clamp( <calc-sum>#{3} )"
@@ -8754,7 +8758,7 @@
8754
8758
  syntax: "element( <id-selector> )"
8755
8759
  },
8756
8760
  ellipse: {
8757
- syntax: "ellipse( [ <shape-radius>{2} ]? [ at <position> ]? )"
8761
+ syntax: "ellipse( <radial-size>? [ at <position> ]? )"
8758
8762
  },
8759
8763
  env: {
8760
8764
  syntax: "env( <custom-ident> , <declaration-value>? )"
@@ -8769,16 +8773,16 @@
8769
8773
  syntax: "grayscale( [ <number> | <percentage> ]? )"
8770
8774
  },
8771
8775
  hsl: {
8772
- syntax: "hsl( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsl( <hue>, <percentage>, <percentage>, <alpha-value>? )"
8776
+ syntax: "hsl( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsl( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )"
8773
8777
  },
8774
8778
  hsla: {
8775
- syntax: "hsla( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsla( <hue>, <percentage>, <percentage>, <alpha-value>? )"
8779
+ syntax: "hsla( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsla( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )"
8776
8780
  },
8777
8781
  "hue-rotate": {
8778
8782
  syntax: "hue-rotate( [ <angle> | <zero> ]? )"
8779
8783
  },
8780
8784
  hwb: {
8781
- syntax: "hwb( [<hue> | none] [<percentage> | none] [<percentage> | none] [ / [<alpha-value> | none] ]? )"
8785
+ syntax: "hwb( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )"
8782
8786
  },
8783
8787
  hypot: {
8784
8788
  syntax: "hypot( <calc-sum># )"
@@ -8867,6 +8871,9 @@
8867
8871
  ray: {
8868
8872
  syntax: "ray( <angle> && <ray-size>? && contain? && [at <position>]? )"
8869
8873
  },
8874
+ rect: {
8875
+ syntax: "rect( [ <length-percentage> | auto ]{4} [ round <'border-radius'> ]? )"
8876
+ },
8870
8877
  rem: {
8871
8878
  syntax: "rem( <calc-sum>, <calc-sum> )"
8872
8879
  },
@@ -8880,10 +8887,10 @@
8880
8887
  syntax: "repeating-radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )"
8881
8888
  },
8882
8889
  rgb: {
8883
- syntax: "rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )"
8890
+ syntax: "rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? ) | rgb( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? )"
8884
8891
  },
8885
8892
  rgba: {
8886
- syntax: "rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? )"
8893
+ syntax: "rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? ) | rgba( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? )"
8887
8894
  },
8888
8895
  rotate: {
8889
8896
  syntax: "rotate( [ <angle> | <zero> ] )"
@@ -8945,6 +8952,9 @@
8945
8952
  sqrt: {
8946
8953
  syntax: "sqrt( <calc-sum> )"
8947
8954
  },
8955
+ symbols: {
8956
+ syntax: "symbols( <symbols-type>? [ <string> | <image> ]+ )"
8957
+ },
8948
8958
  tan: {
8949
8959
  syntax: "tan( <calc-sum> )"
8950
8960
  },
@@ -8977,6 +8987,9 @@
8977
8987
  },
8978
8988
  view: {
8979
8989
  syntax: "view([<axis> || <'view-timeline-inset'>]?)"
8990
+ },
8991
+ xywh: {
8992
+ syntax: "xywh( <length-percentage>{2} <length-percentage [0,∞]>{2} [ round <'border-radius'> ]? )"
8980
8993
  }
8981
8994
  };
8982
8995
  var syntaxes = {
@@ -8992,6 +9005,9 @@
8992
9005
  "alpha-value": {
8993
9006
  syntax: "<number> | <percentage>"
8994
9007
  },
9008
+ "an+b": {
9009
+ 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>"
9010
+ },
8995
9011
  "anchor()": {
8996
9012
  syntax: "anchor( <anchor-name>? && <anchor-side>, <length-percentage>? )"
8997
9013
  },
@@ -9113,7 +9129,7 @@
9113
9129
  syntax: "<percentage>? && <image>"
9114
9130
  },
9115
9131
  "circle()": {
9116
- syntax: "circle( [ <shape-radius> ]? [ at <position> ]? )"
9132
+ syntax: "circle( <radial-size>? [ at <position> ]? )"
9117
9133
  },
9118
9134
  "clamp()": {
9119
9135
  syntax: "clamp( <calc-sum>#{3} )"
@@ -9127,15 +9143,15 @@
9127
9143
  color: {
9128
9144
  syntax: "<color-base> | currentColor | <system-color> | <light-dark()> | <deprecated-system-color>"
9129
9145
  },
9146
+ "color()": {
9147
+ syntax: "color( [ from <color> ]? <colorspace-params> [ / [ <alpha-value> | none ] ]? )"
9148
+ },
9130
9149
  "color-base": {
9131
9150
  syntax: "<hex-color> | <color-function> | <named-color> | <color-mix()> | transparent"
9132
9151
  },
9133
9152
  "color-function": {
9134
9153
  syntax: "<rgb()> | <rgba()> | <hsl()> | <hsla()> | <hwb()> | <lab()> | <lch()> | <oklab()> | <oklch()> | <color()>"
9135
9154
  },
9136
- "color()": {
9137
- syntax: "color( [from <color>]? <colorspace-params> [ / [ <alpha-value> | none ] ]? )"
9138
- },
9139
9155
  "color-interpolation-method": {
9140
9156
  syntax: "in [ <rectangular-color-space> | <polar-color-space> <hue-interpolation-method>? | <custom-color-space> ]"
9141
9157
  },
@@ -9244,6 +9260,9 @@
9244
9260
  dasharray: {
9245
9261
  syntax: "[ [ <length-percentage> | <number> ]+ ]#"
9246
9262
  },
9263
+ "dashndashdigit-ident": {
9264
+ syntax: "<ident-token>"
9265
+ },
9247
9266
  "deprecated-system-color": {
9248
9267
  syntax: "ActiveBorder | ActiveCaption | AppWorkspace | Background | ButtonHighlight | ButtonShadow | CaptionText | InactiveBorder | InactiveCaption | InactiveCaptionText | InfoBackground | InfoText | Menu | MenuText | Scrollbar | ThreeDDarkShadow | ThreeDFace | ThreeDHighlight | ThreeDLightShadow | ThreeDShadow | Window | WindowFrame | WindowText"
9249
9268
  },
@@ -9284,7 +9303,7 @@
9284
9303
  syntax: "element( <id-selector> )"
9285
9304
  },
9286
9305
  "ellipse()": {
9287
- syntax: "ellipse( [ <shape-radius>{2} ]? [ at <position> ]? )"
9306
+ syntax: "ellipse( <radial-size>? [ at <position> ]? )"
9288
9307
  },
9289
9308
  "ending-shape": {
9290
9309
  syntax: "circle | ellipse"
@@ -9325,7 +9344,7 @@
9325
9344
  "filter-function": {
9326
9345
  syntax: "<blur()> | <brightness()> | <contrast()> | <drop-shadow()> | <grayscale()> | <hue-rotate()> | <invert()> | <opacity()> | <saturate()> | <sepia()>"
9327
9346
  },
9328
- "filter-function-list": {
9347
+ "filter-value-list": {
9329
9348
  syntax: "[ <filter-function> | <url> ]+"
9330
9349
  },
9331
9350
  "final-bg-layer": {
@@ -9380,10 +9399,10 @@
9380
9399
  syntax: "[ historical-ligatures | no-historical-ligatures ]"
9381
9400
  },
9382
9401
  "hsl()": {
9383
- syntax: "hsl( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsl( <hue>, <percentage>, <percentage>, <alpha-value>? )"
9402
+ syntax: "hsl( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsl( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )"
9384
9403
  },
9385
9404
  "hsla()": {
9386
- syntax: "hsla( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsla( <hue>, <percentage>, <percentage>, <alpha-value>? )"
9405
+ syntax: "hsla( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsla( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )"
9387
9406
  },
9388
9407
  hue: {
9389
9408
  syntax: "<number> | <angle>"
@@ -9395,7 +9414,7 @@
9395
9414
  syntax: "hue-rotate( [ <angle> | <zero> ]? )"
9396
9415
  },
9397
9416
  "hwb()": {
9398
- syntax: "hwb( [<hue> | none] [<percentage> | none] [<percentage> | none] [ / [<alpha-value> | none] ]? )"
9417
+ syntax: "hwb( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )"
9399
9418
  },
9400
9419
  "hypot()": {
9401
9420
  syntax: "hypot( <calc-sum># )"
@@ -9403,6 +9422,9 @@
9403
9422
  "id-selector": {
9404
9423
  syntax: "<hash-token>"
9405
9424
  },
9425
+ integer: {
9426
+ syntax: "<number-token>"
9427
+ },
9406
9428
  image: {
9407
9429
  syntax: "<url> | <image()> | <image-set()> | <element()> | <paint()> | <cross-fade()> | <gradient>"
9408
9430
  },
@@ -9568,6 +9590,18 @@
9568
9590
  "mod()": {
9569
9591
  syntax: "mod( <calc-sum>, <calc-sum> )"
9570
9592
  },
9593
+ "n-dimension": {
9594
+ syntax: "<dimension-token>"
9595
+ },
9596
+ "ndash-dimension": {
9597
+ syntax: "<dimension-token>"
9598
+ },
9599
+ "ndashdigit-dimension": {
9600
+ syntax: "<dimension-token>"
9601
+ },
9602
+ "ndashdigit-ident": {
9603
+ syntax: "<ident-token>"
9604
+ },
9571
9605
  "name-repeat": {
9572
9606
  syntax: "repeat( [ <integer [1,∞]> | auto-fill ], <line-names>+ )"
9573
9607
  },
@@ -9580,9 +9614,6 @@
9580
9614
  "ns-prefix": {
9581
9615
  syntax: "[ <ident-token> | '*' ]? '|'"
9582
9616
  },
9583
- nth: {
9584
- syntax: "<an-plus-b> | even | odd"
9585
- },
9586
9617
  "number-percentage": {
9587
9618
  syntax: "<number> | <percentage>"
9588
9619
  },
@@ -9691,9 +9722,15 @@
9691
9722
  quote: {
9692
9723
  syntax: "open-quote | close-quote | no-open-quote | no-close-quote"
9693
9724
  },
9725
+ "radial-extent": {
9726
+ syntax: "closest-corner | closest-side | farthest-corner | farthest-side"
9727
+ },
9694
9728
  "radial-gradient()": {
9695
9729
  syntax: "radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )"
9696
9730
  },
9731
+ "radial-size": {
9732
+ syntax: "<radial-extent> | <length [0,∞]> | <length-percentage [0,∞]>{2}"
9733
+ },
9697
9734
  ratio: {
9698
9735
  syntax: "<number [0,∞]> [ / <number [0,∞]> ]?"
9699
9736
  },
@@ -9715,6 +9752,9 @@
9715
9752
  "relative-size": {
9716
9753
  syntax: "larger | smaller"
9717
9754
  },
9755
+ "rect()": {
9756
+ syntax: "rect( [ <length-percentage> | auto ]{4} [ round <'border-radius'> ]? )"
9757
+ },
9718
9758
  "rem()": {
9719
9759
  syntax: "rem( <calc-sum>, <calc-sum> )"
9720
9760
  },
@@ -9734,10 +9774,10 @@
9734
9774
  syntax: "reversed( <counter-name> )"
9735
9775
  },
9736
9776
  "rgb()": {
9737
- syntax: "rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )"
9777
+ syntax: "rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? ) | rgb( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? )"
9738
9778
  },
9739
9779
  "rgba()": {
9740
- syntax: "rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? )"
9780
+ syntax: "rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? ) | rgba( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? )"
9741
9781
  },
9742
9782
  "rotate()": {
9743
9783
  syntax: "rotate( [ <angle> | <zero> ] )"
@@ -9811,15 +9851,18 @@
9811
9851
  "shape-box": {
9812
9852
  syntax: "<visual-box> | margin-box"
9813
9853
  },
9814
- "shape-radius": {
9815
- syntax: "<length-percentage> | closest-side | farthest-side"
9816
- },
9817
9854
  "side-or-corner": {
9818
9855
  syntax: "[ left | right ] || [ top | bottom ]"
9819
9856
  },
9820
9857
  "sign()": {
9821
9858
  syntax: "sign( <calc-sum> )"
9822
9859
  },
9860
+ "signed-integer": {
9861
+ syntax: "<number-token>"
9862
+ },
9863
+ "signless-integer": {
9864
+ syntax: "<number-token>"
9865
+ },
9823
9866
  "sin()": {
9824
9867
  syntax: "sin( <calc-sum> )"
9825
9868
  },
@@ -9892,6 +9935,12 @@
9892
9935
  symbol: {
9893
9936
  syntax: "<string> | <image> | <custom-ident>"
9894
9937
  },
9938
+ "symbols()": {
9939
+ syntax: "symbols( <symbols-type>? [ <string> | <image> ]+ )"
9940
+ },
9941
+ "symbols-type": {
9942
+ syntax: "cyclic | numeric | alphabetic | symbolic | fixed"
9943
+ },
9895
9944
  "system-color": {
9896
9945
  syntax: "AccentColor | AccentColorText | ActiveText | ButtonBorder | ButtonFace | ButtonText | Canvas | CanvasText | Field | FieldText | GrayText | Highlight | HighlightText | LinkText | Mark | MarkText | SelectedItem | SelectedItemText | VisitedText"
9897
9946
  },
@@ -9982,6 +10031,9 @@
9982
10031
  "wq-name": {
9983
10032
  syntax: "<ns-prefix>? <ident-token>"
9984
10033
  },
10034
+ "xywh()": {
10035
+ syntax: "xywh( <length-percentage>{2} <length-percentage [0,∞]>{2} [ round <'border-radius'> ]? )"
10036
+ },
9985
10037
  xyz: {
9986
10038
  syntax: "xyz | xyz-d50 | xyz-d65"
9987
10039
  },
@@ -10117,16 +10169,16 @@
10117
10169
  syntax: ":not( <complex-selector-list> )"
10118
10170
  },
10119
10171
  ":nth-child()": {
10120
- syntax: ":nth-child( <nth> [ of <complex-selector-list> ]? )"
10172
+ syntax: ":nth-child( <an+b> [ of <complex-selector-list> ]? )"
10121
10173
  },
10122
10174
  ":nth-last-child()": {
10123
- syntax: ":nth-last-child( <nth> [ of <complex-selector-list> ]? )"
10175
+ syntax: ":nth-last-child( <an+b> [ of <complex-selector-list> ]? )"
10124
10176
  },
10125
10177
  ":nth-last-of-type()": {
10126
- syntax: ":nth-last-of-type( <nth> )"
10178
+ syntax: ":nth-last-of-type( <an+b> )"
10127
10179
  },
10128
10180
  ":nth-of-type()": {
10129
- syntax: ":nth-of-type( <nth> )"
10181
+ syntax: ":nth-of-type( <an+b> )"
10130
10182
  },
10131
10183
  ":only-child": {
10132
10184
  syntax: ":only-child"
@@ -10409,7 +10461,7 @@
10409
10461
  syntax: "normal | <percentage>"
10410
10462
  },
10411
10463
  "font-display": {
10412
- syntax: "[ auto | block | swap | fallback | optional ]"
10464
+ syntax: "auto | block | swap | fallback | optional"
10413
10465
  },
10414
10466
  "font-family": {
10415
10467
  syntax: "<family-name>"
@@ -10530,7 +10582,7 @@
10530
10582
  }
10531
10583
  }
10532
10584
  };
10533
- var config$3 = {
10585
+ var config$2 = {
10534
10586
  declarations: declarations,
10535
10587
  functions: functions,
10536
10588
  syntaxes: syntaxes,
@@ -10538,7 +10590,6 @@
10538
10590
  atRules: atRules
10539
10591
  };
10540
10592
 
10541
- const specialValues = ['inherit', 'initial', 'unset', 'revert', 'revert-layer'];
10542
10593
  var ValidationTokenEnum;
10543
10594
  (function (ValidationTokenEnum) {
10544
10595
  ValidationTokenEnum[ValidationTokenEnum["Root"] = 0] = "Root";
@@ -11540,100 +11591,6 @@
11540
11591
  }
11541
11592
  return position;
11542
11593
  }
11543
- function renderSyntax(token, parent) {
11544
- let glue;
11545
- switch (token.typ) {
11546
- case ValidationTokenEnum.Root:
11547
- return token.chi.reduce((acc, curr) => acc + renderSyntax(curr), '');
11548
- case ValidationTokenEnum.Whitespace:
11549
- return ' ';
11550
- case ValidationTokenEnum.ValidationFunctionDefinition:
11551
- return '<' + token.val + '()>';
11552
- case ValidationTokenEnum.HashMark:
11553
- return '#';
11554
- case ValidationTokenEnum.Pipe:
11555
- return '|';
11556
- case ValidationTokenEnum.Column:
11557
- return '||';
11558
- case ValidationTokenEnum.PipeToken:
11559
- return token.chi.reduce((acc, curr) => acc + (acc.trim().length > 0 ? '|' : '') + curr.reduce((acc, curr) => acc + renderSyntax(curr), ''), '');
11560
- case ValidationTokenEnum.ColumnToken:
11561
- case ValidationTokenEnum.AmpersandToken:
11562
- glue = token.typ == ValidationTokenEnum.ColumnToken ? '||' : '&&';
11563
- return token.l.reduce((acc, curr) => acc + renderSyntax(curr), '') +
11564
- glue +
11565
- token.r.reduce((acc, curr) => acc + renderSyntax(curr), '');
11566
- case ValidationTokenEnum.Function:
11567
- case ValidationTokenEnum.PseudoClassFunctionToken:
11568
- case ValidationTokenEnum.Parens:
11569
- return token.val + '(' + token.chi.reduce((acc, curr) => acc + renderSyntax(curr), '') + ')' + renderAttributes(token);
11570
- case ValidationTokenEnum.Comma:
11571
- return ',';
11572
- case ValidationTokenEnum.Keyword:
11573
- return token.val + renderAttributes(token);
11574
- case ValidationTokenEnum.OpenBracket:
11575
- return '[';
11576
- case ValidationTokenEnum.Ampersand:
11577
- return '&&';
11578
- case ValidationTokenEnum.QuestionMark:
11579
- return '?';
11580
- case ValidationTokenEnum.Separator:
11581
- return '/';
11582
- case ValidationTokenEnum.Bracket:
11583
- return '[' + token.chi.reduce((acc, curr) => acc + renderSyntax(curr), '') + ']' + renderAttributes(token);
11584
- case ValidationTokenEnum.PropertyType:
11585
- return '<' + token.val + '>' + renderAttributes(token);
11586
- case ValidationTokenEnum.DeclarationType:
11587
- return "<'" + token.val + "'>" + renderAttributes(token);
11588
- case ValidationTokenEnum.Number:
11589
- case ValidationTokenEnum.PseudoClassToken:
11590
- case ValidationTokenEnum.StringToken:
11591
- return token.val + '';
11592
- case ValidationTokenEnum.SemiColon:
11593
- return ';';
11594
- case ValidationTokenEnum.AtRule:
11595
- return '@' + token.val;
11596
- case ValidationTokenEnum.AtRuleDefinition:
11597
- return '@' + token.val +
11598
- (token.prelude == null ? '' : ' ' + token.prelude.reduce((acc, curr) => acc + renderSyntax(curr), '')) +
11599
- (token.chi == null ? '' : ' {\n' + token.chi.reduce((acc, curr) => acc + renderSyntax(curr), '')).slice(1, -1) + '\n}';
11600
- case ValidationTokenEnum.Block:
11601
- return '{' + token.chi.reduce((acc, t) => acc + renderSyntax(t), '') + '}';
11602
- case ValidationTokenEnum.DeclarationDefinitionToken:
11603
- return token.nam + ': ' + renderSyntax(token.val);
11604
- case ValidationTokenEnum.ColumnArrayToken:
11605
- return token.chi.reduce((acc, curr) => acc + (acc.trim().length > 0 ? '||' : '') + renderSyntax(curr), '');
11606
- default:
11607
- throw new Error('Unhandled token: ' + JSON.stringify({ token }));
11608
- }
11609
- }
11610
- function renderAttributes(token) {
11611
- let result = '';
11612
- if (token.isList) {
11613
- result += '#';
11614
- }
11615
- if (token.isOptional) {
11616
- result += '?';
11617
- }
11618
- if (token.isRepeatableGroup) {
11619
- result += '!';
11620
- }
11621
- if (token.isRepeatable) {
11622
- result += '*';
11623
- }
11624
- if (token.atLeastOnce) {
11625
- result += '+';
11626
- }
11627
- if (token.occurence != null) {
11628
- if (token.occurence.max == 0 || token.occurence.max == token.occurence.min || Number.isNaN(token.occurence.max)) {
11629
- result += '{' + token.occurence.min + '}';
11630
- }
11631
- else {
11632
- result += '{' + token.occurence.min + ',' + token.occurence.max + '}';
11633
- }
11634
- }
11635
- return result;
11636
- }
11637
11594
  function minify$1(ast) {
11638
11595
  if (Array.isArray(ast)) {
11639
11596
  // @ts-ignore
@@ -11735,14 +11692,14 @@
11735
11692
  }
11736
11693
 
11737
11694
  const parsedSyntaxes = new Map();
11738
- Object.freeze(config$3);
11695
+ Object.freeze(config$2);
11739
11696
  function getSyntaxConfig() {
11740
11697
  // @ts-ignore
11741
- return config$3;
11698
+ return config$2;
11742
11699
  }
11743
11700
  function getParsedSyntax(group, key) {
11744
11701
  // @ts-ignore
11745
- let obj = config$3[group];
11702
+ let obj = config$2[group];
11746
11703
  const keys = Array.isArray(key) ? key : [key];
11747
11704
  for (let i = 0; i < keys.length; i++) {
11748
11705
  key = keys[i];
@@ -11780,7 +11737,7 @@
11780
11737
  acc[acc.length - 1].push(curr);
11781
11738
  }
11782
11739
  return acc;
11783
- }, [[]]).slice(1);
11740
+ }, [[]]);
11784
11741
  for (let i = 0; i < slice.length; i++) {
11785
11742
  if (slice[i].length == 0) {
11786
11743
  // @ts-ignore
@@ -11793,26 +11750,15 @@
11793
11750
  tokens
11794
11751
  };
11795
11752
  }
11796
- if (slice[i][0].typ != exports.EnumToken.IdenTokenType) {
11797
- // @ts-ignore
11798
- return {
11799
- valid: ValidationLevel.Drop,
11800
- matches: tokens,
11801
- node: slice[i][0],
11802
- syntax: 'ident',
11803
- error: 'expecting ident',
11804
- tokens
11805
- };
11806
- }
11807
- for (let j = 1; j < slice[i].length; j++) {
11808
- if (slice[i][j].typ != exports.EnumToken.ClassSelectorTokenType) {
11753
+ for (let j = 0; j < slice[i].length; j++) {
11754
+ if (slice[i][j].typ != exports.EnumToken.IdenTokenType && slice[i][j].typ != exports.EnumToken.ClassSelectorTokenType) {
11809
11755
  // @ts-ignore
11810
11756
  return {
11811
11757
  valid: ValidationLevel.Drop,
11812
11758
  matches: tokens,
11813
11759
  node: slice[i][j],
11814
- syntax: 'layer-name',
11815
- error: 'expecting class selector',
11760
+ syntax: '<layer-name>',
11761
+ error: 'expecting ident or class selector',
11816
11762
  tokens
11817
11763
  };
11818
11764
  }
@@ -12009,8 +11955,8 @@
12009
11955
  tokens.shift();
12010
11956
  consumeWhitespace(tokens);
12011
11957
  }
12012
- while (tokens.length > 0 && tokens[0].typ == exports.EnumToken.PseudoClassTokenType) {
12013
- const isPseudoElement = tokens[0].val.startsWith('::');
11958
+ while (tokens.length > 0 && (tokens[0].typ == exports.EnumToken.PseudoElementTokenType || tokens[0].typ == exports.EnumToken.PseudoClassTokenType)) {
11959
+ const isPseudoElement = tokens[0].typ == exports.EnumToken.PseudoElementTokenType;
12014
11960
  if (
12015
11961
  // https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions#pseudo-elements
12016
11962
  !(isPseudoElement && tokens[0].val.startsWith('::-webkit-')) &&
@@ -12441,1603 +12387,127 @@
12441
12387
  return validateKeyframeSelector(i == j ? tokens.slice(i) : tokens.slice(j, i + 1), atRule);
12442
12388
  }
12443
12389
 
12444
- const config$2 = getSyntaxConfig();
12445
- function consumeToken(tokens) {
12446
- tokens.shift();
12447
- }
12448
- function consumeSyntax(syntaxes) {
12449
- syntaxes.shift();
12390
+ function validateURL(token) {
12391
+ if (token.typ == exports.EnumToken.UrlTokenTokenType) {
12392
+ // @ts-ignore
12393
+ return {
12394
+ valid: ValidationLevel.Valid,
12395
+ matches: [],
12396
+ node: token,
12397
+ // @ts-ignore
12398
+ syntax: 'url()',
12399
+ error: '',
12400
+ tokens: []
12401
+ };
12402
+ }
12403
+ if (token.typ != exports.EnumToken.UrlFunctionTokenType) {
12404
+ // @ts-ignore
12405
+ return {
12406
+ valid: ValidationLevel.Drop,
12407
+ matches: [],
12408
+ node: token,
12409
+ // @ts-ignore
12410
+ syntax: 'url()',
12411
+ error: 'expected url()',
12412
+ tokens: []
12413
+ };
12414
+ }
12415
+ const children = token.chi.slice();
12416
+ consumeWhitespace(children);
12417
+ if (children.length == 0 || ![exports.EnumToken.UrlTokenTokenType, exports.EnumToken.StringTokenType, exports.EnumToken.HashTokenType].includes(children[0].typ)) {
12418
+ // @ts-ignore
12419
+ return {
12420
+ valid: ValidationLevel.Drop,
12421
+ matches: [],
12422
+ node: children[0] ?? token,
12423
+ // @ts-ignore
12424
+ syntax: 'url()',
12425
+ error: 'expected url-token',
12426
+ tokens: children
12427
+ };
12428
+ }
12429
+ children.shift();
12430
+ consumeWhitespace(children);
12431
+ if (children.length > 0) {
12432
+ // @ts-ignore
12433
+ return {
12434
+ valid: ValidationLevel.Drop,
12435
+ matches: [],
12436
+ node: children[0] ?? token,
12437
+ // @ts-ignore
12438
+ syntax: 'url()',
12439
+ error: 'unexpected token',
12440
+ tokens: children
12441
+ };
12442
+ }
12443
+ // @ts-ignore
12444
+ return {
12445
+ valid: ValidationLevel.Valid,
12446
+ matches: [],
12447
+ node: token,
12448
+ // @ts-ignore
12449
+ syntax: 'url()',
12450
+ error: '',
12451
+ tokens: []
12452
+ };
12450
12453
  }
12451
- function splice(tokens, matches) {
12452
- if (matches.length == 0) {
12453
- return tokens;
12454
+
12455
+ const validateSelectorList = validateComplexSelectorList;
12456
+
12457
+ function validateSelector(selector, options, root) {
12458
+ if (root == null) {
12459
+ return validateSelectorList(selector, root, options);
12454
12460
  }
12455
12461
  // @ts-ignore
12456
- const index = tokens.indexOf(matches.at(-1));
12457
- if (index > -1) {
12458
- tokens.splice(0, index + 1);
12462
+ if (root.typ == exports.EnumToken.AtRuleNodeType && root.nam.match(/^(-[a-z]+-)?keyframes$/)) {
12463
+ return validateKeyframeBlockList(selector, root);
12459
12464
  }
12460
- return tokens;
12465
+ let isNested = root.typ == exports.EnumToken.RuleNodeType ? 1 : 0;
12466
+ let currentRoot = root.parent;
12467
+ while (currentRoot != null && isNested == 0) {
12468
+ if (currentRoot.typ == exports.EnumToken.RuleNodeType) {
12469
+ isNested++;
12470
+ if (isNested > 0) {
12471
+ // @ts-ignore
12472
+ return validateRelativeSelectorList(selector, root, { ...(options ?? {}), nestedSelector: true });
12473
+ }
12474
+ }
12475
+ currentRoot = currentRoot.parent;
12476
+ }
12477
+ const nestedSelector = isNested > 0;
12478
+ // @ts-ignore
12479
+ return nestedSelector ? validateRelativeSelectorList(selector, root, { ...(options ?? {}), nestedSelector }) : validateSelectorList(selector, root, { ...(options ?? {}), nestedSelector });
12461
12480
  }
12462
- function validateSyntax(syntaxes, tokens, root, options, context = { level: 0 }) {
12463
- console.error(JSON.stringify({
12464
- syntax: syntaxes.reduce((acc, curr) => acc + renderSyntax(curr), ''),
12465
- syntaxes,
12466
- tokens,
12467
- s: new Error('bar').stack
12468
- }, null, 1));
12469
- if (syntaxes == null) {
12481
+
12482
+ function validateAtRuleMedia(atRule, options, root) {
12483
+ // media-query-list
12484
+ if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
12470
12485
  // @ts-ignore
12471
12486
  return {
12472
- valid: ValidationLevel.Drop,
12487
+ valid: ValidationLevel.Valid,
12473
12488
  matches: [],
12474
- node: tokens[0] ?? null,
12489
+ node: null,
12475
12490
  syntax: null,
12476
- error: 'no matching syntaxes found',
12477
- tokens
12491
+ error: '',
12492
+ tokens: []
12478
12493
  };
12479
12494
  }
12480
- let token = null;
12481
- let syntax;
12482
12495
  let result = null;
12483
- let validSyntax = false;
12484
- let matched = false;
12485
- const matches = [];
12486
- tokens = tokens.slice();
12487
- syntaxes = syntaxes.slice();
12488
- tokens = tokens.slice();
12489
- if (context.cache == null) {
12490
- context.cache = new WeakMap;
12496
+ const slice = atRule.tokens.slice();
12497
+ consumeWhitespace(slice);
12498
+ if (slice.length == 0) {
12499
+ return {
12500
+ valid: ValidationLevel.Valid,
12501
+ matches: [],
12502
+ node: atRule,
12503
+ syntax: '@media',
12504
+ error: '',
12505
+ tokens: []
12506
+ };
12491
12507
  }
12492
- if (context.tokens == null) {
12493
- context.tokens = tokens.slice();
12494
- }
12495
- context = { ...context };
12496
- main: while (tokens.length > 0) {
12497
- if (syntaxes.length == 0) {
12498
- break;
12499
- }
12500
- token = tokens[0];
12501
- syntax = syntaxes[0];
12502
- // @ts-ignore
12503
- context.position = context.tokens.indexOf(token);
12504
- const cached = context.cache.get(token)?.get(syntax.text) ?? null;
12505
- if (cached != null) {
12506
- if (cached.error.length > 0) {
12507
- return { ...cached, tokens, node: cached.valid == ValidationLevel.Valid ? null : token };
12508
- }
12509
- syntaxes.shift();
12510
- tokens.shift();
12511
- continue;
12512
- }
12513
- if (token.typ == exports.EnumToken.DescendantCombinatorTokenType) {
12514
- tokens.shift();
12515
- if (syntax.typ == ValidationTokenEnum.Whitespace) {
12516
- syntaxes.shift();
12517
- }
12518
- continue;
12519
- }
12520
- else if (syntax.typ == ValidationTokenEnum.Whitespace) {
12521
- syntaxes.shift();
12522
- if (token.typ == exports.EnumToken.WhitespaceTokenType) {
12523
- tokens.shift();
12524
- }
12525
- continue;
12526
- }
12527
- else if (syntax.typ == ValidationTokenEnum.Block && exports.EnumToken.AtRuleTokenType == token.typ && ('chi' in token)) {
12528
- syntaxes.shift();
12529
- tokens.shift();
12530
- // @ts-ignore
12531
- matches.push(token);
12532
- continue;
12533
- }
12534
- if (syntax.isOptional) {
12535
- if (!context.cache.has(token)) {
12536
- context.cache.set(token, new Map);
12537
- }
12538
- if (context.cache.get(token).has(syntax.text)) {
12539
- result = context.cache.get(token).get(syntax.text);
12540
- return { ...result, tokens, node: result.valid == ValidationLevel.Valid ? null : token };
12541
- }
12542
- // @ts-ignore
12543
- const { isOptional, ...c } = syntax;
12544
- // @ts-ignore
12545
- let result2;
12546
- // @ts-ignore
12547
- result2 = validateSyntax([c], tokens, root, options, context);
12548
- if (result2.valid == ValidationLevel.Valid && result2.matches.length > 0) {
12549
- tokens = result2.tokens;
12550
- // splice(tokens, result2.matches);
12551
- // tokens = result2.tokens;
12552
- // @ts-ignore
12553
- matches.push(...result2.matches);
12554
- matched = true;
12555
- result = result2;
12556
- }
12557
- else {
12558
- syntaxes.shift();
12559
- continue;
12560
- }
12561
- syntaxes.shift();
12562
- if (syntaxes.length == 0) {
12563
- // @ts-ignore
12564
- return {
12565
- valid: ValidationLevel.Valid,
12566
- matches: result2.matches,
12567
- node: result2.node,
12568
- syntax: result2.syntax,
12569
- error: result2.error,
12570
- tokens
12571
- };
12572
- }
12573
- continue;
12574
- }
12575
- if (syntax.isList) {
12576
- let index = -1;
12577
- // @ts-ignore
12578
- let { isList, ...c } = syntax;
12579
- // const c: ValidationToken = {...syntaxes, isList: false} as ValidationToken;
12580
- let result2 = null;
12581
- validSyntax = false;
12582
- do {
12583
- for (let i = index + 1; i < tokens.length; i++) {
12584
- if (tokens[i].typ == exports.EnumToken.CommaTokenType) {
12585
- index = i;
12586
- break;
12587
- }
12588
- }
12589
- if (tokens[index + 1]?.typ == exports.EnumToken.CommaTokenType) {
12590
- return {
12591
- valid: ValidationLevel.Drop,
12592
- matches,
12593
- node: tokens[0],
12594
- syntax,
12595
- error: 'unexpected token',
12596
- tokens
12597
- };
12598
- }
12599
- if (index == -1) {
12600
- index = tokens.length;
12601
- }
12602
- if (index == 0) {
12603
- break;
12604
- }
12605
- // @ts-ignore
12606
- result2 = validateSyntax([c], tokens.slice(0, index), root, options, context);
12607
- matched = result2.valid == ValidationLevel.Valid && result2.matches.length > 0;
12608
- if (matched) {
12609
- const l = tokens.length;
12610
- validSyntax = true;
12611
- // @ts-ignore
12612
- // matches.push(...result2.matches);
12613
- // splice(tokens, result2.matches);
12614
- if (tokens.length == 1 && tokens[0].typ == exports.EnumToken.CommaTokenType) {
12615
- return {
12616
- valid: ValidationLevel.Drop,
12617
- matches,
12618
- node: tokens[0],
12619
- syntax,
12620
- error: 'unexpected token',
12621
- tokens
12622
- };
12623
- }
12624
- tokens = tokens.slice(index);
12625
- result = result2;
12626
- // @ts-ignore
12627
- matches.push(...result2.matches);
12628
- if (result.tokens.length > 0) {
12629
- if (index == -1) {
12630
- tokens = result.tokens;
12631
- }
12632
- else {
12633
- tokens = tokens.slice(index - result.tokens.length);
12634
- }
12635
- }
12636
- else if (index > 0) {
12637
- tokens = tokens.slice(index);
12638
- }
12639
- index = -1;
12640
- if (l == tokens.length) {
12641
- break;
12642
- }
12643
- }
12644
- else {
12645
- break;
12646
- }
12647
- } while (tokens.length > 0);
12648
- // if (level == 0) {
12649
- // }
12650
- if (!matched) {
12651
- return {
12652
- valid: ValidationLevel.Drop,
12653
- // @ts-ignore
12654
- matches: [...new Set(matches)],
12655
- node: token,
12656
- syntax,
12657
- error: 'unexpected token',
12658
- tokens
12659
- };
12660
- }
12661
- syntaxes.shift();
12662
- continue;
12663
- }
12664
- if (syntax.isRepeatable) {
12665
- // @ts-ignore
12666
- let { isRepeatable, ...c } = syntax;
12667
- let result2 = null;
12668
- validSyntax = false;
12669
- let l = tokens.length;
12670
- let tok = null;
12671
- do {
12672
- // @ts-ignore
12673
- result2 = validateSyntax([c], tokens, root, options, context);
12674
- if (result2.matches.length == 0 && result2.error.length > 0) {
12675
- syntaxes.shift();
12676
- break main;
12677
- }
12678
- if (result2.valid == ValidationLevel.Valid) {
12679
- tokens = result2.tokens;
12680
- // @ts-ignore
12681
- matches.push(...result2.matches);
12682
- result = result2;
12683
- if (l == tokens.length) {
12684
- if (tok == tokens[0]) {
12685
- break;
12686
- }
12687
- if (result2.matches.length == 0 && tokens.length > 0) {
12688
- tokens = result2.tokens;
12689
- tok = tokens[0];
12690
- continue;
12691
- }
12692
- break;
12693
- }
12694
- if (matches.length == 0) {
12695
- tokens = result2.tokens;
12696
- }
12697
- l = tokens.length;
12698
- continue;
12699
- }
12700
- break;
12701
- } while (result2.valid == ValidationLevel.Valid && tokens.length > 0);
12702
- // if (lastResult != null) {
12703
- //
12704
- // splice(tokens, lastResult.matches);
12705
- // // tokens = lastResult.tokens;
12706
- // }
12707
- syntaxes.shift();
12708
- continue;
12709
- }
12710
- // at least one match
12711
- if (syntax.isRepeatableGroup) {
12712
- validSyntax = false;
12713
- let count = 0;
12714
- let l = tokens.length;
12715
- let result2 = null;
12716
- do {
12717
- // @ts-ignore
12718
- const { isRepeatableGroup, ...c } = syntax;
12719
- // @ts-ignore
12720
- result2 = validateSyntax([c], tokens, root, options, context);
12721
- if (result2.valid == ValidationLevel.Drop || result2.matches.length == 0) {
12722
- if (count > 0) {
12723
- syntaxes.shift();
12724
- // if (result2.matches.length == 0) {
12725
- tokens = result2.tokens;
12726
- // break main;
12727
- if (syntaxes.length == 0) {
12728
- return result2;
12729
- }
12730
- break main;
12731
- }
12732
- return result2;
12733
- }
12734
- if (result2.valid == ValidationLevel.Valid && result2.matches.length > 0) {
12735
- count++;
12736
- // lastResult = result;
12737
- validSyntax = true;
12738
- tokens = result2.tokens;
12739
- // splice(tokens, result2.matches);
12740
- // tokens = result2.tokens;
12741
- // @ts-ignore
12742
- matches.push(...result2.matches);
12743
- result = result2;
12744
- if (l == tokens.length) {
12745
- break;
12746
- }
12747
- l = tokens.length;
12748
- }
12749
- else {
12750
- break;
12751
- }
12752
- } while (tokens.length > 0 && result.valid == ValidationLevel.Valid);
12753
- // if (lastResult != null) {
12754
- //
12755
- // splice(tokens, lastResult.matches);
12756
- // // tokens = lastResult.tokens;
12757
- // }
12758
- // at least one match is expected
12759
- if (!validSyntax /* || result.matches.length == 0 */) {
12760
- // @ts-ignore
12761
- return {
12762
- valid: ValidationLevel.Drop,
12763
- node: token,
12764
- tokens,
12765
- syntax,
12766
- error: 'unexpected token',
12767
- matches: []
12768
- };
12769
- }
12770
- syntaxes.shift();
12771
- continue;
12772
- }
12773
- if (syntax.atLeastOnce) {
12774
- const { atLeastOnce, ...c } = syntax;
12775
- result = validateSyntax([c], tokens, root, options, context);
12776
- if (result.valid == ValidationLevel.Drop) {
12777
- return result;
12778
- }
12779
- splice(tokens, result.matches);
12780
- // tokens = result.tokens;
12781
- // @ts-ignore
12782
- matches.push(...result.matches);
12783
- let l = tokens.length;
12784
- let r = validateSyntax([c], tokens, root, options, context);
12785
- while (r.valid == ValidationLevel.Valid) {
12786
- splice(tokens, r.matches);
12787
- // tokens = r.tokens;
12788
- r = validateSyntax([c], tokens, root, options, context);
12789
- if (l == tokens.length) {
12790
- break;
12791
- }
12792
- if (r.valid == ValidationLevel.Valid && r.matches.length > 0) {
12793
- // @ts-ignore
12794
- matches.push(...result.matches);
12795
- }
12796
- l = tokens.length;
12797
- }
12798
- syntaxes.shift();
12799
- continue;
12800
- }
12801
- // @ts-ignore
12802
- if (syntax.occurence != null) {
12803
- // @ts-ignore
12804
- const { occurence, ...c } = syntax;
12805
- // && syntaxes.occurence.max != null
12806
- // consume all tokens
12807
- let match = 1;
12808
- // @ts-ignore
12809
- result = validateSyntax([c], tokens, root, options, context);
12810
- if (result.valid == ValidationLevel.Drop) {
12811
- return result;
12812
- }
12813
- if (result.matches.length == 0) {
12814
- syntaxes.shift();
12815
- continue;
12816
- }
12817
- // splice(tokens, result.matches);
12818
- // tokens = result.tokens;
12819
- // @ts-ignore
12820
- matches.push(...result.matches);
12821
- matched = true;
12822
- tokens = result.tokens;
12823
- while (occurence.max == null || match < occurence.max) {
12824
- // trim whitespace
12825
- if (tokens[0]?.typ == exports.EnumToken.WhitespaceTokenType) {
12826
- tokens.shift();
12827
- }
12828
- // @ts-ignore
12829
- let r = validateSyntax([c], tokens, root, options, context);
12830
- if (r.valid != ValidationLevel.Valid || r.matches.length == 0) {
12831
- break;
12832
- }
12833
- result = r;
12834
- // splice(tokens, r.matches);
12835
- // tokens = r.tokens;
12836
- // @ts-ignore
12837
- matches.push(...result.matches);
12838
- match++;
12839
- tokens = r.tokens;
12840
- result = r;
12841
- if (tokens.length == 0 || (occurence.max != null && match >= occurence.max)) {
12842
- break;
12843
- }
12844
- // @ts-ignore
12845
- // r = validateSyntax([c], tokens, root, options, context);
12846
- }
12847
- syntaxes.shift();
12848
- continue;
12849
- }
12850
- // @ts-ignore
12851
- if (syntax.typ == ValidationTokenEnum.Whitespace) {
12852
- if (token.typ == exports.EnumToken.WhitespaceTokenType) {
12853
- tokens.shift();
12854
- }
12855
- syntaxes.shift();
12856
- continue;
12857
- }
12858
- // @ts-ignore
12859
- if (token.val != null && specialValues.includes(token.val)) {
12860
- matched = true;
12861
- result = {
12862
- valid: ValidationLevel.Valid,
12863
- matches: [token],
12864
- node: null,
12865
- syntax,
12866
- error: '',
12867
- tokens
12868
- };
12869
- // @ts-ignore
12870
- matches.push(...result.matches);
12871
- }
12872
- else {
12873
- result = doValidateSyntax(syntax, token, tokens, root, options, context);
12874
- matched = result.valid == ValidationLevel.Valid && result.matches.length > 0;
12875
- if (matched) {
12876
- // splice(tokens, result.matches);
12877
- tokens = result.tokens;
12878
- // @ts-ignore
12879
- matches.push(...result.matches);
12880
- }
12881
- }
12882
- if (result.valid == ValidationLevel.Drop) {
12883
- // @ts-ignore
12884
- return { ...result, matches, tokens, node: result.valid == ValidationLevel.Valid ? null : token };
12885
- }
12886
- consumeSyntax(syntaxes);
12887
- if (tokens.length == 0) {
12888
- return result;
12889
- }
12890
- }
12891
- if (result?.valid == ValidationLevel.Valid) {
12892
- // splice(tokens, result.matches);
12893
- tokens = result.tokens;
12894
- // @ts-ignore
12895
- matches.push(...result.matches);
12896
- }
12897
- if ( /* result == null && */tokens.length == 0 && syntaxes.length > 0) {
12898
- validSyntax = isOptionalSyntax(syntaxes);
12899
- }
12900
- if (result == null) {
12901
- result = {
12902
- valid: validSyntax ? ValidationLevel.Valid : ValidationLevel.Drop,
12903
- matches,
12904
- node: validSyntax ? null : tokens[0] ?? null,
12905
- // @ts-ignore
12906
- syntax,
12907
- error: validSyntax ? '' : 'unexpected token',
12908
- tokens
12909
- };
12910
- }
12911
- if (token != null) {
12912
- if (!context.cache.has(token)) {
12913
- context.cache.set(token, new Map);
12914
- }
12915
- context.cache.get(token).set(syntax.text, result);
12916
- }
12917
- if (result != null) {
12918
- // @ts-ignore
12919
- return { ...result, matches: [...(new Set(matches))] };
12920
- }
12921
- return result;
12922
- }
12923
- function isOptionalSyntax(syntaxes) {
12924
- return syntaxes.length > 0 && syntaxes.every(t => t.typ == ValidationTokenEnum.Whitespace || t.isOptional || t.isRepeatable || (t.typ == ValidationTokenEnum.PropertyType && isOptionalSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, t.val) ?? getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, t.val) ?? [])));
12925
- }
12926
- function doValidateSyntax(syntax, token, tokens, root, options, context) {
12927
- let valid = false;
12928
- let result;
12929
- let children;
12930
- let queue;
12931
- let matches;
12932
- let child;
12933
- let astNodes = new Set;
12934
- if (token.typ == exports.EnumToken.NestingSelectorTokenType && syntax.typ == 2) {
12935
- valid = root != null && 'relative-selector' == syntax.val;
12936
- return {
12937
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
12938
- matches: valid ? [token] : [],
12939
- node: valid ? null : token,
12940
- syntax,
12941
- error: valid ? '' : 'unexpected token',
12942
- tokens
12943
- };
12944
- }
12945
- switch (syntax.typ) {
12946
- case ValidationTokenEnum.Comma:
12947
- valid = token.typ === exports.EnumToken.CommaTokenType;
12948
- // @ts-ignore
12949
- result = {
12950
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
12951
- matches: valid ? [token] : [],
12952
- node: valid ? null : token,
12953
- syntax,
12954
- error: valid ? '' : 'unexpected token',
12955
- tokens
12956
- };
12957
- break;
12958
- case ValidationTokenEnum.AtRule:
12959
- if (token.typ != exports.EnumToken.AtRuleNodeType) {
12960
- // @ts-ignore
12961
- return {
12962
- valid: ValidationLevel.Drop,
12963
- matches: [],
12964
- node: token,
12965
- syntax,
12966
- error: 'expecting at-rule',
12967
- tokens
12968
- };
12969
- }
12970
- if (token.nam != syntax.val) {
12971
- // @ts-ignore
12972
- return {
12973
- valid: ValidationLevel.Drop,
12974
- matches: [],
12975
- node: token,
12976
- syntax,
12977
- error: `expecting '@${syntax.val}' but found '@${token.nam}'`,
12978
- tokens
12979
- };
12980
- }
12981
- if (root == null) {
12982
- return {
12983
- valid: ValidationLevel.Valid,
12984
- matches: [token],
12985
- node: null,
12986
- syntax,
12987
- error: '',
12988
- tokens
12989
- };
12990
- }
12991
- if (root.typ != exports.EnumToken.AtRuleNodeType) {
12992
- // @ts-ignore
12993
- return {
12994
- valid: ValidationLevel.Drop,
12995
- matches: [],
12996
- node: token,
12997
- syntax,
12998
- error: 'not allowed here',
12999
- tokens
13000
- };
13001
- }
13002
- if (!('chi' in token)) {
13003
- // @ts-ignore
13004
- return {
13005
- valid: ValidationLevel.Drop,
13006
- matches: [],
13007
- node: token,
13008
- syntax,
13009
- error: '@at-rule must have children',
13010
- tokens
13011
- };
13012
- }
13013
- // @ts-ignore
13014
- result = {
13015
- valid: ValidationLevel.Valid,
13016
- matches: [token],
13017
- node: null,
13018
- syntax,
13019
- error: '',
13020
- tokens
13021
- };
13022
- break;
13023
- case ValidationTokenEnum.AtRuleDefinition:
13024
- if (token.typ != exports.EnumToken.AtRuleNodeType) {
13025
- // @ts-ignore
13026
- return {
13027
- valid: ValidationLevel.Drop,
13028
- matches: [],
13029
- node: token,
13030
- syntax,
13031
- error: 'expecting at-rule',
13032
- tokens
13033
- };
13034
- }
13035
- if ('chi' in syntax && !('chi' in token)) {
13036
- // @ts-ignore
13037
- return {
13038
- valid: ValidationLevel.Drop,
13039
- matches: [],
13040
- node: token,
13041
- syntax,
13042
- error: '@at-rule must have children',
13043
- tokens
13044
- };
13045
- }
13046
- if ('chi' in token && !('chi' in token)) {
13047
- // @ts-ignore
13048
- return {
13049
- valid: ValidationLevel.Drop,
13050
- matches: [],
13051
- node: token,
13052
- syntax,
13053
- error: 'children not allowed here',
13054
- tokens
13055
- };
13056
- }
13057
- const s = getParsedSyntax("atRules" /* ValidationSyntaxGroupEnum.AtRules */, '@' + token.nam);
13058
- if ('prelude' in syntax) {
13059
- if (!('tokens' in token)) {
13060
- // @ts-ignore
13061
- return {
13062
- valid: ValidationLevel.Drop,
13063
- matches: [],
13064
- node: token,
13065
- syntax,
13066
- error: 'expected at-rule prelude',
13067
- tokens
13068
- };
13069
- }
13070
- result = validateSyntax(s[0].prelude, token.tokens, root, options, {
13071
- ...context,
13072
- tokens: null,
13073
- level: context.level + 1
13074
- });
13075
- if (result.valid == ValidationLevel.Drop) {
13076
- return result;
13077
- }
13078
- }
13079
- const hasBody = 'chi' in s[0];
13080
- if ('chi' in token) {
13081
- if (!hasBody) {
13082
- // @ts-ignore
13083
- return {
13084
- valid: ValidationLevel.Drop,
13085
- matches: [],
13086
- node: token,
13087
- syntax,
13088
- error: 'unexpected at-rule body',
13089
- tokens
13090
- };
13091
- }
13092
- }
13093
- else if (hasBody) {
13094
- // @ts-ignore
13095
- return {
13096
- valid: ValidationLevel.Drop,
13097
- matches: [],
13098
- node: token,
13099
- syntax,
13100
- error: 'expecting at-rule body',
13101
- tokens
13102
- };
13103
- }
13104
- break;
13105
- case ValidationTokenEnum.DeclarationType:
13106
- // @ts-ignore
13107
- result = validateSyntax(getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, syntax.val), [token], root, options, context);
13108
- break;
13109
- case ValidationTokenEnum.Keyword:
13110
- valid = (token.typ == exports.EnumToken.IdenTokenType && token.val.localeCompare(syntax.val, 'en', { sensitivity: 'base' }) == 0) ||
13111
- (token.typ == exports.EnumToken.ColorTokenType && token.kin == 'lit' && syntax.val.localeCompare(token.val, 'en', { sensitivity: 'base' }) == 0);
13112
- result = {
13113
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13114
- matches: valid ? [token] : [],
13115
- node: valid ? null : token,
13116
- syntax,
13117
- error: valid ? '' : 'unexpected token',
13118
- tokens
13119
- };
13120
- break;
13121
- case ValidationTokenEnum.SemiColon:
13122
- valid = root == null || [exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType, exports.EnumToken.StyleSheetNodeType].includes(root.typ);
13123
- result = {
13124
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13125
- matches: valid ? [token] : [],
13126
- node: valid ? null : token,
13127
- syntax,
13128
- error: valid ? '' : 'unexpected token',
13129
- tokens
13130
- };
13131
- break;
13132
- case ValidationTokenEnum.Separator:
13133
- valid = token.typ == exports.EnumToken.LiteralTokenType && token.val != '/';
13134
- result = {
13135
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13136
- matches: valid ? [token] : [],
13137
- node: valid ? null : token,
13138
- syntax,
13139
- error: valid ? '' : 'unexpected token',
13140
- tokens
13141
- };
13142
- break;
13143
- case ValidationTokenEnum.PropertyType:
13144
- //
13145
- if ('image' == syntax.val) {
13146
- valid = token.typ == exports.EnumToken.UrlFunctionTokenType || token.typ == exports.EnumToken.ImageFunctionTokenType;
13147
- if (!valid) {
13148
- return {
13149
- valid: ValidationLevel.Drop,
13150
- matches: [],
13151
- node: token,
13152
- syntax,
13153
- error: 'unexpected <image>',
13154
- tokens
13155
- };
13156
- }
13157
- result = validateImage(token);
13158
- }
13159
- else if (['media-feature', 'mf-plain'].includes(syntax.val)) {
13160
- valid = token.typ == exports.EnumToken.DeclarationNodeType;
13161
- result = {
13162
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13163
- matches: valid ? [token] : [],
13164
- node: valid ? null : token,
13165
- syntax,
13166
- error: valid ? '' : 'unexpected token',
13167
- tokens
13168
- };
13169
- }
13170
- else if (syntax.val == 'pseudo-page') {
13171
- valid = token.typ == exports.EnumToken.PseudoClassTokenType && [':left', ':right', ':first', ':blank'].includes(token.val);
13172
- result = {
13173
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13174
- matches: valid ? [token] : [],
13175
- node: valid ? null : token,
13176
- syntax,
13177
- error: valid ? '' : 'unexpected token',
13178
- tokens
13179
- };
13180
- }
13181
- else if (syntax.val == 'page-body') {
13182
- if (token.typ == exports.EnumToken.DeclarationNodeType) {
13183
- valid = true;
13184
- // @ts-ignore
13185
- result = {
13186
- valid: ValidationLevel.Valid,
13187
- matches: [token],
13188
- node: null,
13189
- syntax,
13190
- error: '',
13191
- tokens
13192
- };
13193
- while (tokens.length > 0 && [exports.EnumToken.DeclarationNodeType].includes(tokens[0].typ)) {
13194
- // @ts-ignore
13195
- result.matches.push(tokens.shift());
13196
- }
13197
- }
13198
- else if (token.typ == exports.EnumToken.AtRuleNodeType) {
13199
- result = validateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, 'page-margin-box-type'), [token], root, options, context);
13200
- }
13201
- }
13202
- else if (syntax.val == 'group-rule-body') {
13203
- valid = [exports.EnumToken.AtRuleNodeType, exports.EnumToken.RuleNodeType].includes(token.typ);
13204
- if (!valid && token.typ == exports.EnumToken.DeclarationNodeType && root?.typ == exports.EnumToken.AtRuleNodeType && root.nam == 'media') {
13205
- // allowed only if nested rule
13206
- let parent = root;
13207
- while (parent != null) {
13208
- if (parent.typ == exports.EnumToken.RuleNodeType) {
13209
- valid = true;
13210
- break;
13211
- }
13212
- // @ts-ignore
13213
- parent = parent.parent;
13214
- }
13215
- }
13216
- // @ts-ignore
13217
- result = {
13218
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13219
- matches: [],
13220
- node: valid ? null : token,
13221
- syntax,
13222
- error: valid ? '' : 'token is not allowed as a child',
13223
- tokens
13224
- };
13225
- if (!valid) {
13226
- return result;
13227
- }
13228
- }
13229
- //
13230
- else if ('type-selector' == syntax.val) {
13231
- valid = (token.typ == exports.EnumToken.UniversalSelectorTokenType) ||
13232
- token.typ == exports.EnumToken.IdenTokenType || (token.typ == exports.EnumToken.NameSpaceAttributeTokenType &&
13233
- (token.l == null || token.l.typ == exports.EnumToken.IdenTokenType ||
13234
- (token.l.typ == exports.EnumToken.LiteralTokenType && token.l.val == '*')) &&
13235
- token.r.typ == exports.EnumToken.IdenTokenType);
13236
- result = {
13237
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13238
- matches: valid ? [token] : [],
13239
- node: token,
13240
- syntax,
13241
- error: valid ? '' : 'unexpected token',
13242
- tokens
13243
- };
13244
- }
13245
- else if ('wq-name' == syntax.val) {
13246
- valid = token.typ == exports.EnumToken.IdenTokenType || (token.typ == exports.EnumToken.NameSpaceAttributeTokenType &&
13247
- (token.l == null || token.l.typ == exports.EnumToken.IdenTokenType || (token.l.typ == exports.EnumToken.LiteralTokenType && token.l.val == '*')) &&
13248
- token.r.typ == exports.EnumToken.IdenTokenType);
13249
- result = {
13250
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13251
- matches: valid ? [token] : [],
13252
- node: token,
13253
- syntax,
13254
- error: valid ? '' : 'unexpected token',
13255
- tokens
13256
- };
13257
- }
13258
- else if (exports.EnumToken.UniversalSelectorTokenType == token.typ && 'subclass-selector' == syntax.val) {
13259
- valid = true;
13260
- result = {
13261
- valid: ValidationLevel.Valid,
13262
- matches: [token],
13263
- node: null,
13264
- syntax,
13265
- error: '',
13266
- tokens
13267
- };
13268
- }
13269
- else if ('attribute-selector' == syntax.val) {
13270
- valid = token.typ == exports.EnumToken.AttrTokenType && token.chi.length > 0;
13271
- if (valid) {
13272
- const children = token.chi.filter(t => t.typ != exports.EnumToken.WhitespaceTokenType && t.typ != exports.EnumToken.CommaTokenType);
13273
- valid = children.length == 1 && [
13274
- exports.EnumToken.IdenTokenType,
13275
- exports.EnumToken.NameSpaceAttributeTokenType,
13276
- exports.EnumToken.MatchExpressionTokenType
13277
- ].includes(children[0].typ);
13278
- if (valid && children[0].typ == exports.EnumToken.MatchExpressionTokenType) {
13279
- const t = children[0];
13280
- valid = [
13281
- exports.EnumToken.IdenTokenType,
13282
- exports.EnumToken.NameSpaceAttributeTokenType
13283
- ].includes(t.l.typ) &&
13284
- (t.op == null || ([
13285
- exports.EnumToken.DelimTokenType, exports.EnumToken.DashMatchTokenType,
13286
- exports.EnumToken.StartMatchTokenType, exports.EnumToken.ContainMatchTokenType,
13287
- exports.EnumToken.EndMatchTokenType, exports.EnumToken.IncludeMatchTokenType
13288
- ].includes(t.op.typ) &&
13289
- t.r != null &&
13290
- [
13291
- exports.EnumToken.StringTokenType,
13292
- exports.EnumToken.IdenTokenType
13293
- ].includes(t.r.typ)));
13294
- if (valid && t.attr != null) {
13295
- const s = getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, 'attr-modifier')[0];
13296
- valid = s.chi.some((l) => l.some((r) => r.val == t.attr));
13297
- }
13298
- }
13299
- }
13300
- result = {
13301
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13302
- matches: valid ? [token] : [],
13303
- node: valid ? null : token,
13304
- syntax,
13305
- error: valid ? '' : 'unexpected token',
13306
- tokens
13307
- };
13308
- if (!valid) {
13309
- return result;
13310
- }
13311
- }
13312
- else if ('combinator' == syntax.val) {
13313
- valid = [
13314
- exports.EnumToken.DescendantCombinatorTokenType,
13315
- exports.EnumToken.SubsequentSiblingCombinatorTokenType,
13316
- exports.EnumToken.NextSiblingCombinatorTokenType,
13317
- exports.EnumToken.ChildCombinatorTokenType,
13318
- exports.EnumToken.ColumnCombinatorTokenType
13319
- ].includes(token.typ);
13320
- if (valid) {
13321
- // @ts-ignore
13322
- const position = context.tokens.indexOf(token);
13323
- if (root == null) {
13324
- valid = position > 0 && context.tokens[position - 1]?.typ != exports.EnumToken.CommaTokenType;
13325
- }
13326
- }
13327
- result = {
13328
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13329
- matches: valid ? [token] : [],
13330
- node: valid ? null : token,
13331
- syntax,
13332
- error: valid ? '' : 'unexpected token',
13333
- tokens
13334
- };
13335
- if (!valid) {
13336
- return result;
13337
- }
13338
- }
13339
- else if ('ident-token' == syntax.val) {
13340
- valid = token.typ == exports.EnumToken.IdenTokenType;
13341
- result = {
13342
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13343
- matches: valid ? [token] : [],
13344
- node: valid ? null : token,
13345
- syntax,
13346
- error: valid ? '' : 'unexpected token',
13347
- tokens
13348
- };
13349
- }
13350
- else if ('hex-color' == syntax.val) {
13351
- valid = token.typ == exports.EnumToken.ColorTokenType && token.kin == 'hex';
13352
- result = {
13353
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13354
- matches: valid ? [token] : [],
13355
- node: valid ? null : token,
13356
- syntax,
13357
- error: valid ? '' : 'unexpected token',
13358
- tokens
13359
- };
13360
- }
13361
- else if ('resolution' == syntax.val) {
13362
- valid = token.typ == exports.EnumToken.ResolutionTokenType;
13363
- result = {
13364
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13365
- matches: valid ? [token] : [],
13366
- node: valid ? null : token,
13367
- syntax,
13368
- error: valid ? '' : 'unexpected token',
13369
- tokens
13370
- };
13371
- }
13372
- else if ('angle' == syntax.val) {
13373
- valid = token.typ == exports.EnumToken.AngleTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val == '0');
13374
- result = {
13375
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13376
- matches: valid ? [token] : [],
13377
- node: valid ? null : token,
13378
- syntax,
13379
- error: valid ? '' : 'unexpected token',
13380
- tokens
13381
- };
13382
- }
13383
- else if ('time' == syntax.val) {
13384
- valid = token.typ == exports.EnumToken.TimingFunctionTokenType;
13385
- result = {
13386
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13387
- matches: valid ? [token] : [],
13388
- node: valid ? null : token,
13389
- syntax,
13390
- error: valid ? '' : 'unexpected token',
13391
- tokens
13392
- };
13393
- }
13394
- else if ('ident' == syntax.val) {
13395
- valid = token.typ == exports.EnumToken.IdenTokenType;
13396
- result = {
13397
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13398
- matches: valid ? [token] : [],
13399
- node: valid ? null : token,
13400
- syntax,
13401
- error: valid ? '' : 'unexpected token',
13402
- tokens
13403
- };
13404
- }
13405
- else if (['id-selector', 'hash-token'].includes(syntax.val)) {
13406
- valid = token.typ == exports.EnumToken.HashTokenType;
13407
- result = {
13408
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13409
- matches: valid ? [token] : [],
13410
- node: valid ? null : token,
13411
- syntax,
13412
- error: valid ? '' : 'unexpected token',
13413
- tokens
13414
- };
13415
- }
13416
- else if (['integer', 'number'].includes(syntax.val)) {
13417
- // valid = token.typ == EnumToken.NumberTokenType;
13418
- valid = token.typ == exports.EnumToken.NumberTokenType && ('integer' != syntax.val || Number.isInteger(+token.val));
13419
- if (valid && 'range' in syntax) {
13420
- const value = Number(token.val);
13421
- const range = syntax.range;
13422
- valid = value >= range[0] && (range[1] == null || value <= range[1]);
13423
- }
13424
- result = {
13425
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13426
- matches: valid ? [token] : [],
13427
- node: valid ? null : token,
13428
- syntax,
13429
- error: valid ? '' : 'unexpected token',
13430
- tokens
13431
- };
13432
- }
13433
- else if ('length' == syntax.val) {
13434
- valid = isLength(token) || (token.typ == exports.EnumToken.NumberTokenType && token.val == '0');
13435
- // @ts-ignore
13436
- result = {
13437
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13438
- matches: valid ? [token] : [],
13439
- node: valid ? null : token,
13440
- syntax,
13441
- error: valid ? '' : 'unexpected token',
13442
- tokens
13443
- };
13444
- }
13445
- else if ('percentage' == syntax.val) {
13446
- valid = token.typ == exports.EnumToken.PercentageTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val == '0');
13447
- result = {
13448
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13449
- matches: valid ? [token] : [],
13450
- node: valid ? null : token,
13451
- syntax,
13452
- error: valid ? '' : 'unexpected token',
13453
- tokens
13454
- };
13455
- }
13456
- else if ('dashed-ident' == syntax.val) {
13457
- valid = token.typ == exports.EnumToken.DashedIdenTokenType;
13458
- result = {
13459
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13460
- matches: valid ? [token] : [],
13461
- node: valid ? null : token,
13462
- syntax,
13463
- error: valid ? '' : 'unexpected token',
13464
- tokens
13465
- };
13466
- }
13467
- else if ('custom-ident' == syntax.val) {
13468
- valid = token.typ == exports.EnumToken.DashedIdenTokenType || token.typ == exports.EnumToken.IdenTokenType;
13469
- result = {
13470
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13471
- matches: valid ? [token] : [],
13472
- node: valid ? null : token,
13473
- syntax,
13474
- error: valid ? '' : 'unexpected token',
13475
- tokens
13476
- };
13477
- }
13478
- else if ('custom-property-name' == syntax.val) {
13479
- valid = token.typ == exports.EnumToken.DashedIdenTokenType;
13480
- result = {
13481
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13482
- matches: valid ? [token] : [],
13483
- node: valid ? null : token,
13484
- syntax,
13485
- error: valid ? '' : 'unexpected token',
13486
- tokens
13487
- };
13488
- }
13489
- else if ('string' == syntax.val) {
13490
- valid = token.typ == exports.EnumToken.StringTokenType;
13491
- result = {
13492
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13493
- matches: valid ? [token] : [],
13494
- node: valid ? null : token,
13495
- syntax,
13496
- error: valid ? '' : 'unexpected token',
13497
- tokens
13498
- };
13499
- }
13500
- else if ('declaration-value' == syntax.val) {
13501
- valid = token.typ != exports.EnumToken.LiteralTokenType;
13502
- result = {
13503
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13504
- matches: valid ? [token] : [],
13505
- node: valid ? null : token,
13506
- syntax,
13507
- error: valid ? '' : 'unexpected token',
13508
- tokens
13509
- };
13510
- }
13511
- else if ('url' == syntax.val) {
13512
- valid = token.typ == exports.EnumToken.UrlFunctionTokenType || token.typ == exports.EnumToken.StringTokenType;
13513
- result = {
13514
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13515
- matches: valid ? [token] : [],
13516
- node: valid ? null : token,
13517
- syntax,
13518
- error: valid ? '' : 'unexpected token',
13519
- tokens
13520
- };
13521
- }
13522
- else if ('declaration' == syntax.val) {
13523
- valid = token.typ == exports.EnumToken.DeclarationNodeType && (token.nam.startsWith(('--')) || token.nam in config$2.declarations || token.nam in config$2.syntaxes);
13524
- if (!valid) {
13525
- // @ts-ignore
13526
- result = {
13527
- valid: ValidationLevel.Drop,
13528
- matches: [],
13529
- node: token,
13530
- syntax,
13531
- error: 'unexpected token',
13532
- tokens
13533
- };
13534
- }
13535
- else if (token.nam.startsWith(('--'))) {
13536
- result = {
13537
- valid: ValidationLevel.Valid,
13538
- matches: [token],
13539
- node: null,
13540
- syntax,
13541
- error: '',
13542
- tokens
13543
- };
13544
- }
13545
- else {
13546
- result = validateSyntax(getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, token.nam) ?? getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, token.nam), token.val, token, options, {
13547
- ...context,
13548
- tokens: null,
13549
- level: 0
13550
- });
13551
- if (result.valid == ValidationLevel.Valid && result.error.length == 0) {
13552
- tokens = result.tokens;
13553
- }
13554
- }
13555
- }
13556
- else if ('class-selector' == syntax.val) {
13557
- valid = exports.EnumToken.ClassSelectorTokenType == token.typ || exports.EnumToken.UniversalSelectorTokenType == token.typ;
13558
- result = {
13559
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13560
- matches: valid ? [token] : [],
13561
- node: token,
13562
- syntax,
13563
- error: valid ? '' : 'unexpected token',
13564
- tokens
13565
- };
13566
- }
13567
- // else if ('complex-selector' == (syntaxes as ValidationPropertyToken).val) {
13568
- //
13569
- // result = validateSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (syntaxes as ValidationPropertyToken).val) as ValidationToken[], tokens, root as AstNode, options, context);
13570
- //
13571
- // }
13572
- else if (['pseudo-element-selector', 'pseudo-class-selector'].includes(syntax.val)) {
13573
- valid = false;
13574
- if (token.typ == exports.EnumToken.PseudoClassTokenType) {
13575
- let val = token.val;
13576
- if (val == ':before' || val == ':after') {
13577
- val = ':' + val;
13578
- }
13579
- valid = val in config$2.selectors;
13580
- if (!valid && val.match(/^:?:-/) != null) {
13581
- const match = token.val.match(/^(:?:)(-[^-]+-)(.*)$/);
13582
- if (match != null) {
13583
- valid = true;
13584
- }
13585
- }
13586
- result = {
13587
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13588
- matches: valid ? [token] : [],
13589
- node: valid ? null : token,
13590
- syntax,
13591
- error: valid ? '' : 'invalid pseudo class',
13592
- tokens
13593
- };
13594
- }
13595
- else if (token.typ == exports.EnumToken.PseudoClassFuncTokenType) {
13596
- let key = token.val in config$2.selectors ? token.val : token.val + '()';
13597
- valid = key in config$2.selectors;
13598
- if (!valid && token.val.match(/^:?:-/)) {
13599
- const match = token.val.match(/^(:?:)(-[^-]+-)(.*)$/);
13600
- if (match != null) {
13601
- key = match[1] + match[3] in config$2.selectors ? match[1] + match[3] : match[1] + match[3] + '()';
13602
- valid = key in config$2.selectors;
13603
- }
13604
- }
13605
- const s = getParsedSyntax("selectors" /* ValidationSyntaxGroupEnum.Selectors */, key);
13606
- if (s != null) {
13607
- const r = s[0];
13608
- if (r.typ != ValidationTokenEnum.PseudoClassFunctionToken) {
13609
- valid = false;
13610
- }
13611
- else {
13612
- result = validateSyntax(s[0].chi, token.chi, root, options, {
13613
- ...context,
13614
- tokens: null,
13615
- level: context.level + 1
13616
- });
13617
- break;
13618
- }
13619
- }
13620
- }
13621
- result = {
13622
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13623
- matches: valid ? [token] : [],
13624
- node: token,
13625
- syntax,
13626
- error: valid ? '' : 'unexpected token',
13627
- tokens
13628
- };
13629
- }
13630
- // <relative-selector-list>
13631
- // <complex-selector-list>
13632
- else if ('relative-selector' == syntax.val) {
13633
- if (tokens.length == 1 && token.typ == exports.EnumToken.NestingSelectorTokenType) {
13634
- return {
13635
- valid: ValidationLevel.Valid,
13636
- matches: [token],
13637
- node: token,
13638
- syntax,
13639
- error: '',
13640
- tokens
13641
- };
13642
- }
13643
- result = validateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, syntax.val), token.typ == exports.EnumToken.NestingSelectorTokenType ? tokens.slice(1) : tokens, root, options, context);
13644
- }
13645
- // <relative-selector-list>
13646
- // <complex-selector-list>
13647
- else if (['forgiving-selector-list', 'forgiving-relative-selector-list'].includes(syntax.val)) {
13648
- // @ts-ignore
13649
- result = { tokens: tokens.slice(), ...validateSelector(tokens, options, root) };
13650
- }
13651
- // https://github.com/mdn/data/pull/186#issuecomment-369604537
13652
- else if (syntax.val.endsWith('-token')) {
13653
- const val = syntax.val;
13654
- valid = true;
13655
- switch (val) {
13656
- case 'function-token':
13657
- valid = token.typ != exports.EnumToken.ParensTokenType && funcLike.includes(token.typ);
13658
- break;
13659
- case 'ident-token':
13660
- valid = token.typ == exports.EnumToken.DashedIdenTokenType || token.typ == exports.EnumToken.IdenTokenType;
13661
- break;
13662
- case 'hash-token':
13663
- valid = token.typ == exports.EnumToken.HashTokenType;
13664
- break;
13665
- case 'string-token':
13666
- valid = token.typ == exports.EnumToken.StringTokenType;
13667
- break;
13668
- default:
13669
- console.error(new Error(`unhandled syntax: '<${val}>'`));
13670
- break;
13671
- }
13672
- result = {
13673
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13674
- matches: valid ? [token] : [],
13675
- node: valid ? null : token,
13676
- syntax,
13677
- error: valid ? '' : 'unexpected token',
13678
- tokens
13679
- };
13680
- }
13681
- else if ('wq-name' == syntax.val) {
13682
- valid = token.typ == exports.EnumToken.IdenTokenType || (token.typ == exports.EnumToken.NameSpaceAttributeTokenType &&
13683
- (token.l == null || token.l.typ == exports.EnumToken.IdenTokenType || (token.l.typ == exports.EnumToken.LiteralTokenType && token.l.val == '*')) &&
13684
- token.r.typ == exports.EnumToken.IdenTokenType);
13685
- result = {
13686
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13687
- matches: valid ? [token] : [],
13688
- node: token,
13689
- syntax,
13690
- error: valid ? '' : 'unexpected token',
13691
- tokens
13692
- };
13693
- }
13694
- else {
13695
- const val = syntax.val;
13696
- // https://github.com/mdn/data/pull/186#issuecomment-369604537
13697
- if (val == 'any-value') {
13698
- return {
13699
- valid: ValidationLevel.Valid,
13700
- matches: [token],
13701
- node: null,
13702
- syntax,
13703
- error: '',
13704
- tokens
13705
- };
13706
- }
13707
- else if (val in config$2.declarations || val in config$2.syntaxes) {
13708
- result = validateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, val) ?? getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, val), tokens, root, options, context);
13709
- }
13710
- else {
13711
- // @ts-ignore
13712
- result = {
13713
- valid: ValidationLevel.Drop,
13714
- matches: [],
13715
- node: token,
13716
- syntax,
13717
- error: 'unexpected token',
13718
- tokens
13719
- };
13720
- }
13721
- }
13722
- break;
13723
- case ValidationTokenEnum.Parens:
13724
- case ValidationTokenEnum.Function:
13725
- if (syntax.typ == ValidationTokenEnum.Parens) {
13726
- valid = token.typ == exports.EnumToken.ParensTokenType;
13727
- }
13728
- else {
13729
- valid = 'chi' in token && 'val' in token &&
13730
- token.val.localeCompare(syntax.val, 'en', { sensitivity: 'base' }) == 0;
13731
- }
13732
- result = !valid ?
13733
- // @ts-ignore
13734
- {
13735
- valid: ValidationLevel.Drop,
13736
- matches: [],
13737
- node: token,
13738
- syntax,
13739
- error: 'unexpected token',
13740
- tokens
13741
- } : validateSyntax(syntax.chi, token.chi, root, options, {
13742
- ...context,
13743
- tokens: null,
13744
- level: context.level + 1
13745
- });
13746
- break;
13747
- case ValidationTokenEnum.ValidationFunctionDefinition:
13748
- valid = 'val' in token && 'chi' in token;
13749
- result = {
13750
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13751
- matches: valid ? [token] : [],
13752
- node: valid ? null : token,
13753
- syntax,
13754
- error: '',
13755
- tokens
13756
- };
13757
- if (result.valid == ValidationLevel.Valid) {
13758
- valid = token.val.localeCompare(syntax.val, 'en', { sensitivity: 'base' }) == 0;
13759
- result = {
13760
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13761
- matches: valid ? [token] : [],
13762
- node: valid ? null : token,
13763
- error: '',
13764
- syntax,
13765
- tokens
13766
- };
13767
- if (result.valid == ValidationLevel.Valid) {
13768
- const s = getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, syntax.val + '()'); // config[ValidationSyntaxGroupEnum.Syntaxes][(syntaxes as ValidationFunctionDefinitionToken).val + '()'] as ValidationSyntaxNode;
13769
- result = validateSyntax(s, tokens, root, options, context);
13770
- }
13771
- }
13772
- break;
13773
- case ValidationTokenEnum.Bracket:
13774
- result = validateSyntax(syntax.chi, tokens, root, options, context);
13775
- break;
13776
- case ValidationTokenEnum.PipeToken:
13777
- for (const lines of syntax.chi) {
13778
- result = validateSyntax(lines, tokens, root, options, context);
13779
- if (result.valid == ValidationLevel.Valid) {
13780
- break;
13781
- }
13782
- }
13783
- break;
13784
- case ValidationTokenEnum.AmpersandToken:
13785
- children = [...syntax.l.slice(), ...syntax.r.slice()];
13786
- matches = [];
13787
- queue = [];
13788
- let m = [];
13789
- for (let j = 0; j < children.length; j++) {
13790
- const res = validateSyntax([children[j]], tokens, root, options, context);
13791
- // @ts-ignore
13792
- if (res.valid == ValidationLevel.Valid) {
13793
- m.push(...res.matches);
13794
- matches.push(...children.splice(j, 1));
13795
- j = 0;
13796
- // @ts-ignore
13797
- astNodes.delete(token);
13798
- consumeToken(tokens);
13799
- token = tokens[0];
13800
- if (token == null) {
13801
- break;
13802
- }
13803
- // @ts-ignore
13804
- astNodes.add(token);
13805
- }
13806
- }
13807
- if (astNodes.size > 0) {
13808
- // @ts-ignore
13809
- tokens.unshift(...astNodes);
13810
- astNodes = new Set();
13811
- }
13812
- valid = matches.length > 0;
13813
- result = {
13814
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13815
- matches: m,
13816
- node: valid ? null : token,
13817
- syntax,
13818
- error: valid ? '' : 'expecting token',
13819
- tokens
13820
- };
13821
- break;
13822
- case ValidationTokenEnum.ColumnToken:
13823
- children = [...syntax.l.slice(), ...syntax.r.slice()];
13824
- matches = [];
13825
- queue = [];
13826
- while ((child = children.shift())) {
13827
- const res = validateSyntax([child], tokens, root, options, context);
13828
- if (res.valid == ValidationLevel.Valid) {
13829
- matches.push(child);
13830
- consumeToken(tokens);
13831
- token = tokens[0];
13832
- if (queue.length > 0) {
13833
- children.unshift(...queue);
13834
- queue = [];
13835
- }
13836
- if (token == null) {
13837
- break;
13838
- }
13839
- }
13840
- else {
13841
- queue.push(child);
13842
- }
13843
- }
13844
- valid = matches.length > 0;
13845
- result = {
13846
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13847
- matches: valid ? [token] : [],
13848
- node: valid ? null : token,
13849
- syntax,
13850
- error: valid ? '' : 'expecting token',
13851
- tokens
13852
- };
13853
- break;
13854
- case ValidationTokenEnum.StringToken:
13855
- valid = token.typ == exports.EnumToken.StringTokenType && syntax.val.slice(1, -1) == token.val.slice(1, -1);
13856
- return {
13857
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13858
- matches: valid ? [token] : [],
13859
- node: valid ? null : token,
13860
- syntax,
13861
- error: valid ? '' : 'expecting token',
13862
- tokens
13863
- };
13864
- case ValidationTokenEnum.PseudoClassFunctionToken:
13865
- valid = token.typ == exports.EnumToken.PseudoClassFuncTokenType;
13866
- if (valid) {
13867
- let key = token.val in config$2.selectors ? token.val : token.val + '()';
13868
- const s = getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, key);
13869
- valid = s != null && validateSyntax(s, token.chi, root, options, {
13870
- ...context,
13871
- tokens: null,
13872
- level: context.level + 1
13873
- }).valid == ValidationLevel.Valid;
13874
- }
13875
- result = {
13876
- valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
13877
- matches: valid ? [token] : [],
13878
- node: valid ? null : token,
13879
- syntax,
13880
- error: valid ? '' : 'invalid token',
13881
- tokens
13882
- };
13883
- break;
13884
- case ValidationTokenEnum.DeclarationDefinitionToken:
13885
- if (token.typ != exports.EnumToken.DeclarationNodeType || token.nam != syntax.nam) {
13886
- return {
13887
- valid: ValidationLevel.Drop,
13888
- matches: [],
13889
- node: token,
13890
- syntax,
13891
- error: '',
13892
- tokens
13893
- };
13894
- }
13895
- return validateSyntax([syntax.val], token.val, root, options, context);
13896
- default:
13897
- throw new Error('not implemented: ' + JSON.stringify({ syntax, token, tokens }, null, 1));
13898
- }
13899
- // @ts-ignore
13900
- return result;
13901
- }
13902
-
13903
- function validateURL(token) {
13904
- if (token.typ == exports.EnumToken.UrlTokenTokenType) {
13905
- // @ts-ignore
13906
- return {
13907
- valid: ValidationLevel.Valid,
13908
- matches: [],
13909
- node: token,
13910
- // @ts-ignore
13911
- syntax: 'url()',
13912
- error: '',
13913
- tokens: []
13914
- };
13915
- }
13916
- if (token.typ != exports.EnumToken.UrlFunctionTokenType) {
13917
- // @ts-ignore
13918
- return {
13919
- valid: ValidationLevel.Drop,
13920
- matches: [],
13921
- node: token,
13922
- // @ts-ignore
13923
- syntax: 'url()',
13924
- error: 'expected url()',
13925
- tokens: []
13926
- };
13927
- }
13928
- const children = token.chi.slice();
13929
- consumeWhitespace(children);
13930
- if (children.length == 0 || ![exports.EnumToken.UrlTokenTokenType, exports.EnumToken.StringTokenType, exports.EnumToken.HashTokenType].includes(children[0].typ)) {
13931
- // @ts-ignore
13932
- return {
13933
- valid: ValidationLevel.Drop,
13934
- matches: [],
13935
- node: children[0] ?? token,
13936
- // @ts-ignore
13937
- syntax: 'url()',
13938
- error: 'expected url-token',
13939
- tokens: children
13940
- };
13941
- }
13942
- children.shift();
13943
- consumeWhitespace(children);
13944
- if (children.length > 0) {
13945
- // @ts-ignore
13946
- return {
13947
- valid: ValidationLevel.Drop,
13948
- matches: [],
13949
- node: children[0] ?? token,
13950
- // @ts-ignore
13951
- syntax: 'url()',
13952
- error: 'unexpected token',
13953
- tokens: children
13954
- };
13955
- }
13956
- // @ts-ignore
13957
- return {
13958
- valid: ValidationLevel.Valid,
13959
- matches: [],
13960
- node: token,
13961
- // @ts-ignore
13962
- syntax: 'url()',
13963
- error: '',
13964
- tokens: []
13965
- };
13966
- }
13967
-
13968
- function validateImage(token) {
13969
- if (token.typ == exports.EnumToken.UrlFunctionTokenType) {
13970
- return validateURL(token);
13971
- }
13972
- if (token.typ == exports.EnumToken.ImageFunctionTokenType) {
13973
- return validateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, token.val + '()'), token.chi);
13974
- }
13975
- return {
13976
- valid: ValidationLevel.Drop,
13977
- matches: [],
13978
- node: token,
13979
- syntax: 'image()',
13980
- error: 'expected <image> or <url>',
13981
- tokens: []
13982
- };
13983
- }
13984
-
13985
- const validateSelectorList = validateComplexSelectorList;
13986
-
13987
- function validateSelector(selector, options, root) {
13988
- if (root == null) {
13989
- return validateSelectorList(selector, root, options);
13990
- }
13991
- // @ts-ignore
13992
- if (root.typ == exports.EnumToken.AtRuleNodeType && root.nam.match(/^(-[a-z]+-)?keyframes$/)) {
13993
- return validateKeyframeBlockList(selector, root);
13994
- }
13995
- let isNested = root.typ == exports.EnumToken.RuleNodeType ? 1 : 0;
13996
- let currentRoot = root.parent;
13997
- while (currentRoot != null && isNested == 0) {
13998
- if (currentRoot.typ == exports.EnumToken.RuleNodeType) {
13999
- isNested++;
14000
- if (isNested > 0) {
14001
- // @ts-ignore
14002
- return validateRelativeSelectorList(selector, root, { ...(options ?? {}), nestedSelector: true });
14003
- }
14004
- }
14005
- currentRoot = currentRoot.parent;
14006
- }
14007
- const nestedSelector = isNested > 0;
14008
- // @ts-ignore
14009
- return nestedSelector ? validateRelativeSelectorList(selector, root, { ...(options ?? {}), nestedSelector }) : validateSelectorList(selector, root, { ...(options ?? {}), nestedSelector });
14010
- }
14011
-
14012
- function validateAtRuleMedia(atRule, options, root) {
14013
- // media-query-list
14014
- if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
14015
- // @ts-ignore
14016
- return {
14017
- valid: ValidationLevel.Valid,
14018
- matches: [],
14019
- node: null,
14020
- syntax: null,
14021
- error: '',
14022
- tokens: []
14023
- };
14024
- }
14025
- let result = null;
14026
- const slice = atRule.tokens.slice();
14027
- consumeWhitespace(slice);
14028
- if (slice.length == 0) {
14029
- return {
14030
- valid: ValidationLevel.Valid,
14031
- matches: [],
14032
- node: atRule,
14033
- syntax: '@media',
14034
- error: '',
14035
- tokens: []
14036
- };
14037
- }
14038
- result = validateAtRuleMediaQueryList(atRule.tokens, atRule);
14039
- if (result.valid == ValidationLevel.Drop) {
14040
- return result;
12508
+ result = validateAtRuleMediaQueryList(atRule.tokens, atRule);
12509
+ if (result.valid == ValidationLevel.Drop) {
12510
+ return result;
14041
12511
  }
14042
12512
  if (!('chi' in atRule)) {
14043
12513
  // @ts-ignore
@@ -14226,7 +12696,7 @@
14226
12696
  if (token.typ == exports.EnumToken.MediaFeatureNotTokenType) {
14227
12697
  return validateMediaCondition(token.val, atRule);
14228
12698
  }
14229
- if (token.typ != exports.EnumToken.ParensTokenType && !(['when', 'else'].includes(atRule.nam) && token.typ == exports.EnumToken.FunctionTokenType && ['media', 'supports'].includes(token.val))) {
12699
+ if (token.typ != exports.EnumToken.ParensTokenType && !(['when', 'else', 'import'].includes(atRule.nam) && token.typ == exports.EnumToken.FunctionTokenType && ['media', 'supports', 'selector'].includes(token.val))) {
14230
12700
  return false;
14231
12701
  }
14232
12702
  const chi = token.chi.filter((t) => t.typ != exports.EnumToken.CommentTokenType && t.typ != exports.EnumToken.WhitespaceTokenType);
@@ -14242,6 +12712,7 @@
14242
12712
  if (chi[0].typ == exports.EnumToken.MediaQueryConditionTokenType) {
14243
12713
  return chi[0].l.typ == exports.EnumToken.IdenTokenType;
14244
12714
  }
12715
+ console.error(chi[0].parent);
14245
12716
  return false;
14246
12717
  }
14247
12718
  function validateMediaFeature(token) {
@@ -14488,6 +12959,7 @@
14488
12959
  };
14489
12960
  }
14490
12961
  function validateAtRuleSupportsConditions(atRule, tokenList) {
12962
+ let result = null;
14491
12963
  for (const tokens of splitTokenList(tokenList)) {
14492
12964
  if (tokens.length == 0) {
14493
12965
  // @ts-ignore
@@ -14501,22 +12973,46 @@
14501
12973
  };
14502
12974
  }
14503
12975
  let previousToken = null;
14504
- let result = null;
14505
12976
  while (tokens.length > 0) {
14506
12977
  result = validateSupportCondition(atRule, tokens[0]);
14507
12978
  // supports-condition
14508
- if (result == null || result.valid == ValidationLevel.Valid) {
12979
+ if (result.valid == ValidationLevel.Valid) {
14509
12980
  previousToken = tokens[0];
14510
12981
  tokens.shift();
14511
12982
  }
14512
12983
  else {
14513
12984
  result = validateSupportFeature(tokens[0]);
14514
- if (result == null || result.valid == ValidationLevel.Valid) {
12985
+ if ( /*result == null || */result.valid == ValidationLevel.Valid) {
14515
12986
  previousToken = tokens[0];
14516
12987
  tokens.shift();
14517
12988
  }
14518
12989
  else {
14519
- return result;
12990
+ if (tokens[0].typ == exports.EnumToken.ParensTokenType) {
12991
+ result = validateAtRuleSupportsConditions(atRule, tokens[0].chi);
12992
+ if ( /* result == null || */result.valid == ValidationLevel.Valid) {
12993
+ previousToken = tokens[0];
12994
+ tokens.shift();
12995
+ // continue;
12996
+ }
12997
+ else {
12998
+ return result;
12999
+ }
13000
+ }
13001
+ else {
13002
+ return result;
13003
+ }
13004
+ // if (result!= null && result.valid == ValidationLevel.Drop) {
13005
+ //
13006
+ // return {
13007
+ // valid: ValidationLevel.Drop,
13008
+ // matches: [],
13009
+ // node: tokens[0] ?? atRule,
13010
+ // syntax: '@' + atRule.nam,
13011
+ // // @ts-ignore
13012
+ // error: result.error as string ?? 'unexpected token',
13013
+ // tokens: []
13014
+ // };
13015
+ // }
14520
13016
  }
14521
13017
  }
14522
13018
  if (tokens.length == 0) {
@@ -14571,7 +13067,14 @@
14571
13067
  }
14572
13068
  }
14573
13069
  }
14574
- return null;
13070
+ return {
13071
+ valid: ValidationLevel.Valid,
13072
+ matches: [],
13073
+ node: atRule,
13074
+ syntax: '@' + atRule.nam,
13075
+ error: '',
13076
+ tokens: []
13077
+ };
14575
13078
  }
14576
13079
  function validateSupportCondition(atRule, token) {
14577
13080
  if (token.typ == exports.EnumToken.MediaFeatureNotTokenType) {
@@ -14638,7 +13141,7 @@
14638
13141
  function validateSupportFeature(token) {
14639
13142
  if (token.typ == exports.EnumToken.FunctionTokenType) {
14640
13143
  if (token.val.localeCompare('selector', undefined, { sensitivity: 'base' }) == 0) {
14641
- return validateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, 'complex-selector'), token.chi);
13144
+ return validateComplexSelector(parseSelector(token.chi));
14642
13145
  }
14643
13146
  if (token.val.localeCompare('font-tech', undefined, { sensitivity: 'base' }) == 0) {
14644
13147
  const chi = token.chi.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ));
@@ -14762,6 +13265,9 @@
14762
13265
  };
14763
13266
  }
14764
13267
  }
13268
+ tokens.shift();
13269
+ // @ts-ignore
13270
+ consumeWhitespace(tokens);
14765
13271
  }
14766
13272
  else {
14767
13273
  // @ts-ignore
@@ -14797,71 +13303,70 @@
14797
13303
  // @ts-ignore
14798
13304
  else if (tokens[0].typ == exports.EnumToken.FunctionTokenType) {
14799
13305
  // @ts-ignore
14800
- if ('layer'.localeCompare(tokens[0].val, undefined, { sensitivity: 'base' }) != 0) {
14801
- // @ts-ignore
14802
- return {
14803
- valid: ValidationLevel.Drop,
14804
- matches: [],
14805
- node: tokens[0],
14806
- syntax: '@' + atRule.nam,
14807
- error: 'expecting layer()',
14808
- tokens
14809
- };
14810
- }
14811
- // @ts-ignore
14812
- const result = validateLayerName(tokens[0].chi);
14813
- if (result.valid == ValidationLevel.Drop) {
14814
- return result;
14815
- }
14816
- tokens.shift();
14817
- // @ts-ignore
14818
- if (!consumeWhitespace(tokens)) {
14819
- // @ts-ignore
14820
- return {
14821
- valid: ValidationLevel.Drop,
14822
- matches: [],
14823
- node: tokens[0],
14824
- syntax: '@' + atRule.nam,
14825
- error: 'expecting whitespace',
14826
- tokens
14827
- };
14828
- }
14829
- }
14830
- }
14831
- if (tokens.length > 0) {
14832
- // @ts-ignore
14833
- if (tokens[0].typ == exports.EnumToken.AtRuleTokenType) {
14834
- if (tokens[0].nam != 'supports') {
13306
+ if ('layer'.localeCompare(tokens[0].val, undefined, { sensitivity: 'base' }) == 0) {
13307
+ const result = validateLayerName(tokens[0].chi);
13308
+ if (result.valid == ValidationLevel.Drop) {
13309
+ return result;
13310
+ }
13311
+ tokens.shift();
14835
13312
  // @ts-ignore
14836
- return {
14837
- valid: ValidationLevel.Drop,
14838
- matches: [],
14839
- node: tokens[0],
14840
- syntax: '@' + atRule.nam,
14841
- error: 'expecting @supports or media query list',
14842
- tokens
14843
- };
14844
- }
14845
- // @ts-ignore
14846
- const result = validateAtRuleSupports(tokens[0]);
14847
- if (result.valid == ValidationLevel.Drop) {
14848
- return result;
13313
+ consumeWhitespace(tokens);
14849
13314
  }
14850
- tokens.shift();
14851
13315
  // @ts-ignore
14852
- if (!consumeWhitespace(tokens)) {
13316
+ if ('supports'.localeCompare(tokens[0]?.val, undefined, { sensitivity: 'base' }) == 0) {
13317
+ const result = validateAtRuleSupportsConditions(atRule, tokens[0].chi);
13318
+ if (result.valid == ValidationLevel.Drop) {
13319
+ return result;
13320
+ }
13321
+ tokens.shift();
14853
13322
  // @ts-ignore
14854
- return {
14855
- valid: ValidationLevel.Drop,
14856
- matches: [],
14857
- node: tokens[0],
14858
- syntax: '@' + atRule.nam,
14859
- error: 'expecting whitespace',
14860
- tokens
14861
- };
13323
+ consumeWhitespace(tokens);
14862
13324
  }
14863
13325
  }
14864
13326
  }
13327
+ // if (tokens.length > 0) {
13328
+ //
13329
+ // // @ts-ignore
13330
+ // if (tokens[0].typ == EnumToken.AtRuleTokenType) {
13331
+ //
13332
+ // if ((tokens[0] as AstAtRule).nam != 'supports') {
13333
+ //
13334
+ // // @ts-ignore
13335
+ // return {
13336
+ // valid: ValidationLevel.Drop,
13337
+ // matches: [],
13338
+ // node: tokens[0],
13339
+ // syntax: '@' + atRule.nam,
13340
+ // error: 'expecting @supports or media query list',
13341
+ // tokens
13342
+ // }
13343
+ // }
13344
+ //
13345
+ // // @ts-ignore
13346
+ // const result: ValidationSyntaxResult = validateAtRuleSupports(tokens[0] as AstAtRule, options, atRule);
13347
+ //
13348
+ // if (result.valid == ValidationLevel.Drop) {
13349
+ //
13350
+ // return result;
13351
+ // }
13352
+ //
13353
+ // tokens.shift();
13354
+ //
13355
+ // // @ts-ignore
13356
+ // if (!consumeWhitespace(tokens)) {
13357
+ //
13358
+ // // @ts-ignore
13359
+ // return {
13360
+ // valid: ValidationLevel.Drop,
13361
+ // matches: [],
13362
+ // node: tokens[0],
13363
+ // syntax: '@' + atRule.nam,
13364
+ // error: 'expecting whitespace',
13365
+ // tokens
13366
+ // }
13367
+ // }
13368
+ // }
13369
+ // }
14865
13370
  if (tokens.length > 0) {
14866
13371
  return validateAtRuleMediaQueryList(tokens, atRule);
14867
13372
  }
@@ -15030,71 +13535,50 @@
15030
13535
  tokens
15031
13536
  };
15032
13537
  }
15033
- if (tokens[0].typ == exports.EnumToken.CommaTokenType) {
13538
+ for (const t of splitTokenList(tokens)) {
13539
+ if (t.length != 1) {
13540
+ return {
13541
+ valid: ValidationLevel.Drop,
13542
+ matches: [],
13543
+ node: t[0] ?? atRule,
13544
+ syntax: '@document',
13545
+ error: 'unexpected token',
13546
+ tokens
13547
+ };
13548
+ }
15034
13549
  // @ts-ignore
15035
- return {
15036
- valid: ValidationLevel.Drop,
15037
- matches: [],
15038
- node: tokens[0],
15039
- syntax: '@document',
15040
- error: 'unexpected token',
15041
- tokens
15042
- };
15043
- }
15044
- while (tokens.length > 0) {
15045
- if (tokens[0].typ == exports.EnumToken.CommentTokenType) {
15046
- tokens.shift();
15047
- consumeWhitespace(tokens);
13550
+ if ((t[0].typ != exports.EnumToken.FunctionTokenType && t[0].typ != exports.EnumToken.UrlFunctionTokenType) || !['url', 'url-prefix', 'domain', 'media-document', 'regexp'].some((f) => f.localeCompare(t[0].val, undefined, { sensitivity: 'base' }) == 0)) {
13551
+ return {
13552
+ valid: ValidationLevel.Drop,
13553
+ matches: [],
13554
+ node: t[0] ?? atRule,
13555
+ syntax: '@document',
13556
+ error: 'expecting any of url-prefix(), domain(), media-document(), regexp() but found ' + t[0].val,
13557
+ tokens
13558
+ };
15048
13559
  }
15049
- result = validateURL(tokens[0]);
15050
- if (result.valid == ValidationLevel.Valid) {
15051
- tokens.shift();
15052
- consumeWhitespace(tokens);
13560
+ if (t[0].typ == exports.EnumToken.UrlFunctionTokenType) {
13561
+ result = validateURL(t[0]);
13562
+ if (result.valid == ValidationLevel.Drop) {
13563
+ return result;
13564
+ }
15053
13565
  continue;
15054
13566
  }
15055
- if (tokens[0].typ == exports.EnumToken.FunctionTokenType) {
15056
- if (!['url-prefix', 'domain', 'media-document', 'regexp'].some((t) => t.localeCompare(tokens[0].val, undefined, { sensitivity: 'base' }) == 0)) {
15057
- // @ts-ignore
15058
- return {
15059
- valid: ValidationLevel.Drop,
15060
- matches: [],
15061
- node: tokens[0],
15062
- syntax: '@document',
15063
- error: 'unexpected token',
15064
- tokens
15065
- };
15066
- }
15067
- const children = tokens[0].chi.slice();
15068
- consumeWhitespace(children);
15069
- if (children.length == 0) {
15070
- // @ts-ignore
15071
- return {
15072
- valid: ValidationLevel.Drop,
15073
- matches: [],
15074
- node: tokens[0],
15075
- syntax: '@document',
15076
- error: 'expecting string argument',
15077
- tokens
15078
- };
15079
- }
15080
- if (children[0].typ == exports.EnumToken.StringTokenType) {
15081
- children.shift();
15082
- consumeWhitespace(children);
15083
- }
15084
- if (children.length > 0) {
15085
- // @ts-ignore
15086
- return {
15087
- valid: ValidationLevel.Drop,
15088
- matches: [],
15089
- node: children[0],
15090
- syntax: '@document',
15091
- error: 'unexpected token',
15092
- tokens
15093
- };
15094
- }
15095
- tokens.shift();
15096
- consumeWhitespace(tokens);
13567
+ const children = t[0].chi.slice();
13568
+ consumeWhitespace(children);
13569
+ if (children.length != 1 || (children[0].typ != exports.EnumToken.StringTokenType && children[0].typ != exports.EnumToken.UrlTokenTokenType)) {
13570
+ // @ts-ignore
13571
+ return {
13572
+ valid: ValidationLevel.Drop,
13573
+ matches: [],
13574
+ node: tokens[0],
13575
+ syntax: '@document',
13576
+ error: 'expecting string argument',
13577
+ tokens
13578
+ };
15097
13579
  }
13580
+ tokens.shift();
13581
+ consumeWhitespace(tokens);
15098
13582
  }
15099
13583
  // @ts-ignore
15100
13584
  return {
@@ -15910,6 +14394,7 @@
15910
14394
  src: '',
15911
14395
  sourcemap: false,
15912
14396
  minify: true,
14397
+ pass: 1,
15913
14398
  parseColor: true,
15914
14399
  nestingRules: false,
15915
14400
  resolveImport: false,
@@ -16029,7 +14514,7 @@
16029
14514
  await parseNode(tokens, context, stats, options, errors, src, map, rawTokens);
16030
14515
  rawTokens.length = 0;
16031
14516
  if (context != null && context.typ == exports.EnumToken.InvalidRuleTokenType) {
16032
- const index = context.chi.findIndex(node => node == context);
14517
+ const index = context.chi.findIndex((node) => node == context);
16033
14518
  if (index > -1) {
16034
14519
  context.chi.splice(index, 1);
16035
14520
  }
@@ -16089,7 +14574,10 @@
16089
14574
  }
16090
14575
  if (options.minify) {
16091
14576
  if (ast.chi.length > 0) {
16092
- minify(ast, options, true, errors, false);
14577
+ let passes = options.pass ?? 1;
14578
+ while (passes--) {
14579
+ minify(ast, options, true, errors, false);
14580
+ }
16093
14581
  }
16094
14582
  }
16095
14583
  const endTime = performance.now();
@@ -16190,8 +14678,13 @@
16190
14678
  continue;
16191
14679
  }
16192
14680
  if (type != exports.EnumToken.AtRuleNodeType) {
16193
- errors.push({ action: 'drop', message: 'invalid @import', location: { src, ...position } });
16194
- return null;
14681
+ // @ts-ignore
14682
+ if (!(type == exports.EnumToken.InvalidAtRuleTokenType &&
14683
+ // @ts-ignore
14684
+ ['charset', 'layer', 'import'].includes(context.chi[i].nam))) {
14685
+ errors.push({ action: 'drop', message: 'invalid @import', location: { src, ...position } });
14686
+ return null;
14687
+ }
16195
14688
  }
16196
14689
  // @ts-ignore
16197
14690
  const name = context.chi[i].nam;
@@ -16226,12 +14719,20 @@
16226
14719
  if (tokens[0].typ == exports.EnumToken.UrlFunctionTokenType) {
16227
14720
  if (tokens[1].typ == exports.EnumToken.UrlTokenTokenType || tokens[1].typ == exports.EnumToken.StringTokenType) {
16228
14721
  tokens.shift();
16229
- if (tokens[1].typ == exports.EnumToken.UrlTokenTokenType) {
14722
+ if (tokens[0]?.typ == exports.EnumToken.UrlTokenTokenType) {
16230
14723
  // @ts-ignore
16231
14724
  tokens[0].typ = exports.EnumToken.StringTokenType;
16232
14725
  // @ts-ignore
16233
14726
  tokens[0].val = `"${tokens[0].val}"`;
16234
14727
  }
14728
+ // @ts-ignore
14729
+ while (tokens[1]?.typ == exports.EnumToken.WhitespaceTokenType || tokens[1]?.typ == exports.EnumToken.CommentTokenType) {
14730
+ tokens.splice(1, 1);
14731
+ }
14732
+ // @ts-ignore
14733
+ if (tokens[1]?.typ == exports.EnumToken.EndParensTokenType) {
14734
+ tokens.splice(1, 1);
14735
+ }
16235
14736
  }
16236
14737
  }
16237
14738
  // @ts-ignore
@@ -16315,11 +14816,11 @@
16315
14816
  const node = {
16316
14817
  typ: exports.EnumToken.AtRuleNodeType,
16317
14818
  nam: renderToken(atRule, { removeComments: true }),
16318
- tokens: t,
14819
+ // tokens: t,
16319
14820
  val: raw.join('')
16320
14821
  };
16321
14822
  Object.defineProperties(node, {
16322
- tokens: { ...definedPropertySettings, enumerable: true, value: tokens.slice() },
14823
+ tokens: { ...definedPropertySettings, enumerable: false, value: tokens.slice() },
16323
14824
  raw: { ...definedPropertySettings, value: raw }
16324
14825
  });
16325
14826
  if (delim.typ == exports.EnumToken.BlockStartTokenType) {
@@ -16444,7 +14945,7 @@
16444
14945
  };
16445
14946
  Object.defineProperty(node, 'tokens', {
16446
14947
  ...definedPropertySettings,
16447
- enumerable: true,
14948
+ enumerable: false,
16448
14949
  value: tokens.slice()
16449
14950
  });
16450
14951
  let raw = [...uniq.values()];
@@ -16545,7 +15046,7 @@
16545
15046
  //
16546
15047
  // const valid: ValidationResult = validateDeclaration(result, options, context);
16547
15048
  //
16548
- // console.error({valid});
15049
+ // // console.error({valid});
16549
15050
  //
16550
15051
  // if (valid.valid == ValidationLevel.Drop) {
16551
15052
  //
@@ -16917,10 +15418,16 @@
16917
15418
  val: val.slice(0, -1),
16918
15419
  chi: []
16919
15420
  }
16920
- : {
16921
- typ: exports.EnumToken.PseudoClassTokenType,
15421
+ : (
15422
+ // https://www.w3.org/TR/selectors-4/#single-colon-pseudos
15423
+ val.startsWith('::') || pseudoElements.includes(val) ? {
15424
+ typ: exports.EnumToken.PseudoElementTokenType,
16922
15425
  val
16923
- };
15426
+ } :
15427
+ {
15428
+ typ: exports.EnumToken.PseudoClassTokenType,
15429
+ val
15430
+ });
16924
15431
  }
16925
15432
  if (isAtKeyword(val)) {
16926
15433
  return {
@@ -17097,25 +15604,25 @@
17097
15604
  break;
17098
15605
  }
17099
15606
  }
17100
- Object.assign(t, {
15607
+ const attr = Object.assign(t, {
17101
15608
  typ: inAttr == 0 ? exports.EnumToken.AttrTokenType : exports.EnumToken.InvalidAttrTokenType,
17102
15609
  chi: tokens.splice(i + 1, k - i)
17103
15610
  });
17104
15611
  // @ts-ignore
17105
- if (t.chi.at(-1).typ == exports.EnumToken.AttrEndTokenType) {
15612
+ if (attr.chi.at(-1).typ == exports.EnumToken.AttrEndTokenType) {
17106
15613
  // @ts-ignore
17107
- t.chi.pop();
15614
+ attr.chi.pop();
17108
15615
  }
17109
15616
  // @ts-ignore
17110
- if (t.chi.length > 1) {
15617
+ if (attr.chi.length > 1) {
17111
15618
  /*(<AttrToken>t).chi =*/
17112
15619
  // @ts-ignore
17113
- parseTokens(t.chi, t.typ);
15620
+ parseTokens(attr.chi, t.typ);
17114
15621
  }
17115
- let m = t.chi.length;
15622
+ let m = attr.chi.length;
17116
15623
  let val;
17117
- for (m = 0; m < t.chi.length; m++) {
17118
- val = t.chi[m];
15624
+ for (m = 0; m < attr.chi.length; m++) {
15625
+ val = attr.chi[m];
17119
15626
  if (val.typ == exports.EnumToken.StringTokenType) {
17120
15627
  const slice = val.val.slice(1, -1);
17121
15628
  if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
@@ -17125,55 +15632,55 @@
17125
15632
  else if (val.typ == exports.EnumToken.LiteralTokenType && val.val == '|') {
17126
15633
  let upper = m;
17127
15634
  let lower = m;
17128
- while (++upper < t.chi.length) {
17129
- if (t.chi[upper].typ == exports.EnumToken.CommentTokenType) {
15635
+ while (++upper < attr.chi.length) {
15636
+ if (attr.chi[upper].typ == exports.EnumToken.CommentTokenType) {
17130
15637
  continue;
17131
15638
  }
17132
15639
  break;
17133
15640
  }
17134
15641
  while (lower-- > 0) {
17135
- if (t.chi[lower].typ == exports.EnumToken.CommentTokenType) {
15642
+ if (attr.chi[lower].typ == exports.EnumToken.CommentTokenType) {
17136
15643
  continue;
17137
15644
  }
17138
15645
  break;
17139
15646
  }
17140
15647
  // @ts-ignore
17141
- t.chi[m] = {
15648
+ attr.chi[m] = {
17142
15649
  typ: exports.EnumToken.NameSpaceAttributeTokenType,
17143
- l: t.chi[lower],
17144
- r: t.chi[upper]
15650
+ l: attr.chi[lower],
15651
+ r: attr.chi[upper]
17145
15652
  };
17146
- t.chi.splice(upper, 1);
15653
+ attr.chi.splice(upper, 1);
17147
15654
  if (lower >= 0) {
17148
- t.chi.splice(lower, 1);
15655
+ attr.chi.splice(lower, 1);
17149
15656
  m--;
17150
15657
  }
17151
15658
  }
17152
15659
  else if ([
17153
15660
  exports.EnumToken.DashMatchTokenType, exports.EnumToken.StartMatchTokenType, exports.EnumToken.ContainMatchTokenType, exports.EnumToken.EndMatchTokenType, exports.EnumToken.IncludeMatchTokenType, exports.EnumToken.DelimTokenType
17154
- ].includes(t.chi[m].typ)) {
15661
+ ].includes(attr.chi[m].typ)) {
17155
15662
  let upper = m;
17156
15663
  let lower = m;
17157
- while (++upper < t.chi.length) {
17158
- if (t.chi[upper].typ == exports.EnumToken.CommentTokenType) {
15664
+ while (++upper < attr.chi.length) {
15665
+ if (attr.chi[upper].typ == exports.EnumToken.CommentTokenType) {
17159
15666
  continue;
17160
15667
  }
17161
15668
  break;
17162
15669
  }
17163
15670
  while (lower-- > 0) {
17164
- if (t.chi[lower].typ == exports.EnumToken.CommentTokenType) {
15671
+ if (attr.chi[lower].typ == exports.EnumToken.CommentTokenType) {
17165
15672
  continue;
17166
15673
  }
17167
15674
  break;
17168
15675
  }
17169
- val = t.chi[lower];
15676
+ val = attr.chi[lower];
17170
15677
  if (val.typ == exports.EnumToken.StringTokenType) {
17171
15678
  const slice = val.val.slice(1, -1);
17172
15679
  if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
17173
15680
  Object.assign(val, { typ: exports.EnumToken.IdenTokenType, val: slice });
17174
15681
  }
17175
15682
  }
17176
- val = t.chi[upper];
15683
+ val = attr.chi[upper];
17177
15684
  if (val.typ == exports.EnumToken.StringTokenType) {
17178
15685
  const slice = val.val.slice(1, -1);
17179
15686
  if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
@@ -17293,7 +15800,9 @@
17293
15800
  t.typ = exports.EnumToken.ColorTokenType;
17294
15801
  // @ts-ignore
17295
15802
  t.kin = t.val;
15803
+ // @ts-ignore
17296
15804
  if (t.chi[0].typ == exports.EnumToken.IdenTokenType) {
15805
+ // @ts-ignore
17297
15806
  if (t.chi[0].val == 'from') {
17298
15807
  // @ts-ignore
17299
15808
  t.cal = 'rel';
@@ -17303,10 +15812,11 @@
17303
15812
  // @ts-ignore
17304
15813
  t.cal = 'mix';
17305
15814
  }
17306
- else if (t.val == 'color') {
17307
- // @ts-ignore
17308
- t.cal = 'col';
17309
- // t.chi = t.chi.filter((t: Token) => [EnumToken.IdenTokenType, EnumToken.NumberTokenType, EnumToken.PercentageTokenType].includes(t.typ));
15815
+ else { // @ts-ignore
15816
+ if (t.val == 'color') {
15817
+ // @ts-ignore
15818
+ t.cal = 'col';
15819
+ }
17310
15820
  }
17311
15821
  }
17312
15822
  const filter = [exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType];
@@ -17340,7 +15850,7 @@
17340
15850
  if (t.chi.length > 0) {
17341
15851
  if (t.typ == exports.EnumToken.PseudoClassFuncTokenType && t.val == ':is' && options.minify) {
17342
15852
  //
17343
- const count = t.chi.filter(t => t.typ != exports.EnumToken.CommentTokenType).length;
15853
+ const count = t.chi.filter((t) => t.typ != exports.EnumToken.CommentTokenType).length;
17344
15854
  if (count == 1 ||
17345
15855
  (i == 0 &&
17346
15856
  (tokens[i + 1]?.typ == exports.EnumToken.CommaTokenType || tokens.length == i + 1)) ||
@@ -17614,7 +16124,14 @@
17614
16124
  rule.sel = splitRule(ast.sel).reduce((a, b) => a.concat([b.join('') + r]), []).join(',');
17615
16125
  }
17616
16126
  else {
17617
- selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(ast.sel) : arr.unshift(ast.sel, ' '));
16127
+ // selRule = splitRule(selRule.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.join(''), ''));
16128
+ const arSelf = splitRule(ast.sel).filter((r) => r.every((t) => t != ':before' && t != ':after' && !t.startsWith('::'))).reduce((acc, curr) => acc.concat([curr.join('')]), []).join(',');
16129
+ if (arSelf.length == 0) {
16130
+ ast.chi.splice(i--, 1);
16131
+ continue;
16132
+ }
16133
+ //
16134
+ selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(arSelf) : arr.unshift(arSelf, ' '));
17618
16135
  rule.sel = selRule.reduce((acc, curr) => {
17619
16136
  acc.push(curr.join(''));
17620
16137
  return acc;
@@ -17625,8 +16142,14 @@
17625
16142
  let childSelectorCompound = [];
17626
16143
  let withCompound = [];
17627
16144
  let withoutCompound = [];
17628
- const rules = splitRule(ast.sel);
16145
+ // pseudo elements cannot be used with '&'
16146
+ // https://www.w3.org/TR/css-nesting-1/#example-7145ff1e
16147
+ const rules = splitRule(ast.sel).filter((r) => r.every((t) => t != ':before' && t != ':after' && !t.startsWith('::')));
17629
16148
  const parentSelector = !node.sel.includes('&');
16149
+ if (rules.length == 0) {
16150
+ ast.chi.splice(i--, 1);
16151
+ continue;
16152
+ }
17630
16153
  for (const sel of (rule.raw ?? splitRule(rule.sel))) {
17631
16154
  const s = sel.join('');
17632
16155
  if (s.includes('&') || parentSelector) {
@@ -19323,7 +17846,7 @@
19323
17846
  return s.join('');
19324
17847
  }).join(',');
19325
17848
  // @ts-ignore
19326
- let sel = wrap ? node.optimized.optimized[0] + `:is(${rule})` : rule;
17849
+ let sel = wrap ? node.optimized.optimized.join('') + `:is(${rule})` : rule;
19327
17850
  if (rule.includes('&')) {
19328
17851
  // @ts-ignore
19329
17852
  rule = replaceCompound(rule, node.optimized.optimized[0]);