@tbela99/css-parser 1.6.0 → 1.6.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.
@@ -2569,7 +2569,7 @@
2569
2569
  syntax: "none | nearest"
2570
2570
  },
2571
2571
  "scroll-margin": {
2572
- syntax: "<length>{1,4}"
2572
+ syntax: " <length>{1,4}"
2573
2573
  },
2574
2574
  "scroll-margin-block": {
2575
2575
  syntax: "<length>{1,2}"
@@ -2581,7 +2581,7 @@
2581
2581
  syntax: "<length>"
2582
2582
  },
2583
2583
  "scroll-margin-bottom": {
2584
- syntax: "<length>"
2584
+ syntax: " auto | <length-percentage [0,∞]>"
2585
2585
  },
2586
2586
  "scroll-margin-inline": {
2587
2587
  syntax: "<length>{1,2}"
@@ -2593,13 +2593,13 @@
2593
2593
  syntax: "<length>"
2594
2594
  },
2595
2595
  "scroll-margin-left": {
2596
- syntax: "<length>"
2596
+ syntax: " auto | <length-percentage [0,∞]>"
2597
2597
  },
2598
2598
  "scroll-margin-right": {
2599
- syntax: "<length>"
2599
+ syntax: " auto | <length-percentage [0,∞]>"
2600
2600
  },
2601
2601
  "scroll-margin-top": {
2602
- syntax: "<length>"
2602
+ syntax: " auto | <length-percentage [0,∞]>"
2603
2603
  },
2604
2604
  "scroll-marker-group": {
2605
2605
  syntax: "none | before | after"
@@ -2668,13 +2668,13 @@
2668
2668
  syntax: "none | auto"
2669
2669
  },
2670
2670
  "scroll-timeline": {
2671
- syntax: "[ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#"
2671
+ syntax: " [ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#"
2672
2672
  },
2673
2673
  "scroll-timeline-axis": {
2674
- syntax: "[ block | inline | x | y ]#"
2674
+ syntax: " [ block | inline | x | y ]#"
2675
2675
  },
2676
2676
  "scroll-timeline-name": {
2677
- syntax: "[ none | <dashed-ident> ]#"
2677
+ syntax: " [ none | <dashed-ident> ]#"
2678
2678
  },
2679
2679
  "scrollbar-color": {
2680
2680
  syntax: "auto | <color>{2}"
@@ -3167,6 +3167,9 @@
3167
3167
  acos: {
3168
3168
  syntax: "acos( <calc-sum> )"
3169
3169
  },
3170
+ alpha: {
3171
+ syntax: "alpha( from <color> / [ <alpha-value> | none ] )"
3172
+ },
3170
3173
  anchor: {
3171
3174
  syntax: "anchor( <anchor-name>? && <anchor-side>, <length-percentage>? )"
3172
3175
  },
@@ -7951,10 +7954,11 @@
7951
7954
  t = components[3];
7952
7955
  // @ts-ignore
7953
7956
  const k = getNumber(t);
7957
+ const mul = 1 - k;
7954
7958
  const rgb = [
7955
- 1 - Math.min(1, c * (1 - k) + k),
7956
- 1 - Math.min(1, m * (1 - k) + k),
7957
- 1 - Math.min(1, y * (1 - k) + k),
7959
+ 1 - Math.min(1, c * mul + k),
7960
+ 1 - Math.min(1, m * mul + k),
7961
+ 1 - Math.min(1, y * mul + k),
7958
7962
  ];
7959
7963
  if (components.length == 5) {
7960
7964
  rgb.push(getNumber(components[4]));
@@ -10262,7 +10266,9 @@
10262
10266
  }
10263
10267
  const value = evaluate(values);
10264
10268
  // @ts-ignore
10265
- let val = value[0].typ == exports.EnumToken.NumberTokenType || value[0].typ == exports.EnumToken.AngleTokenType
10269
+ let val = value[0].typ == exports.EnumToken.NumberTokenType ||
10270
+ value[0].typ == exports.EnumToken.AngleTokenType ||
10271
+ value[0].typ == exports.EnumToken.PercentageTokenType
10266
10272
  ? +value[0].val
10267
10273
  : // @ts-expect-error
10268
10274
  value[0].l.val / value[0].r.val;
@@ -10277,7 +10283,7 @@
10277
10283
  [LOCEND]: value[0][LOCEND],
10278
10284
  }
10279
10285
  : {
10280
- typ: exports.EnumToken.NumberTokenType,
10286
+ typ: token.val == "sign" ? exports.EnumToken.NumberTokenType : value[0].typ,
10281
10287
  val: Math[token.val](val),
10282
10288
  [LOCSRCID]: value[0][LOCSRCID],
10283
10289
  [LOCSTA]: value[0][LOCSTA],
@@ -10307,10 +10313,23 @@
10307
10313
  },
10308
10314
  ];
10309
10315
  }
10316
+ case "mod":
10310
10317
  case "atan2":
10311
10318
  case "pow":
