@tbela99/css-parser 0.9.1 → 1.0.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/LICENSE.md +1 -1
- package/README.md +15 -8
- package/dist/index-umd-web.js +1815 -498
- package/dist/index.cjs +1816 -499
- package/dist/index.d.ts +46 -14
- package/dist/lib/ast/features/calc.js +7 -10
- package/dist/lib/ast/features/index.js +1 -0
- package/dist/lib/ast/features/inlinecssvariables.js +0 -5
- package/dist/lib/ast/features/prefix.js +2 -7
- package/dist/lib/ast/features/shorthand.js +6 -9
- package/dist/lib/ast/features/transform.js +60 -0
- package/dist/lib/ast/math/expression.js +14 -10
- package/dist/lib/ast/math/math.js +14 -2
- package/dist/lib/ast/minify.js +46 -5
- package/dist/lib/ast/transform/compute.js +336 -0
- package/dist/lib/ast/transform/convert.js +33 -0
- package/dist/lib/ast/transform/matrix.js +111 -0
- package/dist/lib/ast/transform/minify.js +296 -0
- package/dist/lib/ast/transform/perspective.js +10 -0
- package/dist/lib/ast/transform/rotate.js +40 -0
- package/dist/lib/ast/transform/scale.js +32 -0
- package/dist/lib/ast/transform/skew.js +23 -0
- package/dist/lib/ast/transform/translate.js +32 -0
- package/dist/lib/ast/transform/utils.js +198 -0
- package/dist/lib/ast/types.js +1 -0
- package/dist/lib/ast/walk.js +23 -17
- package/dist/lib/parser/parse.js +109 -88
- package/dist/lib/parser/utils/declaration.js +1 -1
- package/dist/lib/renderer/color/{colormix.js → color-mix.js} +6 -0
- package/dist/lib/renderer/color/color.js +94 -18
- package/dist/lib/renderer/color/hex.js +17 -7
- package/dist/lib/renderer/color/hsl.js +7 -2
- package/dist/lib/renderer/color/lab.js +8 -0
- package/dist/lib/renderer/color/lch.js +8 -0
- package/dist/lib/renderer/color/oklab.js +8 -0
- package/dist/lib/renderer/color/oklch.js +8 -0
- package/dist/lib/renderer/color/relativecolor.js +10 -21
- package/dist/lib/renderer/color/rgb.js +10 -7
- package/dist/lib/renderer/color/srgb.js +30 -6
- package/dist/lib/renderer/color/utils/components.js +13 -2
- package/dist/lib/renderer/render.js +67 -30
- package/dist/lib/syntax/syntax.js +74 -56
- package/dist/lib/validation/at-rules/container.js +6 -6
- package/dist/lib/validation/at-rules/document.js +1 -1
- package/dist/lib/validation/at-rules/keyframes.js +1 -1
- package/dist/lib/validation/at-rules/media.js +0 -1
- package/dist/lib/validation/atrule.js +0 -4
- package/dist/lib/validation/selector.js +5 -2
- package/dist/lib/validation/syntaxes/keyframe-block-list.js +2 -2
- package/dist/lib/validation/syntaxes/keyframe-selector.js +11 -90
- package/dist/lib/validation/syntaxes/relative-selector.js +15 -14
- package/dist/lib/validation/utils/list.js +18 -1
- package/dist/node/load.js +1 -1
- package/package.json +12 -12
- package/dist/lib/renderer/color/prophotoRgb.js +0 -56
- package/dist/lib/validation/declaration.js +0 -94
- package/dist/lib/validation/syntax.js +0 -1509
- package/dist/lib/validation/syntaxes/image.js +0 -29
package/dist/index-umd-web.js
CHANGED
|
@@ -108,6 +108,7 @@
|
|
|
108
108
|
EnumToken[EnumToken["MediaFeatureOrTokenType"] = 90] = "MediaFeatureOrTokenType";
|
|
109
109
|
EnumToken[EnumToken["PseudoPageTokenType"] = 91] = "PseudoPageTokenType";
|
|
110
110
|
EnumToken[EnumToken["PseudoElementTokenType"] = 92] = "PseudoElementTokenType";
|
|
111
|
+
EnumToken[EnumToken["KeyframeAtRuleNodeType"] = 93] = "KeyframeAtRuleNodeType";
|
|
111
112
|
/* aliases */
|
|
112
113
|
EnumToken[EnumToken["Time"] = 25] = "Time";
|
|
113
114
|
EnumToken[EnumToken["Iden"] = 7] = "Iden";
|
|
@@ -430,25 +431,35 @@
|
|
|
430
431
|
return value;
|
|
431
432
|
}
|
|
432
433
|
function hsl2hex(token) {
|
|
433
|
-
|
|
434
|
+
const t = hsl2rgb(token);
|
|
435
|
+
return t == null ? null : `${t.reduce(toHexString, '#')}`;
|
|
434
436
|
}
|
|
435
437
|
function hwb2hex(token) {
|
|
436
|
-
|
|
438
|
+
const t = hwb2rgb(token);
|
|
439
|
+
return t == null ? null : `${t.reduce(toHexString, '#')}`;
|
|
437
440
|
}
|
|
438
441
|
function cmyk2hex(token) {
|
|
439
|
-
|
|
442
|
+
const t = cmyk2rgb(token);
|
|
443
|
+
return t == null ? null : `#${t.reduce(toHexString, '')}`;
|
|
440
444
|
}
|
|
441
445
|
function oklab2hex(token) {
|
|
442
|
-
|
|
446
|
+
const t = oklab2rgb(token);
|
|
447
|
+
return t == null ? null : `${t.reduce(toHexString, '#')}`;
|
|
443
448
|
}
|
|
444
449
|
function oklch2hex(token) {
|
|
445
|
-
|
|
450
|
+
const value = oklch2rgb(token);
|
|
451
|
+
if (value == null) {
|
|
452
|
+
return null;
|
|
453
|
+
}
|
|
454
|
+
return `${value.reduce(toHexString, '#')}`;
|
|
446
455
|
}
|
|
447
456
|
function lab2hex(token) {
|
|
448
|
-
|
|
457
|
+
const t = lab2rgb(token);
|
|
458
|
+
return t == null ? null : `${t.reduce(toHexString, '#')}`;
|
|
449
459
|
}
|
|
450
460
|
function lch2hex(token) {
|
|
451
|
-
|
|
461
|
+
const t = lch2rgb(token);
|
|
462
|
+
return t == null ? null : `${t.reduce(toHexString, '#')}`;
|
|
452
463
|
}
|
|
453
464
|
function srgb2hexvalues(r, g, b, alpha) {
|
|
454
465
|
return [r, g, b].concat(alpha == null || alpha == 1 ? [] : [alpha]).reduce((acc, value) => acc + minmax(Math.round(255 * value), 0, 255).toString(16).padStart(2, '0'), '#');
|
|
@@ -462,8 +473,19 @@
|
|
|
462
473
|
return { typ: exports.EnumToken.Number, val: parseInt(t, 16).toString() };
|
|
463
474
|
});
|
|
464
475
|
}
|
|
465
|
-
|
|
466
|
-
|
|
476
|
+
const result = [];
|
|
477
|
+
for (const child of (token.chi)) {
|
|
478
|
+
if ([
|
|
479
|
+
exports.EnumToken.LiteralTokenType, exports.EnumToken.CommentTokenType, exports.EnumToken.CommaTokenType, exports.EnumToken.WhitespaceTokenType
|
|
480
|
+
].includes(child.typ)) {
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
if (child.typ == exports.EnumToken.ColorTokenType && child.val == 'currentcolor') {
|
|
484
|
+
return null;
|
|
485
|
+
}
|
|
486
|
+
result.push(child);
|
|
487
|
+
}
|
|
488
|
+
return result;
|
|
467
489
|
}
|
|
468
490
|
|
|
469
491
|
function XYZ_to_lin_sRGB(x, y, z) {
|
|
@@ -555,6 +577,14 @@
|
|
|
555
577
|
}
|
|
556
578
|
function getLCHComponents(token) {
|
|
557
579
|
const components = getComponents(token);
|
|
580
|
+
if (components == null) {
|
|
581
|
+
return null;
|
|
582
|
+
}
|
|
583
|
+
for (let i = 0; i < components.length; i++) {
|
|
584
|
+
if (![exports.EnumToken.NumberTokenType, exports.EnumToken.PercentageTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.IdenTokenType].includes(components[i].typ)) {
|
|
585
|
+
return null;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
558
588
|
// @ts-ignore
|
|
559
589
|
let t = components[0];
|
|
560
590
|
// @ts-ignore
|
|
@@ -608,6 +638,14 @@
|
|
|
608
638
|
}
|
|
609
639
|
function getOKLCHComponents(token) {
|
|
610
640
|
const components = getComponents(token);
|
|
641
|
+
if (components == null) {
|
|
642
|
+
return null;
|
|
643
|
+
}
|
|
644
|
+
for (let i = 0; i < components.length; i++) {
|
|
645
|
+
if (![exports.EnumToken.NumberTokenType, exports.EnumToken.PercentageTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.IdenTokenType].includes(components[i].typ)) {
|
|
646
|
+
return [];
|
|
647
|
+
}
|
|
648
|
+
}
|
|
611
649
|
// @ts-ignore
|
|
612
650
|
let t = components[0];
|
|
613
651
|
// @ts-ignore
|
|
@@ -667,6 +705,14 @@
|
|
|
667
705
|
}
|
|
668
706
|
function getOKLABComponents(token) {
|
|
669
707
|
const components = getComponents(token);
|
|
708
|
+
if (components == null) {
|
|
709
|
+
return null;
|
|
710
|
+
}
|
|
711
|
+
for (let i = 0; i < components.length; i++) {
|
|
712
|
+
if (![exports.EnumToken.NumberTokenType, exports.EnumToken.PercentageTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.IdenTokenType].includes(components[i].typ)) {
|
|
713
|
+
return null;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
670
716
|
// @ts-ignore
|
|
671
717
|
let t = components[0];
|
|
672
718
|
// @ts-ignore
|
|
@@ -847,6 +893,14 @@
|
|
|
847
893
|
}
|
|
848
894
|
function getLABComponents(token) {
|
|
849
895
|
const components = getComponents(token);
|
|
896
|
+
if (components == null) {
|
|
897
|
+
return null;
|
|
898
|
+
}
|
|
899
|
+
for (let i = 0; i < components.length; i++) {
|
|
900
|
+
if (![exports.EnumToken.NumberTokenType, exports.EnumToken.PercentageTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.IdenTokenType].includes(components[i].typ)) {
|
|
901
|
+
return [];
|
|
902
|
+
}
|
|
903
|
+
}
|
|
850
904
|
// @ts-ignore
|
|
851
905
|
let t = components[0];
|
|
852
906
|
// @ts-ignore
|
|
@@ -926,7 +980,7 @@
|
|
|
926
980
|
return null;
|
|
927
981
|
}
|
|
928
982
|
function rgb2srgb(token) {
|
|
929
|
-
return getComponents(token)
|
|
983
|
+
return getComponents(token)?.map?.((t, index) => index == 3 ? ((t.typ == exports.EnumToken.IdenTokenType && t.val == 'none') ? 1 : getNumber(t)) : (t.typ == exports.EnumToken.PercentageTokenType ? 255 : 1) * getNumber(t) / 255) ?? null;
|
|
930
984
|
}
|
|
931
985
|
function hex2srgb(token) {
|
|
932
986
|
const value = expandHexValue(token.kin == 'lit' ? COLORS_NAMES[token.val.toLowerCase()] : token.val);
|
|
@@ -941,7 +995,10 @@
|
|
|
941
995
|
return lsrgb2srgbvalues(...XYZ_to_lin_sRGB(x, y, z));
|
|
942
996
|
}
|
|
943
997
|
function hwb2srgb(token) {
|
|
944
|
-
const { h: hue, s: white, l: black, a: alpha } = hslvalues(token);
|
|
998
|
+
const { h: hue, s: white, l: black, a: alpha } = hslvalues(token) ?? {};
|
|
999
|
+
if (hue == null || white == null || black == null) {
|
|
1000
|
+
return [];
|
|
1001
|
+
}
|
|
945
1002
|
const rgb = hsl2srgbvalues(hue, 1, .5);
|
|
946
1003
|
for (let i = 0; i < 3; i++) {
|
|
947
1004
|
rgb[i] *= (1 - white - black);
|
|
@@ -953,11 +1010,17 @@
|
|
|
953
1010
|
return rgb;
|
|
954
1011
|
}
|
|
955
1012
|
function hsl2srgb(token) {
|
|
956
|
-
let { h, s, l, a } = hslvalues(token);
|
|
1013
|
+
let { h, s, l, a } = hslvalues(token) ?? {};
|
|
1014
|
+
if (h == null || s == null || l == null) {
|
|
1015
|
+
return null;
|
|
1016
|
+
}
|
|
957
1017
|
return hsl2srgbvalues(h, s, l, a);
|
|
958
1018
|
}
|
|
959
1019
|
function cmyk2srgb(token) {
|
|
960
1020
|
const components = getComponents(token);
|
|
1021
|
+
if (components == null) {
|
|
1022
|
+
return null;
|
|
1023
|
+
}
|
|
961
1024
|
// @ts-ignore
|
|
962
1025
|
let t = components[0];
|
|
963
1026
|
// @ts-ignore
|
|
@@ -989,7 +1052,10 @@
|
|
|
989
1052
|
return rgb;
|
|
990
1053
|
}
|
|
991
1054
|
function oklab2srgb(token) {
|
|
992
|
-
const [l, a, b, alpha] = getOKLABComponents(token);
|
|
1055
|
+
const [l, a, b, alpha] = getOKLABComponents(token) ?? [];
|
|
1056
|
+
if (l == null || a == null || b == null) {
|
|
1057
|
+
return null;
|
|
1058
|
+
}
|
|
993
1059
|
const rgb = OKLab_to_sRGB(l, a, b);
|
|
994
1060
|
if (alpha != null && alpha != 1) {
|
|
995
1061
|
rgb.push(alpha);
|
|
@@ -997,7 +1063,10 @@
|
|
|
997
1063
|
return rgb;
|
|
998
1064
|
}
|
|
999
1065
|
function oklch2srgb(token) {
|
|
1000
|
-
const [l, c, h, alpha] = getOKLCHComponents(token);
|
|
1066
|
+
const [l, c, h, alpha] = getOKLCHComponents(token) ?? [];
|
|
1067
|
+
if (l == null || c == null || h == null) {
|
|
1068
|
+
return null;
|
|
1069
|
+
}
|
|
1001
1070
|
// @ts-ignore
|
|
1002
1071
|
const rgb = OKLab_to_sRGB(...lch2labvalues(l, c, h));
|
|
1003
1072
|
if (alpha != 1) {
|
|
@@ -1007,6 +1076,9 @@
|
|
|
1007
1076
|
}
|
|
1008
1077
|
function hslvalues(token) {
|
|
1009
1078
|
const components = getComponents(token);
|
|
1079
|
+
if (components == null) {
|
|
1080
|
+
return null;
|
|
1081
|
+
}
|
|
1010
1082
|
let t;
|
|
1011
1083
|
// @ts-ignore
|
|
1012
1084
|
let h = getAngle(components[0]);
|
|
@@ -1081,7 +1153,10 @@
|
|
|
1081
1153
|
return values;
|
|
1082
1154
|
}
|
|
1083
1155
|
function lab2srgb(token) {
|
|
1084
|
-
const [l, a, b, alpha] = getLABComponents(token);
|
|
1156
|
+
const [l, a, b, alpha] = getLABComponents(token) ?? [];
|
|
1157
|
+
if (l == null || a == null || b == null) {
|
|
1158
|
+
return null;
|
|
1159
|
+
}
|
|
1085
1160
|
const rgb = Lab_to_sRGB(l, a, b);
|
|
1086
1161
|
if (alpha != null && alpha != 1) {
|
|
1087
1162
|
rgb.push(alpha);
|
|
@@ -1091,6 +1166,9 @@
|
|
|
1091
1166
|
function lch2srgb(token) {
|
|
1092
1167
|
// @ts-ignore
|
|
1093
1168
|
const [l, a, b, alpha] = lch2labvalues(...getLCHComponents(token));
|
|
1169
|
+
if (l == null || a == null || b == null) {
|
|
1170
|
+
return null;
|
|
1171
|
+
}
|
|
1094
1172
|
// https://www.w3.org/TR/css-color-4/#lab-to-lch
|
|
1095
1173
|
const rgb = Lab_to_sRGB(l, a, b);
|
|
1096
1174
|
if (alpha != 1) {
|
|
@@ -1150,26 +1228,29 @@
|
|
|
1150
1228
|
return rgb;
|
|
1151
1229
|
}
|
|
1152
1230
|
function hwb2rgb(token) {
|
|
1153
|
-
return hwb2srgb(token)
|
|
1231
|
+
return hwb2srgb(token)?.map?.(srgb2rgb) ?? null;
|
|
1154
1232
|
}
|
|
1155
1233
|
function hsl2rgb(token) {
|
|
1156
|
-
let { h, s, l, a } = hslvalues(token);
|
|
1234
|
+
let { h, s, l, a } = hslvalues(token) ?? {};
|
|
1235
|
+
if (h == null || s == null || l == null) {
|
|
1236
|
+
return null;
|
|
1237
|
+
}
|
|
1157
1238
|
return hsl2srgbvalues(h, s, l, a).map((t) => minmax(Math.round(t * 255), 0, 255));
|
|
1158
1239
|
}
|
|
1159
1240
|
function cmyk2rgb(token) {
|
|
1160
|
-
return cmyk2srgb(token)
|
|
1241
|
+
return cmyk2srgb(token)?.map?.(srgb2rgb) ?? null;
|
|
1161
1242
|
}
|
|
1162
1243
|
function oklab2rgb(token) {
|
|
1163
|
-
return oklab2srgb(token)
|
|
1244
|
+
return oklab2srgb(token)?.map?.(srgb2rgb) ?? null;
|
|
1164
1245
|
}
|
|
1165
1246
|
function oklch2rgb(token) {
|
|
1166
|
-
return oklch2srgb(token)
|
|
1247
|
+
return oklch2srgb(token)?.map?.(srgb2rgb) ?? null;
|
|
1167
1248
|
}
|
|
1168
1249
|
function lab2rgb(token) {
|
|
1169
|
-
return lab2srgb(token)
|
|
1250
|
+
return lab2srgb(token)?.map?.(srgb2rgb) ?? null;
|
|
1170
1251
|
}
|
|
1171
1252
|
function lch2rgb(token) {
|
|
1172
|
-
return lch2srgb(token)
|
|
1253
|
+
return lch2srgb(token)?.map?.(srgb2rgb) ?? null;
|
|
1173
1254
|
}
|
|
1174
1255
|
|
|
1175
1256
|
function hwb2hsv(h, w, b, a) {
|
|
@@ -1197,6 +1278,9 @@
|
|
|
1197
1278
|
}
|
|
1198
1279
|
function rgb2hsl(token) {
|
|
1199
1280
|
const chi = getComponents(token);
|
|
1281
|
+
if (chi == null) {
|
|
1282
|
+
return null;
|
|
1283
|
+
}
|
|
1200
1284
|
// @ts-ignore
|
|
1201
1285
|
let t = chi[0];
|
|
1202
1286
|
// @ts-ignore
|
|
@@ -1255,12 +1339,14 @@
|
|
|
1255
1339
|
return rgb2hslvalues(...lch2rgb(token));
|
|
1256
1340
|
}
|
|
1257
1341
|
function oklab2hsl(token) {
|
|
1342
|
+
const t = oklab2rgb(token);
|
|
1258
1343
|
// @ts-ignore
|
|
1259
|
-
return rgb2hslvalues(...
|
|
1344
|
+
return t == null ? null : rgb2hslvalues(...t);
|
|
1260
1345
|
}
|
|
1261
1346
|
function oklch2hsl(token) {
|
|
1347
|
+
const t = oklch2rgb(token);
|
|
1262
1348
|
// @ts-ignore
|
|
1263
|
-
return rgb2hslvalues(...
|
|
1349
|
+
return t == null ? null : rgb2hslvalues(...t);
|
|
1264
1350
|
}
|
|
1265
1351
|
function rgb2hslvalues(r, g, b, a = null) {
|
|
1266
1352
|
return srgb2hsl(r / 255, g / 255, b / 255, a);
|
|
@@ -1610,10 +1696,15 @@
|
|
|
1610
1696
|
}
|
|
1611
1697
|
let values = [];
|
|
1612
1698
|
if (to == 'hsl') {
|
|
1699
|
+
let t;
|
|
1613
1700
|
switch (token.kin) {
|
|
1614
1701
|
case 'rgb':
|
|
1615
1702
|
case 'rgba':
|
|
1616
|
-
|
|
1703
|
+
t = rgb2hsl(token);
|
|
1704
|
+
if (t == null) {
|
|
1705
|
+
return null;
|
|
1706
|
+
}
|
|
1707
|
+
values.push(...t);
|
|
1617
1708
|
break;
|
|
1618
1709
|
case 'hex':
|
|
1619
1710
|
case 'lit':
|
|
@@ -1623,10 +1714,18 @@
|
|
|
1623
1714
|
values.push(...hwb2hsl(token));
|
|
1624
1715
|
break;
|
|
1625
1716
|
case 'oklab':
|
|
1626
|
-
|
|
1717
|
+
t = oklab2hsl(token);
|
|
1718
|
+
if (t == null) {
|
|
1719
|
+
return null;
|
|
1720
|
+
}
|
|
1721
|
+
values.push(...t);
|
|
1627
1722
|
break;
|
|
1628
1723
|
case 'oklch':
|
|
1629
|
-
|
|
1724
|
+
t = oklch2hsl(token);
|
|
1725
|
+
if (t == null) {
|
|
1726
|
+
return null;
|
|
1727
|
+
}
|
|
1728
|
+
values.push(...t);
|
|
1630
1729
|
break;
|
|
1631
1730
|
case 'lab':
|
|
1632
1731
|
values.push(...lab2hsl(token));
|
|
@@ -1675,28 +1774,53 @@
|
|
|
1675
1774
|
}
|
|
1676
1775
|
}
|
|
1677
1776
|
else if (to == 'rgb') {
|
|
1777
|
+
let t;
|
|
1678
1778
|
switch (token.kin) {
|
|
1679
1779
|
case 'hex':
|
|
1680
1780
|
case 'lit':
|
|
1681
1781
|
values.push(...hex2rgb(token));
|
|
1682
1782
|
break;
|
|
1683
1783
|
case 'hsl':
|
|
1684
|
-
|
|
1784
|
+
t = hsl2rgb(token);
|
|
1785
|
+
if (t == null) {
|
|
1786
|
+
return null;
|
|
1787
|
+
}
|
|
1788
|
+
values.push(...t);
|
|
1685
1789
|
break;
|
|
1686
1790
|
case 'hwb':
|
|
1687
|
-
|
|
1791
|
+
t = hwb2rgb(token);
|
|
1792
|
+
if (t == null) {
|
|
1793
|
+
return null;
|
|
1794
|
+
}
|
|
1795
|
+
values.push(...t);
|
|
1688
1796
|
break;
|
|
1689
1797
|
case 'oklab':
|
|
1690
|
-
|
|
1798
|
+
t = oklab2rgb(token);
|
|
1799
|
+
if (t == null) {
|
|
1800
|
+
return null;
|
|
1801
|
+
}
|
|
1802
|
+
values.push(...t);
|
|
1691
1803
|
break;
|
|
1692
1804
|
case 'oklch':
|
|
1693
|
-
|
|
1805
|
+
t = oklch2rgb(token);
|
|
1806
|
+
if (t == null) {
|
|
1807
|
+
return null;
|
|
1808
|
+
}
|
|
1809
|
+
values.push(...t);
|
|
1694
1810
|
break;
|
|
1695
1811
|
case 'lab':
|
|
1696
|
-
|
|
1812
|
+
t = lab2rgb(token);
|
|
1813
|
+
if (t == null) {
|
|
1814
|
+
return null;
|
|
1815
|
+
}
|
|
1816
|
+
values.push(...t);
|
|
1697
1817
|
break;
|
|
1698
1818
|
case 'lch':
|
|
1699
|
-
|
|
1819
|
+
t = lch2rgb(token);
|
|
1820
|
+
if (t == null) {
|
|
1821
|
+
return null;
|
|
1822
|
+
}
|
|
1823
|
+
values.push(...t);
|
|
1700
1824
|
break;
|
|
1701
1825
|
case 'color':
|
|
1702
1826
|
// @ts-ignore
|
|
@@ -1882,6 +2006,7 @@
|
|
|
1882
2006
|
}
|
|
1883
2007
|
}
|
|
1884
2008
|
else if (colorFuncColorSpace.includes(to)) {
|
|
2009
|
+
let t;
|
|
1885
2010
|
switch (token.kin) {
|
|
1886
2011
|
case 'hex':
|
|
1887
2012
|
case 'lit':
|
|
@@ -1889,30 +2014,60 @@
|
|
|
1889
2014
|
break;
|
|
1890
2015
|
case 'rgb':
|
|
1891
2016
|
case 'rgba':
|
|
1892
|
-
|
|
2017
|
+
t = rgb2srgb(token);
|
|
2018
|
+
if (t == null) {
|
|
2019
|
+
return null;
|
|
2020
|
+
}
|
|
2021
|
+
values.push(...t);
|
|
1893
2022
|
break;
|
|
1894
2023
|
case 'hsl':
|
|
1895
2024
|
case 'hsla':
|
|
1896
|
-
|
|
2025
|
+
t = hsl2srgb(token);
|
|
2026
|
+
if (t == null) {
|
|
2027
|
+
return null;
|
|
2028
|
+
}
|
|
2029
|
+
values.push(...t);
|
|
1897
2030
|
break;
|
|
1898
2031
|
case 'hwb':
|
|
1899
|
-
|
|
2032
|
+
t = hwb2srgb(token);
|
|
2033
|
+
if (t == null) {
|
|
2034
|
+
return null;
|
|
2035
|
+
}
|
|
2036
|
+
values.push(...t);
|
|
1900
2037
|
break;
|
|
1901
2038
|
case 'lab':
|
|
1902
|
-
|
|
2039
|
+
t = lab2srgb(token);
|
|
2040
|
+
if (t == null) {
|
|
2041
|
+
return null;
|
|
2042
|
+
}
|
|
2043
|
+
values.push(...t);
|
|
1903
2044
|
break;
|
|
1904
2045
|
case 'oklab':
|
|
1905
|
-
|
|
2046
|
+
t = oklab2srgb(token);
|
|
2047
|
+
if (t == null) {
|
|
2048
|
+
return null;
|
|
2049
|
+
}
|
|
2050
|
+
values.push(...t);
|
|
1906
2051
|
break;
|
|
1907
2052
|
case 'lch':
|
|
1908
|
-
|
|
2053
|
+
t = lch2srgb(token);
|
|
2054
|
+
if (t == null) {
|
|
2055
|
+
return null;
|
|
2056
|
+
}
|
|
2057
|
+
values.push(...t);
|
|
1909
2058
|
break;
|
|
1910
2059
|
case 'oklch':
|
|
1911
|
-
|
|
1912
|
-
|
|
2060
|
+
t = color2srgbvalues(token);
|
|
2061
|
+
if (t == null) {
|
|
2062
|
+
return null;
|
|
2063
|
+
}
|
|
2064
|
+
values.push(...t);
|
|
1913
2065
|
break;
|
|
1914
2066
|
case 'color':
|
|
1915
2067
|
const val = color2srgbvalues(token);
|
|
2068
|
+
if (val == null) {
|
|
2069
|
+
return null;
|
|
2070
|
+
}
|
|
1916
2071
|
switch (to) {
|
|
1917
2072
|
case 'srgb':
|
|
1918
2073
|
values.push(...val);
|
|
@@ -1966,6 +2121,9 @@
|
|
|
1966
2121
|
}
|
|
1967
2122
|
function color2srgbvalues(token) {
|
|
1968
2123
|
const components = getComponents(token);
|
|
2124
|
+
if (components == null) {
|
|
2125
|
+
return null;
|
|
2126
|
+
}
|
|
1969
2127
|
const colorSpace = components.shift();
|
|
1970
2128
|
let values = components.map((val) => getNumber(val));
|
|
1971
2129
|
switch (colorSpace.val) {
|
|
@@ -2108,6 +2266,10 @@
|
|
|
2108
2266
|
// @ts-ignore
|
|
2109
2267
|
return token.typ == exports.EnumToken.PercentageTokenType ? token.val / 100 : +token.val;
|
|
2110
2268
|
}
|
|
2269
|
+
/**
|
|
2270
|
+
* convert angle to turn
|
|
2271
|
+
* @param token
|
|
2272
|
+
*/
|
|
2111
2273
|
function getAngle(token) {
|
|
2112
2274
|
if (token.typ == exports.EnumToken.IdenTokenType) {
|
|
2113
2275
|
if (token.val == 'none') {
|
|
@@ -2168,6 +2330,9 @@
|
|
|
2168
2330
|
return [h1, h2];
|
|
2169
2331
|
}
|
|
2170
2332
|
function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color2, percentage2) {
|
|
2333
|
+
if (color1.val == 'currentcolor' || color2.val == 'currentcolor') {
|
|
2334
|
+
return null;
|
|
2335
|
+
}
|
|
2171
2336
|
if (hueInterpolationMethod != null && isRectangularOrthogonalColorspace(colorSpace)) {
|
|
2172
2337
|
return null;
|
|
2173
2338
|
}
|
|
@@ -2221,6 +2386,9 @@
|
|
|
2221
2386
|
}
|
|
2222
2387
|
const components1 = getComponents(color1);
|
|
2223
2388
|
const components2 = getComponents(color2);
|
|
2389
|
+
if (components1 == null || components2 == null) {
|
|
2390
|
+
return null;
|
|
2391
|
+
}
|
|
2224
2392
|
if ((components1[3] != null && components1[3].typ == exports.EnumToken.IdenTokenType && components1[3].val == 'none') && values2.length == 4) {
|
|
2225
2393
|
values1[3] = values2[3];
|
|
2226
2394
|
}
|
|
@@ -2449,9 +2617,20 @@
|
|
|
2449
2617
|
function gcd(x, y) {
|
|
2450
2618
|
x = Math.abs(x);
|
|
2451
2619
|
y = Math.abs(y);
|
|
2620
|
+
if (x == y) {
|
|
2621
|
+
return x;
|
|
2622
|
+
}
|
|
2452
2623
|
let t;
|
|
2453
|
-
if (x == 0
|
|
2454
|
-
return
|
|
2624
|
+
if (x == 0) {
|
|
2625
|
+
return y;
|
|
2626
|
+
}
|
|
2627
|
+
if (y == 0) {
|
|
2628
|
+
return x;
|
|
2629
|
+
}
|
|
2630
|
+
if (y > x) {
|
|
2631
|
+
t = x;
|
|
2632
|
+
x = y;
|
|
2633
|
+
y = t;
|
|
2455
2634
|
}
|
|
2456
2635
|
while (y) {
|
|
2457
2636
|
t = y;
|
|
@@ -2460,7 +2639,7 @@
|
|
|
2460
2639
|
}
|
|
2461
2640
|
return x;
|
|
2462
2641
|
}
|
|
2463
|
-
function compute(a, b, op) {
|
|
2642
|
+
function compute$1(a, b, op) {
|
|
2464
2643
|
if (typeof a == 'number' && typeof b == 'number') {
|
|
2465
2644
|
switch (op) {
|
|
2466
2645
|
case exports.EnumToken.Add:
|
|
@@ -2521,6 +2700,7 @@
|
|
|
2521
2700
|
r2 = l1.r.val * r1.l.val;
|
|
2522
2701
|
break;
|
|
2523
2702
|
}
|
|
2703
|
+
// @ts-ignore
|
|
2524
2704
|
const a2 = simplify(l2, r2);
|
|
2525
2705
|
if (a2[1] == 1) {
|
|
2526
2706
|
return a2[0];
|
|
@@ -2579,14 +2759,19 @@
|
|
|
2579
2759
|
return tokens;
|
|
2580
2760
|
}
|
|
2581
2761
|
if (nodes.length <= 1) {
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2762
|
+
if (nodes.length == 1) {
|
|
2763
|
+
if (nodes[0].typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
2764
|
+
return inlineExpression(nodes[0]);
|
|
2765
|
+
}
|
|
2766
|
+
// @ts-ignore
|
|
2767
|
+
if (nodes[0].typ == exports.EnumToken.IdenTokenType && typeof Math[nodes[0].val.toUpperCase()] == 'number') {
|
|
2768
|
+
return [{
|
|
2769
|
+
...nodes[0],
|
|
2770
|
+
// @ts-ignore
|
|
2771
|
+
val: '' + Math[nodes[0].val.toUpperCase()],
|
|
2772
|
+
typ: exports.EnumToken.NumberTokenType
|
|
2773
|
+
}];
|
|
2774
|
+
}
|
|
2590
2775
|
}
|
|
2591
2776
|
return nodes;
|
|
2592
2777
|
}
|
|
@@ -2706,8 +2891,7 @@
|
|
|
2706
2891
|
}
|
|
2707
2892
|
}
|
|
2708
2893
|
// @ts-ignore
|
|
2709
|
-
const val = compute(v1, v2, op);
|
|
2710
|
-
// typ = typeof val == 'number' ? EnumToken.NumberTokenType : EnumToken.FractionTokenType;
|
|
2894
|
+
const val = compute$1(v1, v2, op);
|
|
2711
2895
|
const token = {
|
|
2712
2896
|
...(l.typ == exports.EnumToken.NumberTokenType ? r : l),
|
|
2713
2897
|
typ,
|
|
@@ -3186,30 +3370,19 @@
|
|
|
3186
3370
|
return expr;
|
|
3187
3371
|
}
|
|
3188
3372
|
function replaceValue(parent, value, newValue) {
|
|
3189
|
-
|
|
3190
|
-
if (
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
parent.r = newValue;
|
|
3195
|
-
}
|
|
3196
|
-
}
|
|
3197
|
-
else {
|
|
3198
|
-
for (let i = 0; i < parent.chi.length; i++) {
|
|
3199
|
-
if (parent.chi[i] == value) {
|
|
3200
|
-
parent.chi.splice(i, 1, newValue);
|
|
3201
|
-
break;
|
|
3202
|
-
}
|
|
3203
|
-
if (parent.chi[i].typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
3204
|
-
if (parent.chi[i].l == value) {
|
|
3205
|
-
parent.chi[i].l = newValue;
|
|
3206
|
-
break;
|
|
3373
|
+
for (const { value: val, parent: pr } of walkValues([parent])) {
|
|
3374
|
+
if (val.typ == value.typ && val.val == value.val) {
|
|
3375
|
+
if (pr.typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
3376
|
+
if (pr.l == val) {
|
|
3377
|
+
pr.l = newValue;
|
|
3207
3378
|
}
|
|
3208
|
-
else
|
|
3209
|
-
|
|
3210
|
-
break;
|
|
3379
|
+
else {
|
|
3380
|
+
pr.r = newValue;
|
|
3211
3381
|
}
|
|
3212
3382
|
}
|
|
3383
|
+
else {
|
|
3384
|
+
pr.chi.splice(pr.chi.indexOf(val), 1, newValue);
|
|
3385
|
+
}
|
|
3213
3386
|
}
|
|
3214
3387
|
}
|
|
3215
3388
|
}
|
|
@@ -3403,7 +3576,7 @@
|
|
|
3403
3576
|
return result;
|
|
3404
3577
|
}
|
|
3405
3578
|
function updateSourceMap(node, options, cache, sourcemap, position, str) {
|
|
3406
|
-
if ([exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyFrameRuleNodeType].includes(node.typ)) {
|
|
3579
|
+
if ([exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyFrameRuleNodeType, exports.EnumToken.KeyframeAtRuleNodeType].includes(node.typ)) {
|
|
3407
3580
|
let src = node.loc?.src ?? '';
|
|
3408
3581
|
let output = options.output ?? '';
|
|
3409
3582
|
if (!(src in cache)) {
|
|
@@ -3446,7 +3619,7 @@
|
|
|
3446
3619
|
const indentSub = indents[level + 1];
|
|
3447
3620
|
switch (data.typ) {
|
|
3448
3621
|
case exports.EnumToken.DeclarationNodeType:
|
|
3449
|
-
return `${data.nam}:${options.indent}${data.val.reduce(reducer, '')}`;
|
|
3622
|
+
return `${data.nam}:${options.indent}${(options.minify ? filterValues(data.val) : data.val).reduce(reducer, '')}`;
|
|
3450
3623
|
case exports.EnumToken.CommentNodeType:
|
|
3451
3624
|
case exports.EnumToken.CDOCOMMNodeType:
|
|
3452
3625
|
if (data.val.startsWith('/*# sourceMappingURL=')) {
|
|
@@ -3475,7 +3648,8 @@
|
|
|
3475
3648
|
case exports.EnumToken.AtRuleNodeType:
|
|
3476
3649
|
case exports.EnumToken.RuleNodeType:
|
|
3477
3650
|
case exports.EnumToken.KeyFrameRuleNodeType:
|
|
3478
|
-
|
|
3651
|
+
case exports.EnumToken.KeyframeAtRuleNodeType:
|
|
3652
|
+
if ([exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyframeAtRuleNodeType].includes(data.typ) && !('chi' in data)) {
|
|
3479
3653
|
return `${indent}@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val};`;
|
|
3480
3654
|
}
|
|
3481
3655
|
// @ts-ignore
|
|
@@ -3485,7 +3659,7 @@
|
|
|
3485
3659
|
str = options.removeComments && (!options.preserveLicense || !node.val.startsWith('/*!')) ? '' : node.val;
|
|
3486
3660
|
}
|
|
3487
3661
|
else if (node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
3488
|
-
if (node.val.length == 0) {
|
|
3662
|
+
if (!node.nam.startsWith('--') && node.val.length == 0) {
|
|
3489
3663
|
// @ts-ignore
|
|
3490
3664
|
errors.push({
|
|
3491
3665
|
action: 'ignore',
|
|
@@ -3494,7 +3668,7 @@
|
|
|
3494
3668
|
});
|
|
3495
3669
|
return '';
|
|
3496
3670
|
}
|
|
3497
|
-
str = `${node.nam}:${options.indent}${node.val.reduce(reducer, '').trimEnd()};`;
|
|
3671
|
+
str = `${node.nam}:${options.indent}${(options.minify ? filterValues(node.val) : node.val).reduce(reducer, '').trimEnd()};`;
|
|
3498
3672
|
}
|
|
3499
3673
|
else if (node.typ == exports.EnumToken.AtRuleNodeType && !('chi' in node)) {
|
|
3500
3674
|
str = `${data.val === '' ? '' : options.indent || ' '}${data.val};`;
|
|
@@ -3516,7 +3690,7 @@
|
|
|
3516
3690
|
if (children.endsWith(';')) {
|
|
3517
3691
|
children = children.slice(0, -1);
|
|
3518
3692
|
}
|
|
3519
|
-
if (
|
|
3693
|
+
if ([exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyframeAtRuleNodeType].includes(data.typ)) {
|
|
3520
3694
|
return `@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val}${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
|
|
3521
3695
|
}
|
|
3522
3696
|
return data.sel + `${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
|
|
@@ -3552,20 +3726,25 @@
|
|
|
3552
3726
|
if (isColor(token)) {
|
|
3553
3727
|
// @ts-ignore
|
|
3554
3728
|
token.typ = exports.EnumToken.ColorTokenType;
|
|
3729
|
+
// @ts-ignore
|
|
3555
3730
|
if (token.chi[0].typ == exports.EnumToken.IdenTokenType && token.chi[0].val == 'from') {
|
|
3556
3731
|
// @ts-ignore
|
|
3557
3732
|
token.cal = 'rel';
|
|
3558
3733
|
}
|
|
3559
|
-
else
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3734
|
+
else { // @ts-ignore
|
|
3735
|
+
if (token.val == 'color-mix' && token.chi[0].typ == exports.EnumToken.IdenTokenType && token.chi[0].val == 'in') {
|
|
3736
|
+
// @ts-ignore
|
|
3737
|
+
token.cal = 'mix';
|
|
3738
|
+
}
|
|
3739
|
+
else {
|
|
3740
|
+
// @ts-ignore
|
|
3741
|
+
if (token.val == 'color') {
|
|
3742
|
+
// @ts-ignore
|
|
3743
|
+
token.cal = 'col';
|
|
3744
|
+
}
|
|
3565
3745
|
// @ts-ignore
|
|
3566
|
-
token.
|
|
3746
|
+
token.chi = token.chi.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommaTokenType, exports.EnumToken.CommentTokenType].includes(t.typ));
|
|
3567
3747
|
}
|
|
3568
|
-
token.chi = token.chi.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommaTokenType, exports.EnumToken.CommentTokenType].includes(t.typ));
|
|
3569
3748
|
}
|
|
3570
3749
|
}
|
|
3571
3750
|
}
|
|
@@ -3632,22 +3811,36 @@
|
|
|
3632
3811
|
if (value != null) {
|
|
3633
3812
|
token = value;
|
|
3634
3813
|
}
|
|
3814
|
+
else if (!token.chi.some(t => t.typ == exports.EnumToken.CommaTokenType)) {
|
|
3815
|
+
token.chi = children.reduce((acc, curr, index) => {
|
|
3816
|
+
if (acc.length > 0) {
|
|
3817
|
+
acc.push({ typ: exports.EnumToken.CommaTokenType });
|
|
3818
|
+
}
|
|
3819
|
+
acc.push(...curr);
|
|
3820
|
+
return acc;
|
|
3821
|
+
}, []);
|
|
3822
|
+
}
|
|
3635
3823
|
}
|
|
3636
3824
|
if (token.cal == 'rel' && ['rgb', 'hsl', 'hwb', 'lab', 'lch', 'oklab', 'oklch', 'color'].includes(token.val)) {
|
|
3637
3825
|
const chi = getComponents(token);
|
|
3638
3826
|
const offset = token.val == 'color' ? 2 : 1;
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3827
|
+
if (chi != null) {
|
|
3828
|
+
// @ts-ignore
|
|
3829
|
+
const color = chi[1];
|
|
3830
|
+
const components = parseRelativeColor(token.val == 'color' ? chi[offset].val : token.val, color, chi[offset + 1], chi[offset + 2], chi[offset + 3], chi[offset + 4]);
|
|
3831
|
+
if (components != null) {
|
|
3832
|
+
token.chi = [...(token.val == 'color' ? [chi[offset]] : []), ...Object.values(components)];
|
|
3833
|
+
delete token.cal;
|
|
3834
|
+
}
|
|
3645
3835
|
}
|
|
3646
3836
|
}
|
|
3647
3837
|
if (token.val == 'color') {
|
|
3648
3838
|
if (token.chi[0].typ == exports.EnumToken.IdenTokenType && colorFuncColorSpace.includes(token.chi[0].val.toLowerCase())) {
|
|
3649
|
-
|
|
3650
|
-
|
|
3839
|
+
const values = color2srgbvalues(token);
|
|
3840
|
+
if (Array.isArray(values) && values.every(t => !Number.isNaN(t))) {
|
|
3841
|
+
// @ts-ignore
|
|
3842
|
+
return reduceHexValue(srgb2hexvalues(...values));
|
|
3843
|
+
}
|
|
3651
3844
|
}
|
|
3652
3845
|
}
|
|
3653
3846
|
if (token.cal != null) {
|
|
@@ -3704,7 +3897,7 @@
|
|
|
3704
3897
|
else if (token.val == 'lch') {
|
|
3705
3898
|
value = lch2hex(token);
|
|
3706
3899
|
}
|
|
3707
|
-
if (value !== '') {
|
|
3900
|
+
if (value !== '' && value != null) {
|
|
3708
3901
|
return reduceHexValue(value);
|
|
3709
3902
|
}
|
|
3710
3903
|
}
|
|
@@ -3894,7 +4087,11 @@
|
|
|
3894
4087
|
if (!('original' in token)) {
|
|
3895
4088
|
// do not modify original token
|
|
3896
4089
|
token = { ...token };
|
|
3897
|
-
Object.defineProperty(token, 'original', {
|
|
4090
|
+
Object.defineProperty(token, 'original', {
|
|
4091
|
+
enumerable: false,
|
|
4092
|
+
writable: false,
|
|
4093
|
+
value: token.val
|
|
4094
|
+
});
|
|
3898
4095
|
}
|
|
3899
4096
|
// @ts-ignore
|
|
3900
4097
|
if (!(token.original in cache)) {
|
|
@@ -3927,7 +4124,7 @@
|
|
|
3927
4124
|
case exports.EnumToken.InvalidClassSelectorTokenType:
|
|
3928
4125
|
return token.val;
|
|
3929
4126
|
case exports.EnumToken.DeclarationNodeType:
|
|
3930
|
-
return token.nam + ':' + token.val.reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
4127
|
+
return token.nam + ':' + (options.minify ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
3931
4128
|
case exports.EnumToken.MediaQueryConditionTokenType:
|
|
3932
4129
|
return renderToken(token.l, options, cache, reducer, errors) + renderToken(token.op, options, cache, reducer, errors) + token.r.reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
3933
4130
|
case exports.EnumToken.MediaFeatureTokenType:
|
|
@@ -3940,12 +4137,25 @@
|
|
|
3940
4137
|
return 'and';
|
|
3941
4138
|
case exports.EnumToken.MediaFeatureOrTokenType:
|
|
3942
4139
|
return 'or';
|
|
3943
|
-
default:
|
|
3944
|
-
|
|
4140
|
+
// default:
|
|
4141
|
+
//
|
|
4142
|
+
// throw new Error(`render: unexpected token ${JSON.stringify(token, null, 1)}`);
|
|
3945
4143
|
}
|
|
3946
4144
|
errors?.push({ action: 'ignore', message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
|
|
3947
4145
|
return '';
|
|
3948
4146
|
}
|
|
4147
|
+
function filterValues(values) {
|
|
4148
|
+
let i = 0;
|
|
4149
|
+
for (; i < values.length; i++) {
|
|
4150
|
+
if (values[i].typ == exports.EnumToken.ImportantTokenType && values[i - 1]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
4151
|
+
values.splice(i - 1, 1);
|
|
4152
|
+
}
|
|
4153
|
+
else if (funcLike.includes(values[i].typ) && !['var', 'calc'].includes(values[i].val) && values[i + 1]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
4154
|
+
values.splice(i + 1, 1);
|
|
4155
|
+
}
|
|
4156
|
+
}
|
|
4157
|
+
return values;
|
|
4158
|
+
}
|
|
3949
4159
|
|
|
3950
4160
|
// https://www.w3.org/TR/CSS21/syndata.html#syntax
|
|
3951
4161
|
// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token
|
|
@@ -3960,6 +4170,14 @@
|
|
|
3960
4170
|
const fontFormat = ['collection', 'embedded-opentype', 'opentype', 'svg', 'truetype', 'woff', 'woff2'];
|
|
3961
4171
|
const colorFontTech = ['color-colrv0', 'color-colrv1', 'color-svg', 'color-sbix', 'color-cbdt'];
|
|
3962
4172
|
const fontFeaturesTech = ['features-opentype', 'features-aat', 'features-graphite', 'incremental-patch', 'incremental-range', 'incremental-auto', 'variations', 'palettes'];
|
|
4173
|
+
const transformFunctions = [
|
|
4174
|
+
'translate', 'scale', 'rotate', 'skew', 'perspective',
|
|
4175
|
+
'translateX', 'translateY', 'translateZ',
|
|
4176
|
+
'scaleX', 'scaleY', 'scaleZ',
|
|
4177
|
+
'rotateX', 'rotateY', 'rotateZ',
|
|
4178
|
+
'skewX', 'skewY',
|
|
4179
|
+
'rotate3d', 'translate3d', 'scale3d', 'matrix', 'matrix3d'
|
|
4180
|
+
];
|
|
3963
4181
|
// https://drafts.csswg.org/mediaqueries/#media-types
|
|
3964
4182
|
const mediaTypes = ['all', 'print', 'screen',
|
|
3965
4183
|
/* deprecated */
|
|
@@ -4351,7 +4569,9 @@
|
|
|
4351
4569
|
}
|
|
4352
4570
|
let isLegacySyntax = false;
|
|
4353
4571
|
if (token.typ == exports.EnumToken.FunctionTokenType && token.chi.length > 0 && colorsFunc.includes(token.val)) {
|
|
4572
|
+
// @ts-ignore
|
|
4354
4573
|
if (token.val == 'light-dark') {
|
|
4574
|
+
// @ts-ignore
|
|
4355
4575
|
const children = token.chi.filter((t) => [exports.EnumToken.IdenTokenType, exports.EnumToken.NumberTokenType, exports.EnumToken.LiteralTokenType, exports.EnumToken.ColorTokenType, exports.EnumToken.FunctionTokenType, exports.EnumToken.PercentageTokenType].includes(t.typ));
|
|
4356
4576
|
if (children.length != 2) {
|
|
4357
4577
|
return false;
|
|
@@ -4360,7 +4580,9 @@
|
|
|
4360
4580
|
return true;
|
|
4361
4581
|
}
|
|
4362
4582
|
}
|
|
4583
|
+
// @ts-ignore
|
|
4363
4584
|
if (token.val == 'color') {
|
|
4585
|
+
// @ts-ignore
|
|
4364
4586
|
const children = token.chi.filter((t) => [exports.EnumToken.IdenTokenType, exports.EnumToken.NumberTokenType, exports.EnumToken.LiteralTokenType, exports.EnumToken.ColorTokenType, exports.EnumToken.FunctionTokenType, exports.EnumToken.PercentageTokenType].includes(t.typ));
|
|
4365
4587
|
const isRelative = children[0].typ == exports.EnumToken.IdenTokenType && children[0].val == 'from';
|
|
4366
4588
|
if (children.length < 4 || children.length > 8) {
|
|
@@ -4409,73 +4631,79 @@
|
|
|
4409
4631
|
}
|
|
4410
4632
|
return true;
|
|
4411
4633
|
}
|
|
4412
|
-
else
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
if (![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ)) {
|
|
4419
|
-
acc[acc.length - 1].push(t);
|
|
4634
|
+
else { // @ts-ignore
|
|
4635
|
+
if (token.val == 'color-mix') {
|
|
4636
|
+
// @ts-ignore
|
|
4637
|
+
const children = token.chi.reduce((acc, t) => {
|
|
4638
|
+
if (t.typ == exports.EnumToken.CommaTokenType) {
|
|
4639
|
+
acc.push([]);
|
|
4420
4640
|
}
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
if (children[0].length > 3 ||
|
|
4426
|
-
children[0][0].typ != exports.EnumToken.IdenTokenType ||
|
|
4427
|
-
children[0][0].val != 'in' ||
|
|
4428
|
-
!isColorspace(children[0][1]) ||
|
|
4429
|
-
(children[0].length == 3 && !isHueInterpolationMethod(children[0][2])) ||
|
|
4430
|
-
children[1].length > 2 ||
|
|
4431
|
-
children[1][0].typ != exports.EnumToken.ColorTokenType ||
|
|
4432
|
-
children[2].length > 2 ||
|
|
4433
|
-
children[2][0].typ != exports.EnumToken.ColorTokenType) {
|
|
4434
|
-
return false;
|
|
4435
|
-
}
|
|
4436
|
-
if (children[1].length == 2) {
|
|
4437
|
-
if (!(children[1][1].typ == exports.EnumToken.PercentageTokenType || (children[1][1].typ == exports.EnumToken.NumberTokenType && children[1][1].val == '0'))) {
|
|
4438
|
-
return false;
|
|
4641
|
+
else {
|
|
4642
|
+
if (![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ)) {
|
|
4643
|
+
acc[acc.length - 1].push(t);
|
|
4644
|
+
}
|
|
4439
4645
|
}
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4646
|
+
return acc;
|
|
4647
|
+
}, [[]]);
|
|
4648
|
+
if (children.length == 3) {
|
|
4649
|
+
if (children[0].length > 3 ||
|
|
4650
|
+
children[0][0].typ != exports.EnumToken.IdenTokenType ||
|
|
4651
|
+
children[0][0].val != 'in' ||
|
|
4652
|
+
!isColorspace(children[0][1]) ||
|
|
4653
|
+
(children[0].length == 3 && !isHueInterpolationMethod(children[0][2])) ||
|
|
4654
|
+
children[1].length > 2 ||
|
|
4655
|
+
children[1][0].typ != exports.EnumToken.ColorTokenType ||
|
|
4656
|
+
children[2].length > 2 ||
|
|
4657
|
+
children[2][0].typ != exports.EnumToken.ColorTokenType) {
|
|
4443
4658
|
return false;
|
|
4444
4659
|
}
|
|
4660
|
+
if (children[1].length == 2) {
|
|
4661
|
+
if (!(children[1][1].typ == exports.EnumToken.PercentageTokenType || (children[1][1].typ == exports.EnumToken.NumberTokenType && children[1][1].val == '0'))) {
|
|
4662
|
+
return false;
|
|
4663
|
+
}
|
|
4664
|
+
}
|
|
4665
|
+
if (children[2].length == 2) {
|
|
4666
|
+
if (!(children[2][1].typ == exports.EnumToken.PercentageTokenType || (children[2][1].typ == exports.EnumToken.NumberTokenType && children[2][1].val == '0'))) {
|
|
4667
|
+
return false;
|
|
4668
|
+
}
|
|
4669
|
+
}
|
|
4670
|
+
return true;
|
|
4445
4671
|
}
|
|
4446
|
-
return
|
|
4447
|
-
}
|
|
4448
|
-
return false;
|
|
4449
|
-
}
|
|
4450
|
-
else {
|
|
4451
|
-
const keywords = ['from', 'none'];
|
|
4452
|
-
if (['rgb', 'hsl', 'hwb', 'lab', 'lch', 'oklab', 'oklch'].includes(token.val)) {
|
|
4453
|
-
keywords.push('alpha', ...token.val.slice(-3).split(''));
|
|
4672
|
+
return false;
|
|
4454
4673
|
}
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4674
|
+
else {
|
|
4675
|
+
const keywords = ['from', 'none'];
|
|
4676
|
+
// @ts-ignore
|
|
4677
|
+
if (['rgb', 'hsl', 'hwb', 'lab', 'lch', 'oklab', 'oklch'].includes(token.val)) {
|
|
4678
|
+
// @ts-ignore
|
|
4679
|
+
keywords.push('alpha', ...token.val.slice(-3).split(''));
|
|
4459
4680
|
}
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4681
|
+
// @ts-ignore
|
|
4682
|
+
for (const v of token.chi) {
|
|
4683
|
+
if (v.typ == exports.EnumToken.CommaTokenType) {
|
|
4684
|
+
isLegacySyntax = true;
|
|
4463
4685
|
}
|
|
4464
|
-
if (
|
|
4465
|
-
if (
|
|
4686
|
+
if (v.typ == exports.EnumToken.IdenTokenType) {
|
|
4687
|
+
if (!(keywords.includes(v.val) || v.val.toLowerCase() in COLORS_NAMES)) {
|
|
4466
4688
|
return false;
|
|
4467
4689
|
}
|
|
4468
|
-
if (
|
|
4469
|
-
|
|
4690
|
+
if (keywords.includes(v.val)) {
|
|
4691
|
+
if (isLegacySyntax) {
|
|
4692
|
+
return false;
|
|
4693
|
+
}
|
|
4694
|
+
// @ts-ignore
|
|
4695
|
+
if (v.val == 'from' && ['rgba', 'hsla'].includes(token.val)) {
|
|
4696
|
+
return false;
|
|
4697
|
+
}
|
|
4470
4698
|
}
|
|
4699
|
+
continue;
|
|
4700
|
+
}
|
|
4701
|
+
if (v.typ == exports.EnumToken.FunctionTokenType && (mathFuncs.includes(v.val) || v.val == 'var' || colorsFunc.includes(v.val))) {
|
|
4702
|
+
continue;
|
|
4703
|
+
}
|
|
4704
|
+
if (![exports.EnumToken.ColorTokenType, exports.EnumToken.IdenTokenType, exports.EnumToken.NumberTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.PercentageTokenType, exports.EnumToken.CommaTokenType, exports.EnumToken.WhitespaceTokenType, exports.EnumToken.LiteralTokenType].includes(v.typ)) {
|
|
4705
|
+
return false;
|
|
4471
4706
|
}
|
|
4472
|
-
continue;
|
|
4473
|
-
}
|
|
4474
|
-
if (v.typ == exports.EnumToken.FunctionTokenType && (mathFuncs.includes(v.val) || v.val == 'var' || colorsFunc.includes(v.val))) {
|
|
4475
|
-
continue;
|
|
4476
|
-
}
|
|
4477
|
-
if (![exports.EnumToken.ColorTokenType, exports.EnumToken.IdenTokenType, exports.EnumToken.NumberTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.PercentageTokenType, exports.EnumToken.CommaTokenType, exports.EnumToken.WhitespaceTokenType, exports.EnumToken.LiteralTokenType].includes(v.typ)) {
|
|
4478
|
-
return false;
|
|
4479
4707
|
}
|
|
4480
4708
|
}
|
|
4481
4709
|
}
|
|
@@ -6259,7 +6487,7 @@
|
|
|
6259
6487
|
while (node.val[0]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
6260
6488
|
node.val.shift();
|
|
6261
6489
|
}
|
|
6262
|
-
if (node.val.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ)).length == 0) {
|
|
6490
|
+
if (!node.nam.startsWith('--') && node.val.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ)).length == 0) {
|
|
6263
6491
|
errors.push({
|
|
6264
6492
|
action: 'drop',
|
|
6265
6493
|
message: 'doParse: invalid declaration',
|
|
@@ -10882,7 +11110,7 @@
|
|
|
10882
11110
|
chi: []
|
|
10883
11111
|
}, 'pos', { ...objectProperties, value: { ind: 0, lin: 1, col: 0 } });
|
|
10884
11112
|
// return minify(doParseSyntax(syntaxes, tokenize(syntaxes), root)) as ValidationRootToken;
|
|
10885
|
-
return minify$
|
|
11113
|
+
return minify$2(transform$1(doParseSyntax(syntax, tokenize(syntax), root)));
|
|
10886
11114
|
}
|
|
10887
11115
|
function matchParens(syntax, iterator) {
|
|
10888
11116
|
let item;
|
|
@@ -11133,12 +11361,12 @@
|
|
|
11133
11361
|
const t = { typ: ValidationTokenEnum.Root, chi: token.prelude };
|
|
11134
11362
|
doParseSyntax(syntax, t.chi[Symbol.iterator](), t);
|
|
11135
11363
|
token.prelude = t.chi;
|
|
11136
|
-
minify$
|
|
11364
|
+
minify$2(token.prelude);
|
|
11137
11365
|
}
|
|
11138
11366
|
}
|
|
11139
11367
|
// @ts-ignore
|
|
11140
11368
|
if (token?.chi?.length > 0) {
|
|
11141
|
-
minify$
|
|
11369
|
+
minify$2(doParseSyntax(syntax, token.chi[Symbol.iterator](), token));
|
|
11142
11370
|
}
|
|
11143
11371
|
}
|
|
11144
11372
|
else {
|
|
@@ -11591,7 +11819,7 @@
|
|
|
11591
11819
|
}
|
|
11592
11820
|
return position;
|
|
11593
11821
|
}
|
|
11594
|
-
function minify$
|
|
11822
|
+
function minify$2(ast) {
|
|
11595
11823
|
if (Array.isArray(ast)) {
|
|
11596
11824
|
// @ts-ignore
|
|
11597
11825
|
while (ast.length > 0 && ast[0].typ == ValidationTokenEnum.Whitespace) {
|
|
@@ -11604,7 +11832,7 @@
|
|
|
11604
11832
|
for (let i = 0; i < ast.length; i++) {
|
|
11605
11833
|
// if ([ValidationTokenEnum.ColumnToken, ValidationTokenEnum.PipeToken, ValidationTokenEnum.AmpersandToken].includes(ast[i].typ)) {
|
|
11606
11834
|
// for (const j of (ast[i] as ValidationPipeToken | ValidationColumnToken | ValidationAmpersandToken).l) {
|
|
11607
|
-
minify$
|
|
11835
|
+
minify$2(ast[i]);
|
|
11608
11836
|
// }
|
|
11609
11837
|
// for (const j of (ast[i] as ValidationPipeToken | ValidationColumnToken | ValidationAmpersandToken).r) {
|
|
11610
11838
|
//
|
|
@@ -11636,18 +11864,18 @@
|
|
|
11636
11864
|
// if ([ValidationTokenEnum.ColumnToken, ValidationTokenEnum.PipeToken, ValidationTokenEnum.AmpersandToken].includes(ast.typ)) {
|
|
11637
11865
|
// for (const j of (ast as ValidationPipeToken | ValidationColumnToken | ValidationAmpersandToken).l) {
|
|
11638
11866
|
if ('l' in ast) {
|
|
11639
|
-
minify$
|
|
11867
|
+
minify$2(ast.l);
|
|
11640
11868
|
}
|
|
11641
11869
|
// }
|
|
11642
11870
|
// for (const j of (ast as ValidationPipeToken | ValidationColumnToken | ValidationAmpersandToken).r) {
|
|
11643
11871
|
if ('r' in ast) {
|
|
11644
|
-
minify$
|
|
11872
|
+
minify$2(ast.r);
|
|
11645
11873
|
}
|
|
11646
11874
|
if ('chi' in ast) {
|
|
11647
|
-
minify$
|
|
11875
|
+
minify$2(ast.chi);
|
|
11648
11876
|
}
|
|
11649
11877
|
if ('prelude' in ast) {
|
|
11650
|
-
minify$
|
|
11878
|
+
minify$2(ast.prelude);
|
|
11651
11879
|
}
|
|
11652
11880
|
return ast;
|
|
11653
11881
|
}
|
|
@@ -11788,6 +12016,23 @@
|
|
|
11788
12016
|
return true;
|
|
11789
12017
|
}
|
|
11790
12018
|
|
|
12019
|
+
function stripCommaToken(tokenList) {
|
|
12020
|
+
let result = [];
|
|
12021
|
+
let last = null;
|
|
12022
|
+
for (let i = 0; i < tokenList.length; i++) {
|
|
12023
|
+
if (tokenList[i].typ == exports.EnumToken.CommaTokenType && last != null && last.typ == exports.EnumToken.CommaTokenType) {
|
|
12024
|
+
return null;
|
|
12025
|
+
}
|
|
12026
|
+
if (tokenList[i].typ != exports.EnumToken.WhitespaceTokenType) {
|
|
12027
|
+
last = tokenList[i];
|
|
12028
|
+
}
|
|
12029
|
+
if (tokenList[i].typ == exports.EnumToken.CommentTokenType || tokenList[i].typ == exports.EnumToken.CommaTokenType) {
|
|
12030
|
+
continue;
|
|
12031
|
+
}
|
|
12032
|
+
result.push(tokenList[i]);
|
|
12033
|
+
}
|
|
12034
|
+
return result;
|
|
12035
|
+
}
|
|
11791
12036
|
function splitTokenList(tokenList, split = [exports.EnumToken.CommaTokenType]) {
|
|
11792
12037
|
return tokenList.reduce((acc, curr) => {
|
|
11793
12038
|
if (curr.typ == exports.EnumToken.CommentTokenType) {
|
|
@@ -12144,19 +12389,20 @@
|
|
|
12144
12389
|
function validateRelativeSelector(tokens, root, options) {
|
|
12145
12390
|
tokens = tokens.slice();
|
|
12146
12391
|
consumeWhitespace(tokens);
|
|
12147
|
-
if (tokens.length == 0) {
|
|
12148
|
-
|
|
12149
|
-
|
|
12150
|
-
|
|
12151
|
-
|
|
12152
|
-
|
|
12153
|
-
|
|
12154
|
-
|
|
12155
|
-
|
|
12156
|
-
|
|
12157
|
-
|
|
12158
|
-
|
|
12159
|
-
}
|
|
12392
|
+
// if (tokens.length == 0) {
|
|
12393
|
+
//
|
|
12394
|
+
// // @ts-ignore
|
|
12395
|
+
// return {
|
|
12396
|
+
// valid: ValidationLevel.Drop,
|
|
12397
|
+
// matches: [],
|
|
12398
|
+
// // @ts-ignore
|
|
12399
|
+
// node: root,
|
|
12400
|
+
// // @ts-ignore
|
|
12401
|
+
// syntax: null,
|
|
12402
|
+
// error: 'expected selector',
|
|
12403
|
+
// tokens
|
|
12404
|
+
// }
|
|
12405
|
+
// }
|
|
12160
12406
|
// , EnumToken.DescendantCombinatorTokenType
|
|
12161
12407
|
if (combinatorsTokens.includes(tokens[0].typ)) {
|
|
12162
12408
|
tokens.shift();
|
|
@@ -12243,126 +12489,46 @@
|
|
|
12243
12489
|
};
|
|
12244
12490
|
}
|
|
12245
12491
|
|
|
12246
|
-
function validateKeyframeSelector(tokens,
|
|
12492
|
+
function validateKeyframeSelector(tokens, options) {
|
|
12247
12493
|
consumeWhitespace(tokens);
|
|
12248
12494
|
if (tokens.length == 0) {
|
|
12249
12495
|
// @ts-ignore
|
|
12250
12496
|
return {
|
|
12251
12497
|
valid: ValidationLevel.Drop,
|
|
12252
12498
|
matches: [],
|
|
12253
|
-
node:
|
|
12499
|
+
node: null,
|
|
12254
12500
|
syntax: null,
|
|
12255
12501
|
error: 'expected keyframe selector',
|
|
12256
12502
|
tokens
|
|
12257
12503
|
};
|
|
12258
12504
|
}
|
|
12259
|
-
|
|
12260
|
-
|
|
12261
|
-
consumeWhitespace(tokens);
|
|
12262
|
-
if (tokens.length == 0) {
|
|
12263
|
-
// @ts-ignore
|
|
12505
|
+
for (const t of splitTokenList(tokens)) {
|
|
12506
|
+
if (t.length != 1) {
|
|
12264
12507
|
return {
|
|
12265
|
-
valid: ValidationLevel.
|
|
12508
|
+
valid: ValidationLevel.Drop,
|
|
12266
12509
|
matches: [],
|
|
12267
|
-
node:
|
|
12510
|
+
node: t[0] ?? null,
|
|
12268
12511
|
syntax: null,
|
|
12269
|
-
error: '',
|
|
12512
|
+
error: 'unexpected token',
|
|
12513
|
+
tokens
|
|
12514
|
+
};
|
|
12515
|
+
}
|
|
12516
|
+
if (t[0].typ != exports.EnumToken.PercentageTokenType && !(t[0].typ == exports.EnumToken.IdenTokenType && ['from', 'to', 'cover', 'contain', 'entry', 'exit', 'entry-crossing', 'exit-crossing'].includes(t[0].val))) {
|
|
12517
|
+
return {
|
|
12518
|
+
valid: ValidationLevel.Drop,
|
|
12519
|
+
matches: [],
|
|
12520
|
+
node: t[0],
|
|
12521
|
+
syntax: null,
|
|
12522
|
+
error: 'expected keyframe selector',
|
|
12270
12523
|
tokens
|
|
12271
12524
|
};
|
|
12272
12525
|
}
|
|
12273
|
-
|
|
12274
|
-
|
|
12275
|
-
|
|
12276
|
-
|
|
12277
|
-
|
|
12278
|
-
|
|
12279
|
-
error: 'unexpected token',
|
|
12280
|
-
tokens
|
|
12281
|
-
};
|
|
12282
|
-
}
|
|
12283
|
-
if (tokens[0].typ != exports.EnumToken.IdenTokenType) {
|
|
12284
|
-
// @ts-ignore
|
|
12285
|
-
return {
|
|
12286
|
-
valid: ValidationLevel.Drop,
|
|
12287
|
-
matches: [],
|
|
12288
|
-
node: tokens[0],
|
|
12289
|
-
// @ts-ignore
|
|
12290
|
-
syntax: null,
|
|
12291
|
-
error: 'expected keyframe selector',
|
|
12292
|
-
tokens
|
|
12293
|
-
};
|
|
12294
|
-
}
|
|
12295
|
-
if (['from', 'to'].includes(tokens[0].val)) {
|
|
12296
|
-
tokens.shift();
|
|
12297
|
-
consumeWhitespace(tokens);
|
|
12298
|
-
if (tokens.length > 0) {
|
|
12299
|
-
// @ts-ignore
|
|
12300
|
-
return {
|
|
12301
|
-
valid: ValidationLevel.Drop,
|
|
12302
|
-
matches: [],
|
|
12303
|
-
node: tokens[0],
|
|
12304
|
-
syntax: null,
|
|
12305
|
-
error: 'unexpected token',
|
|
12306
|
-
tokens
|
|
12307
|
-
};
|
|
12308
|
-
}
|
|
12309
|
-
// @ts-ignore
|
|
12310
|
-
return {
|
|
12311
|
-
valid: ValidationLevel.Valid,
|
|
12312
|
-
matches: [],
|
|
12313
|
-
node: null,
|
|
12314
|
-
// @ts-ignore
|
|
12315
|
-
syntax: null,
|
|
12316
|
-
error: '',
|
|
12317
|
-
tokens
|
|
12318
|
-
};
|
|
12319
|
-
}
|
|
12320
|
-
if (!['cover', 'contain', 'entry', 'exit', 'entry-crossing', 'exit-crossing'].includes(tokens[0].val)) {
|
|
12321
|
-
// @ts-ignore
|
|
12322
|
-
return {
|
|
12323
|
-
valid: ValidationLevel.Drop,
|
|
12324
|
-
matches: [],
|
|
12325
|
-
node: tokens[0],
|
|
12326
|
-
// @ts-ignore
|
|
12327
|
-
syntax: null,
|
|
12328
|
-
error: 'unexpected token',
|
|
12329
|
-
tokens
|
|
12330
|
-
};
|
|
12331
|
-
}
|
|
12332
|
-
tokens.shift();
|
|
12333
|
-
consumeWhitespace(tokens);
|
|
12334
|
-
// @ts-ignore
|
|
12335
|
-
if (tokens.length == 0 || tokens[0].typ != exports.EnumToken.PercentageTokenType) {
|
|
12336
|
-
// @ts-ignore
|
|
12337
|
-
return {
|
|
12338
|
-
valid: ValidationLevel.Drop,
|
|
12339
|
-
matches: [],
|
|
12340
|
-
node: tokens[0],
|
|
12341
|
-
// @ts-ignore
|
|
12342
|
-
syntax: null,
|
|
12343
|
-
error: 'expecting percentage token',
|
|
12344
|
-
tokens
|
|
12345
|
-
};
|
|
12346
|
-
}
|
|
12347
|
-
tokens.shift();
|
|
12348
|
-
consumeWhitespace(tokens);
|
|
12349
|
-
if (tokens.length > 0) {
|
|
12350
|
-
// @ts-ignore
|
|
12351
|
-
return {
|
|
12352
|
-
valid: ValidationLevel.Drop,
|
|
12353
|
-
matches: [],
|
|
12354
|
-
node: tokens[0],
|
|
12355
|
-
// @ts-ignore
|
|
12356
|
-
syntax: null,
|
|
12357
|
-
error: 'unexpected token',
|
|
12358
|
-
tokens
|
|
12359
|
-
};
|
|
12360
|
-
}
|
|
12361
|
-
// @ts-ignore
|
|
12362
|
-
return {
|
|
12363
|
-
valid: ValidationLevel.Valid,
|
|
12364
|
-
matches: [],
|
|
12365
|
-
node: null,
|
|
12526
|
+
}
|
|
12527
|
+
// @ts-ignore
|
|
12528
|
+
return {
|
|
12529
|
+
valid: ValidationLevel.Valid,
|
|
12530
|
+
matches: [],
|
|
12531
|
+
node: null,
|
|
12366
12532
|
// @ts-ignore
|
|
12367
12533
|
syntax: null,
|
|
12368
12534
|
error: '',
|
|
@@ -12376,7 +12542,7 @@
|
|
|
12376
12542
|
let result = null;
|
|
12377
12543
|
while (i + 1 < tokens.length) {
|
|
12378
12544
|
if (tokens[++i].typ == exports.EnumToken.CommaTokenType) {
|
|
12379
|
-
result = validateKeyframeSelector(tokens.slice(j, i)
|
|
12545
|
+
result = validateKeyframeSelector(tokens.slice(j, i));
|
|
12380
12546
|
if (result.valid == ValidationLevel.Drop) {
|
|
12381
12547
|
return result;
|
|
12382
12548
|
}
|
|
@@ -12384,7 +12550,7 @@
|
|
|
12384
12550
|
i = j;
|
|
12385
12551
|
}
|
|
12386
12552
|
}
|
|
12387
|
-
return validateKeyframeSelector(i == j ? tokens.slice(i) : tokens.slice(j, i + 1)
|
|
12553
|
+
return validateKeyframeSelector(i == j ? tokens.slice(i) : tokens.slice(j, i + 1));
|
|
12388
12554
|
}
|
|
12389
12555
|
|
|
12390
12556
|
function validateURL(token) {
|
|
@@ -12460,7 +12626,7 @@
|
|
|
12460
12626
|
}
|
|
12461
12627
|
// @ts-ignore
|
|
12462
12628
|
if (root.typ == exports.EnumToken.AtRuleNodeType && root.nam.match(/^(-[a-z]+-)?keyframes$/)) {
|
|
12463
|
-
return validateKeyframeBlockList(selector
|
|
12629
|
+
return validateKeyframeBlockList(selector);
|
|
12464
12630
|
}
|
|
12465
12631
|
let isNested = root.typ == exports.EnumToken.RuleNodeType ? 1 : 0;
|
|
12466
12632
|
let currentRoot = root.parent;
|
|
@@ -12476,7 +12642,10 @@
|
|
|
12476
12642
|
}
|
|
12477
12643
|
const nestedSelector = isNested > 0;
|
|
12478
12644
|
// @ts-ignore
|
|
12479
|
-
return nestedSelector ? validateRelativeSelectorList(selector, root, {
|
|
12645
|
+
return nestedSelector ? validateRelativeSelectorList(selector, root, {
|
|
12646
|
+
...(options ?? {}),
|
|
12647
|
+
nestedSelector
|
|
12648
|
+
}) : validateSelectorList(selector, root, { ...(options ?? {}), nestedSelector });
|
|
12480
12649
|
}
|
|
12481
12650
|
|
|
12482
12651
|
function validateAtRuleMedia(atRule, options, root) {
|
|
@@ -12712,7 +12881,6 @@
|
|
|
12712
12881
|
if (chi[0].typ == exports.EnumToken.MediaQueryConditionTokenType) {
|
|
12713
12882
|
return chi[0].l.typ == exports.EnumToken.IdenTokenType;
|
|
12714
12883
|
}
|
|
12715
|
-
console.error(chi[0].parent);
|
|
12716
12884
|
return false;
|
|
12717
12885
|
}
|
|
12718
12886
|
function validateMediaFeature(token) {
|
|
@@ -13559,7 +13727,7 @@
|
|
|
13559
13727
|
}
|
|
13560
13728
|
if (t[0].typ == exports.EnumToken.UrlFunctionTokenType) {
|
|
13561
13729
|
result = validateURL(t[0]);
|
|
13562
|
-
if (result
|
|
13730
|
+
if (result?.valid == ValidationLevel.Drop) {
|
|
13563
13731
|
return result;
|
|
13564
13732
|
}
|
|
13565
13733
|
continue;
|
|
@@ -13598,7 +13766,7 @@
|
|
|
13598
13766
|
valid: ValidationLevel.Drop,
|
|
13599
13767
|
matches: [],
|
|
13600
13768
|
node: atRule,
|
|
13601
|
-
syntax: '@
|
|
13769
|
+
syntax: '@keyframes',
|
|
13602
13770
|
error: 'expecting at-rule prelude',
|
|
13603
13771
|
tokens: []
|
|
13604
13772
|
};
|
|
@@ -13905,10 +14073,10 @@
|
|
|
13905
14073
|
break;
|
|
13906
14074
|
}
|
|
13907
14075
|
token = queries[0];
|
|
13908
|
-
if (token
|
|
14076
|
+
if (token?.typ == exports.EnumToken.MediaFeatureNotTokenType) {
|
|
13909
14077
|
token = token.val;
|
|
13910
14078
|
}
|
|
13911
|
-
if (token
|
|
14079
|
+
if (token?.typ != exports.EnumToken.ParensTokenType && (token?.typ != exports.EnumToken.FunctionTokenType || !['scroll-state', 'style'].includes(token.val))) {
|
|
13912
14080
|
return {
|
|
13913
14081
|
valid: ValidationLevel.Drop,
|
|
13914
14082
|
matches: [],
|
|
@@ -13918,7 +14086,7 @@
|
|
|
13918
14086
|
tokens
|
|
13919
14087
|
};
|
|
13920
14088
|
}
|
|
13921
|
-
if (token
|
|
14089
|
+
if (token?.typ == exports.EnumToken.ParensTokenType) {
|
|
13922
14090
|
result = validateContainerSizeFeature(token.chi, atRule);
|
|
13923
14091
|
}
|
|
13924
14092
|
else if (token.val == 'scroll-state') {
|
|
@@ -13936,7 +14104,7 @@
|
|
|
13936
14104
|
break;
|
|
13937
14105
|
}
|
|
13938
14106
|
token = queries[0];
|
|
13939
|
-
if (token
|
|
14107
|
+
if (token?.typ != exports.EnumToken.MediaFeatureAndTokenType && token?.typ != exports.EnumToken.MediaFeatureOrTokenType) {
|
|
13940
14108
|
return {
|
|
13941
14109
|
valid: ValidationLevel.Drop,
|
|
13942
14110
|
matches: [],
|
|
@@ -13947,9 +14115,9 @@
|
|
|
13947
14115
|
};
|
|
13948
14116
|
}
|
|
13949
14117
|
if (tokenType == null) {
|
|
13950
|
-
tokenType = token
|
|
14118
|
+
tokenType = token?.typ;
|
|
13951
14119
|
}
|
|
13952
|
-
if (tokenType != token
|
|
14120
|
+
if (tokenType == null || tokenType != token?.typ) {
|
|
13953
14121
|
return {
|
|
13954
14122
|
valid: ValidationLevel.Drop,
|
|
13955
14123
|
matches: [],
|
|
@@ -14211,9 +14379,6 @@
|
|
|
14211
14379
|
error: ''
|
|
14212
14380
|
};
|
|
14213
14381
|
}
|
|
14214
|
-
if (atRule.nam == 'keyframes') {
|
|
14215
|
-
return validateAtRuleKeyframes(atRule);
|
|
14216
|
-
}
|
|
14217
14382
|
if (['font-face', 'view-transition', 'starting-style'].includes(atRule.nam)) {
|
|
14218
14383
|
return {
|
|
14219
14384
|
valid: ValidationLevel.Valid,
|
|
@@ -14396,12 +14561,13 @@
|
|
|
14396
14561
|
minify: true,
|
|
14397
14562
|
pass: 1,
|
|
14398
14563
|
parseColor: true,
|
|
14399
|
-
nestingRules:
|
|
14564
|
+
nestingRules: true,
|
|
14400
14565
|
resolveImport: false,
|
|
14401
14566
|
resolveUrls: false,
|
|
14402
14567
|
removeCharset: true,
|
|
14403
14568
|
removeEmpty: true,
|
|
14404
14569
|
removeDuplicateDeclarations: true,
|
|
14570
|
+
computeTransform: true,
|
|
14405
14571
|
computeShorthand: true,
|
|
14406
14572
|
computeCalcExpression: true,
|
|
14407
14573
|
inlineCssVariables: false,
|
|
@@ -14470,11 +14636,13 @@
|
|
|
14470
14636
|
}
|
|
14471
14637
|
else if (item.token == '{') {
|
|
14472
14638
|
let inBlock = 1;
|
|
14639
|
+
tokens = [item];
|
|
14473
14640
|
do {
|
|
14474
14641
|
item = iter.next().value;
|
|
14475
14642
|
if (item == null) {
|
|
14476
14643
|
break;
|
|
14477
14644
|
}
|
|
14645
|
+
tokens.push(item);
|
|
14478
14646
|
if (item.token == '{') {
|
|
14479
14647
|
inBlock++;
|
|
14480
14648
|
}
|
|
@@ -14482,6 +14650,13 @@
|
|
|
14482
14650
|
inBlock--;
|
|
14483
14651
|
}
|
|
14484
14652
|
} while (inBlock != 0);
|
|
14653
|
+
if (tokens.length > 0) {
|
|
14654
|
+
errors.push({
|
|
14655
|
+
action: 'drop',
|
|
14656
|
+
message: 'invalid block',
|
|
14657
|
+
rawTokens: tokens.slice()
|
|
14658
|
+
});
|
|
14659
|
+
}
|
|
14485
14660
|
}
|
|
14486
14661
|
tokens = [];
|
|
14487
14662
|
map = new Map;
|
|
@@ -14514,6 +14689,7 @@
|
|
|
14514
14689
|
await parseNode(tokens, context, stats, options, errors, src, map, rawTokens);
|
|
14515
14690
|
rawTokens.length = 0;
|
|
14516
14691
|
if (context != null && context.typ == exports.EnumToken.InvalidRuleTokenType) {
|
|
14692
|
+
// @ts-ignore
|
|
14517
14693
|
const index = context.chi.findIndex((node) => node == context);
|
|
14518
14694
|
if (index > -1) {
|
|
14519
14695
|
context.chi.splice(index, 1);
|
|
@@ -14813,9 +14989,11 @@
|
|
|
14813
14989
|
acc.push(renderToken(curr, { removeComments: true }));
|
|
14814
14990
|
return acc;
|
|
14815
14991
|
}, []);
|
|
14992
|
+
const nam = renderToken(atRule, { removeComments: true });
|
|
14993
|
+
// @ts-ignore
|
|
14816
14994
|
const node = {
|
|
14817
|
-
typ: exports.EnumToken.AtRuleNodeType,
|
|
14818
|
-
nam
|
|
14995
|
+
typ: /^(-[a-z]+-)?keyframes$/.test(nam) ? exports.EnumToken.KeyframeAtRuleNodeType : exports.EnumToken.AtRuleNodeType,
|
|
14996
|
+
nam,
|
|
14819
14997
|
// tokens: t,
|
|
14820
14998
|
val: raw.join('')
|
|
14821
14999
|
};
|
|
@@ -14846,7 +15024,7 @@
|
|
|
14846
15024
|
isValid = false;
|
|
14847
15025
|
}
|
|
14848
15026
|
}
|
|
14849
|
-
const valid = isValid ? validateAtRule(node, options, context) : {
|
|
15027
|
+
const valid = isValid ? (node.typ == exports.EnumToken.KeyframeAtRuleNodeType ? validateAtRuleKeyframes(node) : validateAtRule(node, options, context)) : {
|
|
14850
15028
|
valid: ValidationLevel.Drop,
|
|
14851
15029
|
node,
|
|
14852
15030
|
syntax: '@' + node.nam,
|
|
@@ -14862,7 +15040,10 @@
|
|
|
14862
15040
|
node.typ = exports.EnumToken.InvalidAtRuleTokenType;
|
|
14863
15041
|
}
|
|
14864
15042
|
else {
|
|
14865
|
-
node.val = node.tokens.reduce((acc, curr) => acc + renderToken(curr, {
|
|
15043
|
+
node.val = node.tokens.reduce((acc, curr) => acc + renderToken(curr, {
|
|
15044
|
+
minify: false,
|
|
15045
|
+
removeComments: true
|
|
15046
|
+
}), '');
|
|
14866
15047
|
}
|
|
14867
15048
|
}
|
|
14868
15049
|
// @ts-ignore
|
|
@@ -14875,72 +15056,79 @@
|
|
|
14875
15056
|
if (delim.typ == exports.EnumToken.BlockStartTokenType) {
|
|
14876
15057
|
const position = map.get(tokens[0]);
|
|
14877
15058
|
const uniq = new Map;
|
|
14878
|
-
parseTokens(tokens, { minify: true })
|
|
14879
|
-
|
|
14880
|
-
return acc;
|
|
14881
|
-
}
|
|
14882
|
-
if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
14883
|
-
if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
|
|
14884
|
-
trimWhiteSpace.includes(array[index + 1]?.typ) ||
|
|
14885
|
-
combinators.includes(array[index - 1]?.val) ||
|
|
14886
|
-
combinators.includes(array[index + 1]?.val)) {
|
|
14887
|
-
return acc;
|
|
14888
|
-
}
|
|
14889
|
-
}
|
|
14890
|
-
let t = renderToken(curr, { minify: false });
|
|
14891
|
-
if (t == ',') {
|
|
14892
|
-
acc.push([]);
|
|
14893
|
-
// uniqTokens.push([]);
|
|
14894
|
-
}
|
|
14895
|
-
else {
|
|
14896
|
-
acc[acc.length - 1].push(t);
|
|
14897
|
-
// uniqTokens[uniqTokens.length - 1].push(curr);
|
|
14898
|
-
}
|
|
14899
|
-
return acc;
|
|
14900
|
-
}, [[]]).reduce((acc, curr) => {
|
|
14901
|
-
let i = 0;
|
|
14902
|
-
for (; i < curr.length; i++) {
|
|
14903
|
-
if (i + 1 < curr.length && curr[i] == '*') {
|
|
14904
|
-
if (curr[i] == '*') {
|
|
14905
|
-
let index = curr[i + 1] == ' ' ? 2 : 1;
|
|
14906
|
-
if (!['>', '~', '+'].includes(curr[index])) {
|
|
14907
|
-
curr.splice(i, index);
|
|
14908
|
-
}
|
|
14909
|
-
}
|
|
14910
|
-
}
|
|
14911
|
-
}
|
|
14912
|
-
acc.set(curr.join(''), curr);
|
|
14913
|
-
return acc;
|
|
14914
|
-
}, uniq);
|
|
14915
|
-
const ruleType = context.typ == exports.EnumToken.AtRuleNodeType && context.nam == 'keyframes' ? exports.EnumToken.KeyFrameRuleNodeType : exports.EnumToken.RuleNodeType;
|
|
15059
|
+
parseTokens(tokens, { minify: true });
|
|
15060
|
+
const ruleType = context.typ == exports.EnumToken.KeyframeAtRuleNodeType ? exports.EnumToken.KeyFrameRuleNodeType : exports.EnumToken.RuleNodeType;
|
|
14916
15061
|
if (ruleType == exports.EnumToken.RuleNodeType) {
|
|
14917
15062
|
parseSelector(tokens);
|
|
14918
|
-
|
|
14919
|
-
|
|
14920
|
-
|
|
14921
|
-
|
|
14922
|
-
|
|
14923
|
-
|
|
14924
|
-
|
|
14925
|
-
|
|
14926
|
-
|
|
14927
|
-
|
|
14928
|
-
|
|
14929
|
-
|
|
14930
|
-
|
|
14931
|
-
// @ts-ignore
|
|
14932
|
-
location: { src, ...(map.get(valid.node) ?? position) }
|
|
14933
|
-
});
|
|
15063
|
+
}
|
|
15064
|
+
if (options.validation) {
|
|
15065
|
+
// @ts-ignore
|
|
15066
|
+
const valid = ruleType == exports.EnumToken.KeyFrameRuleNodeType ? validateKeyframeSelector(tokens) : validateSelector(tokens, options, context);
|
|
15067
|
+
if (valid.valid != ValidationLevel.Valid) {
|
|
15068
|
+
const node = {
|
|
15069
|
+
typ: exports.EnumToken.InvalidRuleTokenType,
|
|
15070
|
+
sel: tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), ''),
|
|
15071
|
+
chi: []
|
|
15072
|
+
};
|
|
15073
|
+
errors.push({
|
|
15074
|
+
action: 'drop',
|
|
15075
|
+
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), '') + '"',
|
|
14934
15076
|
// @ts-ignore
|
|
14935
|
-
|
|
14936
|
-
|
|
14937
|
-
|
|
14938
|
-
|
|
15077
|
+
location: { src, ...(map.get(valid.node) ?? position) }
|
|
15078
|
+
});
|
|
15079
|
+
// @ts-ignore
|
|
15080
|
+
context.chi.push(node);
|
|
15081
|
+
Object.defineProperty(node, 'parent', { ...definedPropertySettings, value: context });
|
|
15082
|
+
return node;
|
|
14939
15083
|
}
|
|
14940
15084
|
}
|
|
14941
15085
|
const node = {
|
|
14942
15086
|
typ: ruleType,
|
|
14943
|
-
sel: [...
|
|
15087
|
+
sel: [...tokens.reduce((acc, curr, index, array) => {
|
|
15088
|
+
if (curr.typ == exports.EnumToken.CommentTokenType) {
|
|
15089
|
+
return acc;
|
|
15090
|
+
}
|
|
15091
|
+
if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
15092
|
+
if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
|
|
15093
|
+
trimWhiteSpace.includes(array[index + 1]?.typ) ||
|
|
15094
|
+
combinators.includes(array[index - 1]?.val) ||
|
|
15095
|
+
combinators.includes(array[index + 1]?.val)) {
|
|
15096
|
+
return acc;
|
|
15097
|
+
}
|
|
15098
|
+
}
|
|
15099
|
+
if (ruleType == exports.EnumToken.KeyFrameRuleNodeType) {
|
|
15100
|
+
if (curr.typ == exports.EnumToken.IdenTokenType && curr.val == 'from') {
|
|
15101
|
+
Object.assign(curr, { typ: exports.EnumToken.PercentageTokenType, val: '0' });
|
|
15102
|
+
}
|
|
15103
|
+
else if (curr.typ == exports.EnumToken.PercentageTokenType && curr.val == '100') {
|
|
15104
|
+
Object.assign(curr, { typ: exports.EnumToken.IdenTokenType, val: 'to' });
|
|
15105
|
+
}
|
|
15106
|
+
}
|
|
15107
|
+
let t = renderToken(curr, { minify: false });
|
|
15108
|
+
if (t == ',') {
|
|
15109
|
+
acc.push([]);
|
|
15110
|
+
// uniqTokens.push([]);
|
|
15111
|
+
}
|
|
15112
|
+
else {
|
|
15113
|
+
acc[acc.length - 1].push(t);
|
|
15114
|
+
// uniqTokens[uniqTokens.length - 1].push(curr);
|
|
15115
|
+
}
|
|
15116
|
+
return acc;
|
|
15117
|
+
}, [[]]).reduce((acc, curr) => {
|
|
15118
|
+
let i = 0;
|
|
15119
|
+
for (; i < curr.length; i++) {
|
|
15120
|
+
if (i + 1 < curr.length && curr[i] == '*') {
|
|
15121
|
+
if (curr[i] == '*') {
|
|
15122
|
+
let index = curr[i + 1] == ' ' ? 2 : 1;
|
|
15123
|
+
if (!['>', '~', '+'].includes(curr[index])) {
|
|
15124
|
+
curr.splice(i, index);
|
|
15125
|
+
}
|
|
15126
|
+
}
|
|
15127
|
+
}
|
|
15128
|
+
}
|
|
15129
|
+
acc.set(curr.join(''), curr);
|
|
15130
|
+
return acc;
|
|
15131
|
+
}, uniq).keys()].join(','),
|
|
14944
15132
|
chi: []
|
|
14945
15133
|
};
|
|
14946
15134
|
Object.defineProperty(node, 'tokens', {
|
|
@@ -15025,7 +15213,8 @@
|
|
|
15025
15213
|
}
|
|
15026
15214
|
}
|
|
15027
15215
|
}
|
|
15028
|
-
|
|
15216
|
+
const nam = renderToken(name.shift(), { removeComments: true });
|
|
15217
|
+
if (value == null || (!nam.startsWith('--') && value.length == 0)) {
|
|
15029
15218
|
errors.push({
|
|
15030
15219
|
action: 'drop',
|
|
15031
15220
|
message: 'doParse: invalid declaration',
|
|
@@ -15033,33 +15222,30 @@
|
|
|
15033
15222
|
});
|
|
15034
15223
|
return null;
|
|
15035
15224
|
}
|
|
15225
|
+
for (const { value: token } of walkValues(value, null, {
|
|
15226
|
+
fn: (node) => node.typ == exports.EnumToken.FunctionTokenType && node.val == 'calc' ? WalkerOptionEnum.IgnoreChildren : null,
|
|
15227
|
+
type: exports.EnumToken.FunctionTokenType
|
|
15228
|
+
})) {
|
|
15229
|
+
if (token.typ == exports.EnumToken.FunctionTokenType && token.val == 'calc') {
|
|
15230
|
+
for (const { value: node, parent } of walkValues(token.chi, token)) {
|
|
15231
|
+
// fix expressions starting with '/' or '*' such as '/4' in (1 + 1)/4
|
|
15232
|
+
if (node.typ == exports.EnumToken.LiteralTokenType && node.val.length > 0) {
|
|
15233
|
+
if (node.val[0] == '/' || node.val[0] == '*') {
|
|
15234
|
+
parent.chi.splice(parent.chi.indexOf(node), 1, { typ: node.val[0] == '/' ? exports.EnumToken.Div : exports.EnumToken.Mul }, ...parseString(node.val.slice(1)));
|
|
15235
|
+
}
|
|
15236
|
+
}
|
|
15237
|
+
}
|
|
15238
|
+
}
|
|
15239
|
+
}
|
|
15036
15240
|
const node = {
|
|
15037
15241
|
typ: exports.EnumToken.DeclarationNodeType,
|
|
15038
15242
|
// @ts-ignore
|
|
15039
|
-
nam
|
|
15243
|
+
nam,
|
|
15040
15244
|
// @ts-ignore
|
|
15041
15245
|
val: value
|
|
15042
15246
|
};
|
|
15043
15247
|
const result = parseDeclarationNode(node, errors, src, position);
|
|
15044
15248
|
if (result != null) {
|
|
15045
|
-
// if (options.validation) {
|
|
15046
|
-
//
|
|
15047
|
-
// const valid: ValidationResult = validateDeclaration(result, options, context);
|
|
15048
|
-
//
|
|
15049
|
-
// // console.error({valid});
|
|
15050
|
-
//
|
|
15051
|
-
// if (valid.valid == ValidationLevel.Drop) {
|
|
15052
|
-
//
|
|
15053
|
-
// errors.push({
|
|
15054
|
-
// action: 'drop',
|
|
15055
|
-
// message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, {minify: false}), '') + '"',
|
|
15056
|
-
// // @ts-ignore
|
|
15057
|
-
// location: {src, ...(map.get(valid.node) ?? position)}
|
|
15058
|
-
// });
|
|
15059
|
-
//
|
|
15060
|
-
// return null;
|
|
15061
|
-
// }
|
|
15062
|
-
// }
|
|
15063
15249
|
// @ts-ignore
|
|
15064
15250
|
context.chi.push(result);
|
|
15065
15251
|
Object.defineProperty(result, 'parent', { ...definedPropertySettings, value: context });
|
|
@@ -15142,8 +15328,6 @@
|
|
|
15142
15328
|
}
|
|
15143
15329
|
}
|
|
15144
15330
|
if (value.typ == exports.EnumToken.ParensTokenType || (value.typ == exports.EnumToken.FunctionTokenType && ['media', 'supports', 'style', 'scroll-state'].includes(value.val))) {
|
|
15145
|
-
// @todo parse range and declarations
|
|
15146
|
-
// parseDeclaration(parent.chi);
|
|
15147
15331
|
let i;
|
|
15148
15332
|
let nameIndex = -1;
|
|
15149
15333
|
let valueIndex = -1;
|
|
@@ -15707,7 +15891,7 @@
|
|
|
15707
15891
|
upper++;
|
|
15708
15892
|
}
|
|
15709
15893
|
if (upper < t.chi.length &&
|
|
15710
|
-
t.chi[upper].typ == exports.EnumToken.
|
|
15894
|
+
t.chi[upper].typ == exports.EnumToken.IdenTokenType &&
|
|
15711
15895
|
['i', 's'].includes(t.chi[upper].val.toLowerCase())) {
|
|
15712
15896
|
t.chi[m].attr = t.chi[upper].val;
|
|
15713
15897
|
t.chi.splice(upper, 1);
|
|
@@ -15923,6 +16107,13 @@
|
|
|
15923
16107
|
return true;
|
|
15924
16108
|
}
|
|
15925
16109
|
|
|
16110
|
+
var WalkerOptionEnum;
|
|
16111
|
+
(function (WalkerOptionEnum) {
|
|
16112
|
+
WalkerOptionEnum[WalkerOptionEnum["Ignore"] = 0] = "Ignore";
|
|
16113
|
+
WalkerOptionEnum[WalkerOptionEnum["Stop"] = 1] = "Stop";
|
|
16114
|
+
WalkerOptionEnum[WalkerOptionEnum["Children"] = 2] = "Children";
|
|
16115
|
+
WalkerOptionEnum[WalkerOptionEnum["IgnoreChildren"] = 3] = "IgnoreChildren";
|
|
16116
|
+
})(WalkerOptionEnum || (WalkerOptionEnum = {}));
|
|
15926
16117
|
var WalkerValueEvent;
|
|
15927
16118
|
(function (WalkerValueEvent) {
|
|
15928
16119
|
WalkerValueEvent[WalkerValueEvent["Enter"] = 0] = "Enter";
|
|
@@ -15941,10 +16132,10 @@
|
|
|
15941
16132
|
let option = null;
|
|
15942
16133
|
if (filter != null) {
|
|
15943
16134
|
option = filter(node);
|
|
15944
|
-
if (option ===
|
|
16135
|
+
if (option === WalkerOptionEnum.Ignore) {
|
|
15945
16136
|
continue;
|
|
15946
16137
|
}
|
|
15947
|
-
if (option ===
|
|
16138
|
+
if (option === WalkerOptionEnum.Stop) {
|
|
15948
16139
|
break;
|
|
15949
16140
|
}
|
|
15950
16141
|
}
|
|
@@ -15953,7 +16144,7 @@
|
|
|
15953
16144
|
// @ts-ignore
|
|
15954
16145
|
yield { node, parent: map.get(node), root };
|
|
15955
16146
|
}
|
|
15956
|
-
if (option !==
|
|
16147
|
+
if (option !== WalkerOptionEnum.IgnoreChildren && 'chi' in node) {
|
|
15957
16148
|
parents.unshift(...node.chi);
|
|
15958
16149
|
for (const child of node.chi.slice()) {
|
|
15959
16150
|
map.set(child, node);
|
|
@@ -15985,19 +16176,20 @@
|
|
|
15985
16176
|
event: WalkerValueEvent.Enter
|
|
15986
16177
|
};
|
|
15987
16178
|
}
|
|
16179
|
+
const eventType = filter.event ?? WalkerValueEvent.Enter;
|
|
15988
16180
|
while (stack.length > 0) {
|
|
15989
16181
|
let value = reverse ? stack.pop() : stack.shift();
|
|
15990
16182
|
let option = null;
|
|
15991
|
-
if (filter.fn != null &&
|
|
16183
|
+
if (filter.fn != null && eventType == WalkerValueEvent.Enter) {
|
|
15992
16184
|
const isValid = filter.type == null || value.typ == filter.type ||
|
|
15993
16185
|
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
15994
16186
|
(typeof filter.type == 'function' && filter.type(value));
|
|
15995
16187
|
if (isValid) {
|
|
15996
|
-
option = filter.fn(value, map.get(value) ?? root
|
|
15997
|
-
if (option ===
|
|
16188
|
+
option = filter.fn(value, map.get(value) ?? root);
|
|
16189
|
+
if (option === WalkerOptionEnum.Ignore) {
|
|
15998
16190
|
continue;
|
|
15999
16191
|
}
|
|
16000
|
-
if (option ===
|
|
16192
|
+
if (option === WalkerOptionEnum.Stop) {
|
|
16001
16193
|
break;
|
|
16002
16194
|
}
|
|
16003
16195
|
// @ts-ignore
|
|
@@ -16006,8 +16198,7 @@
|
|
|
16006
16198
|
}
|
|
16007
16199
|
}
|
|
16008
16200
|
}
|
|
16009
|
-
|
|
16010
|
-
if (filter.event == WalkerValueEvent.Enter && option !== 'children') {
|
|
16201
|
+
if (eventType == WalkerValueEvent.Enter && option !== WalkerOptionEnum.Children) {
|
|
16011
16202
|
yield {
|
|
16012
16203
|
value,
|
|
16013
16204
|
parent: map.get(value) ?? root,
|
|
@@ -16017,7 +16208,7 @@
|
|
|
16017
16208
|
root: root ?? null
|
|
16018
16209
|
};
|
|
16019
16210
|
}
|
|
16020
|
-
if (option !==
|
|
16211
|
+
if (option !== WalkerOptionEnum.IgnoreChildren && 'chi' in value) {
|
|
16021
16212
|
const sliced = value.chi.slice();
|
|
16022
16213
|
for (const child of sliced) {
|
|
16023
16214
|
map.set(child, value);
|
|
@@ -16030,24 +16221,23 @@
|
|
|
16030
16221
|
}
|
|
16031
16222
|
}
|
|
16032
16223
|
else if (value.typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
16033
|
-
map.set(value.l,
|
|
16034
|
-
map.set(value.r,
|
|
16224
|
+
map.set(value.l, value);
|
|
16225
|
+
map.set(value.r, value);
|
|
16035
16226
|
stack.unshift(value.l, value.r);
|
|
16036
16227
|
}
|
|
16037
|
-
if (
|
|
16228
|
+
if (eventType == WalkerValueEvent.Leave && filter.fn != null) {
|
|
16038
16229
|
const isValid = filter.type == null || value.typ == filter.type ||
|
|
16039
16230
|
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
16040
16231
|
(typeof filter.type == 'function' && filter.type(value));
|
|
16041
16232
|
if (isValid) {
|
|
16042
|
-
option = filter.fn(value, map.get(value)
|
|
16233
|
+
option = filter.fn(value, map.get(value));
|
|
16043
16234
|
// @ts-ignore
|
|
16044
16235
|
if (option != null && 'typ' in option) {
|
|
16045
16236
|
map.set(option, map.get(value) ?? root);
|
|
16046
16237
|
}
|
|
16047
16238
|
}
|
|
16048
16239
|
}
|
|
16049
|
-
|
|
16050
|
-
if (filter.event == WalkerValueEvent.Leave && option !== 'children') {
|
|
16240
|
+
if (eventType == WalkerValueEvent.Leave && option !== WalkerOptionEnum.Children) {
|
|
16051
16241
|
yield {
|
|
16052
16242
|
value,
|
|
16053
16243
|
parent: map.get(value) ?? root,
|
|
@@ -16335,11 +16525,6 @@
|
|
|
16335
16525
|
}
|
|
16336
16526
|
static register(options) {
|
|
16337
16527
|
if (options.removePrefix) {
|
|
16338
|
-
for (const feature of options.features) {
|
|
16339
|
-
if (feature instanceof ComputePrefixFeature) {
|
|
16340
|
-
return;
|
|
16341
|
-
}
|
|
16342
|
-
}
|
|
16343
16528
|
// @ts-ignore
|
|
16344
16529
|
options.features.push(new ComputePrefixFeature(options));
|
|
16345
16530
|
}
|
|
@@ -16366,9 +16551,9 @@
|
|
|
16366
16551
|
for (const { value } of walkValues(node.val)) {
|
|
16367
16552
|
if (value.typ == exports.EnumToken.IdenTokenType && value.val.charAt(0) == '-' && value.val.charAt(1) != '-') {
|
|
16368
16553
|
// @ts-ignore
|
|
16369
|
-
const values = config$1.declarations[node.nam].ast
|
|
16554
|
+
const values = config$1.declarations[node.nam].ast?.slice?.();
|
|
16370
16555
|
const match = value.val.match(/^-(.*?)-(.*)$/);
|
|
16371
|
-
if (match != null) {
|
|
16556
|
+
if (values != null && match != null) {
|
|
16372
16557
|
const val = matchToken({ ...value, val: match[2] }, values);
|
|
16373
16558
|
if (val != null) {
|
|
16374
16559
|
// @ts-ignore
|
|
@@ -16470,11 +16655,6 @@
|
|
|
16470
16655
|
}
|
|
16471
16656
|
static register(options) {
|
|
16472
16657
|
if (options.inlineCssVariables) {
|
|
16473
|
-
for (const feature of options.features) {
|
|
16474
|
-
if (feature instanceof InlineCssVariablesFeature) {
|
|
16475
|
-
return;
|
|
16476
|
-
}
|
|
16477
|
-
}
|
|
16478
16658
|
// @ts-ignore
|
|
16479
16659
|
options.features.push(new InlineCssVariablesFeature());
|
|
16480
16660
|
}
|
|
@@ -17466,15 +17646,10 @@
|
|
|
17466
17646
|
|
|
17467
17647
|
class ComputeShorthandFeature {
|
|
17468
17648
|
static get ordering() {
|
|
17469
|
-
return
|
|
17649
|
+
return 3;
|
|
17470
17650
|
}
|
|
17471
17651
|
static register(options) {
|
|
17472
17652
|
if (options.computeShorthand) {
|
|
17473
|
-
for (const feature of options.features) {
|
|
17474
|
-
if (feature instanceof ComputeShorthandFeature) {
|
|
17475
|
-
return;
|
|
17476
|
-
}
|
|
17477
|
-
}
|
|
17478
17653
|
// @ts-ignore
|
|
17479
17654
|
options.features.push(new ComputeShorthandFeature(options));
|
|
17480
17655
|
}
|
|
@@ -17484,18 +17659,20 @@
|
|
|
17484
17659
|
const j = ast.chi.length;
|
|
17485
17660
|
let k = 0;
|
|
17486
17661
|
let properties = new PropertyList(options);
|
|
17662
|
+
const rules = [];
|
|
17487
17663
|
// @ts-ignore
|
|
17488
17664
|
for (; k < j; k++) {
|
|
17489
17665
|
// @ts-ignore
|
|
17490
17666
|
const node = ast.chi[k];
|
|
17491
17667
|
if (node.typ == exports.EnumToken.CommentNodeType || node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
17492
17668
|
properties.add(node);
|
|
17493
|
-
continue;
|
|
17494
17669
|
}
|
|
17495
|
-
|
|
17670
|
+
else {
|
|
17671
|
+
rules.push(node);
|
|
17672
|
+
}
|
|
17496
17673
|
}
|
|
17497
17674
|
// @ts-ignore
|
|
17498
|
-
ast.chi = [...properties]
|
|
17675
|
+
ast.chi = [...properties, ...rules];
|
|
17499
17676
|
return ast;
|
|
17500
17677
|
}
|
|
17501
17678
|
}
|
|
@@ -17506,11 +17683,6 @@
|
|
|
17506
17683
|
}
|
|
17507
17684
|
static register(options) {
|
|
17508
17685
|
if (options.computeCalcExpression) {
|
|
17509
|
-
for (const feature of options.features) {
|
|
17510
|
-
if (feature instanceof ComputeCalcExpressionFeature) {
|
|
17511
|
-
return;
|
|
17512
|
-
}
|
|
17513
|
-
}
|
|
17514
17686
|
// @ts-ignore
|
|
17515
17687
|
options.features.push(new ComputeCalcExpressionFeature());
|
|
17516
17688
|
}
|
|
@@ -17519,7 +17691,6 @@
|
|
|
17519
17691
|
if (!('chi' in ast)) {
|
|
17520
17692
|
return;
|
|
17521
17693
|
}
|
|
17522
|
-
// @ts-ignore
|
|
17523
17694
|
for (const node of ast.chi) {
|
|
17524
17695
|
if (node.typ != exports.EnumToken.DeclarationNodeType) {
|
|
17525
17696
|
continue;
|
|
@@ -17527,15 +17698,18 @@
|
|
|
17527
17698
|
const set = new Set;
|
|
17528
17699
|
for (const { value, parent } of walkValues(node.val, node, {
|
|
17529
17700
|
event: WalkerValueEvent.Enter,
|
|
17530
|
-
|
|
17701
|
+
// @ts-ignore
|
|
17702
|
+
fn(node, parent) {
|
|
17531
17703
|
if (parent != null &&
|
|
17704
|
+
// @ts-ignore
|
|
17532
17705
|
parent.typ == exports.EnumToken.DeclarationNodeType &&
|
|
17706
|
+
// @ts-ignore
|
|
17533
17707
|
parent.val.length == 1 &&
|
|
17534
17708
|
node.typ == exports.EnumToken.FunctionTokenType &&
|
|
17535
17709
|
mathFuncs.includes(node.val) &&
|
|
17536
17710
|
node.chi.length == 1 &&
|
|
17537
17711
|
node.chi[0].typ == exports.EnumToken.IdenTokenType) {
|
|
17538
|
-
return
|
|
17712
|
+
return WalkerOptionEnum.Ignore;
|
|
17539
17713
|
}
|
|
17540
17714
|
if ((node.typ == exports.EnumToken.FunctionTokenType && node.val == 'var') || (!mathFuncs.includes(parent.val) && [exports.EnumToken.ColorTokenType, exports.EnumToken.DeclarationNodeType, exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType, exports.EnumToken.StyleSheetNodeType].includes(parent?.typ))) {
|
|
17541
17715
|
return null;
|
|
@@ -17557,7 +17731,7 @@
|
|
|
17557
17731
|
// @ts-ignore
|
|
17558
17732
|
node[key] = values;
|
|
17559
17733
|
}
|
|
17560
|
-
return
|
|
17734
|
+
return WalkerOptionEnum.Ignore;
|
|
17561
17735
|
}
|
|
17562
17736
|
return null;
|
|
17563
17737
|
}
|
|
@@ -17619,78 +17793,1180 @@
|
|
|
17619
17793
|
}
|
|
17620
17794
|
}
|
|
17621
17795
|
|
|
17622
|
-
|
|
17623
|
-
|
|
17624
|
-
|
|
17625
|
-
|
|
17626
|
-
|
|
17627
|
-
|
|
17628
|
-
|
|
17629
|
-
|
|
17630
|
-
|
|
17631
|
-
|
|
17632
|
-
|
|
17633
|
-
|
|
17634
|
-
|
|
17635
|
-
|
|
17636
|
-
|
|
17637
|
-
|
|
17638
|
-
* @param options
|
|
17639
|
-
* @param recursive
|
|
17640
|
-
* @param errors
|
|
17641
|
-
* @param nestingContent
|
|
17642
|
-
* @param context
|
|
17643
|
-
*/
|
|
17644
|
-
function minify(ast, options = {}, recursive = false, errors, nestingContent, context = {}) {
|
|
17645
|
-
if (!('nodes' in context)) {
|
|
17646
|
-
context.nodes = new Set;
|
|
17796
|
+
const epsilon = 1e-5;
|
|
17797
|
+
function identity() {
|
|
17798
|
+
return [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
|
|
17799
|
+
}
|
|
17800
|
+
function pLength(point) {
|
|
17801
|
+
// Calcul de la norme euclidienne
|
|
17802
|
+
return Math.sqrt(point[0] * point[0] + point[1] * point[1] + point[2] * point[2]);
|
|
17803
|
+
}
|
|
17804
|
+
function normalize(point) {
|
|
17805
|
+
const [x, y, z] = point;
|
|
17806
|
+
const norm = Math.sqrt(point[0] * point[0] + point[1] * point[1] + point[2] * point[2]);
|
|
17807
|
+
return norm === 0 ? [0, 0, 0] : [x / norm, y / norm, z / norm];
|
|
17808
|
+
}
|
|
17809
|
+
function dot(point1, point2) {
|
|
17810
|
+
if (point1.length === 4 && point2.length === 4) {
|
|
17811
|
+
return point1[0] * point2[0] + point1[1] * point2[1] + point1[2] * point2[2] + point1[3] * point2[3];
|
|
17647
17812
|
}
|
|
17648
|
-
|
|
17649
|
-
|
|
17813
|
+
return point1[0] * point2[0] + point1[1] * point2[1] + point1[2] * point2[2];
|
|
17814
|
+
}
|
|
17815
|
+
function multiply(matrixA, matrixB) {
|
|
17816
|
+
let result = Array(4).fill(0).map(() => Array(4).fill(0));
|
|
17817
|
+
for (let i = 0; i < 4; i++) {
|
|
17818
|
+
for (let j = 0; j < 4; j++) {
|
|
17819
|
+
for (let k = 0; k < 4; k++) {
|
|
17820
|
+
result[j][i] += matrixA[k][i] * matrixB[j][k];
|
|
17821
|
+
}
|
|
17822
|
+
}
|
|
17650
17823
|
}
|
|
17651
|
-
|
|
17652
|
-
|
|
17653
|
-
|
|
17654
|
-
|
|
17655
|
-
|
|
17656
|
-
|
|
17657
|
-
|
|
17658
|
-
|
|
17659
|
-
|
|
17660
|
-
|
|
17661
|
-
|
|
17662
|
-
|
|
17663
|
-
|
|
17824
|
+
return result;
|
|
17825
|
+
}
|
|
17826
|
+
function round(number) {
|
|
17827
|
+
return Math.abs(number) < epsilon ? 0 : +number.toPrecision(6);
|
|
17828
|
+
}
|
|
17829
|
+
// translate3d(25.9808px, 0, 15px ) rotateY(60deg) skewX(49.9999deg) scale(1, 1.2)
|
|
17830
|
+
// translate → rotate → skew → scale
|
|
17831
|
+
function decompose(original) {
|
|
17832
|
+
const matrix = original.flat();
|
|
17833
|
+
// Normalize last row
|
|
17834
|
+
if (matrix[15] === 0) {
|
|
17835
|
+
return null;
|
|
17836
|
+
}
|
|
17837
|
+
for (let i = 0; i < 16; i++)
|
|
17838
|
+
matrix[i] /= matrix[15];
|
|
17839
|
+
// Perspective extraction
|
|
17840
|
+
const perspective = [0, 0, 0, 1];
|
|
17841
|
+
if (matrix[3] !== 0 || matrix[7] !== 0 || matrix[11] !== 0) {
|
|
17842
|
+
const rightHandSide = [matrix[3], matrix[7], matrix[11], matrix[15]];
|
|
17843
|
+
const perspectiveMatrix = matrix.slice();
|
|
17844
|
+
perspectiveMatrix[3] = 0;
|
|
17845
|
+
perspectiveMatrix[7] = 0;
|
|
17846
|
+
perspectiveMatrix[11] = 0;
|
|
17847
|
+
perspectiveMatrix[15] = 1;
|
|
17848
|
+
const inverse = invertMatrix4(perspectiveMatrix);
|
|
17849
|
+
if (!inverse) {
|
|
17850
|
+
return null;
|
|
17664
17851
|
}
|
|
17852
|
+
const transposedInverse = transposeMatrix4(inverse);
|
|
17853
|
+
perspective[0] = dot(rightHandSide, transposedInverse.slice(0, 4));
|
|
17854
|
+
perspective[1] = dot(rightHandSide, transposedInverse.slice(4, 8));
|
|
17855
|
+
perspective[2] = dot(rightHandSide, transposedInverse.slice(8, 12));
|
|
17856
|
+
perspective[3] = dot(rightHandSide, transposedInverse.slice(12, 16));
|
|
17857
|
+
// Clear perspective from matrix
|
|
17858
|
+
matrix[3] = 0;
|
|
17859
|
+
matrix[7] = 0;
|
|
17860
|
+
matrix[11] = 0;
|
|
17861
|
+
matrix[15] = 1;
|
|
17862
|
+
}
|
|
17863
|
+
// Translation
|
|
17864
|
+
const translate = [matrix[12], matrix[13], matrix[14]];
|
|
17865
|
+
matrix[12] = matrix[13] = matrix[14] = 0;
|
|
17866
|
+
// Build the 3x3 matrix
|
|
17867
|
+
const row0 = [matrix[0], matrix[1], matrix[2]];
|
|
17868
|
+
const row1 = [matrix[4], matrix[5], matrix[6]];
|
|
17869
|
+
const row2 = [matrix[8], matrix[9], matrix[10]];
|
|
17870
|
+
// Compute scale
|
|
17871
|
+
const scaleX = pLength(row0);
|
|
17872
|
+
const row0Norm = normalize(row0);
|
|
17873
|
+
const skewXY = dot(row0Norm, row1);
|
|
17874
|
+
const row1Proj = [
|
|
17875
|
+
row1[0] - skewXY * row0Norm[0],
|
|
17876
|
+
row1[1] - skewXY * row0Norm[1],
|
|
17877
|
+
row1[2] - skewXY * row0Norm[2]
|
|
17878
|
+
];
|
|
17879
|
+
const scaleY = pLength(row1Proj);
|
|
17880
|
+
const row1Norm = normalize(row1Proj);
|
|
17881
|
+
const skewXZ = dot(row0Norm, row2);
|
|
17882
|
+
const skewYZ = dot(row1Norm, row2);
|
|
17883
|
+
const row2Proj = [
|
|
17884
|
+
row2[0] - skewXZ * row0Norm[0] - skewYZ * row1Norm[0],
|
|
17885
|
+
row2[1] - skewXZ * row0Norm[1] - skewYZ * row1Norm[1],
|
|
17886
|
+
row2[2] - skewXZ * row0Norm[2] - skewYZ * row1Norm[2]
|
|
17887
|
+
];
|
|
17888
|
+
const scaleZ = pLength(row2Proj);
|
|
17889
|
+
const row2Norm = normalize(row2Proj);
|
|
17890
|
+
// Build rotation matrix from orthonormalized vectors
|
|
17891
|
+
const r00 = row0Norm[0], r01 = row1Norm[0], r02 = row2Norm[0];
|
|
17892
|
+
const r10 = row0Norm[1], r11 = row1Norm[1], r12 = row2Norm[1];
|
|
17893
|
+
const r20 = row0Norm[2], r21 = row1Norm[2], r22 = row2Norm[2];
|
|
17894
|
+
// Convert to quaternion
|
|
17895
|
+
const trace = r00 + r11 + r22;
|
|
17896
|
+
let qw, qx, qy, qz;
|
|
17897
|
+
if (trace > 0) {
|
|
17898
|
+
const s = 0.5 / Math.sqrt(trace + 1.0);
|
|
17899
|
+
qw = 0.25 / s;
|
|
17900
|
+
qx = (r21 - r12) * s;
|
|
17901
|
+
qy = (r02 - r20) * s;
|
|
17902
|
+
qz = (r10 - r01) * s;
|
|
17903
|
+
}
|
|
17904
|
+
else if (r00 > r11 && r00 > r22) {
|
|
17905
|
+
const s = 2.0 * Math.sqrt(1.0 + r00 - r11 - r22);
|
|
17906
|
+
qw = (r21 - r12) / s;
|
|
17907
|
+
qx = 0.25 * s;
|
|
17908
|
+
qy = (r01 + r10) / s;
|
|
17909
|
+
qz = (r02 + r20) / s;
|
|
17910
|
+
}
|
|
17911
|
+
else if (r11 > r22) {
|
|
17912
|
+
const s = 2.0 * Math.sqrt(1.0 + r11 - r00 - r22);
|
|
17913
|
+
qw = (r02 - r20) / s;
|
|
17914
|
+
qx = (r01 + r10) / s;
|
|
17915
|
+
qy = 0.25 * s;
|
|
17916
|
+
qz = (r12 + r21) / s;
|
|
17665
17917
|
}
|
|
17666
|
-
|
|
17667
|
-
|
|
17668
|
-
|
|
17669
|
-
|
|
17918
|
+
else {
|
|
17919
|
+
const s = 2.0 * Math.sqrt(1.0 + r22 - r00 - r11);
|
|
17920
|
+
qw = (r10 - r01) / s;
|
|
17921
|
+
qx = (r02 + r20) / s;
|
|
17922
|
+
qy = (r12 + r21) / s;
|
|
17923
|
+
qz = 0.25 * s;
|
|
17924
|
+
}
|
|
17925
|
+
[qx, qy, qz] = toZero([qx, qy, qz]);
|
|
17926
|
+
// const q = gcd(qx, gcd(qy, qz));
|
|
17927
|
+
let q = [Math.abs(qx), Math.abs(qy), Math.abs(qz)].reduce((acc, curr) => {
|
|
17928
|
+
if (acc == 0 || (curr > 0 && curr < acc)) {
|
|
17929
|
+
acc = curr;
|
|
17670
17930
|
}
|
|
17671
|
-
|
|
17672
|
-
|
|
17673
|
-
|
|
17674
|
-
|
|
17675
|
-
|
|
17676
|
-
|
|
17677
|
-
|
|
17931
|
+
return acc;
|
|
17932
|
+
}, 0);
|
|
17933
|
+
if (q > 0) {
|
|
17934
|
+
qx /= q;
|
|
17935
|
+
qy /= q;
|
|
17936
|
+
qz /= q;
|
|
17937
|
+
}
|
|
17938
|
+
const rotate = [qx, qy, qz, Object.is(qw, 0) ? 0 : 2 * Math.acos(qw) * 180 / Math.PI];
|
|
17939
|
+
const scale = [scaleX, scaleY, scaleZ];
|
|
17940
|
+
const skew = [skewXY, skewXZ, skewYZ];
|
|
17941
|
+
return {
|
|
17942
|
+
translate,
|
|
17943
|
+
scale,
|
|
17944
|
+
rotate,
|
|
17945
|
+
skew,
|
|
17946
|
+
perspective
|
|
17947
|
+
};
|
|
17948
|
+
}
|
|
17949
|
+
function transposeMatrix4(m) {
|
|
17950
|
+
return [
|
|
17951
|
+
m[0], m[4], m[8], m[12],
|
|
17952
|
+
m[1], m[5], m[9], m[13],
|
|
17953
|
+
m[2], m[6], m[10], m[14],
|
|
17954
|
+
m[3], m[7], m[11], m[15],
|
|
17955
|
+
];
|
|
17956
|
+
}
|
|
17957
|
+
function invertMatrix4(m) {
|
|
17958
|
+
new Array(16);
|
|
17959
|
+
const det = m[0] * m[5] * m[10] * m[15] + m[0] * m[9] * m[14] * m[7] + m[0] * m[13] * m[6] * m[11]
|
|
17960
|
+
- m[0] * m[13] * m[10] * m[7] - m[0] * m[9] * m[6] * m[15] - m[0] * m[5] * m[14] * m[11];
|
|
17961
|
+
if (det === 0)
|
|
17962
|
+
return null;
|
|
17963
|
+
// For brevity, not implementing full inverse here — you'd normally use gl-matrix or similar.
|
|
17964
|
+
// Just use a trusted library or expand this if needed.
|
|
17965
|
+
return null; // placeholder
|
|
17966
|
+
}
|
|
17967
|
+
function toZero(v) {
|
|
17968
|
+
for (let i = 0; i < v.length; i++) {
|
|
17969
|
+
if (Math.abs(v[i]) <= epsilon) {
|
|
17970
|
+
v[i] = 0;
|
|
17678
17971
|
}
|
|
17679
|
-
else
|
|
17680
|
-
|
|
17972
|
+
else {
|
|
17973
|
+
v[i] = +v[i].toPrecision(6);
|
|
17681
17974
|
}
|
|
17682
|
-
acc.push(curr.join(''));
|
|
17683
|
-
return acc;
|
|
17684
17975
|
}
|
|
17685
|
-
|
|
17686
|
-
|
|
17687
|
-
|
|
17688
|
-
|
|
17689
|
-
|
|
17690
|
-
|
|
17691
|
-
|
|
17976
|
+
return v;
|
|
17977
|
+
}
|
|
17978
|
+
// https://drafts.csswg.org/css-transforms-1/#2d-matrix
|
|
17979
|
+
function is2DMatrix(matrix) {
|
|
17980
|
+
// m13,m14, m23, m24, m31, m32, m34, m43 are all 0
|
|
17981
|
+
return matrix[0][2] === 0 &&
|
|
17982
|
+
matrix[0][3] === 0 &&
|
|
17983
|
+
matrix[1][2] === 0 &&
|
|
17984
|
+
matrix[1][3] === 0 &&
|
|
17985
|
+
matrix[2][0] === 0 &&
|
|
17986
|
+
matrix[2][1] === 0 &&
|
|
17987
|
+
matrix[2][3] === 0 &&
|
|
17988
|
+
matrix[3][2] === 0 &&
|
|
17989
|
+
matrix[2][2] === 1 &&
|
|
17990
|
+
matrix[3][3] === 1;
|
|
17991
|
+
}
|
|
17992
|
+
|
|
17993
|
+
// https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Values_and_units#absolute_length_units
|
|
17994
|
+
function length2Px(value) {
|
|
17995
|
+
if (value.typ == exports.EnumToken.NumberTokenType) {
|
|
17996
|
+
return +value.val;
|
|
17997
|
+
}
|
|
17998
|
+
switch (value.unit) {
|
|
17999
|
+
case 'cm':
|
|
18000
|
+
// @ts-ignore
|
|
18001
|
+
return value.val * 37.8;
|
|
18002
|
+
case 'mm':
|
|
18003
|
+
// @ts-ignore
|
|
18004
|
+
return value.val * 3.78;
|
|
18005
|
+
case 'Q':
|
|
18006
|
+
// @ts-ignore
|
|
18007
|
+
return value.val * 37.8 / 40;
|
|
18008
|
+
case 'in':
|
|
18009
|
+
// @ts-ignore
|
|
18010
|
+
return value.val / 96;
|
|
18011
|
+
case 'pc':
|
|
18012
|
+
// @ts-ignore
|
|
18013
|
+
return value.val / 16;
|
|
18014
|
+
case 'pt':
|
|
18015
|
+
// @ts-ignore
|
|
18016
|
+
return value.val * 4 / 3;
|
|
18017
|
+
case 'px':
|
|
18018
|
+
return +value.val;
|
|
18019
|
+
}
|
|
18020
|
+
return null;
|
|
18021
|
+
}
|
|
18022
|
+
|
|
18023
|
+
function translateX(x, from) {
|
|
18024
|
+
const matrix = identity();
|
|
18025
|
+
matrix[3][0] = x;
|
|
18026
|
+
return multiply(from, matrix);
|
|
18027
|
+
}
|
|
18028
|
+
function translateY(y, from) {
|
|
18029
|
+
const matrix = identity();
|
|
18030
|
+
matrix[3][1] = y;
|
|
18031
|
+
return multiply(from, matrix);
|
|
18032
|
+
}
|
|
18033
|
+
function translateZ(z, from) {
|
|
18034
|
+
const matrix = identity();
|
|
18035
|
+
matrix[3][2] = z;
|
|
18036
|
+
return multiply(from, matrix);
|
|
18037
|
+
}
|
|
18038
|
+
function translate(translate, from) {
|
|
18039
|
+
const matrix = identity();
|
|
18040
|
+
matrix[3][0] = translate[0];
|
|
18041
|
+
matrix[3][1] = translate[1] ?? 0;
|
|
18042
|
+
return multiply(from, matrix);
|
|
18043
|
+
}
|
|
18044
|
+
function translate3d(translate, from) {
|
|
18045
|
+
const matrix = identity();
|
|
18046
|
+
matrix[3][0] = translate[0];
|
|
18047
|
+
matrix[3][1] = translate[1];
|
|
18048
|
+
matrix[3][2] = translate[2];
|
|
18049
|
+
return multiply(from, matrix);
|
|
18050
|
+
}
|
|
18051
|
+
|
|
18052
|
+
/**
|
|
18053
|
+
* angle in radian
|
|
18054
|
+
* @param angle
|
|
18055
|
+
* @param x
|
|
18056
|
+
* @param y
|
|
18057
|
+
* @param z
|
|
18058
|
+
* @param from
|
|
18059
|
+
*/
|
|
18060
|
+
function rotate3D(angle, x, y, z, from) {
|
|
18061
|
+
const matrix = identity();
|
|
18062
|
+
const sc = Math.sin(angle / 2) * Math.cos(angle / 2);
|
|
18063
|
+
const sq = Math.sin(angle / 2) * Math.sin(angle / 2);
|
|
18064
|
+
const norm = Math.sqrt(x * x + y * y + z * z);
|
|
18065
|
+
const unit = norm === 0 ? 0 : 1 / norm;
|
|
18066
|
+
x *= unit;
|
|
18067
|
+
y *= unit;
|
|
18068
|
+
z *= unit;
|
|
18069
|
+
matrix[0][0] = 1 - 2 * (y * y + z * z) * sq;
|
|
18070
|
+
matrix[0][1] = 2 * (x * y * sq + z * sc);
|
|
18071
|
+
matrix[0][2] = 2 * (x * z * sq - y * sc);
|
|
18072
|
+
matrix[1][0] = 2 * (x * y * sq - z * sc);
|
|
18073
|
+
matrix[1][1] = 1 - 2 * (x * x + z * z) * sq;
|
|
18074
|
+
matrix[1][2] = 2 * (y * z * sq + x * sc);
|
|
18075
|
+
matrix[2][0] = 2 * (x * z * sq + y * sc);
|
|
18076
|
+
matrix[2][1] = 2 * (y * z * sq - x * sc);
|
|
18077
|
+
matrix[2][2] = 1 - 2 * (x * x + y * y) * sq;
|
|
18078
|
+
return multiply(from, matrix);
|
|
18079
|
+
}
|
|
18080
|
+
function rotate(angle, from) {
|
|
18081
|
+
const matrix = identity();
|
|
18082
|
+
matrix[0][0] = Math.cos(angle);
|
|
18083
|
+
matrix[0][1] = Math.sin(angle);
|
|
18084
|
+
matrix[1][0] = -Math.sin(angle);
|
|
18085
|
+
matrix[1][1] = Math.cos(angle);
|
|
18086
|
+
return multiply(from, matrix);
|
|
18087
|
+
}
|
|
18088
|
+
|
|
18089
|
+
function scaleX(x, from) {
|
|
18090
|
+
const matrix = identity();
|
|
18091
|
+
matrix[0][0] = x;
|
|
18092
|
+
return multiply(from, matrix);
|
|
18093
|
+
}
|
|
18094
|
+
function scaleY(y, from) {
|
|
18095
|
+
const matrix = identity();
|
|
18096
|
+
matrix[1][1] = y;
|
|
18097
|
+
return multiply(from, matrix);
|
|
18098
|
+
}
|
|
18099
|
+
function scaleZ(z, from) {
|
|
18100
|
+
const matrix = identity();
|
|
18101
|
+
matrix[2][2] = z;
|
|
18102
|
+
return multiply(from, matrix);
|
|
18103
|
+
}
|
|
18104
|
+
function scale(x, y, from) {
|
|
18105
|
+
const matrix = identity();
|
|
18106
|
+
matrix[0][0] = x;
|
|
18107
|
+
matrix[1][1] = y;
|
|
18108
|
+
return multiply(from, matrix);
|
|
18109
|
+
}
|
|
18110
|
+
function scale3d(x, y, z, from) {
|
|
18111
|
+
const matrix = identity();
|
|
18112
|
+
matrix[0][0] = x;
|
|
18113
|
+
matrix[1][1] = y;
|
|
18114
|
+
matrix[2][2] = z;
|
|
18115
|
+
return multiply(from, matrix);
|
|
18116
|
+
}
|
|
18117
|
+
|
|
18118
|
+
function parseMatrix(mat) {
|
|
18119
|
+
if (mat.typ == exports.EnumToken.IdenTokenType) {
|
|
18120
|
+
return mat.val == 'none' ? identity() : null;
|
|
18121
|
+
}
|
|
18122
|
+
const children = mat.chi.filter((t) => t.typ == exports.EnumToken.NumberTokenType || t.typ == exports.EnumToken.IdenTokenType);
|
|
18123
|
+
const values = [];
|
|
18124
|
+
for (const child of children) {
|
|
18125
|
+
if (child.typ != exports.EnumToken.NumberTokenType) {
|
|
18126
|
+
return null;
|
|
18127
|
+
}
|
|
18128
|
+
// @ts-ignore
|
|
18129
|
+
values.push(getNumber(child));
|
|
18130
|
+
}
|
|
18131
|
+
// @ts-ignore
|
|
18132
|
+
return matrix(values);
|
|
18133
|
+
}
|
|
18134
|
+
// use column-major order
|
|
18135
|
+
function matrix(values) {
|
|
18136
|
+
const matrix = identity();
|
|
18137
|
+
if (values.length === 6) {
|
|
18138
|
+
matrix[0][0] = values[0];
|
|
18139
|
+
matrix[0][1] = values[1];
|
|
18140
|
+
matrix[1][0] = values[2];
|
|
18141
|
+
matrix[1][1] = values[3];
|
|
18142
|
+
matrix[3][0] = values[4];
|
|
18143
|
+
matrix[3][1] = values[5];
|
|
18144
|
+
}
|
|
18145
|
+
else if (values.length === 16) {
|
|
18146
|
+
matrix[0][0] = values[0];
|
|
18147
|
+
matrix[0][1] = values[1];
|
|
18148
|
+
matrix[0][2] = values[2];
|
|
18149
|
+
matrix[0][3] = values[3];
|
|
18150
|
+
matrix[1][0] = values[4];
|
|
18151
|
+
matrix[1][1] = values[5];
|
|
18152
|
+
matrix[1][2] = values[6];
|
|
18153
|
+
matrix[1][3] = values[7];
|
|
18154
|
+
matrix[2][0] = values[8];
|
|
18155
|
+
matrix[2][1] = values[9];
|
|
18156
|
+
matrix[2][2] = values[10];
|
|
18157
|
+
matrix[2][3] = values[11];
|
|
18158
|
+
matrix[3][0] = values[12];
|
|
18159
|
+
matrix[3][1] = values[13];
|
|
18160
|
+
matrix[3][2] = values[14];
|
|
18161
|
+
matrix[3][3] = values[15];
|
|
18162
|
+
}
|
|
18163
|
+
else {
|
|
18164
|
+
return null;
|
|
18165
|
+
}
|
|
18166
|
+
return matrix;
|
|
18167
|
+
}
|
|
18168
|
+
function serialize(matrix) {
|
|
18169
|
+
matrix = matrix.map(t => toZero(t.slice()));
|
|
18170
|
+
// @ts-ignore
|
|
18171
|
+
if (eq(matrix, identity())) {
|
|
18172
|
+
return {
|
|
18173
|
+
typ: exports.EnumToken.IdenTokenType,
|
|
18174
|
+
val: 'none'
|
|
18175
|
+
};
|
|
18176
|
+
}
|
|
18177
|
+
if (is2DMatrix(matrix)) {
|
|
18178
|
+
// https://drafts.csswg.org/css-transforms-2/#two-dimensional-subset
|
|
18179
|
+
return {
|
|
18180
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18181
|
+
val: 'matrix',
|
|
18182
|
+
chi: [
|
|
18183
|
+
matrix[0][0],
|
|
18184
|
+
matrix[0][1],
|
|
18185
|
+
matrix[1][0],
|
|
18186
|
+
matrix[1][1],
|
|
18187
|
+
matrix[3][0],
|
|
18188
|
+
matrix[3][1]
|
|
18189
|
+
].reduce((acc, t) => {
|
|
18190
|
+
if (acc.length > 0) {
|
|
18191
|
+
acc.push({ typ: exports.EnumToken.CommaTokenType });
|
|
18192
|
+
}
|
|
18193
|
+
acc.push({
|
|
18194
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18195
|
+
val: reduceNumber(t)
|
|
18196
|
+
});
|
|
18197
|
+
return acc;
|
|
18198
|
+
}, [])
|
|
18199
|
+
};
|
|
18200
|
+
}
|
|
18201
|
+
return {
|
|
18202
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18203
|
+
val: 'matrix3d',
|
|
18204
|
+
chi: matrix.flat().reduce((acc, curr) => {
|
|
18205
|
+
if (acc.length > 0) {
|
|
18206
|
+
acc.push({ typ: exports.EnumToken.CommaTokenType });
|
|
18207
|
+
}
|
|
18208
|
+
acc.push({
|
|
18209
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18210
|
+
val: reduceNumber(curr)
|
|
18211
|
+
});
|
|
18212
|
+
return acc;
|
|
18213
|
+
}, [])
|
|
18214
|
+
};
|
|
18215
|
+
}
|
|
18216
|
+
|
|
18217
|
+
// translate → rotate → skew → scale
|
|
18218
|
+
function minify$1(matrix) {
|
|
18219
|
+
const decomposed = decompose(matrix);
|
|
18220
|
+
if (decomposed == null) {
|
|
18221
|
+
return null;
|
|
18222
|
+
}
|
|
18223
|
+
const transforms = new Set(['translate', 'scale', 'skew', 'perspective', 'rotate']);
|
|
18224
|
+
const scales = new Set(['x', 'y', 'z']);
|
|
18225
|
+
const skew = new Set(['x', 'y']);
|
|
18226
|
+
let result = [];
|
|
18227
|
+
// check identity
|
|
18228
|
+
if (round(decomposed.translate[0]) == 0 && round(decomposed.translate[1]) == 0 && round(decomposed.translate[2]) == 0) {
|
|
18229
|
+
transforms.delete('translate');
|
|
18230
|
+
}
|
|
18231
|
+
if (round(decomposed.scale[0]) == 1 && round(decomposed.scale[1]) == 1 && round(decomposed.scale[2]) == 1) {
|
|
18232
|
+
transforms.delete('scale');
|
|
18233
|
+
}
|
|
18234
|
+
if (round(decomposed.skew[0]) == 0 && round(decomposed.skew[1]) == 0) {
|
|
18235
|
+
transforms.delete('skew');
|
|
18236
|
+
}
|
|
18237
|
+
if (round(decomposed.perspective[2]) == 0) {
|
|
18238
|
+
transforms.delete('perspective');
|
|
18239
|
+
}
|
|
18240
|
+
if (round(decomposed.rotate[3]) == 0) {
|
|
18241
|
+
transforms.delete('rotate');
|
|
18242
|
+
}
|
|
18243
|
+
if (transforms.has('translate')) {
|
|
18244
|
+
let coordinates = new Set(['x', 'y', 'z']);
|
|
18245
|
+
for (let i = 0; i < 3; i++) {
|
|
18246
|
+
if (round(decomposed.translate[i]) == 0) {
|
|
18247
|
+
coordinates.delete(i == 0 ? 'x' : i == 1 ? 'y' : 'z');
|
|
18248
|
+
}
|
|
18249
|
+
}
|
|
18250
|
+
if (coordinates.size == 3) {
|
|
18251
|
+
result.push({
|
|
18252
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18253
|
+
val: 'translate3d',
|
|
18254
|
+
chi: [
|
|
18255
|
+
{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[0]) + '', unit: 'px' },
|
|
18256
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18257
|
+
{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[1]) + '', unit: 'px' },
|
|
18258
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18259
|
+
{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[2]) + '', unit: 'px' }
|
|
18260
|
+
]
|
|
18261
|
+
});
|
|
18262
|
+
}
|
|
18263
|
+
else if (coordinates.size == 1) {
|
|
18264
|
+
if (coordinates.has('x')) {
|
|
18265
|
+
result.push({
|
|
18266
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18267
|
+
val: 'translate',
|
|
18268
|
+
chi: [{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[0]) + '', unit: 'px' }]
|
|
18269
|
+
});
|
|
18270
|
+
}
|
|
18271
|
+
else {
|
|
18272
|
+
let axis = coordinates.has('y') ? 'y' : 'z';
|
|
18273
|
+
let index = axis == 'y' ? 1 : 2;
|
|
18274
|
+
result.push({
|
|
18275
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18276
|
+
val: 'translate' + axis.toUpperCase(),
|
|
18277
|
+
chi: [{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[index]) + '', unit: 'px' }]
|
|
18278
|
+
});
|
|
18279
|
+
}
|
|
18280
|
+
}
|
|
18281
|
+
else if (coordinates.has('z')) {
|
|
18282
|
+
result.push({
|
|
18283
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18284
|
+
val: 'translate3d',
|
|
18285
|
+
chi: [
|
|
18286
|
+
decomposed.translate[0] == 0 ? {
|
|
18287
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18288
|
+
'val': '0'
|
|
18289
|
+
} : { typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[0]) + '', unit: 'px' },
|
|
18290
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18291
|
+
decomposed.translate[1] == 0 ? {
|
|
18292
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18293
|
+
'val': '0'
|
|
18294
|
+
} : { typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[1]) + '', unit: 'px' },
|
|
18295
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18296
|
+
{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[2]) + '', unit: 'px' }
|
|
18297
|
+
]
|
|
18298
|
+
});
|
|
18299
|
+
}
|
|
18300
|
+
else {
|
|
18301
|
+
result.push({
|
|
18302
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18303
|
+
val: 'translate',
|
|
18304
|
+
chi: [
|
|
18305
|
+
decomposed.translate[0] == 0 ? {
|
|
18306
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18307
|
+
'val': '0'
|
|
18308
|
+
} : { typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[0]) + '', unit: 'px' },
|
|
18309
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18310
|
+
decomposed.translate[1] == 0 ? {
|
|
18311
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18312
|
+
'val': '0'
|
|
18313
|
+
} : { typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[1]) + '', unit: 'px' }
|
|
18314
|
+
]
|
|
18315
|
+
});
|
|
18316
|
+
}
|
|
18317
|
+
}
|
|
18318
|
+
if (transforms.has('rotate')) {
|
|
18319
|
+
const [x, y, z, angle] = decomposed.rotate;
|
|
18320
|
+
if (y == 0 && z == 0) {
|
|
18321
|
+
result.push({
|
|
18322
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18323
|
+
val: 'rotateX',
|
|
18324
|
+
chi: [
|
|
18325
|
+
{
|
|
18326
|
+
typ: exports.EnumToken.AngleTokenType,
|
|
18327
|
+
val: '' + round(angle),
|
|
18328
|
+
unit: 'deg'
|
|
18329
|
+
}
|
|
18330
|
+
]
|
|
18331
|
+
});
|
|
18332
|
+
}
|
|
18333
|
+
else if (x == 0 && z == 0) {
|
|
18334
|
+
result.push({
|
|
18335
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18336
|
+
val: 'rotateY',
|
|
18337
|
+
chi: [
|
|
18338
|
+
{
|
|
18339
|
+
typ: exports.EnumToken.AngleTokenType,
|
|
18340
|
+
val: '' + round(angle),
|
|
18341
|
+
unit: 'deg'
|
|
18342
|
+
}
|
|
18343
|
+
]
|
|
18344
|
+
});
|
|
18345
|
+
}
|
|
18346
|
+
else if (x == 0 && y == 0) {
|
|
18347
|
+
result.push({
|
|
18348
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18349
|
+
val: 'rotate',
|
|
18350
|
+
chi: [
|
|
18351
|
+
{
|
|
18352
|
+
typ: exports.EnumToken.AngleTokenType,
|
|
18353
|
+
val: '' + round(angle),
|
|
18354
|
+
unit: 'deg'
|
|
18355
|
+
}
|
|
18356
|
+
]
|
|
18357
|
+
});
|
|
18358
|
+
}
|
|
18359
|
+
else {
|
|
18360
|
+
result.push({
|
|
18361
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18362
|
+
val: 'rotate3d',
|
|
18363
|
+
chi: [
|
|
18364
|
+
{
|
|
18365
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18366
|
+
val: '' + round(x)
|
|
18367
|
+
},
|
|
18368
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18369
|
+
{
|
|
18370
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18371
|
+
val: '' + round(y)
|
|
18372
|
+
},
|
|
18373
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18374
|
+
{
|
|
18375
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18376
|
+
val: '' + round(z)
|
|
18377
|
+
},
|
|
18378
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18379
|
+
{
|
|
18380
|
+
typ: exports.EnumToken.AngleTokenType,
|
|
18381
|
+
val: '' + round(angle),
|
|
18382
|
+
unit: 'deg'
|
|
18383
|
+
}
|
|
18384
|
+
]
|
|
18385
|
+
});
|
|
18386
|
+
}
|
|
18387
|
+
}
|
|
18388
|
+
if (transforms.has('skew')) {
|
|
18389
|
+
if (round(decomposed.skew[0]) == 0) {
|
|
18390
|
+
skew.delete('x');
|
|
18391
|
+
}
|
|
18392
|
+
if (round(decomposed.skew[1]) == 0) {
|
|
18393
|
+
skew.delete('y');
|
|
18394
|
+
}
|
|
18395
|
+
for (let i = 0; i < 2; i++) {
|
|
18396
|
+
decomposed.skew[i] = round(Math.atan(decomposed.skew[i]) * 180 / Math.PI);
|
|
18397
|
+
}
|
|
18398
|
+
if (skew.size == 1) {
|
|
18399
|
+
result.push({
|
|
18400
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18401
|
+
val: 'skew' + (skew.has('x') ? '' : 'Y'),
|
|
18402
|
+
chi: [
|
|
18403
|
+
{ typ: exports.EnumToken.AngleTokenType, val: '' + round(decomposed.skew[0]), unit: 'deg' }
|
|
18404
|
+
]
|
|
18405
|
+
});
|
|
18406
|
+
}
|
|
18407
|
+
else {
|
|
18408
|
+
result.push({
|
|
18409
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18410
|
+
val: 'skew',
|
|
18411
|
+
chi: [
|
|
18412
|
+
{ typ: exports.EnumToken.AngleTokenType, val: '' + round(decomposed.skew[0]), unit: 'deg' },
|
|
18413
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18414
|
+
{ typ: exports.EnumToken.AngleTokenType, val: '' + round(decomposed.skew[1]), unit: 'deg' }
|
|
18415
|
+
]
|
|
18416
|
+
});
|
|
18417
|
+
}
|
|
18418
|
+
}
|
|
18419
|
+
if (transforms.has('scale')) {
|
|
18420
|
+
const [sx, sy, sz] = toZero(decomposed.scale);
|
|
18421
|
+
if (sz == 1) {
|
|
18422
|
+
scales.delete('z');
|
|
18423
|
+
}
|
|
18424
|
+
if (sy == 1) {
|
|
18425
|
+
scales.delete('y');
|
|
18426
|
+
}
|
|
18427
|
+
if (sx == 1) {
|
|
18428
|
+
scales.delete('x');
|
|
18429
|
+
}
|
|
18430
|
+
if (scales.size == 1) {
|
|
18431
|
+
let prefix = scales.has('x') ? '' : scales.has('y') ? 'Y' : 'Z';
|
|
18432
|
+
result.push({
|
|
18433
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18434
|
+
val: 'scale' + prefix,
|
|
18435
|
+
chi: [
|
|
18436
|
+
{ typ: exports.EnumToken.NumberTokenType, val: '' + round(prefix == 'Z' ? sz : prefix == 'Y' ? sy : sx) }
|
|
18437
|
+
]
|
|
18438
|
+
});
|
|
18439
|
+
}
|
|
18440
|
+
else if (!scales.has('z')) {
|
|
18441
|
+
result.push({
|
|
18442
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18443
|
+
val: 'scale',
|
|
18444
|
+
chi: [
|
|
18445
|
+
{ typ: exports.EnumToken.NumberTokenType, val: '' + round(sx) },
|
|
18446
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18447
|
+
{ typ: exports.EnumToken.NumberTokenType, val: '' + round(sy) },
|
|
18448
|
+
]
|
|
18449
|
+
});
|
|
18450
|
+
}
|
|
18451
|
+
else {
|
|
18452
|
+
result.push({
|
|
18453
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18454
|
+
val: 'scale3d',
|
|
18455
|
+
chi: [
|
|
18456
|
+
{ typ: exports.EnumToken.NumberTokenType, val: '' + round(sx) },
|
|
18457
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18458
|
+
{ typ: exports.EnumToken.NumberTokenType, val: '' + round(sy) },
|
|
18459
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18460
|
+
{ typ: exports.EnumToken.NumberTokenType, val: '' + round(sz) }
|
|
18461
|
+
]
|
|
18462
|
+
});
|
|
18463
|
+
}
|
|
18464
|
+
}
|
|
18465
|
+
if (transforms.has('perspective')) {
|
|
18466
|
+
result.push({
|
|
18467
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18468
|
+
val: 'perspective',
|
|
18469
|
+
chi: [
|
|
18470
|
+
{ typ: exports.EnumToken.Length, val: '' + round(1 / decomposed.perspective[2]), unit: 'px' },
|
|
18471
|
+
]
|
|
18472
|
+
});
|
|
18473
|
+
}
|
|
18474
|
+
// identity
|
|
18475
|
+
return result.length == 0 || (result.length == 1 && eqMatrix(identity(), result)) ? [
|
|
18476
|
+
{
|
|
18477
|
+
typ: exports.EnumToken.IdenTokenType,
|
|
18478
|
+
val: 'none'
|
|
18479
|
+
}
|
|
18480
|
+
] : result;
|
|
18481
|
+
}
|
|
18482
|
+
function eqMatrix(a, b) {
|
|
18483
|
+
let mat = identity();
|
|
18484
|
+
let tmp = identity();
|
|
18485
|
+
// @ts-ignore
|
|
18486
|
+
const data = Array.isArray(a) ? a : parseMatrix(a);
|
|
18487
|
+
for (const transform of b) {
|
|
18488
|
+
tmp = computeMatrix([transform], identity());
|
|
18489
|
+
if (tmp == null) {
|
|
18490
|
+
return false;
|
|
18491
|
+
}
|
|
18492
|
+
mat = multiply(mat, tmp);
|
|
18493
|
+
}
|
|
18494
|
+
if (mat == null) {
|
|
18495
|
+
return false;
|
|
18496
|
+
}
|
|
18497
|
+
for (let i = 0; i < 4; i++) {
|
|
18498
|
+
for (let j = 0; j < 4; j++) {
|
|
18499
|
+
if (Math.abs(mat[i][j] - data[i][j]) > epsilon) {
|
|
18500
|
+
return false;
|
|
18501
|
+
}
|
|
18502
|
+
}
|
|
18503
|
+
}
|
|
18504
|
+
return true;
|
|
18505
|
+
}
|
|
18506
|
+
|
|
18507
|
+
function skewX(x, from) {
|
|
18508
|
+
const matrix = identity();
|
|
18509
|
+
matrix[1][0] = Math.tan(x);
|
|
18510
|
+
return multiply(from, matrix);
|
|
18511
|
+
}
|
|
18512
|
+
function skewY(y, from) {
|
|
18513
|
+
const matrix = identity();
|
|
18514
|
+
matrix[0][1] = Math.tan(y);
|
|
18515
|
+
return multiply(from, matrix);
|
|
18516
|
+
}
|
|
18517
|
+
// convert angle to radian
|
|
18518
|
+
function skew(values, from) {
|
|
18519
|
+
const matrix = identity();
|
|
18520
|
+
matrix[1][0] = Math.tan(values[0]);
|
|
18521
|
+
if (values.length > 1) {
|
|
18522
|
+
matrix[0][1] = Math.tan(values[1]);
|
|
18523
|
+
}
|
|
18524
|
+
return multiply(from, matrix);
|
|
18525
|
+
}
|
|
18526
|
+
|
|
18527
|
+
function perspective(x, from) {
|
|
18528
|
+
const matrix = identity();
|
|
18529
|
+
// @ts-ignore
|
|
18530
|
+
matrix[2][3] = typeof x == 'object' && x.val == 'none' ? 0 : x == 0 ? Number.NEGATIVE_INFINITY : -1 / x;
|
|
18531
|
+
return multiply(from, matrix);
|
|
18532
|
+
}
|
|
18533
|
+
|
|
18534
|
+
function compute(transformLists) {
|
|
18535
|
+
transformLists = transformLists.slice();
|
|
18536
|
+
stripCommaToken(transformLists);
|
|
18537
|
+
if (transformLists.length == 0) {
|
|
18538
|
+
return null;
|
|
18539
|
+
}
|
|
18540
|
+
let matrix = identity();
|
|
18541
|
+
let mat;
|
|
18542
|
+
const cumulative = [];
|
|
18543
|
+
for (const transformList of splitTransformList(transformLists)) {
|
|
18544
|
+
mat = computeMatrix(transformList, identity());
|
|
18545
|
+
if (mat == null) {
|
|
18546
|
+
return null;
|
|
18547
|
+
}
|
|
18548
|
+
matrix = multiply(matrix, mat);
|
|
18549
|
+
cumulative.push(...(minify$1(mat) ?? transformList));
|
|
18550
|
+
}
|
|
18551
|
+
const serialized = serialize(matrix);
|
|
18552
|
+
if (cumulative.length > 0) {
|
|
18553
|
+
for (let i = 0; i < cumulative.length; i++) {
|
|
18554
|
+
if (cumulative[i].typ == exports.EnumToken.IdenTokenType && cumulative[i].val == 'none') {
|
|
18555
|
+
cumulative.splice(i--, 1);
|
|
18556
|
+
}
|
|
18557
|
+
}
|
|
18558
|
+
if (cumulative.length == 0) {
|
|
18559
|
+
cumulative.push({
|
|
18560
|
+
typ: exports.EnumToken.IdenTokenType, val: 'none'
|
|
18561
|
+
});
|
|
18562
|
+
}
|
|
18563
|
+
}
|
|
18564
|
+
return {
|
|
18565
|
+
matrix: serialize(matrix),
|
|
18566
|
+
cumulative,
|
|
18567
|
+
minified: minify$1(matrix) ?? [serialized]
|
|
18568
|
+
};
|
|
18569
|
+
}
|
|
18570
|
+
function computeMatrix(transformList, matrixVar) {
|
|
18571
|
+
let values = [];
|
|
18572
|
+
let val;
|
|
18573
|
+
let i = 0;
|
|
18574
|
+
for (; i < transformList.length; i++) {
|
|
18575
|
+
if (transformList[i].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18576
|
+
continue;
|
|
18577
|
+
}
|
|
18578
|
+
if (transformList[i].typ != exports.EnumToken.FunctionTokenType || !transformFunctions.includes(transformList[i].val)) {
|
|
18579
|
+
return null;
|
|
18580
|
+
}
|
|
18581
|
+
switch (transformList[i].val) {
|
|
18582
|
+
case 'translate':
|
|
18583
|
+
case 'translateX':
|
|
18584
|
+
case 'translateY':
|
|
18585
|
+
case 'translateZ':
|
|
18586
|
+
case 'translate3d':
|
|
18587
|
+
{
|
|
18588
|
+
values.length = 0;
|
|
18589
|
+
const children = stripCommaToken(transformList[i].chi.slice());
|
|
18590
|
+
if (children == null || children.length == 0) {
|
|
18591
|
+
return null;
|
|
18592
|
+
}
|
|
18593
|
+
const valCount = transformList[i].val == 'translate3d' || transformList[i].val == 'translate' ? 3 : 1;
|
|
18594
|
+
if (children.length == 1 && children[0].typ == exports.EnumToken.IdenTokenType && children[0].val == 'none') {
|
|
18595
|
+
values.fill(0, 0, valCount);
|
|
18596
|
+
}
|
|
18597
|
+
else {
|
|
18598
|
+
for (let j = 0; j < children.length; j++) {
|
|
18599
|
+
if (children[j].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18600
|
+
continue;
|
|
18601
|
+
}
|
|
18602
|
+
val = length2Px(children[j]);
|
|
18603
|
+
if (typeof val != 'number' || Number.isNaN(val)) {
|
|
18604
|
+
return null;
|
|
18605
|
+
}
|
|
18606
|
+
values.push(val);
|
|
18607
|
+
}
|
|
18608
|
+
}
|
|
18609
|
+
if (values.length == 0 || values.length > valCount) {
|
|
18610
|
+
return null;
|
|
18611
|
+
}
|
|
18612
|
+
if (transformList[i].val == 'translateX') {
|
|
18613
|
+
matrixVar = translateX(values[0], matrixVar);
|
|
18614
|
+
}
|
|
18615
|
+
else if (transformList[i].val == 'translateY') {
|
|
18616
|
+
matrixVar = translateY(values[0], matrixVar);
|
|
18617
|
+
}
|
|
18618
|
+
else if (transformList[i].val == 'translateZ') {
|
|
18619
|
+
matrixVar = translateZ(values[0], matrixVar);
|
|
18620
|
+
}
|
|
18621
|
+
else if (transformList[i].val == 'translate') {
|
|
18622
|
+
matrixVar = translate(values, matrixVar);
|
|
18623
|
+
}
|
|
18624
|
+
else {
|
|
18625
|
+
// @ts-ignore
|
|
18626
|
+
matrixVar = translate3d(values, matrixVar);
|
|
18627
|
+
}
|
|
18628
|
+
}
|
|
18629
|
+
break;
|
|
18630
|
+
case 'rotate':
|
|
18631
|
+
case 'rotateX':
|
|
18632
|
+
case 'rotateY':
|
|
18633
|
+
case 'rotateZ':
|
|
18634
|
+
case 'rotate3d':
|
|
18635
|
+
{
|
|
18636
|
+
let x = 0;
|
|
18637
|
+
let y = 0;
|
|
18638
|
+
let z = 0;
|
|
18639
|
+
let angle;
|
|
18640
|
+
let values = [];
|
|
18641
|
+
let valuesCount = transformList[i].val == 'rotate3d' ? 4 : 1;
|
|
18642
|
+
for (const child of stripCommaToken(transformList[i].chi.slice())) {
|
|
18643
|
+
if (child.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18644
|
+
continue;
|
|
18645
|
+
}
|
|
18646
|
+
values.push(child);
|
|
18647
|
+
if (transformList[i].val == 'rotateX') {
|
|
18648
|
+
x = 1;
|
|
18649
|
+
}
|
|
18650
|
+
else if (transformList[i].val == 'rotateY') {
|
|
18651
|
+
y = 1;
|
|
18652
|
+
}
|
|
18653
|
+
else if (transformList[i].val == 'rotate' || transformList[i].val == 'rotateZ') {
|
|
18654
|
+
z = 1;
|
|
18655
|
+
}
|
|
18656
|
+
}
|
|
18657
|
+
if (values.length != valuesCount) {
|
|
18658
|
+
return null;
|
|
18659
|
+
}
|
|
18660
|
+
if (transformList[i].val == 'rotate3d') {
|
|
18661
|
+
x = getNumber(values[0]);
|
|
18662
|
+
y = getNumber(values[1]);
|
|
18663
|
+
z = getNumber(values[2]);
|
|
18664
|
+
}
|
|
18665
|
+
angle = getAngle(values.at(-1));
|
|
18666
|
+
if ([x, y, z, angle].some(t => typeof t != 'number' || Number.isNaN(+t))) {
|
|
18667
|
+
return null;
|
|
18668
|
+
}
|
|
18669
|
+
if (transformList[i].val == 'rotate' || transformList[i].val == 'rotateZ') {
|
|
18670
|
+
matrixVar = rotate(angle * 2 * Math.PI, matrixVar);
|
|
18671
|
+
}
|
|
18672
|
+
else {
|
|
18673
|
+
matrixVar = rotate3D(angle * 2 * Math.PI, x, y, z, matrixVar);
|
|
18674
|
+
}
|
|
18675
|
+
}
|
|
18676
|
+
break;
|
|
18677
|
+
case 'scale':
|
|
18678
|
+
case 'scaleX':
|
|
18679
|
+
case 'scaleY':
|
|
18680
|
+
case 'scaleZ':
|
|
18681
|
+
case 'scale3d':
|
|
18682
|
+
{
|
|
18683
|
+
values.length = 0;
|
|
18684
|
+
let child;
|
|
18685
|
+
const children = stripCommaToken(transformList[i].chi.slice());
|
|
18686
|
+
for (let k = 0; k < children.length; k++) {
|
|
18687
|
+
child = children[k];
|
|
18688
|
+
if (child.typ == exports.EnumToken.CommentTokenType || child.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18689
|
+
continue;
|
|
18690
|
+
}
|
|
18691
|
+
if (child.typ != exports.EnumToken.NumberTokenType) {
|
|
18692
|
+
return null;
|
|
18693
|
+
}
|
|
18694
|
+
values.push(getNumber(child));
|
|
18695
|
+
}
|
|
18696
|
+
if (values.length == 0) {
|
|
18697
|
+
return null;
|
|
18698
|
+
}
|
|
18699
|
+
if (transformList[i].val == 'scale3d') {
|
|
18700
|
+
if (values.length != 3) {
|
|
18701
|
+
return null;
|
|
18702
|
+
}
|
|
18703
|
+
matrixVar = scale3d(...values, matrixVar);
|
|
18704
|
+
break;
|
|
18705
|
+
}
|
|
18706
|
+
if (transformList[i].val == 'scale') {
|
|
18707
|
+
if (values.length != 1 && values.length != 2) {
|
|
18708
|
+
return null;
|
|
18709
|
+
}
|
|
18710
|
+
matrixVar = scale(values[0], values[1] ?? values[0], matrixVar);
|
|
18711
|
+
break;
|
|
18712
|
+
}
|
|
18713
|
+
if (values.length != 1) {
|
|
18714
|
+
return null;
|
|
18715
|
+
}
|
|
18716
|
+
else if (transformList[i].val == 'scaleX') {
|
|
18717
|
+
matrixVar = scaleX(values[0], matrixVar);
|
|
18718
|
+
}
|
|
18719
|
+
else if (transformList[i].val == 'scaleY') {
|
|
18720
|
+
matrixVar = scaleY(values[0], matrixVar);
|
|
18721
|
+
}
|
|
18722
|
+
else if (transformList[i].val == 'scaleZ') {
|
|
18723
|
+
matrixVar = scaleZ(values[0], matrixVar);
|
|
18724
|
+
}
|
|
18725
|
+
}
|
|
18726
|
+
break;
|
|
18727
|
+
case 'skew':
|
|
18728
|
+
case 'skewX':
|
|
18729
|
+
case 'skewY':
|
|
18730
|
+
{
|
|
18731
|
+
values.length = 0;
|
|
18732
|
+
let child;
|
|
18733
|
+
let value;
|
|
18734
|
+
for (let k = 0; k < transformList[i].chi.length; k++) {
|
|
18735
|
+
child = transformList[i].chi[k];
|
|
18736
|
+
if (child.typ == exports.EnumToken.CommentTokenType || child.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18737
|
+
continue;
|
|
18738
|
+
}
|
|
18739
|
+
value = getAngle(child);
|
|
18740
|
+
if (value == null) {
|
|
18741
|
+
return null;
|
|
18742
|
+
}
|
|
18743
|
+
values.push(value * 2 * Math.PI);
|
|
18744
|
+
}
|
|
18745
|
+
if (values.length == 0 || (values.length > (transformList[i].val == 'skew' ? 2 : 1))) {
|
|
18746
|
+
return null;
|
|
18747
|
+
}
|
|
18748
|
+
if (transformList[i].val == 'skew') {
|
|
18749
|
+
matrixVar = skew(values, matrixVar);
|
|
18750
|
+
}
|
|
18751
|
+
else {
|
|
18752
|
+
matrixVar = transformList[i].val == 'skewX' ? skewX(values[0], matrixVar) : skewY(values[0], matrixVar);
|
|
18753
|
+
}
|
|
18754
|
+
}
|
|
18755
|
+
break;
|
|
18756
|
+
case 'perspective':
|
|
18757
|
+
{
|
|
18758
|
+
const values = [];
|
|
18759
|
+
let child;
|
|
18760
|
+
let value;
|
|
18761
|
+
for (let k = 0; k < transformList[i].chi.length; k++) {
|
|
18762
|
+
child = transformList[i].chi[k];
|
|
18763
|
+
if (child.typ == exports.EnumToken.CommentTokenType || child.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18764
|
+
continue;
|
|
18765
|
+
}
|
|
18766
|
+
if (child.typ == exports.EnumToken.IdenTokenType && child.val == 'none') {
|
|
18767
|
+
values.push(child);
|
|
18768
|
+
continue;
|
|
18769
|
+
}
|
|
18770
|
+
value = length2Px(child);
|
|
18771
|
+
if (value == null) {
|
|
18772
|
+
return null;
|
|
18773
|
+
}
|
|
18774
|
+
values.push(value);
|
|
18775
|
+
}
|
|
18776
|
+
if (values.length != 1) {
|
|
18777
|
+
return null;
|
|
18778
|
+
}
|
|
18779
|
+
matrixVar = perspective(values[0], matrixVar);
|
|
18780
|
+
}
|
|
18781
|
+
break;
|
|
18782
|
+
case 'matrix3d':
|
|
18783
|
+
// return null;
|
|
18784
|
+
case 'matrix':
|
|
18785
|
+
{
|
|
18786
|
+
const values = [];
|
|
18787
|
+
let value;
|
|
18788
|
+
for (const token of transformList[i].chi) {
|
|
18789
|
+
if ([exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType, exports.EnumToken.CommaTokenType].includes(token.typ)) {
|
|
18790
|
+
continue;
|
|
18791
|
+
}
|
|
18792
|
+
value = getNumber(token);
|
|
18793
|
+
if (value == null) {
|
|
18794
|
+
return null;
|
|
18795
|
+
}
|
|
18796
|
+
values.push(value);
|
|
18797
|
+
}
|
|
18798
|
+
if (transformList[i].val == 'matrix') {
|
|
18799
|
+
if (values.length != 6) {
|
|
18800
|
+
return null;
|
|
18801
|
+
}
|
|
18802
|
+
}
|
|
18803
|
+
else if (values.length != 16) {
|
|
18804
|
+
return null;
|
|
18805
|
+
}
|
|
18806
|
+
matrixVar = multiply(matrixVar, matrix(values));
|
|
18807
|
+
}
|
|
18808
|
+
break;
|
|
18809
|
+
default:
|
|
18810
|
+
return null;
|
|
18811
|
+
}
|
|
18812
|
+
}
|
|
18813
|
+
return matrixVar;
|
|
18814
|
+
}
|
|
18815
|
+
function splitTransformList(transformList) {
|
|
18816
|
+
let pattern = null;
|
|
18817
|
+
const tokens = [];
|
|
18818
|
+
for (let i = 0; i < transformList.length; i++) {
|
|
18819
|
+
if (transformList[i].typ == exports.EnumToken.CommentTokenType || transformList[i].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18820
|
+
continue;
|
|
18821
|
+
}
|
|
18822
|
+
if (pattern == null || (transformList[i].typ == exports.EnumToken.FunctionTokenType && !transformList[i].val.startsWith(pattern))) {
|
|
18823
|
+
if (transformList[i].typ == exports.EnumToken.FunctionTokenType) {
|
|
18824
|
+
if (transformList[i].val.startsWith('scale')) {
|
|
18825
|
+
pattern = 'scale';
|
|
18826
|
+
}
|
|
18827
|
+
else if (transformList[i].val.startsWith('rotate')) {
|
|
18828
|
+
pattern = 'rotate';
|
|
18829
|
+
}
|
|
18830
|
+
else if (transformList[i].val.startsWith('translate')) {
|
|
18831
|
+
pattern = 'translate';
|
|
18832
|
+
}
|
|
18833
|
+
else {
|
|
18834
|
+
pattern = null;
|
|
18835
|
+
}
|
|
18836
|
+
tokens.push([transformList[i]]);
|
|
18837
|
+
continue;
|
|
18838
|
+
}
|
|
18839
|
+
}
|
|
18840
|
+
if (pattern != null && transformList[i].typ == exports.EnumToken.FunctionTokenType && transformList[i].val.startsWith(pattern)) {
|
|
18841
|
+
tokens[tokens.length - 1].push(transformList[i]);
|
|
18842
|
+
continue;
|
|
18843
|
+
}
|
|
18844
|
+
tokens.push([transformList[i]]);
|
|
18845
|
+
}
|
|
18846
|
+
return tokens;
|
|
18847
|
+
}
|
|
18848
|
+
|
|
18849
|
+
class TransformCssFeature {
|
|
18850
|
+
static get ordering() {
|
|
18851
|
+
return 4;
|
|
18852
|
+
}
|
|
18853
|
+
static register(options) {
|
|
18854
|
+
// @ts-ignore
|
|
18855
|
+
if (options.computeTransform) {
|
|
18856
|
+
// @ts-ignore
|
|
18857
|
+
options.features.push(new TransformCssFeature());
|
|
18858
|
+
}
|
|
18859
|
+
}
|
|
18860
|
+
run(ast) {
|
|
18861
|
+
if (!('chi' in ast)) {
|
|
18862
|
+
return;
|
|
18863
|
+
}
|
|
18864
|
+
let i = 0;
|
|
18865
|
+
let node;
|
|
18866
|
+
// @ts-ignore
|
|
18867
|
+
for (; i < ast.chi.length; i++) {
|
|
18868
|
+
// @ts-ignore
|
|
18869
|
+
node = ast.chi[i];
|
|
18870
|
+
if (node.typ != exports.EnumToken.DeclarationNodeType || !node.nam.match(/^(-[a-z]+-)?transform$/)) {
|
|
18871
|
+
continue;
|
|
18872
|
+
}
|
|
18873
|
+
const children = node.val.slice();
|
|
18874
|
+
consumeWhitespace(children);
|
|
18875
|
+
let { matrix, cumulative, minified } = compute(children) ?? {};
|
|
18876
|
+
if (matrix == null || cumulative == null || minified == null) {
|
|
18877
|
+
return;
|
|
18878
|
+
}
|
|
18879
|
+
let r = [filterValues(node.val.slice())];
|
|
18880
|
+
if (eqMatrix(matrix, cumulative)) {
|
|
18881
|
+
r.push(cumulative);
|
|
18882
|
+
}
|
|
18883
|
+
if (eqMatrix(matrix, minified)) {
|
|
18884
|
+
r.push(minified);
|
|
18885
|
+
}
|
|
18886
|
+
const l = renderToken(matrix).length;
|
|
18887
|
+
node.val = r.reduce((acc, curr) => {
|
|
18888
|
+
if (curr.reduce((acc, t) => acc + renderToken(t), '').length < l) {
|
|
18889
|
+
return curr;
|
|
18890
|
+
}
|
|
18891
|
+
return acc;
|
|
18892
|
+
}, [matrix]);
|
|
18893
|
+
}
|
|
18894
|
+
}
|
|
18895
|
+
}
|
|
18896
|
+
|
|
18897
|
+
var allFeatures = /*#__PURE__*/Object.freeze({
|
|
18898
|
+
__proto__: null,
|
|
18899
|
+
ComputeCalcExpressionFeature: ComputeCalcExpressionFeature,
|
|
18900
|
+
ComputePrefixFeature: ComputePrefixFeature,
|
|
18901
|
+
ComputeShorthandFeature: ComputeShorthandFeature,
|
|
18902
|
+
InlineCssVariablesFeature: InlineCssVariablesFeature,
|
|
18903
|
+
TransformCssFeature: TransformCssFeature
|
|
18904
|
+
});
|
|
18905
|
+
|
|
18906
|
+
const combinators = ['+', '>', '~', '||', '|'];
|
|
18907
|
+
const definedPropertySettings = { configurable: true, enumerable: false, writable: true };
|
|
18908
|
+
const notEndingWith = ['(', '['].concat(combinators);
|
|
18909
|
+
// @ts-ignore
|
|
18910
|
+
const features = Object.values(allFeatures).sort((a, b) => a.ordering - b.ordering);
|
|
18911
|
+
/**
|
|
18912
|
+
* minify ast
|
|
18913
|
+
* @param ast
|
|
18914
|
+
* @param options
|
|
18915
|
+
* @param recursive
|
|
18916
|
+
* @param errors
|
|
18917
|
+
* @param nestingContent
|
|
18918
|
+
* @param context
|
|
18919
|
+
*/
|
|
18920
|
+
function minify(ast, options = {}, recursive = false, errors, nestingContent, context = {}) {
|
|
18921
|
+
if (!('nodes' in context)) {
|
|
18922
|
+
context.nodes = new Set;
|
|
18923
|
+
}
|
|
18924
|
+
if (context.nodes.has(ast)) {
|
|
18925
|
+
return ast;
|
|
18926
|
+
}
|
|
18927
|
+
context.nodes.add(ast);
|
|
18928
|
+
if (!('features' in options)) {
|
|
18929
|
+
// @ts-ignore
|
|
18930
|
+
options = {
|
|
18931
|
+
removeDuplicateDeclarations: true,
|
|
18932
|
+
computeShorthand: true,
|
|
18933
|
+
computeCalcExpression: true,
|
|
18934
|
+
removePrefix: false,
|
|
18935
|
+
features: [], ...options
|
|
18936
|
+
};
|
|
18937
|
+
// @ts-ignore
|
|
18938
|
+
for (const feature of features) {
|
|
18939
|
+
feature.register(options);
|
|
18940
|
+
}
|
|
18941
|
+
}
|
|
18942
|
+
function reducer(acc, curr, index, array) {
|
|
18943
|
+
// trim :is()
|
|
18944
|
+
if (array.length == 1 && array[0][0] == ':is(' && array[0].at(-1) == ')') {
|
|
18945
|
+
curr = curr.slice(1, -1);
|
|
18946
|
+
}
|
|
18947
|
+
if (curr[0] == '&') {
|
|
18948
|
+
if (curr[1] == ' ' && !isIdent(curr[2]) && !isFunction(curr[2])) {
|
|
18949
|
+
curr.splice(0, 2);
|
|
18950
|
+
}
|
|
18951
|
+
else if (combinators.includes(curr[1])) {
|
|
18952
|
+
curr.shift();
|
|
18953
|
+
}
|
|
18954
|
+
}
|
|
18955
|
+
else if (ast.typ == exports.EnumToken.RuleNodeType && (isIdent(curr[0]) || isFunction(curr[0]))) {
|
|
18956
|
+
curr.unshift('&', ' ');
|
|
18957
|
+
}
|
|
18958
|
+
acc.push(curr.join(''));
|
|
18959
|
+
return acc;
|
|
18960
|
+
}
|
|
18961
|
+
// @ts-ignore
|
|
18962
|
+
if ('chi' in ast && ast.chi.length > 0) {
|
|
18963
|
+
if (!nestingContent) {
|
|
18964
|
+
nestingContent = options.nestingRules && ast.typ == exports.EnumToken.RuleNodeType;
|
|
18965
|
+
}
|
|
18966
|
+
let i = 0;
|
|
18967
|
+
let previous = null;
|
|
17692
18968
|
let node;
|
|
17693
|
-
let nodeIndex;
|
|
18969
|
+
let nodeIndex = -1;
|
|
17694
18970
|
// @ts-ignore
|
|
17695
18971
|
for (; i < ast.chi.length; i++) {
|
|
17696
18972
|
// @ts-ignore
|
|
@@ -17702,13 +18978,50 @@
|
|
|
17702
18978
|
// @ts-ignore
|
|
17703
18979
|
if (previous == node) {
|
|
17704
18980
|
// @ts-ignore
|
|
17705
|
-
ast.chi.splice(i
|
|
17706
|
-
i--;
|
|
18981
|
+
ast.chi.splice(i--, 1);
|
|
17707
18982
|
continue;
|
|
17708
18983
|
}
|
|
17709
18984
|
if (node.typ == exports.EnumToken.AtRuleNodeType && node.nam == 'font-face') {
|
|
17710
18985
|
continue;
|
|
17711
18986
|
}
|
|
18987
|
+
if (node.typ == exports.EnumToken.KeyframeAtRuleNodeType) {
|
|
18988
|
+
if (previous?.typ == exports.EnumToken.KeyframeAtRuleNodeType &&
|
|
18989
|
+
node.nam == previous.nam &&
|
|
18990
|
+
node.val == previous.val) {
|
|
18991
|
+
ast.chi?.splice(nodeIndex--, 1);
|
|
18992
|
+
previous = ast?.chi?.[nodeIndex] ?? null;
|
|
18993
|
+
i = nodeIndex;
|
|
18994
|
+
continue;
|
|
18995
|
+
}
|
|
18996
|
+
if (node.chi.length > 0) {
|
|
18997
|
+
minify(node, options, true, errors, nestingContent, context);
|
|
18998
|
+
}
|
|
18999
|
+
}
|
|
19000
|
+
if (node.typ == exports.EnumToken.KeyFrameRuleNodeType) {
|
|
19001
|
+
if (previous?.typ == exports.EnumToken.KeyFrameRuleNodeType &&
|
|
19002
|
+
node.sel == previous.sel) {
|
|
19003
|
+
previous.chi.push(...node.chi);
|
|
19004
|
+
// @ts-ignore
|
|
19005
|
+
ast.chi.splice(i--, 1);
|
|
19006
|
+
continue;
|
|
19007
|
+
}
|
|
19008
|
+
let k;
|
|
19009
|
+
for (k = 0; k < node.chi.length; k++) {
|
|
19010
|
+
if (node.chi[k].typ == exports.EnumToken.DeclarationNodeType) {
|
|
19011
|
+
let l = node.chi[k].val.length;
|
|
19012
|
+
while (l--) {
|
|
19013
|
+
if (node.chi[k].val[l].typ == exports.EnumToken.ImportantTokenType) {
|
|
19014
|
+
node.chi.splice(k--, 1);
|
|
19015
|
+
break;
|
|
19016
|
+
}
|
|
19017
|
+
if ([exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(node.chi[k].val[l].typ)) {
|
|
19018
|
+
continue;
|
|
19019
|
+
}
|
|
19020
|
+
break;
|
|
19021
|
+
}
|
|
19022
|
+
}
|
|
19023
|
+
}
|
|
19024
|
+
}
|
|
17712
19025
|
if (node.typ == exports.EnumToken.AtRuleNodeType) {
|
|
17713
19026
|
// @ts-ignore
|
|
17714
19027
|
if (node.nam == 'media' && ['all', '', null].includes(node.val)) {
|
|
@@ -17959,6 +19272,10 @@
|
|
|
17959
19272
|
}
|
|
17960
19273
|
}
|
|
17961
19274
|
}
|
|
19275
|
+
// else if ('chi' in node) {
|
|
19276
|
+
//
|
|
19277
|
+
// minify(node, options, recursive, errors, nestingContent, context);
|
|
19278
|
+
// }
|
|
17962
19279
|
if (!nestingContent &&
|
|
17963
19280
|
// @ts-ignore
|
|
17964
19281
|
previous != null &&
|
|
@@ -17973,7 +19290,7 @@
|
|
|
17973
19290
|
// @ts-ignore
|
|
17974
19291
|
if (recursive && node != null && ('chi' in node)) {
|
|
17975
19292
|
// @ts-ignore
|
|
17976
|
-
if (!node.chi.some(n => n.typ == exports.EnumToken.DeclarationNodeType)) {
|
|
19293
|
+
if (node.typ == exports.EnumToken.KeyframeAtRuleNodeType || !node.chi.some(n => n.typ == exports.EnumToken.DeclarationNodeType)) {
|
|
17977
19294
|
// @ts-ignore
|
|
17978
19295
|
if (!(node.typ == exports.EnumToken.AtRuleNodeType && node.nam != 'font-face')) {
|
|
17979
19296
|
minify(node, options, recursive, errors, nestingContent, context);
|