@tbela99/css-parser 1.4.11 → 1.6.0
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 +39 -0
- package/README.md +18 -11
- package/dist/index-umd-web.js +6558 -5310
- package/dist/index.cjs +6576 -5313
- package/dist/index.d.ts +805 -279
- package/dist/lib/ast/clone.js +13 -8
- package/dist/lib/ast/expand.js +65 -15
- package/dist/lib/ast/features/calc.js +19 -56
- package/dist/lib/ast/features/if.js +28 -4
- package/dist/lib/ast/features/inlinecssvariables.js +6 -5
- package/dist/lib/ast/features/prefix.js +52 -73
- package/dist/lib/ast/features/shorthand.js +11 -6
- package/dist/lib/ast/features/transform.js +6 -3
- package/dist/lib/ast/find.js +7 -5
- package/dist/lib/ast/math/expression.js +190 -32
- package/dist/lib/ast/minify.js +117 -49
- package/dist/lib/ast/node.js +52 -0
- package/dist/lib/ast/transform/compute.js +63 -4
- package/dist/lib/ast/transform/minify.js +6 -6
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.js +1 -1
- package/dist/lib/ast/transform/scale.js +1 -1
- package/dist/lib/ast/transform/skew.js +1 -1
- package/dist/lib/ast/transform/translate.js +1 -1
- package/dist/lib/ast/transform/utils.js +46 -18
- package/dist/lib/ast/types.js +1 -1
- package/dist/lib/ast/walk.js +55 -11
- package/dist/lib/fs/resolve.js +68 -27
- package/dist/lib/parser/declaration/list.js +22 -7
- package/dist/lib/parser/declaration/map.js +40 -13
- package/dist/lib/parser/declaration/set.js +3 -1
- package/dist/lib/parser/linesmap.js +2 -12
- package/dist/lib/parser/parse.js +843 -912
- package/dist/lib/parser/source.js +16 -2
- package/dist/lib/parser/tokenize.js +1489 -725
- package/dist/lib/parser/utils/at-rule-container.js +29 -196
- package/dist/lib/parser/utils/at-rule-generic.js +6 -7
- package/dist/lib/parser/utils/at-rule-import.js +17 -13
- package/dist/lib/parser/utils/at-rule-media.js +36 -19
- package/dist/lib/parser/utils/at-rule-support.js +19 -9
- package/dist/lib/parser/utils/at-rule-when-else.js +11 -38
- package/dist/lib/parser/utils/at-rule.js +0 -18
- package/dist/lib/parser/utils/declaration.js +30 -95
- package/dist/lib/parser/utils/hash.js +4 -4
- package/dist/lib/parser/utils/selector.js +164 -141
- package/dist/lib/parser/utils/text.js +4 -2
- package/dist/lib/renderer/render.js +230 -125
- package/dist/lib/renderer/sourcemap/lib/codec.js +78 -0
- package/dist/lib/renderer/sourcemap/sourcemap.js +187 -34
- package/dist/lib/syntax/color/a98rgb.js +14 -4
- package/dist/lib/syntax/color/cmyk.js +10 -18
- package/dist/lib/syntax/color/color-mix.js +21 -34
- package/dist/lib/syntax/color/color.js +32 -49
- package/dist/lib/syntax/color/hsl.js +15 -15
- package/dist/lib/syntax/color/hwb.js +18 -17
- package/dist/lib/syntax/color/lab.js +17 -17
- package/dist/lib/syntax/color/lch.js +13 -13
- package/dist/lib/syntax/color/oklab.js +10 -11
- package/dist/lib/syntax/color/oklch.js +15 -18
- package/dist/lib/syntax/color/p3.js +18 -12
- package/dist/lib/syntax/color/prophotorgb.js +26 -28
- package/dist/lib/syntax/color/rec2020.js +8 -4
- package/dist/lib/syntax/color/relative-color.js +26 -10
- package/dist/lib/syntax/color/srgb.js +5 -4
- package/dist/lib/syntax/color/utils/distance.js +1 -1
- package/dist/lib/syntax/color/xyz.js +2 -2
- package/dist/lib/syntax/color/xyzd50.js +2 -2
- package/dist/lib/syntax/constants.js +12 -2
- package/dist/lib/syntax/syntax.js +45 -258
- package/dist/lib/validation/config.json.js +3 -0
- package/dist/lib/validation/match.js +110 -27
- package/dist/node.js +55 -33
- package/dist/types.d.ts +5 -1
- package/dist/types.js +4 -0
- package/dist/utils/sync.d.ts +16 -0
- package/dist/utils/sync.js +73 -0
- package/dist/web.js +37 -30
- package/package.json +1 -1
- package/dist/lib/renderer/sourcemap/lib/encode.js +0 -37
- package/llms.txt +0 -73
|
@@ -8,14 +8,19 @@ import { trimArray } from '../validation/match.js';
|
|
|
8
8
|
import { splitTokenList } from '../validation/utils/list.js';
|
|
9
9
|
import { getColorSpace } from './color/utils/colorspace.js';
|
|
10
10
|
import { getColorComponents } from './color/utils/components.js';
|
|
11
|
-
import { nonStandardColors, systemColors, deprecatedSystemColors, COLORS_NAMES, colorsFunc, colorFuncColorSpace, colorPrecision, epsilon
|
|
11
|
+
import { anglePrecision, nonStandardColors, systemColors, deprecatedSystemColors, COLORS_NAMES, colorsFunc, colorFuncColorSpace, colorPrecision, epsilon } from './constants.js';
|
|
12
12
|
import { getSyntaxConfig } from '../validation/config.js';
|
|
13
13
|
|
|
14
14
|
// https://www.w3.org/TR/CSS21/syndata.html#syntax
|
|
15
15
|
// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token
|
|
16
16
|
// '\\'
|
|
17
17
|
const REVERSE_SOLIDUS = 0x5c;
|
|
18
|
-
const
|
|
18
|
+
const flexUnits = ["fr"];
|
|
19
|
+
const frequencyUnits = ["hz", "khz"];
|
|
20
|
+
const timeUnits = ["ms", "s"];
|
|
21
|
+
const angleUnits = ["rad", "turn", "deg", "grad"];
|
|
22
|
+
const resolutionUnits = ["dpi", "dpcm", "dppx", "x"];
|
|
23
|
+
const dimensionUnits = [
|
|
19
24
|
"q",
|
|
20
25
|
"cap",
|
|
21
26
|
"ch",
|
|
@@ -59,7 +64,7 @@ const dimensionUnits = new Set([
|
|
|
59
64
|
"vmax",
|
|
60
65
|
"vmin",
|
|
61
66
|
"vw",
|
|
62
|
-
]
|
|
67
|
+
];
|
|
63
68
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions
|
|
64
69
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions
|
|
65
70
|
const pseudoAliasMap = {
|
|
@@ -196,19 +201,19 @@ const pseudoAliasMap = {
|
|
|
196
201
|
// renamed standard properties
|
|
197
202
|
const renamedStandardProperties = new Map([["color-adjust", "print-color-adjust"]]);
|
|
198
203
|
function isLength(dimension) {
|
|
199
|
-
return "unit" in dimension && dimensionUnits.
|
|
204
|
+
return "unit" in dimension && dimensionUnits.includes(dimension.unit.toLowerCase());
|
|
200
205
|
}
|
|
201
206
|
function isResolution(dimension) {
|
|
202
|
-
return "unit" in dimension &&
|
|
207
|
+
return "unit" in dimension && resolutionUnits.includes(dimension.unit.toLowerCase());
|
|
203
208
|
}
|
|
204
209
|
function isAngle(dimension) {
|
|
205
|
-
return "unit" in dimension &&
|
|
210
|
+
return "unit" in dimension && angleUnits.includes(dimension.unit.toLowerCase());
|
|
206
211
|
}
|
|
207
212
|
function isTime(dimension) {
|
|
208
|
-
return "unit" in dimension &&
|
|
213
|
+
return "unit" in dimension && timeUnits.includes(dimension.unit.toLowerCase());
|
|
209
214
|
}
|
|
210
215
|
function isFrequency(dimension) {
|
|
211
|
-
return "unit" in dimension &&
|
|
216
|
+
return "unit" in dimension && frequencyUnits.includes(dimension.unit.toLowerCase());
|
|
212
217
|
}
|
|
213
218
|
/**
|
|
214
219
|
* Reduce color stops
|
|
@@ -231,7 +236,9 @@ function reduceColorStops(stops) {
|
|
|
231
236
|
if (parts[i - 1].length == 1) {
|
|
232
237
|
parts[i - 1].push({ typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.PercentageTokenType, val: ((k - 1) * 100) / n });
|
|
233
238
|
}
|
|
234
|
-
|
|
239
|
+
for (let m = 1; m < parts[i].length; m++) {
|
|
240
|
+
parts[i - 1].push(parts[i][m]);
|
|
241
|
+
}
|
|
235
242
|
parts.splice(i--, 1);
|
|
236
243
|
updated = true;
|
|
237
244
|
continue;
|
|
@@ -255,7 +262,9 @@ function reduceColorStops(stops) {
|
|
|
255
262
|
if (stops.length > 0) {
|
|
256
263
|
stops.push({ typ: EnumToken.CommaTokenType });
|
|
257
264
|
}
|
|
258
|
-
|
|
265
|
+
for (let m = 0; m < parts[j].length; m++) {
|
|
266
|
+
stops.push(parts[j][m]);
|
|
267
|
+
}
|
|
259
268
|
}
|
|
260
269
|
}
|
|
261
270
|
return stops;
|
|
@@ -353,7 +362,9 @@ function reduceConicColorStops(stops) {
|
|
|
353
362
|
if (parts[i - 1].length == 1) {
|
|
354
363
|
parts[i - 1].push({ typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.AngleTokenType, val: ((k - 1) * 100) / n, unit: "deg" });
|
|
355
364
|
}
|
|
356
|
-
|
|
365
|
+
for (let m = 1; m < parts[i].length; m++) {
|
|
366
|
+
parts[i - 1].push(parts[i][m]);
|
|
367
|
+
}
|
|
357
368
|
parts.splice(i--, 1);
|
|
358
369
|
updated = true;
|
|
359
370
|
continue;
|
|
@@ -376,7 +387,9 @@ function reduceConicColorStops(stops) {
|
|
|
376
387
|
if (stops.length > 0) {
|
|
377
388
|
stops.push({ typ: EnumToken.CommaTokenType });
|
|
378
389
|
}
|
|
379
|
-
|
|
390
|
+
for (const token of parts[j]) {
|
|
391
|
+
stops.push(token);
|
|
392
|
+
}
|
|
380
393
|
}
|
|
381
394
|
}
|
|
382
395
|
return stops;
|
|
@@ -591,7 +604,6 @@ function isColor(token, errors) {
|
|
|
591
604
|
action: "drop",
|
|
592
605
|
message: `Invalid color`,
|
|
593
606
|
node: token,
|
|
594
|
-
// location: options.source!.getSourLocation(token[LOC]!.sta),
|
|
595
607
|
});
|
|
596
608
|
return false;
|
|
597
609
|
}
|
|
@@ -614,31 +626,6 @@ function isColor(token, errors) {
|
|
|
614
626
|
if (children.length == 4 || (isRelative && children.length == 6)) {
|
|
615
627
|
return true;
|
|
616
628
|
}
|
|
617
|
-
if (children.length == 8 || children.length == 6) {
|
|
618
|
-
children.at(-2);
|
|
619
|
-
children.at(-1);
|
|
620
|
-
// @ts-ignore
|
|
621
|
-
// if (
|
|
622
|
-
// ((children.length > 6 || !isRelative) && sep.typ != EnumToken.LiteralTokenType) ||
|
|
623
|
-
// (sep as LiteralToken).val != "/"
|
|
624
|
-
// ) {
|
|
625
|
-
// return false;
|
|
626
|
-
// }
|
|
627
|
-
// if (alpha.typ == EnumToken.IdenTokenType && (alpha as IdentToken).val != "none") {
|
|
628
|
-
// return false;
|
|
629
|
-
// } else {
|
|
630
|
-
// // @ts-ignore
|
|
631
|
-
// if (alpha.typ == EnumToken.PercentageTokenType) {
|
|
632
|
-
// if (+(alpha as PercentageToken).val < 0 || +(alpha as PercentageToken).val > 100) {
|
|
633
|
-
// return false;
|
|
634
|
-
// }
|
|
635
|
-
// } else if (alpha.typ == EnumToken.NumberTokenType) {
|
|
636
|
-
// if (+(alpha as NumberToken).val < 0 || +(alpha as NumberToken).val > 1) {
|
|
637
|
-
// return false;
|
|
638
|
-
// }
|
|
639
|
-
// }
|
|
640
|
-
// }
|
|
641
|
-
}
|
|
642
629
|
return true;
|
|
643
630
|
}
|
|
644
631
|
// @ts-ignore
|
|
@@ -655,9 +642,6 @@ function isColor(token, errors) {
|
|
|
655
642
|
}
|
|
656
643
|
return acc;
|
|
657
644
|
}, [[]]);
|
|
658
|
-
// if (children.length === 0 || children[0].length === 0) {
|
|
659
|
-
// return false;
|
|
660
|
-
// }
|
|
661
645
|
let j = 0;
|
|
662
646
|
let k = 0;
|
|
663
647
|
if (children[j][0].typ === EnumToken.IdenTokenType &&
|
|
@@ -691,77 +675,24 @@ function isColor(token, errors) {
|
|
|
691
675
|
k++;
|
|
692
676
|
}
|
|
693
677
|
}
|
|
694
|
-
// else {
|
|
695
|
-
// return false;
|
|
696
|
-
// }
|
|
697
678
|
}
|
|
698
679
|
else {
|
|
699
680
|
k++;
|
|
700
681
|
}
|
|
701
682
|
}
|
|
702
|
-
// else {
|
|
703
|
-
// return false;
|
|
704
|
-
// }
|
|
705
|
-
// if (k != children[j].length) {
|
|
706
|
-
// return false;
|
|
707
|
-
// }
|
|
708
683
|
j++;
|
|
709
684
|
}
|
|
710
|
-
// while (j < children.length) {
|
|
711
|
-
// if (children[j].length > 2) {
|
|
712
|
-
// return false;
|
|
713
|
-
// }
|
|
714
|
-
// if (
|
|
715
|
-
// !isColor(children[j][0]) &&
|
|
716
|
-
// !(
|
|
717
|
-
// children[j][0].typ == EnumToken.WildCardFunctionTokenType &&
|
|
718
|
-
// equalsIgnoreCase("calc", (children[j][0] as FunctionToken).val)
|
|
719
|
-
// )
|
|
720
|
-
// ) {
|
|
721
|
-
// return false;
|
|
722
|
-
// }
|
|
723
|
-
// if (children[j][0].typ == EnumToken.WildCardFunctionTokenType) {
|
|
724
|
-
// const result = matchAllSyntaxes(
|
|
725
|
-
// getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc()") as ValidationFunctionToken[],
|
|
726
|
-
// createValidationContext([children[j][0]]),
|
|
727
|
-
// {},
|
|
728
|
-
// );
|
|
729
|
-
// if (!result.success) {
|
|
730
|
-
// return false;
|
|
731
|
-
// }
|
|
732
|
-
// }
|
|
733
|
-
// if (children[j].length > 1 && !isPercentageToken(children[j][1])) {
|
|
734
|
-
// return false;
|
|
735
|
-
// }
|
|
736
|
-
// j++;
|
|
737
|
-
// }
|
|
738
685
|
return true;
|
|
739
686
|
}
|
|
740
687
|
else {
|
|
741
|
-
const keywords = ["from", "none"];
|
|
742
688
|
// @ts-ignore
|
|
743
689
|
if (["rgb", "hsl", "hwb", "lab", "lch", "oklab", "oklch"].some((t) => equalsIgnoreCase(t, token.val))) {
|
|
744
|
-
|
|
745
|
-
|
|
690
|
+
for (const keyword of token.val.slice(-3).split("")) {
|
|
691
|
+
}
|
|
746
692
|
}
|
|
747
693
|
// @ts-ignore
|
|
748
694
|
for (const v of token.chi) {
|
|
749
695
|
if (v.typ == EnumToken.IdenTokenType) {
|
|
750
|
-
// if (isColor(v)) {
|
|
751
|
-
// continue;
|
|
752
|
-
// }
|
|
753
|
-
// if (!(keywords.includes(v.val) || COLORS_NAMES[v.val.toLowerCase()] != null)) {
|
|
754
|
-
// return false;
|
|
755
|
-
// }
|
|
756
|
-
// if (keywords.includes(v.val)) {
|
|
757
|
-
// if (isLegacySyntax) {
|
|
758
|
-
// return false;
|
|
759
|
-
// }
|
|
760
|
-
// // @ts-ignore
|
|
761
|
-
// if (v.val == "from" && ["rgba", "hsla"].includes((token as ColorToken).val)) {
|
|
762
|
-
// return false;
|
|
763
|
-
// }
|
|
764
|
-
// }
|
|
765
696
|
continue;
|
|
766
697
|
}
|
|
767
698
|
if (v.typ === EnumToken.MathFunctionTokenType ||
|
|
@@ -769,20 +700,6 @@ function isColor(token, errors) {
|
|
|
769
700
|
colorsFunc.includes(v.val)) {
|
|
770
701
|
continue;
|
|
771
702
|
}
|
|
772
|
-
// if (
|
|
773
|
-
// ![
|
|
774
|
-
// EnumToken.ColorTokenType,
|
|
775
|
-
// EnumToken.IdenTokenType,
|
|
776
|
-
// EnumToken.NumberTokenType,
|
|
777
|
-
// EnumToken.AngleTokenType,
|
|
778
|
-
// EnumToken.PercentageTokenType,
|
|
779
|
-
// EnumToken.CommaTokenType,
|
|
780
|
-
// EnumToken.WhitespaceTokenType,
|
|
781
|
-
// EnumToken.LiteralTokenType,
|
|
782
|
-
// ].includes(v.typ)
|
|
783
|
-
// ) {
|
|
784
|
-
// return false;
|
|
785
|
-
// }
|
|
786
703
|
}
|
|
787
704
|
}
|
|
788
705
|
return true;
|
|
@@ -838,63 +755,12 @@ function parseColor(token) {
|
|
|
838
755
|
}
|
|
839
756
|
if (token.val == "color") {
|
|
840
757
|
let index = token.chi.indexOf(tk);
|
|
841
|
-
// if ((token as ColorToken).cal == "rel") {
|
|
842
|
-
// for (let k = 0; k < (token as ColorToken).chi!.length; k++) {
|
|
843
|
-
// if (EnumToken.DashedIdenTokenType == (token as ColorToken).chi![k].typ) {
|
|
844
|
-
// index = k;
|
|
845
|
-
// break;
|
|
846
|
-
// }
|
|
847
|
-
// }
|
|
848
|
-
// }
|
|
849
758
|
if (EnumToken.DashedIdenTokenType == token?.chi?.[index]?.typ) {
|
|
850
759
|
token.kin = ColorType.CUSTOM_COLOR;
|
|
851
760
|
}
|
|
852
761
|
}
|
|
853
762
|
}
|
|
854
|
-
// return token;
|
|
855
763
|
}
|
|
856
|
-
// @ts-ignore
|
|
857
|
-
// token.typ = EnumToken.ColorTokenType;
|
|
858
|
-
// // @ts-ignore
|
|
859
|
-
// (token as ColorToken).kin = ColorType[token.val.replaceAll("-", "_").toUpperCase()];
|
|
860
|
-
// if (!("chi" in token)) {
|
|
861
|
-
// const val: string = (token as ColorToken).val.toLowerCase();
|
|
862
|
-
// if (val == "currentcolor" || val == "transparent" || val in COLORS_NAMES) {
|
|
863
|
-
// (token as ColorToken).kin = ColorType.LIT;
|
|
864
|
-
// } else if (isHexColor(val)) {
|
|
865
|
-
// (token as ColorToken).kin = ColorType.HEX;
|
|
866
|
-
// }
|
|
867
|
-
// const tk = (token as ColorToken).chi?.find(
|
|
868
|
-
// (t) => t.typ !== EnumToken.WhitespaceTokenType && t.typ !== EnumToken.CommentTokenType,
|
|
869
|
-
// );
|
|
870
|
-
// if (tk?.typ === EnumToken.IdenTokenType && (tk as IdentToken).val === "from") {
|
|
871
|
-
// (token as ColorToken).cal = "rel";
|
|
872
|
-
// } else if ((token as ColorToken).val == "color-mix" && (tk as IdentToken).val == "in") {
|
|
873
|
-
// (token as ColorToken).cal = "mix";
|
|
874
|
-
// } else if ((token as ColorToken).val == "color") {
|
|
875
|
-
// (token as ColorToken).cal = "col";
|
|
876
|
-
// }
|
|
877
|
-
// return token;
|
|
878
|
-
// }
|
|
879
|
-
// // @ts-ignore
|
|
880
|
-
// if (((token as ColorToken).chi as Token[])[0].typ == EnumToken.IdenTokenType) {
|
|
881
|
-
// // @ts-ignore
|
|
882
|
-
// if (((token as ColorToken).chi as Token[])[0].val == "from") {
|
|
883
|
-
// // @ts-ignore
|
|
884
|
-
// (token as ColorToken).cal = "rel";
|
|
885
|
-
// }
|
|
886
|
-
// // @ts-ignore
|
|
887
|
-
// else if ((token as ColorToken).val == "color-mix" && ((token as ColorToken).chi as Token[])[0].val == "in") {
|
|
888
|
-
// // @ts-ignore
|
|
889
|
-
// (token as ColorToken).cal = "mix";
|
|
890
|
-
// } else {
|
|
891
|
-
// // @ts-ignore
|
|
892
|
-
// if ((token as ColorToken).val == "color") {
|
|
893
|
-
// // @ts-ignore
|
|
894
|
-
// (token as ColorToken).cal = "col";
|
|
895
|
-
// }
|
|
896
|
-
// }
|
|
897
|
-
// }
|
|
898
764
|
return token;
|
|
899
765
|
}
|
|
900
766
|
function isLetter(codepoint) {
|
|
@@ -940,6 +806,9 @@ const isIdent = memoize(function (name) {
|
|
|
940
806
|
return false;
|
|
941
807
|
}
|
|
942
808
|
if (codepoint == REVERSE_SOLIDUS) {
|
|
809
|
+
if (i + 1 > j) {
|
|
810
|
+
return false;
|
|
811
|
+
}
|
|
943
812
|
codepoint = name.charCodeAt(i + 1);
|
|
944
813
|
// if (!isIdentCodepoint(codepoint)) {
|
|
945
814
|
// return false;
|
|
@@ -967,85 +836,22 @@ const isIdent = memoize(function (name) {
|
|
|
967
836
|
}
|
|
968
837
|
return true;
|
|
969
838
|
});
|
|
839
|
+
function isNonPrintable(codepoint) {
|
|
840
|
+
// null -> backspace
|
|
841
|
+
return ((codepoint >= 0 && codepoint <= 0x8) ||
|
|
842
|
+
// tab
|
|
843
|
+
codepoint == 0xb ||
|
|
844
|
+
// delete
|
|
845
|
+
codepoint == 0x7f ||
|
|
846
|
+
(codepoint >= 0xe && codepoint <= 0x1f));
|
|
847
|
+
}
|
|
970
848
|
function isPseudo(name) {
|
|
971
849
|
return (name.charAt(0) == ":" &&
|
|
972
850
|
((name.endsWith("(") && isIdent(name.charAt(1) == ":" ? name.slice(2, -1) : name.slice(1, -1))) ||
|
|
973
851
|
isIdent(name.charAt(1) == ":" ? name.slice(2) : name.slice(1))));
|
|
974
852
|
}
|
|
975
853
|
function isHash(name) {
|
|
976
|
-
return name.charAt(0) == "#" &&
|
|
977
|
-
}
|
|
978
|
-
const isNumber = memoize(function (name) {
|
|
979
|
-
// if (name.length == 0) {
|
|
980
|
-
// return false;
|
|
981
|
-
// }
|
|
982
|
-
let codepoint = name.charCodeAt(0);
|
|
983
|
-
let i = 0;
|
|
984
|
-
const j = name.length;
|
|
985
|
-
if (j == 1 && !isDigit(codepoint)) {
|
|
986
|
-
return false;
|
|
987
|
-
}
|
|
988
|
-
// '+' '-'
|
|
989
|
-
if ([0x2b, 0x2d].includes(codepoint)) {
|
|
990
|
-
i++;
|
|
991
|
-
}
|
|
992
|
-
// consume digits
|
|
993
|
-
while (i < j) {
|
|
994
|
-
codepoint = name.charCodeAt(i);
|
|
995
|
-
if (isDigit(codepoint)) {
|
|
996
|
-
i++;
|
|
997
|
-
continue;
|
|
998
|
-
}
|
|
999
|
-
// '.' 'E' 'e'
|
|
1000
|
-
if (codepoint == 0x2e || codepoint == 0x45 || codepoint == 0x65) {
|
|
1001
|
-
break;
|
|
1002
|
-
}
|
|
1003
|
-
return false;
|
|
1004
|
-
}
|
|
1005
|
-
// '.'
|
|
1006
|
-
if (codepoint == 0x2e) {
|
|
1007
|
-
if (!isDigit(name.charCodeAt(++i))) {
|
|
1008
|
-
return false;
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
while (i < j) {
|
|
1012
|
-
codepoint = name.charCodeAt(i);
|
|
1013
|
-
if (isDigit(codepoint)) {
|
|
1014
|
-
i++;
|
|
1015
|
-
continue;
|
|
1016
|
-
}
|
|
1017
|
-
// 'E' 'e'
|
|
1018
|
-
if (codepoint == 0x45 || codepoint == 0x65) {
|
|
1019
|
-
i++;
|
|
1020
|
-
break;
|
|
1021
|
-
}
|
|
1022
|
-
return false;
|
|
1023
|
-
}
|
|
1024
|
-
// 'E' 'e'
|
|
1025
|
-
if (codepoint == 0x45 || codepoint == 0x65) {
|
|
1026
|
-
// if (i == j) {
|
|
1027
|
-
// return false;
|
|
1028
|
-
// }
|
|
1029
|
-
codepoint = name.charCodeAt(i + 1);
|
|
1030
|
-
// '+' '-'
|
|
1031
|
-
// if ([0x2b, 0x2d].includes(codepoint)) {
|
|
1032
|
-
// i++;
|
|
1033
|
-
// }
|
|
1034
|
-
codepoint = name.charCodeAt(i + 1);
|
|
1035
|
-
if (!isDigit(codepoint)) {
|
|
1036
|
-
return false;
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
// while (++i < j) {
|
|
1040
|
-
// codepoint = name.charCodeAt(i) as number;
|
|
1041
|
-
// if (!isDigit(codepoint)) {
|
|
1042
|
-
// return false;
|
|
1043
|
-
// }
|
|
1044
|
-
// }
|
|
1045
|
-
return true;
|
|
1046
|
-
});
|
|
1047
|
-
function isPercentage(name) {
|
|
1048
|
-
return name.endsWith("%") && isNumber(name.slice(0, -1));
|
|
854
|
+
return name.charAt(0) == "#" && isIdentStart(name.charCodeAt(1));
|
|
1049
855
|
}
|
|
1050
856
|
function isFlex(dimension) {
|
|
1051
857
|
return "unit" in dimension && "fr" == dimension.unit.toLowerCase();
|
|
@@ -1087,9 +893,9 @@ function parseDimension(name) {
|
|
|
1087
893
|
else if (isResolution(dimension)) {
|
|
1088
894
|
// @ts-ignore
|
|
1089
895
|
dimension.typ = EnumToken.ResolutionTokenType;
|
|
1090
|
-
if (dimension.unit == "dppx") {
|
|
1091
|
-
|
|
1092
|
-
}
|
|
896
|
+
// if (dimension.unit == "dppx") {
|
|
897
|
+
// dimension.unit = "x";
|
|
898
|
+
// }
|
|
1093
899
|
}
|
|
1094
900
|
else if (isFrequency(dimension)) {
|
|
1095
901
|
// @ts-ignore
|
|
@@ -1101,22 +907,6 @@ function parseDimension(name) {
|
|
|
1101
907
|
}
|
|
1102
908
|
return dimension;
|
|
1103
909
|
}
|
|
1104
|
-
function isHexColor(name) {
|
|
1105
|
-
if (name.charAt(0) != "#" || ![4, 5, 7, 9].includes(name.length)) {
|
|
1106
|
-
return false;
|
|
1107
|
-
}
|
|
1108
|
-
for (let chr of name.slice(1)) {
|
|
1109
|
-
let codepoint = chr.charCodeAt(0);
|
|
1110
|
-
if (!isDigit(codepoint) &&
|
|
1111
|
-
// A-F
|
|
1112
|
-
!(codepoint >= 0x41 && codepoint <= 0x46) &&
|
|
1113
|
-
// a-f
|
|
1114
|
-
!(codepoint >= 0x61 && codepoint <= 0x66)) {
|
|
1115
|
-
return false;
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
return true;
|
|
1119
|
-
}
|
|
1120
910
|
function isFunction(name) {
|
|
1121
911
|
return name.endsWith("(") && isIdent(name.slice(0, -1));
|
|
1122
912
|
}
|
|
@@ -1211,18 +1001,15 @@ function toPrecisionValue(value, precision = colorPrecision) {
|
|
|
1211
1001
|
value = Math.round(value * div) / div;
|
|
1212
1002
|
return Math.abs(value) < epsilon ? 0 : value;
|
|
1213
1003
|
}
|
|
1214
|
-
function toPrecisionAngle(angle, precision =
|
|
1004
|
+
function toPrecisionAngle(angle, precision = anglePrecision, correctValue = true) {
|
|
1215
1005
|
angle = toPrecisionValue(angle, precision);
|
|
1216
1006
|
if (correctValue && Math.abs(angle) >= 360) {
|
|
1217
1007
|
angle %= 360;
|
|
1218
1008
|
}
|
|
1219
|
-
if (Math.abs(angle) < anglePrecision) {
|
|
1220
|
-
angle = 0;
|
|
1221
|
-
}
|
|
1222
1009
|
if (correctValue && angle < 0) {
|
|
1223
1010
|
angle += 360;
|
|
1224
1011
|
}
|
|
1225
1012
|
return angle;
|
|
1226
1013
|
}
|
|
1227
1014
|
|
|
1228
|
-
export { dimensionUnits, isAngle, isColor, isDigit, isFlex, isFrequency, isFunction, isHash,
|
|
1015
|
+
export { angleUnits, dimensionUnits, flexUnits, frequencyUnits, isAngle, isColor, isDigit, isFlex, isFrequency, isFunction, isHash, isIdent, isIdentCodepoint, isIdentColor, isIdentStart, isLength, isLetter, isNewLine, isNonPrintable, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolution, isTime, isWhiteSpace, length2Px, minifyNumber, parseColor, parseDimension, pseudoAliasMap, reduceColorStops, reduceConicColorStops, reducegradientBackgroundPosition, renamedStandardProperties, resolutionUnits, timeUnits, toPrecisionAngle, toPrecisionValue };
|
|
@@ -1814,6 +1814,9 @@ var declarations = {
|
|
|
1814
1814
|
"text-emphasis-style": {
|
|
1815
1815
|
syntax: "none | [ [ filled | open ] || [ dot | circle | double-circle | triangle | sesame ] ] | <string>"
|
|
1816
1816
|
},
|
|
1817
|
+
"text-fit": {
|
|
1818
|
+
syntax: "[ none | grow | shrink ] [consistent | per-line | per-line-all]? <percentage>?"
|
|
1819
|
+
},
|
|
1817
1820
|
"text-indent": {
|
|
1818
1821
|
syntax: "<length-percentage> && hanging? && each-line?"
|
|
1819
1822
|
},
|