10312
- case "rem":
10313
- case "mod": {
10319
+ case "rem": {
10320
+ {
10321
+ let typ = token.chi[0]?.typ;
10322
+ for (let i = 1; i < token.chi.length; i++) {
10323
+ if (token.chi[i].typ == exports.EnumToken.WhitespaceTokenType ||
10324
+ token.chi[i].typ == exports.EnumToken.CommaTokenType ||
10325
+ token.chi[i].typ == exports.EnumToken.CommentTokenType) {
10326
+ continue;
10327
+ }
10328
+ if (token.chi[i].typ != typ) {
10329
+ return null;
10330
+ }
10331
+ }
10332
+ }
10314
10333
  const chi = values.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ));
10315
10334
  if (token.val == "atan2") {
10316
10335
  for (let i = 0; i < chi.length; i++) {
@@ -10931,9 +10950,10 @@
10931
10950
  }
10932
10951
  function srgb2cmykvalues(r, g, b, a = null) {
10933
10952
  const k = 1 - Math.max(r, g, b);
10934
- const c = k == 1 ? 0 : (1 - r - k) / (1 - k);
10935
- const m = k == 1 ? 0 : (1 - g - k) / (1 - k);
10936
- const y = k == 1 ? 0 : (1 - b - k) / (1 - k);
10953
+ const div = 1 - k;
10954
+ const c = k == 1 ? 0 : (1 - r - k) / div;
10955
+ const m = k == 1 ? 0 : (1 - g - k) / div;
10956
+ const y = k == 1 ? 0 : (1 - b - k) / div;
10937
10957
  const result = [c, m, y, k];
10938
10958
  if (a != null && a < 1) {
10939
10959
  result.push(a);
@@ -11747,9 +11767,13 @@
11747
11767
  stack.pop();
11748
11768
  }
11749
11769
  }
11750
- if (stack.length > 0) {
11751
- throw new SyntaxError(`Unexpected token ${ValidationTokenEnum[stack.at(-1)?.typ]} at ${stack.at(-1)?.[LOC]?.lin}:${stack.at(-1)?.[LOC]?.col}`);
11752
- }
11770
+ // if (stack.length > 0) {
11771
+ // throw new SyntaxError(
11772
+ // `Unexpected token ${ValidationTokenEnum[stack.at(-1)?.typ as ValidationTokenEnum]} at ${
11773
+ // stack.at(-1)?.[LOC]?.lin
11774
+ // }:${stack.at(-1)?.[LOC]?.col}`,
11775
+ // );
11776
+ // }
11753
11777
  return trimSyntaxArray(tokens);
11754
11778
  }
11755
11779
 
@@ -17212,6 +17236,65 @@
17212
17236
  "padding-left": {
17213
17237
  shorthand: "padding"
17214
17238
  },
