@tbela99/css-parser 1.4.6 → 1.4.8
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 +23 -0
- package/README.md +1 -0
- package/dist/index-umd-web.js +6578 -6969
- package/dist/index.cjs +7808 -8197
- package/dist/index.d.ts +923 -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 +10 -2
- package/dist/lib/ast/walk.js +1 -1
- package/dist/lib/fs/resolve.js +47 -45
- package/dist/lib/parser/arena.js +206 -0
- package/dist/lib/parser/declaration/list.js +9 -10
- package/dist/lib/parser/declaration/map.js +13 -18
- package/dist/lib/parser/linemap.js +62 -0
- package/dist/lib/parser/parse.js +331 -504
- package/dist/lib/parser/source.js +72 -0
- 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 +284 -283
- 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 +152 -121
- package/dist/lib/syntax/color/alpha.js +1 -4
- package/dist/lib/syntax/color/color-mix.js +8 -1
- package/dist/lib/syntax/color/color.js +17 -9
- package/dist/lib/syntax/color/hex.js +1 -1
- package/dist/lib/syntax/color/p3.js +9 -1
- 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/distance.js +6 -1
- package/dist/lib/syntax/color/utils/matrix.js +12 -11
- package/dist/lib/syntax/constants.js +25 -3
- package/dist/lib/syntax/syntax.js +240 -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 +18 -14
- package/dist/web.js +12 -10
- package/package.json +4 -4
- package/dist/lib/validation/utils/whitespace.js +0 -17
- /package/dist/lib/syntax/color/{relativecolor.js → relative-color.js} +0 -0
|
@@ -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,38 @@ 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
|
-
return [
|
|
407
|
-
"srgb",
|
|
408
|
-
"srgb-linear",
|
|
409
|
-
"display-p3",
|
|
410
|
-
"a98-rgb",
|
|
411
|
-
"prophoto-rgb",
|
|
412
|
-
"rec2020",
|
|
413
|
-
"lab",
|
|
414
|
-
"oklab",
|
|
415
|
-
"xyz",
|
|
416
|
-
"xyz-d50",
|
|
417
|
-
"xyz-d65",
|
|
418
|
-
].some((t) => equalsIgnoreCase(t, token.val));
|
|
389
|
+
return (token.typ === EnumToken.IdenTokenType &&
|
|
390
|
+
colorFuncColorSpace.some((t) => equalsIgnoreCase(t, token.val)));
|
|
419
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* Is polar colorspace
|
|
394
|
+
* @param token
|
|
395
|
+
* @returns
|
|
396
|
+
*/
|
|
420
397
|
function isPolarColorspace(token) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
return ["hsl", "hwb", "lch", "oklch"].some((t) => equalsIgnoreCase(t, token.val));
|
|
398
|
+
return (token.typ === EnumToken.IdenTokenType &&
|
|
399
|
+
["hsl", "hwb", "lch", "oklch"].some((t) => equalsIgnoreCase(t, token.val)));
|
|
425
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* Is ident color
|
|
403
|
+
* @param token
|
|
404
|
+
* @returns
|
|
405
|
+
*/
|
|
426
406
|
function isIdentColor(token) {
|
|
427
407
|
return (token.typ == EnumToken.ColorTokenType &&
|
|
428
408
|
[ColorType.SYS, ColorType.DPSYS, ColorType.LIT].includes(token.kin) &&
|
|
429
409
|
isIdent(token.val));
|
|
430
410
|
}
|
|
431
|
-
function isPercentageToken(token) {
|
|
432
|
-
return (token.typ == EnumToken.PercentageTokenType ||
|
|
433
|
-
(token.typ == EnumToken.NumberTokenType && token.val == 0));
|
|
434
|
-
}
|
|
435
411
|
function isColor(token, errors) {
|
|
436
412
|
if (token.typ == EnumToken.WildCardFunctionTokenType) {
|
|
437
413
|
return true;
|
|
438
414
|
}
|
|
439
|
-
if (token.typ == EnumToken.FunctionTokenType) {
|
|
440
|
-
if (!colorsFunc.includes(token.val.toLowerCase())) {
|
|
441
|
-
return false;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
415
|
if (token.typ == EnumToken.ColorTokenType) {
|
|
445
416
|
if ("kin" in token && !("chi" in token)) {
|
|
446
417
|
return true;
|
|
@@ -454,11 +425,10 @@ function isColor(token, errors) {
|
|
|
454
425
|
// named color
|
|
455
426
|
return val in COLORS_NAMES || "currentcolor" === val || "transparent" === val;
|
|
456
427
|
}
|
|
457
|
-
let isLegacySyntax = false;
|
|
458
428
|
if (token.typ === EnumToken.FunctionTokenType || token.typ === EnumToken.ColorTokenType) {
|
|
459
|
-
if (!colorsFunc.includes(token.val.toLowerCase())) {
|
|
460
|
-
|
|
461
|
-
}
|
|
429
|
+
// if (!colorsFunc.includes((token as FunctionToken).val.toLowerCase())) {
|
|
430
|
+
// return false;
|
|
431
|
+
// }
|
|
462
432
|
if (token.chi.length > 0) {
|
|
463
433
|
// @ts-ignore
|
|
464
434
|
if (token.val === "light-dark") {
|
|
@@ -512,7 +482,7 @@ function isColor(token, errors) {
|
|
|
512
482
|
action: "drop",
|
|
513
483
|
message: `Unexpected constant '${val}'`,
|
|
514
484
|
node: value,
|
|
515
|
-
location: value
|
|
485
|
+
location: value[LOC],
|
|
516
486
|
});
|
|
517
487
|
return false;
|
|
518
488
|
}
|
|
@@ -538,12 +508,11 @@ function isColor(token, errors) {
|
|
|
538
508
|
!colorsFunc.includes(val) &&
|
|
539
509
|
!colorSpace.includes(val) &&
|
|
540
510
|
!colorFuncColorSpace.includes(val)) {
|
|
541
|
-
// console.debug({ val });
|
|
542
511
|
errors?.push({
|
|
543
512
|
action: "drop",
|
|
544
513
|
message: `Unexpected constant '${val}'`,
|
|
545
514
|
node: v.value,
|
|
546
|
-
location: v.value
|
|
515
|
+
location: v.value[LOC],
|
|
547
516
|
});
|
|
548
517
|
return false;
|
|
549
518
|
}
|
|
@@ -591,7 +560,7 @@ function isColor(token, errors) {
|
|
|
591
560
|
action: "drop",
|
|
592
561
|
message: "adding percentage and number is not allowed",
|
|
593
562
|
node: token,
|
|
594
|
-
location: token
|
|
563
|
+
location: token[LOC],
|
|
595
564
|
});
|
|
596
565
|
return false;
|
|
597
566
|
}
|
|
@@ -616,7 +585,13 @@ function isColor(token, errors) {
|
|
|
616
585
|
offset = 2;
|
|
617
586
|
}
|
|
618
587
|
if (children[offset]?.typ == EnumToken.DashedIdenTokenType) {
|
|
619
|
-
if (children.length
|
|
588
|
+
if (children.length <= offset + 1) {
|
|
589
|
+
errors?.push({
|
|
590
|
+
action: "drop",
|
|
591
|
+
message: `Invalid color at ${token[LOC]?.src}:${token[LOC]?.sta.lin}:${token[LOC]?.sta.col}`,
|
|
592
|
+
node: token,
|
|
593
|
+
location: token[LOC],
|
|
594
|
+
});
|
|
620
595
|
return false;
|
|
621
596
|
}
|
|
622
597
|
for (let i = offset + 1; i < children.length; i++) {
|
|
@@ -635,61 +610,33 @@ function isColor(token, errors) {
|
|
|
635
610
|
}
|
|
636
611
|
return true;
|
|
637
612
|
}
|
|
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
613
|
if (children.length == 4 || (isRelative && children.length == 6)) {
|
|
667
614
|
return true;
|
|
668
615
|
}
|
|
669
616
|
if (children.length == 8 || children.length == 6) {
|
|
670
|
-
|
|
671
|
-
|
|
617
|
+
children.at(-2);
|
|
618
|
+
children.at(-1);
|
|
672
619
|
// @ts-ignore
|
|
673
|
-
if (
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
}
|
|
620
|
+
// if (
|
|
621
|
+
// ((children.length > 6 || !isRelative) && sep.typ != EnumToken.LiteralTokenType) ||
|
|
622
|
+
// (sep as LiteralToken).val != "/"
|
|
623
|
+
// ) {
|
|
624
|
+
// return false;
|
|
625
|
+
// }
|
|
626
|
+
// if (alpha.typ == EnumToken.IdenTokenType && (alpha as IdentToken).val != "none") {
|
|
627
|
+
// return false;
|
|
628
|
+
// } else {
|
|
629
|
+
// // @ts-ignore
|
|
630
|
+
// if (alpha.typ == EnumToken.PercentageTokenType) {
|
|
631
|
+
// if (+(alpha as PercentageToken).val < 0 || +(alpha as PercentageToken).val > 100) {
|
|
632
|
+
// return false;
|
|
633
|
+
// }
|
|
634
|
+
// } else if (alpha.typ == EnumToken.NumberTokenType) {
|
|
635
|
+
// if (+(alpha as NumberToken).val < 0 || +(alpha as NumberToken).val > 1) {
|
|
636
|
+
// return false;
|
|
637
|
+
// }
|
|
638
|
+
// }
|
|
639
|
+
// }
|
|
693
640
|
}
|
|
694
641
|
return true;
|
|
695
642
|
}
|
|
@@ -707,9 +654,9 @@ function isColor(token, errors) {
|
|
|
707
654
|
}
|
|
708
655
|
return acc;
|
|
709
656
|
}, [[]]);
|
|
710
|
-
if (children.length === 0 || children[0].length === 0) {
|
|
711
|
-
|
|
712
|
-
}
|
|
657
|
+
// if (children.length === 0 || children[0].length === 0) {
|
|
658
|
+
// return false;
|
|
659
|
+
// }
|
|
713
660
|
let j = 0;
|
|
714
661
|
let k = 0;
|
|
715
662
|
if (children[j][0].typ === EnumToken.IdenTokenType &&
|
|
@@ -743,42 +690,50 @@ function isColor(token, errors) {
|
|
|
743
690
|
k++;
|
|
744
691
|
}
|
|
745
692
|
}
|
|
746
|
-
else {
|
|
747
|
-
|
|
748
|
-
}
|
|
693
|
+
// else {
|
|
694
|
+
// return false;
|
|
695
|
+
// }
|
|
749
696
|
}
|
|
750
697
|
else {
|
|
751
698
|
k++;
|
|
752
699
|
}
|
|
753
700
|
}
|
|
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
|
-
}
|
|
701
|
+
// else {
|
|
702
|
+
// return false;
|
|
703
|
+
// }
|
|
704
|
+
// if (k != children[j].length) {
|
|
705
|
+
// return false;
|
|
706
|
+
// }
|
|
780
707
|
j++;
|
|
781
708
|
}
|
|
709
|
+
// while (j < children.length) {
|
|
710
|
+
// if (children[j].length > 2) {
|
|
711
|
+
// return false;
|
|
712
|
+
// }
|
|
713
|
+
// if (
|
|
714
|
+
// !isColor(children[j][0]) &&
|
|
715
|
+
// !(
|
|
716
|
+
// children[j][0].typ == EnumToken.WildCardFunctionTokenType &&
|
|
717
|
+
// equalsIgnoreCase("calc", (children[j][0] as FunctionToken).val)
|
|
718
|
+
// )
|
|
719
|
+
// ) {
|
|
720
|
+
// return false;
|
|
721
|
+
// }
|
|
722
|
+
// if (children[j][0].typ == EnumToken.WildCardFunctionTokenType) {
|
|
723
|
+
// const result = matchAllSyntaxes(
|
|
724
|
+
// getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc()") as ValidationFunctionToken[],
|
|
725
|
+
// createValidationContext([children[j][0]]),
|
|
726
|
+
// {},
|
|
727
|
+
// );
|
|
728
|
+
// if (!result.success) {
|
|
729
|
+
// return false;
|
|
730
|
+
// }
|
|
731
|
+
// }
|
|
732
|
+
// if (children[j].length > 1 && !isPercentageToken(children[j][1])) {
|
|
733
|
+
// return false;
|
|
734
|
+
// }
|
|
735
|
+
// j++;
|
|
736
|
+
// }
|
|
782
737
|
return true;
|
|
783
738
|
}
|
|
784
739
|
else {
|
|
@@ -790,25 +745,22 @@ function isColor(token, errors) {
|
|
|
790
745
|
}
|
|
791
746
|
// @ts-ignore
|
|
792
747
|
for (const v of token.chi) {
|
|
793
|
-
if (v.typ == EnumToken.CommaTokenType) {
|
|
794
|
-
isLegacySyntax = true;
|
|
795
|
-
}
|
|
796
748
|
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
|
-
}
|
|
749
|
+
// if (isColor(v)) {
|
|
750
|
+
// continue;
|
|
751
|
+
// }
|
|
752
|
+
// if (!(keywords.includes(v.val) || COLORS_NAMES[v.val.toLowerCase()] != null)) {
|
|
753
|
+
// return false;
|
|
754
|
+
// }
|
|
755
|
+
// if (keywords.includes(v.val)) {
|
|
756
|
+
// if (isLegacySyntax) {
|
|
757
|
+
// return false;
|
|
758
|
+
// }
|
|
759
|
+
// // @ts-ignore
|
|
760
|
+
// if (v.val == "from" && ["rgba", "hsla"].includes((token as ColorToken).val)) {
|
|
761
|
+
// return false;
|
|
762
|
+
// }
|
|
763
|
+
// }
|
|
812
764
|
continue;
|
|
813
765
|
}
|
|
814
766
|
if (v.typ === EnumToken.MathFunctionTokenType ||
|
|
@@ -816,18 +768,20 @@ function isColor(token, errors) {
|
|
|
816
768
|
colorsFunc.includes(v.val)) {
|
|
817
769
|
continue;
|
|
818
770
|
}
|
|
819
|
-
if (
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
771
|
+
// if (
|
|
772
|
+
// ![
|
|
773
|
+
// EnumToken.ColorTokenType,
|
|
774
|
+
// EnumToken.IdenTokenType,
|
|
775
|
+
// EnumToken.NumberTokenType,
|
|
776
|
+
// EnumToken.AngleTokenType,
|
|
777
|
+
// EnumToken.PercentageTokenType,
|
|
778
|
+
// EnumToken.CommaTokenType,
|
|
779
|
+
// EnumToken.WhitespaceTokenType,
|
|
780
|
+
// EnumToken.LiteralTokenType,
|
|
781
|
+
// ].includes(v.typ)
|
|
782
|
+
// ) {
|
|
783
|
+
// return false;
|
|
784
|
+
// }
|
|
831
785
|
}
|
|
832
786
|
}
|
|
833
787
|
return true;
|
|
@@ -883,65 +837,63 @@ function parseColor(token) {
|
|
|
883
837
|
}
|
|
884
838
|
if (token.val == "color") {
|
|
885
839
|
let index = token.chi.indexOf(tk);
|
|
886
|
-
if (token.cal == "rel") {
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
}
|
|
840
|
+
// if ((token as ColorToken).cal == "rel") {
|
|
841
|
+
// for (let k = 0; k < (token as ColorToken).chi!.length; k++) {
|
|
842
|
+
// if (EnumToken.DashedIdenTokenType == (token as ColorToken).chi![k].typ) {
|
|
843
|
+
// index = k;
|
|
844
|
+
// break;
|
|
845
|
+
// }
|
|
846
|
+
// }
|
|
847
|
+
// }
|
|
894
848
|
if (EnumToken.DashedIdenTokenType == token?.chi?.[index]?.typ) {
|
|
895
849
|
token.kin = ColorType.CUSTOM_COLOR;
|
|
896
850
|
}
|
|
897
851
|
}
|
|
898
852
|
}
|
|
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;
|
|
853
|
+
// return token;
|
|
924
854
|
}
|
|
925
855
|
// @ts-ignore
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
856
|
+
// token.typ = EnumToken.ColorTokenType;
|
|
857
|
+
// // @ts-ignore
|
|
858
|
+
// (token as ColorToken).kin = ColorType[token.val.replaceAll("-", "_").toUpperCase()];
|
|
859
|
+
// if (!("chi" in token)) {
|
|
860
|
+
// const val: string = (token as ColorToken).val.toLowerCase();
|
|
861
|
+
// if (val == "currentcolor" || val == "transparent" || val in COLORS_NAMES) {
|
|
862
|
+
// (token as ColorToken).kin = ColorType.LIT;
|
|
863
|
+
// } else if (isHexColor(val)) {
|
|
864
|
+
// (token as ColorToken).kin = ColorType.HEX;
|
|
865
|
+
// }
|
|
866
|
+
// const tk = (token as ColorToken).chi?.find(
|
|
867
|
+
// (t) => t.typ !== EnumToken.WhitespaceTokenType && t.typ !== EnumToken.CommentTokenType,
|
|
868
|
+
// );
|
|
869
|
+
// if (tk?.typ === EnumToken.IdenTokenType && (tk as IdentToken).val === "from") {
|
|
870
|
+
// (token as ColorToken).cal = "rel";
|
|
871
|
+
// } else if ((token as ColorToken).val == "color-mix" && (tk as IdentToken).val == "in") {
|
|
872
|
+
// (token as ColorToken).cal = "mix";
|
|
873
|
+
// } else if ((token as ColorToken).val == "color") {
|
|
874
|
+
// (token as ColorToken).cal = "col";
|
|
875
|
+
// }
|
|
876
|
+
// return token;
|
|
877
|
+
// }
|
|
878
|
+
// // @ts-ignore
|
|
879
|
+
// if (((token as ColorToken).chi as Token[])[0].typ == EnumToken.IdenTokenType) {
|
|
880
|
+
// // @ts-ignore
|
|
881
|
+
// if (((token as ColorToken).chi as Token[])[0].val == "from") {
|
|
882
|
+
// // @ts-ignore
|
|
883
|
+
// (token as ColorToken).cal = "rel";
|
|
884
|
+
// }
|
|
885
|
+
// // @ts-ignore
|
|
886
|
+
// else if ((token as ColorToken).val == "color-mix" && ((token as ColorToken).chi as Token[])[0].val == "in") {
|
|
887
|
+
// // @ts-ignore
|
|
888
|
+
// (token as ColorToken).cal = "mix";
|
|
889
|
+
// } else {
|
|
890
|
+
// // @ts-ignore
|
|
891
|
+
// if ((token as ColorToken).val == "color") {
|
|
892
|
+
// // @ts-ignore
|
|
893
|
+
// (token as ColorToken).cal = "col";
|
|
894
|
+
// }
|
|
895
|
+
// }
|
|
896
|
+
// }
|
|
945
897
|
return token;
|
|
946
898
|
}
|
|
947
899
|
function isLetter(codepoint) {
|
|
@@ -964,7 +916,7 @@ function isIdentCodepoint(codepoint) {
|
|
|
964
916
|
// -
|
|
965
917
|
return codepoint == 0x2d || isDigit(codepoint) || isIdentStart(codepoint);
|
|
966
918
|
}
|
|
967
|
-
|
|
919
|
+
const isIdent = memoize(function (name) {
|
|
968
920
|
const j = name.length - 1;
|
|
969
921
|
let i = 0;
|
|
970
922
|
let codepoint = name.charCodeAt(0);
|
|
@@ -974,9 +926,9 @@ function isIdent(name) {
|
|
|
974
926
|
if (Number.isNaN(nextCodepoint)) {
|
|
975
927
|
return false;
|
|
976
928
|
}
|
|
977
|
-
if (nextCodepoint == REVERSE_SOLIDUS) {
|
|
978
|
-
|
|
979
|
-
}
|
|
929
|
+
// if (nextCodepoint == REVERSE_SOLIDUS) {
|
|
930
|
+
// return name.length > 2 && !isNewLine(name.charCodeAt(2) as number);
|
|
931
|
+
// }
|
|
980
932
|
if (isDigit(nextCodepoint)) {
|
|
981
933
|
return false;
|
|
982
934
|
}
|
|
@@ -988,16 +940,16 @@ function isIdent(name) {
|
|
|
988
940
|
}
|
|
989
941
|
if (codepoint == REVERSE_SOLIDUS) {
|
|
990
942
|
codepoint = name.charCodeAt(i + 1);
|
|
991
|
-
if (!isIdentCodepoint(codepoint)) {
|
|
992
|
-
|
|
993
|
-
}
|
|
943
|
+
// if (!isIdentCodepoint(codepoint)) {
|
|
944
|
+
// return false;
|
|
945
|
+
// }
|
|
994
946
|
i += String.fromCodePoint(codepoint).length;
|
|
995
|
-
if (i < j) {
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
}
|
|
947
|
+
// if (i < j) {
|
|
948
|
+
// codepoint = name.charCodeAt(i) as number;
|
|
949
|
+
// if (!isIdentCodepoint(codepoint)) {
|
|
950
|
+
// return false;
|
|
951
|
+
// }
|
|
952
|
+
// }
|
|
1001
953
|
}
|
|
1002
954
|
while (i < j) {
|
|
1003
955
|
i += codepoint < 0x80 ? 1 : String.fromCodePoint(codepoint).length;
|
|
@@ -1013,7 +965,7 @@ function isIdent(name) {
|
|
|
1013
965
|
}
|
|
1014
966
|
}
|
|
1015
967
|
return true;
|
|
1016
|
-
}
|
|
968
|
+
});
|
|
1017
969
|
function isPseudo(name) {
|
|
1018
970
|
return (name.charAt(0) == ":" &&
|
|
1019
971
|
((name.endsWith("(") && isIdent(name.charAt(1) == ":" ? name.slice(2, -1) : name.slice(1, -1))) ||
|
|
@@ -1022,10 +974,10 @@ function isPseudo(name) {
|
|
|
1022
974
|
function isHash(name) {
|
|
1023
975
|
return name.charAt(0) == "#" && isIdent(name.charAt(1));
|
|
1024
976
|
}
|
|
1025
|
-
|
|
1026
|
-
if (name.length == 0) {
|
|
1027
|
-
|
|
1028
|
-
}
|
|
977
|
+
const isNumber = memoize(function (name) {
|
|
978
|
+
// if (name.length == 0) {
|
|
979
|
+
// return false;
|
|
980
|
+
// }
|
|
1029
981
|
let codepoint = name.charCodeAt(0);
|
|
1030
982
|
let i = 0;
|
|
1031
983
|
const j = name.length;
|
|
@@ -1070,27 +1022,27 @@ function isNumber(name) {
|
|
|
1070
1022
|
}
|
|
1071
1023
|
// 'E' 'e'
|
|
1072
1024
|
if (codepoint == 0x45 || codepoint == 0x65) {
|
|
1073
|
-
if (i == j) {
|
|
1074
|
-
|
|
1075
|
-
}
|
|
1025
|
+
// if (i == j) {
|
|
1026
|
+
// return false;
|
|
1027
|
+
// }
|
|
1076
1028
|
codepoint = name.charCodeAt(i + 1);
|
|
1077
1029
|
// '+' '-'
|
|
1078
|
-
if ([0x2b, 0x2d].includes(codepoint)) {
|
|
1079
|
-
|
|
1080
|
-
}
|
|
1030
|
+
// if ([0x2b, 0x2d].includes(codepoint)) {
|
|
1031
|
+
// i++;
|
|
1032
|
+
// }
|
|
1081
1033
|
codepoint = name.charCodeAt(i + 1);
|
|
1082
1034
|
if (!isDigit(codepoint)) {
|
|
1083
1035
|
return false;
|
|
1084
1036
|
}
|
|
1085
1037
|
}
|
|
1086
|
-
while (++i < j) {
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
}
|
|
1038
|
+
// while (++i < j) {
|
|
1039
|
+
// codepoint = name.charCodeAt(i) as number;
|
|
1040
|
+
// if (!isDigit(codepoint)) {
|
|
1041
|
+
// return false;
|
|
1042
|
+
// }
|
|
1043
|
+
// }
|
|
1092
1044
|
return true;
|
|
1093
|
-
}
|
|
1045
|
+
});
|
|
1094
1046
|
function isPercentage(name) {
|
|
1095
1047
|
return name.endsWith("%") && isNumber(name.slice(0, -1));
|
|
1096
1048
|
}
|
|
@@ -1185,28 +1137,5 @@ function isWhiteSpace(codepoint) {
|
|
|
1185
1137
|
codepoint == 0x2028 ||
|
|
1186
1138
|
codepoint == 0x2029);
|
|
1187
1139
|
}
|
|
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
1140
|
|
|
1212
|
-
export { dimensionUnits, isAngle, isColor,
|
|
1141
|
+
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 };
|