@tbela99/css-parser 1.4.6 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +1 -0
- package/dist/index-umd-web.js +6548 -6964
- package/dist/index.cjs +7784 -8198
- package/dist/index.d.ts +919 -51
- package/dist/lib/ast/clone.js +16 -23
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/if.js +88 -87
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +26 -22
- package/dist/lib/ast/features/transform.js +3 -3
- package/dist/lib/ast/find.js +17 -14
- package/dist/lib/ast/minify.js +97 -94
- package/dist/lib/ast/types.js +6 -2
- package/dist/lib/ast/walk.js +1 -1
- package/dist/lib/fs/resolve.js +46 -44
- package/dist/lib/parser/declaration/list.js +9 -10
- package/dist/lib/parser/declaration/map.js +13 -18
- package/dist/lib/parser/parse.js +331 -504
- package/dist/lib/parser/tokenize.js +39 -33
- package/dist/lib/parser/utils/at-rule-container.js +244 -247
- package/dist/lib/parser/utils/at-rule-generic.js +25 -25
- package/dist/lib/parser/utils/at-rule-import.js +194 -234
- package/dist/lib/parser/utils/at-rule-media.js +286 -286
- package/dist/lib/parser/utils/at-rule-support.js +279 -251
- package/dist/lib/parser/utils/at-rule-when-else.js +256 -259
- package/dist/lib/parser/utils/at-rule.js +19 -16
- package/dist/lib/parser/utils/cache.js +33 -5
- package/dist/lib/parser/utils/declaration.js +260 -298
- package/dist/lib/parser/utils/hash.js +15 -15
- package/dist/lib/parser/utils/selector.js +182 -222
- package/dist/lib/parser/utils/token.js +4 -7
- package/dist/lib/renderer/render.js +150 -120
- package/dist/lib/syntax/color/alpha.js +1 -4
- package/dist/lib/syntax/color/color.js +5 -5
- package/dist/lib/syntax/color/utils/colorspace.js +3 -3
- package/dist/lib/syntax/color/utils/components.js +21 -22
- package/dist/lib/syntax/color/utils/matrix.js +12 -11
- package/dist/lib/syntax/constants.js +22 -3
- package/dist/lib/syntax/syntax.js +252 -311
- package/dist/lib/validation/config.js +16 -17
- package/dist/lib/validation/match.js +1118 -1131
- package/dist/lib/validation/parser/parse.js +130 -286
- package/dist/node.js +16 -12
- package/dist/web.js +10 -8
- package/package.json +4 -4
- package/dist/lib/validation/utils/whitespace.js +0 -17
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { EnumToken, ColorType } from '../ast/types.js';
|
|
2
2
|
import { walkValues, WalkerOptionEnum } from '../ast/walk.js';
|
|
3
3
|
import { toDegrees } from '../parser/utils/angle.js';
|
|
4
|
+
import { memoize } from '../parser/utils/cache.js';
|
|
4
5
|
import { equalsIgnoreCase } from '../parser/utils/text.js';
|
|
5
|
-
import {
|
|
6
|
-
import { matchAllSyntaxes, createValidationContext, trimArray } from '../validation/match.js';
|
|
7
|
-
import { ValidationSyntaxGroupEnum } from '../validation/parser/typedef.js';
|
|
6
|
+
import { trimArray } from '../validation/match.js';
|
|
8
7
|
import { splitTokenList } from '../validation/utils/list.js';
|
|
9
8
|
import { getColorSpace } from './color/utils/colorspace.js';
|
|
10
9
|
import { getColorComponents } from './color/utils/components.js';
|
|
11
|
-
import {
|
|
10
|
+
import { nonStandardColors, systemColors, deprecatedSystemColors, COLORS_NAMES, colorsFunc, colorFuncColorSpace, LOC } from './constants.js';
|
|
12
11
|
import { isOkLabClose } from './color/utils/distance.js';
|
|
13
12
|
|
|
14
13
|
// https://www.w3.org/TR/CSS21/syndata.html#syntax
|
|
@@ -60,8 +59,6 @@ const dimensionUnits = new Set([
|
|
|
60
59
|
"vmin",
|
|
61
60
|
"vw",
|
|
62
61
|
]);
|
|
63
|
-
// https://www.w3.org/TR/css-values-4/#math-function
|
|
64
|
-
const pseudoElements = [":before", ":after", ":first-line", ":first-letter"];
|
|
65
62
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions
|
|
66
63
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions
|
|
67
64
|
const pseudoAliasMap = {
|
|
@@ -212,32 +209,11 @@ function isTime(dimension) {
|
|
|
212
209
|
function isFrequency(dimension) {
|
|
213
210
|
return "unit" in dimension && ["hz", "khz"].includes(dimension.unit.toLowerCase());
|
|
214
211
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
return [
|
|
223
|
-
"srgb",
|
|
224
|
-
"srgb-linear",
|
|
225
|
-
"lab",
|
|
226
|
-
"oklab",
|
|
227
|
-
"lch",
|
|
228
|
-
"oklch",
|
|
229
|
-
"xyz",
|
|
230
|
-
"xyz-d50",
|
|
231
|
-
"xyz-d65",
|
|
232
|
-
"display-p3",
|
|
233
|
-
"a98-rgb",
|
|
234
|
-
"prophoto-rgb",
|
|
235
|
-
"rec2020",
|
|
236
|
-
"rgb",
|
|
237
|
-
"hsl",
|
|
238
|
-
"hwb",
|
|
239
|
-
].includes(token.val.toLowerCase());
|
|
240
|
-
}
|
|
212
|
+
/**
|
|
213
|
+
* Reduce color stops
|
|
214
|
+
* @param stops
|
|
215
|
+
* @returns
|
|
216
|
+
*/
|
|
241
217
|
function reduceColorStops(stops) {
|
|
242
218
|
const parts = splitTokenList(stops);
|
|
243
219
|
const n = parts.length == 1 ? 1 : parts.length - 1;
|
|
@@ -296,65 +272,70 @@ function reducegradientBackgroundPosition(positions, position) {
|
|
|
296
272
|
case "center center":
|
|
297
273
|
positions.length = 0;
|
|
298
274
|
break;
|
|
299
|
-
case "0 50%":
|
|
300
275
|
case "0% 50%":
|
|
276
|
+
case "0 50%":
|
|
301
277
|
case "left":
|
|
302
278
|
case "left center":
|
|
303
279
|
case "center left":
|
|
304
|
-
positions.length =
|
|
280
|
+
positions.length = 0;
|
|
305
281
|
positions.push({ typ: EnumToken.PercentageTokenType, val: 0 });
|
|
306
282
|
break;
|
|
307
|
-
case "50% 0":
|
|
308
283
|
case "50% 0%":
|
|
284
|
+
case "50% 0":
|
|
309
285
|
case "top center":
|
|
310
286
|
case "center top":
|
|
311
|
-
positions.length =
|
|
287
|
+
positions.length = 0;
|
|
312
288
|
positions.push({ typ: EnumToken.IdenTokenType, val: "top" });
|
|
313
289
|
break;
|
|
314
|
-
case "bottom":
|
|
315
|
-
case "50% 100%":
|
|
316
290
|
case "bottom center":
|
|
317
291
|
case "center bottom":
|
|
318
|
-
|
|
292
|
+
case "bottom":
|
|
293
|
+
case "50% 100%":
|
|
294
|
+
positions.length = 0;
|
|
319
295
|
positions.push({ typ: EnumToken.IdenTokenType, val: "bottom" });
|
|
320
296
|
break;
|
|
321
|
-
case "left":
|
|
322
|
-
case "0 50%":
|
|
323
|
-
case "0% 50%":
|
|
324
|
-
case "left center":
|
|
325
|
-
case "center left":
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
case "100% 50%":
|
|
330
|
-
case "right":
|
|
297
|
+
// case "left":
|
|
298
|
+
// case "0 50%":
|
|
299
|
+
// case "0% 50%":
|
|
300
|
+
// case "left center":
|
|
301
|
+
// case "center left":
|
|
302
|
+
// positions.length = 0;
|
|
303
|
+
// positions.push({ typ: EnumToken.PercentageTokenType, val: 0 });
|
|
304
|
+
// break;
|
|
331
305
|
case "right center":
|
|
332
306
|
case "center right":
|
|
333
|
-
|
|
307
|
+
case "100% 50%":
|
|
308
|
+
case "right":
|
|
309
|
+
positions.length = 0;
|
|
334
310
|
positions.push({ typ: EnumToken.PercentageTokenType, val: 100 });
|
|
335
311
|
break;
|
|
336
312
|
case "bottom left":
|
|
337
313
|
case "left bottom":
|
|
338
|
-
positions.length =
|
|
314
|
+
positions.length = 0;
|
|
339
315
|
positions.push({ typ: EnumToken.PercentageTokenType, val: 0 }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.PercentageTokenType, val: 100 });
|
|
340
316
|
break;
|
|
341
317
|
case "bottom right":
|
|
342
318
|
case "right bottom":
|
|
343
|
-
positions.length =
|
|
319
|
+
positions.length = 0;
|
|
344
320
|
positions.push({ typ: EnumToken.PercentageTokenType, val: 100 }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.PercentageTokenType, val: 100 });
|
|
345
321
|
break;
|
|
346
322
|
case "top left":
|
|
347
323
|
case "left top":
|
|
348
|
-
positions.length =
|
|
324
|
+
positions.length = 0;
|
|
349
325
|
positions.push({ typ: EnumToken.PercentageTokenType, val: 0 }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.PercentageTokenType, val: 0 });
|
|
350
326
|
break;
|
|
351
327
|
case "top right":
|
|
352
328
|
case "right top":
|
|
353
|
-
positions.length =
|
|
329
|
+
positions.length = 0;
|
|
354
330
|
positions.push({ typ: EnumToken.PercentageTokenType, val: 100 }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.PercentageTokenType, val: 0 });
|
|
355
331
|
break;
|
|
356
332
|
}
|
|
357
333
|
}
|
|
334
|
+
/**
|
|
335
|
+
* Reduce conic-gradient color stops
|
|
336
|
+
* @param stops
|
|
337
|
+
* @returns
|
|
338
|
+
*/
|
|
358
339
|
function reduceConicColorStops(stops) {
|
|
359
340
|
const parts = splitTokenList(stops);
|
|
360
341
|
const n = parts.length == 1 ? 1 : parts.length - 1;
|
|
@@ -399,48 +380,50 @@ function reduceConicColorStops(stops) {
|
|
|
399
380
|
}
|
|
400
381
|
return stops;
|
|
401
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* is rectangular orthogonal colorspace
|
|
385
|
+
* @param token
|
|
386
|
+
* @returns
|
|
387
|
+
*/
|
|
402
388
|
function isRectangularOrthogonalColorspace(token) {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
"xyz-d65",
|
|
418
|
-
].some((t) => equalsIgnoreCase(t, token.val));
|
|
389
|
+
return (token.typ === EnumToken.IdenTokenType &&
|
|
390
|
+
[
|
|
391
|
+
"srgb",
|
|
392
|
+
"srgb-linear",
|
|
393
|
+
"display-p3",
|
|
394
|
+
"a98-rgb",
|
|
395
|
+
"prophoto-rgb",
|
|
396
|
+
"rec2020",
|
|
397
|
+
"lab",
|
|
398
|
+
"oklab",
|
|
399
|
+
"xyz",
|
|
400
|
+
"xyz-d50",
|
|
401
|
+
"xyz-d65",
|
|
402
|
+
].some((t) => equalsIgnoreCase(t, token.val)));
|
|
419
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* Is polar colorspace
|
|
406
|
+
* @param token
|
|
407
|
+
* @returns
|
|
408
|
+
*/
|
|
420
409
|
function isPolarColorspace(token) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
return ["hsl", "hwb", "lch", "oklch"].some((t) => equalsIgnoreCase(t, token.val));
|
|
410
|
+
return (token.typ === EnumToken.IdenTokenType &&
|
|
411
|
+
["hsl", "hwb", "lch", "oklch"].some((t) => equalsIgnoreCase(t, token.val)));
|
|
425
412
|
}
|
|
413
|
+
/**
|
|
414
|
+
* Is ident color
|
|
415
|
+
* @param token
|
|
416
|
+
* @returns
|
|
417
|
+
*/
|
|
426
418
|
function isIdentColor(token) {
|
|
427
419
|
return (token.typ == EnumToken.ColorTokenType &&
|
|
428
420
|
[ColorType.SYS, ColorType.DPSYS, ColorType.LIT].includes(token.kin) &&
|
|
429
421
|
isIdent(token.val));
|
|
430
422
|
}
|
|
431
|
-
function isPercentageToken(token) {
|
|
432
|
-
return (token.typ == EnumToken.PercentageTokenType ||
|
|
433
|
-
(token.typ == EnumToken.NumberTokenType && token.val == 0));
|
|
434
|
-
}
|
|
435
423
|
function isColor(token, errors) {
|
|
436
424
|
if (token.typ == EnumToken.WildCardFunctionTokenType) {
|
|
437
425
|
return true;
|
|
438
426
|
}
|
|
439
|
-
if (token.typ == EnumToken.FunctionTokenType) {
|
|
440
|
-
if (!colorsFunc.includes(token.val.toLowerCase())) {
|
|
441
|
-
return false;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
427
|
if (token.typ == EnumToken.ColorTokenType) {
|
|
445
428
|
if ("kin" in token && !("chi" in token)) {
|
|
446
429
|
return true;
|
|
@@ -454,11 +437,10 @@ function isColor(token, errors) {
|
|
|
454
437
|
// named color
|
|
455
438
|
return val in COLORS_NAMES || "currentcolor" === val || "transparent" === val;
|
|
456
439
|
}
|
|
457
|
-
let isLegacySyntax = false;
|
|
458
440
|
if (token.typ === EnumToken.FunctionTokenType || token.typ === EnumToken.ColorTokenType) {
|
|
459
|
-
if (!colorsFunc.includes(token.val.toLowerCase())) {
|
|
460
|
-
|
|
461
|
-
}
|
|
441
|
+
// if (!colorsFunc.includes((token as FunctionToken).val.toLowerCase())) {
|
|
442
|
+
// return false;
|
|
443
|
+
// }
|
|
462
444
|
if (token.chi.length > 0) {
|
|
463
445
|
// @ts-ignore
|
|
464
446
|
if (token.val === "light-dark") {
|
|
@@ -512,7 +494,7 @@ function isColor(token, errors) {
|
|
|
512
494
|
action: "drop",
|
|
513
495
|
message: `Unexpected constant '${val}'`,
|
|
514
496
|
node: value,
|
|
515
|
-
location: value
|
|
497
|
+
location: value[LOC],
|
|
516
498
|
});
|
|
517
499
|
return false;
|
|
518
500
|
}
|
|
@@ -538,12 +520,11 @@ function isColor(token, errors) {
|
|
|
538
520
|
!colorsFunc.includes(val) &&
|
|
539
521
|
!colorSpace.includes(val) &&
|
|
540
522
|
!colorFuncColorSpace.includes(val)) {
|
|
541
|
-
// console.debug({ val });
|
|
542
523
|
errors?.push({
|
|
543
524
|
action: "drop",
|
|
544
525
|
message: `Unexpected constant '${val}'`,
|
|
545
526
|
node: v.value,
|
|
546
|
-
location: v.value
|
|
527
|
+
location: v.value[LOC],
|
|
547
528
|
});
|
|
548
529
|
return false;
|
|
549
530
|
}
|
|
@@ -591,7 +572,7 @@ function isColor(token, errors) {
|
|
|
591
572
|
action: "drop",
|
|
592
573
|
message: "adding percentage and number is not allowed",
|
|
593
574
|
node: token,
|
|
594
|
-
location: token
|
|
575
|
+
location: token[LOC],
|
|
595
576
|
});
|
|
596
577
|
return false;
|
|
597
578
|
}
|
|
@@ -616,7 +597,13 @@ function isColor(token, errors) {
|
|
|
616
597
|
offset = 2;
|
|
617
598
|
}
|
|
618
599
|
if (children[offset]?.typ == EnumToken.DashedIdenTokenType) {
|
|
619
|
-
if (children.length
|
|
600
|
+
if (children.length <= offset + 1) {
|
|
601
|
+
errors?.push({
|
|
602
|
+
action: "drop",
|
|
603
|
+
message: `Invalid color at ${token[LOC]?.src}:${token[LOC]?.sta.lin}:${token[LOC]?.sta.col}`,
|
|
604
|
+
node: token,
|
|
605
|
+
location: token[LOC],
|
|
606
|
+
});
|
|
620
607
|
return false;
|
|
621
608
|
}
|
|
622
609
|
for (let i = offset + 1; i < children.length; i++) {
|
|
@@ -635,61 +622,33 @@ function isColor(token, errors) {
|
|
|
635
622
|
}
|
|
636
623
|
return true;
|
|
637
624
|
}
|
|
638
|
-
if (children.length < 4 || children.length > 8) {
|
|
639
|
-
return false;
|
|
640
|
-
}
|
|
641
|
-
if (!isRelative && !isColorspace(children[0])) {
|
|
642
|
-
return false;
|
|
643
|
-
}
|
|
644
|
-
for (let i = 1; i < children.length - 2; i++) {
|
|
645
|
-
if (children[i].typ == EnumToken.IdenTokenType) {
|
|
646
|
-
if (isColor(children[i])) {
|
|
647
|
-
continue;
|
|
648
|
-
}
|
|
649
|
-
if (children[i].val != "none" &&
|
|
650
|
-
!((isRelative &&
|
|
651
|
-
["alpha", "r", "g", "b", "x", "y", "z"].includes(children[i].val)) ||
|
|
652
|
-
isColorspace(children[i]))) {
|
|
653
|
-
return false;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
if (children[i].typ === EnumToken.WildCardFunctionTokenType) {
|
|
657
|
-
continue;
|
|
658
|
-
}
|
|
659
|
-
if (children[i].typ === EnumToken.FunctionTokenType ||
|
|
660
|
-
children[i].typ === EnumToken.MathFunctionTokenType) {
|
|
661
|
-
if (!mathFuncs.includes(children[i].val)) {
|
|
662
|
-
return false;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
625
|
if (children.length == 4 || (isRelative && children.length == 6)) {
|
|
667
626
|
return true;
|
|
668
627
|
}
|
|
669
628
|
if (children.length == 8 || children.length == 6) {
|
|
670
|
-
|
|
671
|
-
|
|
629
|
+
children.at(-2);
|
|
630
|
+
children.at(-1);
|
|
672
631
|
// @ts-ignore
|
|
673
|
-
if (
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
}
|
|
632
|
+
// if (
|
|
633
|
+
// ((children.length > 6 || !isRelative) && sep.typ != EnumToken.LiteralTokenType) ||
|
|
634
|
+
// (sep as LiteralToken).val != "/"
|
|
635
|
+
// ) {
|
|
636
|
+
// return false;
|
|
637
|
+
// }
|
|
638
|
+
// if (alpha.typ == EnumToken.IdenTokenType && (alpha as IdentToken).val != "none") {
|
|
639
|
+
// return false;
|
|
640
|
+
// } else {
|
|
641
|
+
// // @ts-ignore
|
|
642
|
+
// if (alpha.typ == EnumToken.PercentageTokenType) {
|
|
643
|
+
// if (+(alpha as PercentageToken).val < 0 || +(alpha as PercentageToken).val > 100) {
|
|
644
|
+
// return false;
|
|
645
|
+
// }
|
|
646
|
+
// } else if (alpha.typ == EnumToken.NumberTokenType) {
|
|
647
|
+
// if (+(alpha as NumberToken).val < 0 || +(alpha as NumberToken).val > 1) {
|
|
648
|
+
// return false;
|
|
649
|
+
// }
|
|
650
|
+
// }
|
|
651
|
+
// }
|
|
693
652
|
}
|
|
694
653
|
return true;
|
|
695
654
|
}
|
|
@@ -707,9 +666,9 @@ function isColor(token, errors) {
|
|
|
707
666
|
}
|
|
708
667
|
return acc;
|
|
709
668
|
}, [[]]);
|
|
710
|
-
if (children.length === 0 || children[0].length === 0) {
|
|
711
|
-
|
|
712
|
-
}
|
|
669
|
+
// if (children.length === 0 || children[0].length === 0) {
|
|
670
|
+
// return false;
|
|
671
|
+
// }
|
|
713
672
|
let j = 0;
|
|
714
673
|
let k = 0;
|
|
715
674
|
if (children[j][0].typ === EnumToken.IdenTokenType &&
|
|
@@ -743,42 +702,50 @@ function isColor(token, errors) {
|
|
|
743
702
|
k++;
|
|
744
703
|
}
|
|
745
704
|
}
|
|
746
|
-
else {
|
|
747
|
-
|
|
748
|
-
}
|
|
705
|
+
// else {
|
|
706
|
+
// return false;
|
|
707
|
+
// }
|
|
749
708
|
}
|
|
750
709
|
else {
|
|
751
710
|
k++;
|
|
752
711
|
}
|
|
753
712
|
}
|
|
754
|
-
else {
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
if (k != children[j].length) {
|
|
758
|
-
|
|
759
|
-
}
|
|
760
|
-
j++;
|
|
761
|
-
}
|
|
762
|
-
while (j < children.length) {
|
|
763
|
-
if (children[j].length > 2) {
|
|
764
|
-
return false;
|
|
765
|
-
}
|
|
766
|
-
if (!isColor(children[j][0]) &&
|
|
767
|
-
!(children[j][0].typ == EnumToken.WildCardFunctionTokenType &&
|
|
768
|
-
equalsIgnoreCase("calc", children[j][0].val))) {
|
|
769
|
-
return false;
|
|
770
|
-
}
|
|
771
|
-
if (children[j][0].typ == EnumToken.WildCardFunctionTokenType) {
|
|
772
|
-
const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc()"), createValidationContext([children[j][0]]), {});
|
|
773
|
-
if (!result.success) {
|
|
774
|
-
return false;
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
if (children[j].length > 1 && !isPercentageToken(children[j][1])) {
|
|
778
|
-
return false;
|
|
779
|
-
}
|
|
713
|
+
// else {
|
|
714
|
+
// return false;
|
|
715
|
+
// }
|
|
716
|
+
// if (k != children[j].length) {
|
|
717
|
+
// return false;
|
|
718
|
+
// }
|
|
780
719
|
j++;
|
|
781
720
|
}
|
|
721
|
+
// while (j < children.length) {
|
|
722
|
+
// if (children[j].length > 2) {
|
|
723
|
+
// return false;
|
|
724
|
+
// }
|
|
725
|
+
// if (
|
|
726
|
+
// !isColor(children[j][0]) &&
|
|
727
|
+
// !(
|
|
728
|
+
// children[j][0].typ == EnumToken.WildCardFunctionTokenType &&
|
|
729
|
+
// equalsIgnoreCase("calc", (children[j][0] as FunctionToken).val)
|
|
730
|
+
// )
|
|
731
|
+
// ) {
|
|
732
|
+
// return false;
|
|
733
|
+
// }
|
|
734
|
+
// if (children[j][0].typ == EnumToken.WildCardFunctionTokenType) {
|
|
735
|
+
// const result = matchAllSyntaxes(
|
|
736
|
+
// getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc()") as ValidationFunctionToken[],
|
|
737
|
+
// createValidationContext([children[j][0]]),
|
|
738
|
+
// {},
|
|
739
|
+
// );
|
|
740
|
+
// if (!result.success) {
|
|
741
|
+
// return false;
|
|
742
|
+
// }
|
|
743
|
+
// }
|
|
744
|
+
// if (children[j].length > 1 && !isPercentageToken(children[j][1])) {
|
|
745
|
+
// return false;
|
|
746
|
+
// }
|
|
747
|
+
// j++;
|
|
748
|
+
// }
|
|
782
749
|
return true;
|
|
783
750
|
}
|
|
784
751
|
else {
|
|
@@ -790,25 +757,22 @@ function isColor(token, errors) {
|
|
|
790
757
|
}
|
|
791
758
|
// @ts-ignore
|
|
792
759
|
for (const v of token.chi) {
|
|
793
|
-
if (v.typ == EnumToken.CommaTokenType) {
|
|
794
|
-
isLegacySyntax = true;
|
|
795
|
-
}
|
|
796
760
|
if (v.typ == EnumToken.IdenTokenType) {
|
|
797
|
-
if (isColor(v)) {
|
|
798
|
-
|
|
799
|
-
}
|
|
800
|
-
if (!(keywords.includes(v.val) || v.val.toLowerCase()
|
|
801
|
-
|
|
802
|
-
}
|
|
803
|
-
if (keywords.includes(v.val)) {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
}
|
|
761
|
+
// if (isColor(v)) {
|
|
762
|
+
// continue;
|
|
763
|
+
// }
|
|
764
|
+
// if (!(keywords.includes(v.val) || COLORS_NAMES[v.val.toLowerCase()] != null)) {
|
|
765
|
+
// return false;
|
|
766
|
+
// }
|
|
767
|
+
// if (keywords.includes(v.val)) {
|
|
768
|
+
// if (isLegacySyntax) {
|
|
769
|
+
// return false;
|
|
770
|
+
// }
|
|
771
|
+
// // @ts-ignore
|
|
772
|
+
// if (v.val == "from" && ["rgba", "hsla"].includes((token as ColorToken).val)) {
|
|
773
|
+
// return false;
|
|
774
|
+
// }
|
|
775
|
+
// }
|
|
812
776
|
continue;
|
|
813
777
|
}
|
|
814
778
|
if (v.typ === EnumToken.MathFunctionTokenType ||
|
|
@@ -816,18 +780,20 @@ function isColor(token, errors) {
|
|
|
816
780
|
colorsFunc.includes(v.val)) {
|
|
817
781
|
continue;
|
|
818
782
|
}
|
|
819
|
-
if (
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
783
|
+
// if (
|
|
784
|
+
// ![
|
|
785
|
+
// EnumToken.ColorTokenType,
|
|
786
|
+
// EnumToken.IdenTokenType,
|
|
787
|
+
// EnumToken.NumberTokenType,
|
|
788
|
+
// EnumToken.AngleTokenType,
|
|
789
|
+
// EnumToken.PercentageTokenType,
|
|
790
|
+
// EnumToken.CommaTokenType,
|
|
791
|
+
// EnumToken.WhitespaceTokenType,
|
|
792
|
+
// EnumToken.LiteralTokenType,
|
|
793
|
+
// ].includes(v.typ)
|
|
794
|
+
// ) {
|
|
795
|
+
// return false;
|
|
796
|
+
// }
|
|
831
797
|
}
|
|
832
798
|
}
|
|
833
799
|
return true;
|
|
@@ -883,65 +849,63 @@ function parseColor(token) {
|
|
|
883
849
|
}
|
|
884
850
|
if (token.val == "color") {
|
|
885
851
|
let index = token.chi.indexOf(tk);
|
|
886
|
-
if (token.cal == "rel") {
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
}
|
|
852
|
+
// if ((token as ColorToken).cal == "rel") {
|
|
853
|
+
// for (let k = 0; k < (token as ColorToken).chi!.length; k++) {
|
|
854
|
+
// if (EnumToken.DashedIdenTokenType == (token as ColorToken).chi![k].typ) {
|
|
855
|
+
// index = k;
|
|
856
|
+
// break;
|
|
857
|
+
// }
|
|
858
|
+
// }
|
|
859
|
+
// }
|
|
894
860
|
if (EnumToken.DashedIdenTokenType == token?.chi?.[index]?.typ) {
|
|
895
861
|
token.kin = ColorType.CUSTOM_COLOR;
|
|
896
862
|
}
|
|
897
863
|
}
|
|
898
864
|
}
|
|
899
|
-
return token;
|
|
900
|
-
}
|
|
901
|
-
// @ts-ignore
|
|
902
|
-
token.typ = EnumToken.ColorTokenType;
|
|
903
|
-
// @ts-ignore
|
|
904
|
-
token.kin = ColorType[token.val.replaceAll("-", "_").toUpperCase()];
|
|
905
|
-
if (!("chi" in token)) {
|
|
906
|
-
const val = token.val.toLowerCase();
|
|
907
|
-
if (val == "currentcolor" || val == "transparent" || val in COLORS_NAMES) {
|
|
908
|
-
token.kin = ColorType.LIT;
|
|
909
|
-
}
|
|
910
|
-
else if (isHexColor(val)) {
|
|
911
|
-
token.kin = ColorType.HEX;
|
|
912
|
-
}
|
|
913
|
-
const tk = token.chi?.find((t) => t.typ !== EnumToken.WhitespaceTokenType && t.typ !== EnumToken.CommentTokenType);
|
|
914
|
-
if (tk?.typ === EnumToken.IdenTokenType && tk.val === "from") {
|
|
915
|
-
token.cal = "rel";
|
|
916
|
-
}
|
|
917
|
-
else if (token.val == "color-mix" && tk.val == "in") {
|
|
918
|
-
token.cal = "mix";
|
|
919
|
-
}
|
|
920
|
-
else if (token.val == "color") {
|
|
921
|
-
token.cal = "col";
|
|
922
|
-
}
|
|
923
|
-
return token;
|
|
865
|
+
// return token;
|
|
924
866
|
}
|
|
925
867
|
// @ts-ignore
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
868
|
+
// token.typ = EnumToken.ColorTokenType;
|
|
869
|
+
// // @ts-ignore
|
|
870
|
+
// (token as ColorToken).kin = ColorType[token.val.replaceAll("-", "_").toUpperCase()];
|
|
871
|
+
// if (!("chi" in token)) {
|
|
872
|
+
// const val: string = (token as ColorToken).val.toLowerCase();
|
|
873
|
+
// if (val == "currentcolor" || val == "transparent" || val in COLORS_NAMES) {
|
|
874
|
+
// (token as ColorToken).kin = ColorType.LIT;
|
|
875
|
+
// } else if (isHexColor(val)) {
|
|
876
|
+
// (token as ColorToken).kin = ColorType.HEX;
|
|
877
|
+
// }
|
|
878
|
+
// const tk = (token as ColorToken).chi?.find(
|
|
879
|
+
// (t) => t.typ !== EnumToken.WhitespaceTokenType && t.typ !== EnumToken.CommentTokenType,
|
|
880
|
+
// );
|
|
881
|
+
// if (tk?.typ === EnumToken.IdenTokenType && (tk as IdentToken).val === "from") {
|
|
882
|
+
// (token as ColorToken).cal = "rel";
|
|
883
|
+
// } else if ((token as ColorToken).val == "color-mix" && (tk as IdentToken).val == "in") {
|
|
884
|
+
// (token as ColorToken).cal = "mix";
|
|
885
|
+
// } else if ((token as ColorToken).val == "color") {
|
|
886
|
+
// (token as ColorToken).cal = "col";
|
|
887
|
+
// }
|
|
888
|
+
// return token;
|
|
889
|
+
// }
|
|
890
|
+
// // @ts-ignore
|
|
891
|
+
// if (((token as ColorToken).chi as Token[])[0].typ == EnumToken.IdenTokenType) {
|
|
892
|
+
// // @ts-ignore
|
|
893
|
+
// if (((token as ColorToken).chi as Token[])[0].val == "from") {
|
|
894
|
+
// // @ts-ignore
|
|
895
|
+
// (token as ColorToken).cal = "rel";
|
|
896
|
+
// }
|
|
897
|
+
// // @ts-ignore
|
|
898
|
+
// else if ((token as ColorToken).val == "color-mix" && ((token as ColorToken).chi as Token[])[0].val == "in") {
|
|
899
|
+
// // @ts-ignore
|
|
900
|
+
// (token as ColorToken).cal = "mix";
|
|
901
|
+
// } else {
|
|
902
|
+
// // @ts-ignore
|
|
903
|
+
// if ((token as ColorToken).val == "color") {
|
|
904
|
+
// // @ts-ignore
|
|
905
|
+
// (token as ColorToken).cal = "col";
|
|
906
|
+
// }
|
|
907
|
+
// }
|
|
908
|
+
// }
|
|
945
909
|
return token;
|
|
946
910
|
}
|
|
947
911
|
function isLetter(codepoint) {
|
|
@@ -964,7 +928,7 @@ function isIdentCodepoint(codepoint) {
|
|
|
964
928
|
// -
|
|
965
929
|
return codepoint == 0x2d || isDigit(codepoint) || isIdentStart(codepoint);
|
|
966
930
|
}
|
|
967
|
-
|
|
931
|
+
const isIdent = memoize(function (name) {
|
|
968
932
|
const j = name.length - 1;
|
|
969
933
|
let i = 0;
|
|
970
934
|
let codepoint = name.charCodeAt(0);
|
|
@@ -974,9 +938,9 @@ function isIdent(name) {
|
|
|
974
938
|
if (Number.isNaN(nextCodepoint)) {
|
|
975
939
|
return false;
|
|
976
940
|
}
|
|
977
|
-
if (nextCodepoint == REVERSE_SOLIDUS) {
|
|
978
|
-
|
|
979
|
-
}
|
|
941
|
+
// if (nextCodepoint == REVERSE_SOLIDUS) {
|
|
942
|
+
// return name.length > 2 && !isNewLine(name.charCodeAt(2) as number);
|
|
943
|
+
// }
|
|
980
944
|
if (isDigit(nextCodepoint)) {
|
|
981
945
|
return false;
|
|
982
946
|
}
|
|
@@ -988,16 +952,16 @@ function isIdent(name) {
|
|
|
988
952
|
}
|
|
989
953
|
if (codepoint == REVERSE_SOLIDUS) {
|
|
990
954
|
codepoint = name.charCodeAt(i + 1);
|
|
991
|
-
if (!isIdentCodepoint(codepoint)) {
|
|
992
|
-
|
|
993
|
-
}
|
|
955
|
+
// if (!isIdentCodepoint(codepoint)) {
|
|
956
|
+
// return false;
|
|
957
|
+
// }
|
|
994
958
|
i += String.fromCodePoint(codepoint).length;
|
|
995
|
-
if (i < j) {
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
}
|
|
959
|
+
// if (i < j) {
|
|
960
|
+
// codepoint = name.charCodeAt(i) as number;
|
|
961
|
+
// if (!isIdentCodepoint(codepoint)) {
|
|
962
|
+
// return false;
|
|
963
|
+
// }
|
|
964
|
+
// }
|
|
1001
965
|
}
|
|
1002
966
|
while (i < j) {
|
|
1003
967
|
i += codepoint < 0x80 ? 1 : String.fromCodePoint(codepoint).length;
|
|
@@ -1013,7 +977,7 @@ function isIdent(name) {
|
|
|
1013
977
|
}
|
|
1014
978
|
}
|
|
1015
979
|
return true;
|
|
1016
|
-
}
|
|
980
|
+
});
|
|
1017
981
|
function isPseudo(name) {
|
|
1018
982
|
return (name.charAt(0) == ":" &&
|
|
1019
983
|
((name.endsWith("(") && isIdent(name.charAt(1) == ":" ? name.slice(2, -1) : name.slice(1, -1))) ||
|
|
@@ -1022,10 +986,10 @@ function isPseudo(name) {
|
|
|
1022
986
|
function isHash(name) {
|
|
1023
987
|
return name.charAt(0) == "#" && isIdent(name.charAt(1));
|
|
1024
988
|
}
|
|
1025
|
-
|
|
1026
|
-
if (name.length == 0) {
|
|
1027
|
-
|
|
1028
|
-
}
|
|
989
|
+
const isNumber = memoize(function (name) {
|
|
990
|
+
// if (name.length == 0) {
|
|
991
|
+
// return false;
|
|
992
|
+
// }
|
|
1029
993
|
let codepoint = name.charCodeAt(0);
|
|
1030
994
|
let i = 0;
|
|
1031
995
|
const j = name.length;
|
|
@@ -1070,27 +1034,27 @@ function isNumber(name) {
|
|
|
1070
1034
|
}
|
|
1071
1035
|
// 'E' 'e'
|
|
1072
1036
|
if (codepoint == 0x45 || codepoint == 0x65) {
|
|
1073
|
-
if (i == j) {
|
|
1074
|
-
|
|
1075
|
-
}
|
|
1037
|
+
// if (i == j) {
|
|
1038
|
+
// return false;
|
|
1039
|
+
// }
|
|
1076
1040
|
codepoint = name.charCodeAt(i + 1);
|
|
1077
1041
|
// '+' '-'
|
|
1078
|
-
if ([0x2b, 0x2d].includes(codepoint)) {
|
|
1079
|
-
|
|
1080
|
-
}
|
|
1042
|
+
// if ([0x2b, 0x2d].includes(codepoint)) {
|
|
1043
|
+
// i++;
|
|
1044
|
+
// }
|
|
1081
1045
|
codepoint = name.charCodeAt(i + 1);
|
|
1082
1046
|
if (!isDigit(codepoint)) {
|
|
1083
1047
|
return false;
|
|
1084
1048
|
}
|
|
1085
1049
|
}
|
|
1086
|
-
while (++i < j) {
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
}
|
|
1050
|
+
// while (++i < j) {
|
|
1051
|
+
// codepoint = name.charCodeAt(i) as number;
|
|
1052
|
+
// if (!isDigit(codepoint)) {
|
|
1053
|
+
// return false;
|
|
1054
|
+
// }
|
|
1055
|
+
// }
|
|
1092
1056
|
return true;
|
|
1093
|
-
}
|
|
1057
|
+
});
|
|
1094
1058
|
function isPercentage(name) {
|
|
1095
1059
|
return name.endsWith("%") && isNumber(name.slice(0, -1));
|
|
1096
1060
|
}
|
|
@@ -1185,28 +1149,5 @@ function isWhiteSpace(codepoint) {
|
|
|
1185
1149
|
codepoint == 0x2028 ||
|
|
1186
1150
|
codepoint == 0x2029);
|
|
1187
1151
|
}
|
|
1188
|
-
function isValue(token) {
|
|
1189
|
-
if (token == null) {
|
|
1190
|
-
return false;
|
|
1191
|
-
}
|
|
1192
|
-
return (token.typ === EnumToken.IdenTokenType ||
|
|
1193
|
-
token.typ === EnumToken.DimensionTokenType ||
|
|
1194
|
-
token.typ === EnumToken.LengthTokenType ||
|
|
1195
|
-
token.typ === EnumToken.AngleTokenType ||
|
|
1196
|
-
token.typ === EnumToken.FlexTokenType ||
|
|
1197
|
-
token.typ === EnumToken.TimeTokenType ||
|
|
1198
|
-
token.typ === EnumToken.ResolutionTokenType ||
|
|
1199
|
-
token.typ === EnumToken.FrequencyTokenType ||
|
|
1200
|
-
token.typ === EnumToken.NumberTokenType ||
|
|
1201
|
-
token.typ === EnumToken.ColorTokenType ||
|
|
1202
|
-
token.typ === EnumToken.FunctionTokenType ||
|
|
1203
|
-
token.typ === EnumToken.UrlFunctionTokenType ||
|
|
1204
|
-
token.typ === EnumToken.GridTemplateFuncTokenType ||
|
|
1205
|
-
token.typ === EnumToken.ImageFunctionTokenType ||
|
|
1206
|
-
token.typ === EnumToken.TimelineFunctionTokenType ||
|
|
1207
|
-
token.typ === EnumToken.TimingFunctionTokenType ||
|
|
1208
|
-
token.typ === EnumToken.MathFunctionTokenType ||
|
|
1209
|
-
token.typ === EnumToken.TransformFunctionTokenType);
|
|
1210
|
-
}
|
|
1211
1152
|
|
|
1212
|
-
export { dimensionUnits, isAngle, isColor,
|
|
1153
|
+
export { dimensionUnits, isAngle, isColor, isDigit, isFlex, isFrequency, isFunction, isHash, isHexColor, isIdent, isIdentCodepoint, isIdentColor, isIdentStart, isLength, isLetter, isNewLine, isNumber, isPercentage, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolution, isTime, isWhiteSpace, parseColor, parseDimension, pseudoAliasMap, reduceColorStops, reduceConicColorStops, reducegradientBackgroundPosition, renamedStandardProperties };
|