17239
+ "scroll-margin": {
17240
+ shorthand: "scroll-margin",
17241
+ properties: [
17242
+ "scroll-margin-top",
17243
+ "scroll-margin-right",
17244
+ "scroll-margin-bottom",
17245
+ "scroll-margin-left"
17246
+ ],
17247
+ types: [
17248
+ "Length",
17249
+ "Perc"
17250
+ ],
17251
+ "default": [
17252
+ "0"
17253
+ ],
17254
+ keywords: [
17255
+ "auto"
17256
+ ]
17257
+ },
17258
+ "scroll-margin-top": {
17259
+ shorthand: "scroll-margin"
17260
+ },
17261
+ "scroll-margin-right": {
17262
+ shorthand: "scroll-margin"
17263
+ },
17264
+ "scroll-margin-bottom": {
17265
+ shorthand: "scroll-margin"
17266
+ },
17267
+ "scroll-margin-left": {
17268
+ shorthand: "scroll-margin"
17269
+ },
17270
+ "scroll-padding": {
17271
+ shorthand: "scroll-padding",
17272
+ properties: [
17273
+ "scroll-padding-top",
17274
+ "scroll-padding-right",
17275
+ "scroll-padding-bottom",
17276
+ "scroll-padding-left"
17277
+ ],
17278
+ types: [
17279
+ "Length",
17280
+ "Perc"
17281
+ ],
17282
+ keywords: [
17283
+ "auto"
17284
+ ]
17285
+ },
17286
+ "scroll-padding-top": {
17287
+ shorthand: "scroll-padding"
17288
+ },
17289
+ "scroll-padding-right": {
17290
+ shorthand: "scroll-padding"
17291
+ },
17292
+ "scroll-padding-bottom": {
17293
+ shorthand: "scroll-padding"
17294
+ },
17295
+ "scroll-padding-left": {
17296
+ shorthand: "scroll-padding"
17297
+ },
17215
17298
  "border-radius": {
17216
17299
  shorthand: "border-radius",
17217
17300
  properties: [
@@ -17433,6 +17516,53 @@
17433
17516
  "flex-wrap": {
17434
17517
  shorthand: "flex-flow"
17435
17518
  },
17519
+ "scroll-timeline": {
17520
+ shorthand: "scroll-timeline",
17521
+ pattern: "scroll-timeline-name scroll-timeline-axis",
17522
+ keywords: [
17523
+ "none",
17524
+ "block",
17525
+ "inline",
17526
+ "x",
17527
+ "y"
17528
+ ],
17529
+ "default": [
17530
+ "none",
17531
+ "block"
17532
+ ],
17533
+ properties: {
17534
+ "scroll-timeline-name": {
17535
+ keywords: [
17536
+ "none"
17537
+ ],
17538
+ "default": [
17539
+ "none"
17540
+ ],
17541
+ types: [
17542
+ "DashedIden"
17543
+ ]
17544
+ },
17545
+ "scroll-timeline-axis": {
17546
+ keywords: [
17547
+ "block",
17548
+ "inline",
17549
+ "x",
17550
+ "y"
17551
+ ],
17552
+ "default": [
17553
+ "block"
17554
+ ],
17555
+ types: [
17556
+ ]
17557
+ }
17558
+ }
17559
+ },
17560
+ "scroll-timeline-name": {
17561
+ shorthand: "scroll-timeline"
17562
+ },
17563
+ "scroll-timeline-axis": {
17564
+ shorthand: "scroll-timeline"
17565
+ },
17436
17566
  container: {
17437
17567
  shorthand: "container",
17438
17568
  pattern: "container-name container-type",
@@ -20637,7 +20767,7 @@
20637
20767
  return true;
20638
20768
  }
20639
20769
  function minifyTransformFunctions(transform) {
20640
- const name = transform.val.toLowerCase();
20770
+ const name = transform.val;
20641
20771
  if ("skewX" == name) {
20642
20772
  transform.val = "skew";
20643
20773
  return transform;
@@ -20772,9 +20902,36 @@
20772
20902
  let matrix = identity();
20773
20903
  let mat;
20774
20904
  let transforms;
20905
+ let shouldComputeMatrix = true;
20775
20906
  const cumulative = [];
20907
+ // all transform function arguments must be 0 or scale(1)
20908
+ for (const transform of transformLists) {
20909
+ switch (transform.val) {
20910
+ case "rotate":
20911
+ case "rotateX":
20912
+ case "rotateY":
20913
+ case "rotateZ":
20914
+ case "rotate3d":
20915
+ for (const child of transform.chi) {
20916
+ if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) {
20917
+ continue;
20918
+ }
20919
+ if ((child.typ != exports.EnumToken.AngleTokenType &&
20920
+ child.typ != exports.EnumToken.NumberTokenType &&
20921
+ child.typ != exports.EnumToken.PercentageTokenType) ||
20922
+ // angle >= 360deg, do not transform
20923
+ Math.abs(getAngle(child)) >= 1) {
20924
+ shouldComputeMatrix = false;
20925
+ }
20926
+ }
20927
+ break;
20928
+ }
20929
+ if (!shouldComputeMatrix) {
20930
+ break;
20931
+ }
20932
+ }
20776
20933
  for (const transformList of splitTransformList(transformLists)) {
20777
- mat = computeMatrix(transformList, identity());
20934
+ mat = shouldComputeMatrix ? computeMatrix(transformList, identity()) : null;
20778
20935
  if (mat == null) {
20779
20936
  return null;
20780
20937
  }
@@ -20803,60 +20960,6 @@
20803
20960
  cumulative,
20804
20961
  minified: minify$1(matrix) ?? [serialized],
20805
20962
  };
20806
- // valid identity matrix
20807
- if ((result.minified.length == 1 &&
20808
- result.minified[0].typ == exports.EnumToken.IdenTokenType &&
20809
- result.minified[0].val == "none") ||
20810
- (result.cumulative.length == 1 &&
20811
- result.cumulative[0].typ == exports.EnumToken.IdenTokenType &&
20812
- result.cumulative[0].val == "none") ||
20813
- (result.matrix?.typ == exports.EnumToken.IdenTokenType && result.matrix.val == "none")) {
20814
- // all transform function arguments must be 0 or scale(1)
20815
- for (const transform of transformLists) {
20816
- switch (transform.val) {
20817
- case "translate":
20818
- case "translateX":
20819
- case "translateY":
20820
- case "translateZ":
20821
- case "translate3d":
20822
- case "rotate":
20823
- case "rotateX":
20824
- case "rotateY":
20825
- case "rotateZ":
20826
- case "rotate3d":
20827
- case "skew":
20828
- case "skewX":
20829
- case "skewY":
20830
- for (const child of transform.chi) {
20831
- if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) {
20832
- continue;
20833
- }
20834
- if ((child.typ != exports.EnumToken.AngleTokenType &&
20835
- child.typ != exports.EnumToken.NumberTokenType &&
20836
- child.typ != exports.EnumToken.PercentageTokenType) ||
20837
- getNumber(child) != 0) {
20838
- return null;
20839
- }
20840
- }
20841
- break;
20842
- case "scale":
20843
- case "scaleX":
20844
- case "scaleY":
20845
- case "scaleZ":
20846
- case "scale3d":
20847
- for (const child of transform.chi) {
20848
- if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) {
20849
- continue;
20850
- }
20851
- if ((child.typ != exports.EnumToken.NumberTokenType && child.typ != exports.EnumToken.PercentageTokenType) ||
20852
- getNumber(child) != 1) {
20853
- return null;
20854
- }
20855
- }
20856
- break;
20857
- }
20858
- }
20859
- }
20860
20963
  return result;
20861
20964
  }
20862
20965
  function computeMatrix(transformList, matrixVar) {
@@ -21184,7 +21287,7 @@
21184
21287
  minified: null,
21185
21288
  };
21186
21289
  if (matrix == null || cumulative == null || minified == null) {
21187
- node.val = children;
21290
+ node.val = children.map((t) => t.typ == exports.EnumToken.TransformFunctionTokenType ? minifyTransformFunctions(t) : t);
21188
21291
  continue;
21189
21292
  }
21190
21293
  let r = [filterValues(children)];
@@ -21868,7 +21971,15 @@
21868
21971
  // trim :is()
21869
21972
  if (curr[0] == "&") {
21870
21973
  if (curr[1] == " " && !isIdent(curr[2]) && !isFunction(curr[2])) {
21871
- curr.splice(0, 2);
21974
+ const all = new Array(Math.max(curr.length - 2, 0));
21975
+ let write = 0;
21976
+ for (let read = 2; read < curr.length; read++) {
21977
+ all[write++] = curr[read];
21978
+ }
21979
+ curr.length = 0;
21980
+ for (let index = 0; index < write; index++) {
21981
+ curr[index] = all[index];
21982
+ }
21872
21983
  }
21873
21984
  }
21874
21985
  acc.push(curr.join(""));
@@ -22146,19 +22257,40 @@
22146
22257
  if (optimized.length > 1) {
22147
22258
  const check = optimized.at(-2);
22148
22259
  if (!combinators.includes(check)) {
22149
- let last = optimized.pop();
22260
+ const last = optimized[optimized.length - 1];
22261
+ const all = new Array(Math.max(optimized.length - 1, 0));
22262
+ let write = 0;
22263
+ for (let read = 0; read < optimized.length - 1; read++) {
22264
+ all[write++] = optimized[read];
22265
+ }
22266
+ optimized.length = 0;
22267
+ for (let index = 0; index < write; index++) {
22268
+ optimized[index] = all[index];
22269
+ }
22150
22270
  wrap = false;
22151
22271
  rule =
22152
22272
  optimized.join("") +
22153
22273
  `:is(${selector
22154
22274
  .map((s) => {
22275
+ const next = s[0] == "&" ? new Array(s.length) : new Array(s.length + 1);
22276
+ let write = 0;
22155
22277
  if (s[0] == "&") {
22156
- s.splice(0, 1, last);
22278
+ next[write++] = last;
22279
+ for (let read = 1; read < s.length; read++) {
22280
+ next[write++] = s[read];
22281
+ }
22157
22282
  }
22158
22283
  else {
22159
- s.unshift(last);
22284
+ next[write++] = last;
22285
+ for (let read = 0; read < s.length; read++) {
22286
+ next[write++] = s[read];
22287
+ }
22288
+ }
22289
+ const rebuilt = new Array(write);
22290
+ for (let index = 0; index < write; index++) {
22291
+ rebuilt[index] = next[index];
22160
22292
  }
22161
- return s.join("");
22293
+ return rebuilt.join("");
22162
22294
  })
22163
22295
  .join(",")})`;
22164
22296
  }
@@ -22167,7 +22299,20 @@
22167
22299
  rule = selector
22168
22300
  .map((s) => {
22169
22301
  if (s[0] == "&") {
22170
- s.splice(0, 1, ...node[OPTIMIZED].optimized);
22302
+ const replacement = node[OPTIMIZED].optimized;
22303
+ const all = new Array(Math.max(s.length - 1 + replacement.length, 0));
22304
+ let write = 0;
22305
+ for (let read = 0; read < replacement.length; read++) {
22306
+ all[write++] = replacement[read];
22307
+ }
22308
+ for (let read = 1; read < s.length; read++) {
22309
+ all[write++] = s[read];
22310
+ }
22311
+ const rebuilt = new Array(write);
22312
+ for (let index = 0; index < write; index++) {
22313
+ rebuilt[index] = all[index];
22314
+ }
22315
+ return rebuilt.join("");
22171
22316
  }
22172
22317
  return s.join("");
22173
22318
  })
@@ -22399,18 +22544,42 @@
22399
22544
  while (optimized.length > 0) {
22400
22545
  const last = optimized.at(-1);
22401
22546
  if (last == " " || combinators.includes(last)) {
22402
- optimized.pop();
22547
+ const all = new Array(Math.max(optimized.length - 1, 0));
22548
+ let write = 0;
22549
+ for (let read = 0; read < optimized.length - 1; read++) {
22550
+ all[write++] = optimized[read];
22551
+ }
22552
+ optimized.length = 0;
22553
+ for (let index = 0; index < write; index++) {
22554
+ optimized[index] = all[index];
22555
+ }
22403
22556
  continue;
22404
22557
  }
22405
22558
  break;
22406
22559
  }
22407
22560
  for (let i1 = 0; i1 < selector.length; i1++) {
22408
- selector[i1].splice(0, optimized.length);
22561
+ const all = new Array(Math.max(selector[i1].length - optimized.length, 0));
22562
+ let write = 0;
22563
+ for (let read = optimized.length; read < selector[i1].length; read++) {
22564
+ all[write++] = selector[i1][read];
22565
+ }
22566
+ selector[i1].length = 0;
22567
+ for (let index = 0; index < write; index++) {
22568
+ selector[i1][index] = all[index];
22569
+ }
22409
22570
  }
22410
22571
  let reducible = optimized.length == 1;
22411
22572
  if (optimized[0] == "&") {
22412
22573
  if (optimized[1] == " ") {
22413
- optimized.splice(0, 2);
22574
+ const all = new Array(Math.max(optimized.length - 2, 0));
22575
+ let write = 0;
22576
+ for (let read = 2; read < optimized.length; read++) {
22577
+ all[write++] = optimized[read];
22578
+ }
22579
+ optimized.length = 0;
22580
+ for (let index = 0; index < write; index++) {
22581
+ optimized[index] = all[index];
22582
+ }
22414
22583
  }
22415
22584
  }
22416
22585
  if (optimized.length == 0 || optimized[0].charAt(0) == "&" || selector.length == 1) {
@@ -22997,7 +23166,15 @@
22997
23166
  if (selector.length > 1 &&
22998
23167
  selector[0] == "&" &&
22999
23168
  (combinators.includes(selector[1]) || !/^[a-zA-Z:]/.test(selector[1]))) {
23000
- selector.shift();
23169
+ const all = new Array(Math.max(selector.length - 1, 0));
23170
+ let write = 0;
23171
+ for (let read = 1; read < selector.length; read++) {
23172
+ all[write++] = selector[read];
23173
+ }
23174
+ selector.length = 0;
23175
+ for (let index = 0; index < write; index++) {
23176
+ selector[index] = all[index];
23177
+ }
23001
23178
  }
23002
23179
  }
23003
23180
  const unique = new Set();
@@ -23368,9 +23545,9 @@
23368
23545
  * @returns
23369
23546
  */
23370
23547
  function encode(value) {
23371
- if (typeof value === 'number') {
23372
- return encode_integer(value);
23373
- }
23548
+ // if (typeof value === 'number') {
23549
+ // return encode_integer(value);
23550
+ // }
23374
23551
  let result = '';
23375
23552
  for (let i = 0; i < value.length; i += 1) {
23376
23553
  result += encode_integer(value[i]);
@@ -24534,8 +24711,8 @@
24534
24711
  return token.val;
24535
24712
  }
24536
24713
  if (Array.isArray(token.chi)) {
24537
- const fnName = token.val.toLowerCase();
24538
- const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val.toLowerCase());
24714
+ const fnName = token.val;
24715
+ const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val);
24539
24716
  const hasAlpha = [
24540
24717
  "rgb",
24541
24718
  "rgba",
@@ -25713,7 +25890,7 @@
25713
25890
  * @param parseInfo
25714
25891
  * @returns
25715
25892
  */
25716
- consumeURLToken(parseInfo) {
25893
+ consumeStringAsURLToken(parseInfo) {
25717
25894
  const quote = this.advance(parseInfo).charCodeAt(0);
25718
25895
  let charCode;
25719
25896
  let decodeSegments = false;
@@ -26155,7 +26332,7 @@
26155
26332
  }
26156
26333
  return 0;
26157
26334
  }
26158
- parseURLToken(parseInfo, endPosition) {
26335
+ consumeURLToken(parseInfo, endPosition) {
26159
26336
  let charCode;
26160
26337
  // consume an <url>
26161
26338
  while (isWhiteSpace(this.peekCharCode(parseInfo))) {
@@ -26163,7 +26340,7 @@
26163
26340
  }
26164
26341
  charCode = this.peekCharCode(parseInfo);
26165
26342
  if (charCode == 34 /* TokenMap.DOUBLE_QUOTE */ || charCode == 39 /* TokenMap.SINGLE_QUOTE */) {
26166
- return this.consumeURLToken(parseInfo);
26343
+ return this.consumeStringAsURLToken(parseInfo);
26167
26344
  }
26168
26345
  do {
26169
26346
  this.advance(parseInfo);
@@ -26427,27 +26604,24 @@
26427
26604
  * @param end
26428
26605
  * @returns
26429
26606
  */
26430
- isIdentToken(parseInfo, start, end) {
26607
+ isIdentToken(parseInfo /* , start?: number, end?: number */) {
26431
26608
  let j = parseInfo.currentPosition - parseInfo.offset;
26432
26609
  let i = parseInfo.position - parseInfo.offset;
26433
- if (start != null) {
26434
- if (end == null) {
26435
- if (start < 0) {
26436
- j += start;
26437
- }
26438
- else {
26439
- i += start;
26440
- }
26441
- }
26442
- else {
26443
- if (end < 0) {
26444
- j += end;
26445
- }
26446
- else {
26447
- j = parseInfo.position + end;
26448
- }
26449
- }
26450
- }
26610
+ // if (start != null) {
26611
+ // if (end == null) {
26612
+ // if (start < 0) {
26613
+ // j += start;
26614
+ // } else {
26615
+ // i += start;
26616
+ // }
26617
+ // } else {
26618
+ // if (end < 0) {
26619
+ // j += end;
26620
+ // } else {
26621
+ // j = parseInfo.position + end;
26622
+ // }
26623
+ // }
26624
+ // }
26451
26625
  j--;
26452
26626
  let codepoint = parseInfo.stream.charCodeAt(i);
26453
26627
  // -
@@ -26490,18 +26664,18 @@
26490
26664
  * @param parseInfo
26491
26665
  * @returns
26492
26666
  */
26493
- isPseudo(parseInfo) {
26494
- let position = parseInfo.currentPosition - parseInfo.offset;
26495
- let endPosition = parseInfo.currentPosition - parseInfo.offset;
26496
- return (parseInfo.stream.charAt(position) == ":" &&
26497
- parseInfo.stream.charAt(endPosition - 1) == "(" &&
26498
- (parseInfo.stream.charAt(position + 1) == ":"
26499
- ? this.isIdentToken(parseInfo, 2, -1)
26500
- : this.isIdentToken(parseInfo, 1, -1))) ||
26501
- parseInfo.stream.charAt(position + 1) == ":"
26502
- ? this.isIdentToken(parseInfo, 2)
26503
- : this.isIdentToken(parseInfo, 1);
26504
- }
26667
+ // isPseudo(parseInfo: ParseInfo): boolean {
26668
+ // let position: number = parseInfo.currentPosition - parseInfo.offset;
26669
+ // let endPosition: number = parseInfo.currentPosition - parseInfo.offset;
26670
+ // return (parseInfo.stream.charAt(position) == ":" &&
26671
+ // parseInfo.stream.charAt(endPosition - 1) == "(" &&
26672
+ // (parseInfo.stream.charAt(position + 1) == ":"
26673
+ // ? this.isIdentToken(parseInfo, 2, -1)
26674
+ // : this.isIdentToken(parseInfo, 1, -1))) ||
26675
+ // parseInfo.stream.charAt(position + 1) == ":"
26676
+ // ? this.isIdentToken(parseInfo, 2)
26677
+ // : this.isIdentToken(parseInfo, 1);
26678
+ // }
26505
26679
  /**
26506
26680
  *
26507
26681
  * @param parseInfo
@@ -26574,7 +26748,7 @@
26574
26748
  while ((charCode = this.peekCharCode(parseInfo)) == charCode) {
26575
26749
  if (this.state === exports.EnumToken.UrlFunctionTokenDefType) {
26576
26750
  this.state = null;
26577
- return this.parseURLToken(parseInfo, endPosition);
26751
+ return this.consumeURLToken(parseInfo, endPosition);
26578
26752
  }
26579
26753
  if (parseInfo.position == parseInfo.currentPosition) {
26580
26754
  if (charCode == 45 /* TokenMap.MINUS */ ||
@@ -26694,12 +26868,14 @@
26694
26868
  // '('
26695
26869
  case 40 /* TokenMap.LEFT_PARENTHESIS */:
26696
26870
  if (parseInfo.position < parseInfo.currentPosition) {
26697
- if (parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" &&
26698
- this.isPseudo(parseInfo)) {
26699
- this.advance(parseInfo);
26700
- return this.makeToken(parseInfo, exports.EnumToken.PseudoClassFunctionTokenDefType);
26701
- }
26702
- else if (this.isIdentToken(parseInfo)) {
26871
+ // if (
26872
+ // parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" &&
26873
+ // this.isPseudo(parseInfo)
26874
+ // ) {
26875
+ // this.advance(parseInfo);
26876
+ // return this.makeToken(parseInfo, EnumToken.PseudoClassFunctionTokenDefType);
26877
+ // } else
26878
+ if (this.isIdentToken(parseInfo)) {
26703
26879
  const hint = this.startsWith(parseInfo, "--")
26704
26880
  ? exports.EnumToken.CustomFunctionTokenDefType
26705
26881
  : (getSymbolHint(parseInfo, parseInfo.position - parseInfo.offset, parseInfo.currentPosition - parseInfo.offset + 1) ?? exports.EnumToken.FunctionTokenDefType);
@@ -27062,7 +27238,6 @@
27062
27238
  const stack = [];
27063
27239
  const uniq = new Map();
27064
27240
  let allowed = true;
27065
- let i = 0;
27066
27241
  let index;
27067
27242
  let parent = context;
27068
27243
  let nested = false;
@@ -27096,119 +27271,130 @@
27096
27271
  nested = parent?.typ == exports.EnumToken.RuleNodeType;
27097
27272
  parent = parent?.[PARENT];
27098
27273
  } while (!nested && parent != null);
27099
- for (; i < tokens.length; i++) {
27100
- if (tokens[i].typ == exports.EnumToken.ColonTokenType) {
27101
- if (tokens[i + 1]?.typ == exports.EnumToken.IdenTokenType) {
27102
- Object.assign(tokens[i], {
27274
+ const all = new Array(tokens.length);
27275
+ let write = 0;
27276
+ for (let read = 0; read < tokens.length; read++) {
27277
+ let token = tokens[read];
27278
+ if (token.typ == exports.EnumToken.ColonTokenType) {
27279
+ const next = tokens[read + 1];
27280
+ if (next?.typ == exports.EnumToken.IdenTokenType) {
27281
+ all[write++] = {
27282
+ ...token,
27103
27283
  typ: exports.EnumToken.PseudoElementTokenType,
27104
- val: ":" + tokens[i + 1].val,
27105
- });
27106
- tokens[i][LOCEND] = tokens[i + 1][LOCEND];
27107
- tokens.splice(i + 1, 1);
27284
+ val: ":" + next.val,
27285
+ [LOCEND]: next[LOCEND],
27286
+ };
27287
+ read++;
27108
27288
  continue;
27109
27289
  }
27110
- if (tokens[i + 1]?.typ == exports.EnumToken.FunctionTokenDefType) {
27111
- val = ":" + tokens[i + 1].val;
27112
- Object.assign(tokens[i], {
27290
+ if (next?.typ == exports.EnumToken.FunctionTokenDefType) {
27291
+ val = ":" + next.val;
27292
+ all[write++] = {
27293
+ ...token,
27113
27294
  typ: val + "()" in getSyntaxConfig().selectors
27114
27295
  ? exports.EnumToken.PseudoClassFunctionTokenDefType
27115
- : tokens[i + 1].typ,
27296
+ : next.typ,
27116
27297
  val,
27117
- });
27118
- tokens[i][LOCEND] = tokens[i + 1][LOCEND];
27119
- tokens.splice(i + 1, 1);
27298
+ [LOCEND]: next[LOCEND],
27299
+ };
27300
+ read++;
27120
27301
  continue;
27121
27302
  }
27122
27303
  }
27123
- if (tokens[i].typ == exports.EnumToken.DoubleColonTokenType) {
27124
- val = ":" + tokens[i + 1].val;
27125
- if (tokens[i + 1]?.typ == exports.EnumToken.IdenTokenType) {
27126
- Object.assign(tokens[i], {
27304
+ if (token.typ == exports.EnumToken.DoubleColonTokenType) {
27305
+ const next = tokens[read + 1];
27306
+ val = ":" + next.val;
27307
+ if (next?.typ == exports.EnumToken.IdenTokenType) {
27308
+ all[write++] = {
27309
+ ...token,
27127
27310
  typ: exports.EnumToken.PseudoClassTokenType,
27128
27311
  val: (pseudoElements.includes(val) ? "" : ":") + val,
27129
- });
27130
- tokens[i][LOCEND] = tokens[i + 1][LOCEND];
27131
- tokens.splice(i + 1, 1);
27312
+ [LOCEND]: next[LOCEND],
27313
+ };
27314
+ read++;
27132
27315
  continue;
27133
27316
  }
27134
- if (tokens[i + 1]?.typ == exports.EnumToken.FunctionTokenDefType) {
27135
- val = "::" + tokens[i + 1].val;
27136
- Object.assign(tokens[i], {
27317
+ if (next?.typ == exports.EnumToken.FunctionTokenDefType) {
27318
+ val = "::" + next.val;
27319
+ all[write++] = {
27320
+ ...token,
27137
27321
  typ: val + "()" in getSyntaxConfig().selectors
27138
27322
  ? exports.EnumToken.PseudoClassFunctionTokenDefType
27139
27323
  : exports.EnumToken.FunctionTokenDefType,
27140
27324
  val,
27141
- });
27142
- tokens[i][LOCEND] = tokens[i + 1][LOCEND];
27143
- tokens.splice(i + 1, 1);
27325
+ [LOCEND]: next[LOCEND],
27326
+ };
27327
+ read++;
27144
27328
  continue;
27145
27329
  }
27146
27330
  }
27147
- if (tokens[i].typ == exports.EnumToken.ColorTokenType) {
27148
- if (isHash(tokens[i].val)) {
27149
- Object.assign(tokens[i], {
27150
- typ: exports.EnumToken.HashTokenType,
27151
- });
27331
+ if (token.typ == exports.EnumToken.ColorTokenType) {
27332
+ if (isHash(token.val)) {
27333
+ token.typ = exports.EnumToken.HashTokenType;
27334
+ all[write++] = token;
27335
+ continue;
27152
27336
  }
27153
- else {
27154
- return {
27155
- typ: exports.EnumToken.RuleNodeType,
27156
- sel: [
27157
- ...tokens
27158
- .reduce((acc, curr, index, array) => {
27159
- // if (curr.typ == EnumToken.CommentTokenType) {
27160
- // return acc;
27161
- // }
27162
- if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
27163
- if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
27164
- trimWhiteSpace.includes(array[index + 1]?.typ) ||
27165
- combinators.includes(array[index - 1]?.val) ||
27166
- combinators.includes(array[index + 1]?.val)) {
27167
- return acc;
27168
- }
27169
- }
27170
- let t = renderValue(curr, { minify: false });
27171
- if (t == ",") {
27172
- acc.push([]);
27173
- }
27174
- else {
27175
- acc[acc.length - 1].push(t);
27337
+ return {
27338
+ typ: exports.EnumToken.RuleNodeType,
27339
+ sel: [
27340
+ ...tokens
27341
+ .reduce((acc, curr, index, array) => {
27342
+ if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
27343
+ if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
27344
+ trimWhiteSpace.includes(array[index + 1]?.typ) ||
27345
+ combinators.includes(array[index - 1]?.val) ||
27346
+ combinators.includes(array[index + 1]?.val)) {
27347
+ return acc;
27176
27348
  }
27177
- return acc;
27178
- }, [[]])
27179
- .reduce((acc, curr) => {
27180
- let i = 0;
27181
- for (; i < curr.length; i++) {
27182
- if (i + 1 < curr.length && curr[i] == "*") {
27183
- if (curr[i] == "*") {
27184
- let index = curr[i + 1] == " " ? 2 : 1;
27185
- if (![">", "~", "+"].includes(curr[index])) {
27186
- curr.splice(i, index);
27187
- }
27349
+ }
27350
+ let t = renderValue(curr, { minify: false });
27351
+ if (t == ",") {
27352
+ acc.push([]);
27353
+ }
27354
+ else {
27355
+ acc[acc.length - 1].push(t);
27356
+ }
27357
+ return acc;
27358
+ }, [[]])
27359
+ .reduce((acc, curr) => {
27360
+ let i = 0;
27361
+ for (; i < curr.length; i++) {
27362
+ if (i + 1 < curr.length && curr[i] == "*") {
27363
+ if (curr[i] == "*") {
27364
+ let index = curr[i + 1] == " " ? 2 : 1;
27365
+ if (![">", "~", "+"].includes(curr[index])) {
27366
+ curr.splice(i, index);
27188
27367
  }
27189
27368
  }
27190
27369
  }
27191
- acc.set(curr.join(""), curr);
27192
- return acc;
27193
- }, uniq)
27194
- .keys(),
27195
- ].join(","),
27196
- chi: [],
27197
- [LOCSRCID]: tokens[0][LOCSRCID],
27198
- [LOCSTA]: tokens[0][LOCSTA],
27199
- [LOCEND]: tokens[tokens.length - 1][LOCEND],
27200
- [TOKENS]: tokens,
27201
- [STATE]: exports.EnumAstNodeStatus.Invalid,
27202
- [ERRORS]: [
27203
- {
27204
- action: "drop",
27205
- node: tokens[i],
27206
- message: "invalid hash id",
27207
- },
27208
- ],
27209
- };
27210
- }
27370
+ }
27371
+ acc.set(curr.join(""), curr);
27372
+ return acc;
27373
+ }, uniq)
27374
+ .keys(),
27375
+ ].join(","),
27376
+ chi: [],
27377
+ [LOCSRCID]: tokens[0][LOCSRCID],
27378
+ [LOCSTA]: tokens[0][LOCSTA],
27379
+ [LOCEND]: tokens[tokens.length - 1][LOCEND],
27380
+ [TOKENS]: tokens,
27381
+ [STATE]: exports.EnumAstNodeStatus.Invalid,
27382
+ [ERRORS]: [
27383
+ {
27384
+ action: "drop",
27385
+ node: token,
27386
+ message: "invalid hash id",
27387
+ },
27388
+ ],
27389
+ };
27211
27390
  }
27391
+ all[write++] = token;
27392
+ }
27393
+ if (write !== tokens.length) {
27394
+ for (let index = 0; index < write; index++) {
27395
+ tokens[index] = all[index];
27396
+ }
27397
+ tokens.length = write;
27212
27398
  }
27213
27399
  const result = matchSelectorSyntax(tokens, errors, options, nested === true);
27214
27400
  trimArray(tokens);
@@ -27527,7 +27713,6 @@
27527
27713
  * @param errors
27528
27714
  */
27529
27715
  function parseDeclaration(tokens, parent, options, errors) {
27530
- // console.error(tokens);
27531
27716
  const name = tokens.shift();
27532
27717
  let i;
27533
27718
  let rules = null;
@@ -27861,10 +28046,19 @@
27861
28046
  }
27862
28047
  if (trimTokenSpace$1.has(token.typ)) {
27863
28048
  if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
27864
- tokens.splice(i + 1, 1);
28049
+ for (let index = i + 1; index < tokens.length - 1; index++) {
28050
+ tokens[index] = tokens[index + 1];
28051
+ }
28052
+ tokens.length--;
28053
+ i--;
28054
+ continue;
27865
28055
  }
27866
28056
  if (tokens[i - 1]?.typ == exports.EnumToken.WhitespaceTokenType) {
27867
- tokens.splice(--i, 1);
28057
+ for (let index = i - 1; index < tokens.length - 1; index++) {
28058
+ tokens[index] = tokens[index + 1];
28059
+ }
28060
+ tokens.length--;
28061
+ i--;
27868
28062
  }
27869
28063
  }
27870
28064
  }
@@ -32606,17 +32800,18 @@
32606
32800
  * console.log(declarations);
32607
32801
  * ```
32608
32802
  */
32609
- async function parseDeclarations(declaration) {
32803
+ function parseDeclarations(declaration) {
32610
32804
  const stream = `.x{${declaration}}`;
32611
- return doParse(new Tokenizer({
32805
+ const result = doParseSync(new Tokenizer({
32612
32806
  stream,
32613
32807
  offset: 0,
32614
32808
  position: 0,
32615
32809
  source: new SourceFile(stream, [], ""),
32616
32810
  currentPosition: 0,
32617
- }), { setParent: false, minify: false, validation: false }).then((result) => {
32618
- return result.ast.chi[0].chi.filter((t) => t.typ == exports.EnumToken.DeclarationNodeType || t.typ == exports.EnumToken.CommentNodeType);
32619
- });
32811
+ }), { setParent: false, minify: false, validation: false });
32812
+ // .then((result) => {
32813
+ return result.ast.chi[0].chi.filter((t) => t.typ == exports.EnumToken.DeclarationNodeType || t.typ == exports.EnumToken.CommentNodeType);
32814
+ // });
32620
32815
  }
32621
32816
  /**
32622
32817
  * Parse css string and return an array of tokens