@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.cjs
CHANGED
|
@@ -107,6 +107,7 @@ exports.EnumToken = void 0;
|
|
|
107
107
|
EnumToken[EnumToken["MediaFeatureOrTokenType"] = 90] = "MediaFeatureOrTokenType";
|
|
108
108
|
EnumToken[EnumToken["PseudoPageTokenType"] = 91] = "PseudoPageTokenType";
|
|
109
109
|
EnumToken[EnumToken["PseudoElementTokenType"] = 92] = "PseudoElementTokenType";
|
|
110
|
+
EnumToken[EnumToken["KeyframeAtRuleNodeType"] = 93] = "KeyframeAtRuleNodeType";
|
|
110
111
|
/* aliases */
|
|
111
112
|
EnumToken[EnumToken["Time"] = 25] = "Time";
|
|
112
113
|
EnumToken[EnumToken["Iden"] = 7] = "Iden";
|
|
@@ -429,25 +430,35 @@ function rgb2hex(token) {
|
|
|
429
430
|
return value;
|
|
430
431
|
}
|
|
431
432
|
function hsl2hex(token) {
|
|
432
|
-
|
|
433
|
+
const t = hsl2rgb(token);
|
|
434
|
+
return t == null ? null : `${t.reduce(toHexString, '#')}`;
|
|
433
435
|
}
|
|
434
436
|
function hwb2hex(token) {
|
|
435
|
-
|
|
437
|
+
const t = hwb2rgb(token);
|
|
438
|
+
return t == null ? null : `${t.reduce(toHexString, '#')}`;
|
|
436
439
|
}
|
|
437
440
|
function cmyk2hex(token) {
|
|
438
|
-
|
|
441
|
+
const t = cmyk2rgb(token);
|
|
442
|
+
return t == null ? null : `#${t.reduce(toHexString, '')}`;
|
|
439
443
|
}
|
|
440
444
|
function oklab2hex(token) {
|
|
441
|
-
|
|
445
|
+
const t = oklab2rgb(token);
|
|
446
|
+
return t == null ? null : `${t.reduce(toHexString, '#')}`;
|
|
442
447
|
}
|
|
443
448
|
function oklch2hex(token) {
|
|
444
|
-
|
|
449
|
+
const value = oklch2rgb(token);
|
|
450
|
+
if (value == null) {
|
|
451
|
+
return null;
|
|
452
|
+
}
|
|
453
|
+
return `${value.reduce(toHexString, '#')}`;
|
|
445
454
|
}
|
|
446
455
|
function lab2hex(token) {
|
|
447
|
-
|
|
456
|
+
const t = lab2rgb(token);
|
|
457
|
+
return t == null ? null : `${t.reduce(toHexString, '#')}`;
|
|
448
458
|
}
|
|
449
459
|
function lch2hex(token) {
|
|
450
|
-
|
|
460
|
+
const t = lch2rgb(token);
|
|
461
|
+
return t == null ? null : `${t.reduce(toHexString, '#')}`;
|
|
451
462
|
}
|
|
452
463
|
function srgb2hexvalues(r, g, b, alpha) {
|
|
453
464
|
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'), '#');
|
|
@@ -461,8 +472,19 @@ function getComponents(token) {
|
|
|
461
472
|
return { typ: exports.EnumToken.Number, val: parseInt(t, 16).toString() };
|
|
462
473
|
});
|
|
463
474
|
}
|
|
464
|
-
|
|
465
|
-
|
|
475
|
+
const result = [];
|
|
476
|
+
for (const child of (token.chi)) {
|
|
477
|
+
if ([
|
|
478
|
+
exports.EnumToken.LiteralTokenType, exports.EnumToken.CommentTokenType, exports.EnumToken.CommaTokenType, exports.EnumToken.WhitespaceTokenType
|
|
479
|
+
].includes(child.typ)) {
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
if (child.typ == exports.EnumToken.ColorTokenType && child.val == 'currentcolor') {
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
result.push(child);
|
|
486
|
+
}
|
|
487
|
+
return result;
|
|
466
488
|
}
|
|
467
489
|
|
|
468
490
|
function XYZ_to_lin_sRGB(x, y, z) {
|
|
@@ -554,6 +576,14 @@ function xyz2lchvalues(x, y, z, alpha) {
|
|
|
554
576
|
}
|
|
555
577
|
function getLCHComponents(token) {
|
|
556
578
|
const components = getComponents(token);
|
|
579
|
+
if (components == null) {
|
|
580
|
+
return null;
|
|
581
|
+
}
|
|
582
|
+
for (let i = 0; i < components.length; i++) {
|
|
583
|
+
if (![exports.EnumToken.NumberTokenType, exports.EnumToken.PercentageTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.IdenTokenType].includes(components[i].typ)) {
|
|
584
|
+
return null;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
557
587
|
// @ts-ignore
|
|
558
588
|
let t = components[0];
|
|
559
589
|
// @ts-ignore
|
|
@@ -607,6 +637,14 @@ function srgb2oklch(r, g, blue, alpha) {
|
|
|
607
637
|
}
|
|
608
638
|
function getOKLCHComponents(token) {
|
|
609
639
|
const components = getComponents(token);
|
|
640
|
+
if (components == null) {
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
643
|
+
for (let i = 0; i < components.length; i++) {
|
|
644
|
+
if (![exports.EnumToken.NumberTokenType, exports.EnumToken.PercentageTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.IdenTokenType].includes(components[i].typ)) {
|
|
645
|
+
return [];
|
|
646
|
+
}
|
|
647
|
+
}
|
|
610
648
|
// @ts-ignore
|
|
611
649
|
let t = components[0];
|
|
612
650
|
// @ts-ignore
|
|
@@ -666,6 +704,14 @@ function srgb2oklab(r, g, blue, alpha) {
|
|
|
666
704
|
}
|
|
667
705
|
function getOKLABComponents(token) {
|
|
668
706
|
const components = getComponents(token);
|
|
707
|
+
if (components == null) {
|
|
708
|
+
return null;
|
|
709
|
+
}
|
|
710
|
+
for (let i = 0; i < components.length; i++) {
|
|
711
|
+
if (![exports.EnumToken.NumberTokenType, exports.EnumToken.PercentageTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.IdenTokenType].includes(components[i].typ)) {
|
|
712
|
+
return null;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
669
715
|
// @ts-ignore
|
|
670
716
|
let t = components[0];
|
|
671
717
|
// @ts-ignore
|
|
@@ -846,6 +892,14 @@ function lch2labvalues(l, c, h, a = null) {
|
|
|
846
892
|
}
|
|
847
893
|
function getLABComponents(token) {
|
|
848
894
|
const components = getComponents(token);
|
|
895
|
+
if (components == null) {
|
|
896
|
+
return null;
|
|
897
|
+
}
|
|
898
|
+
for (let i = 0; i < components.length; i++) {
|
|
899
|
+
if (![exports.EnumToken.NumberTokenType, exports.EnumToken.PercentageTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.IdenTokenType].includes(components[i].typ)) {
|
|
900
|
+
return [];
|
|
901
|
+
}
|
|
902
|
+
}
|
|
849
903
|
// @ts-ignore
|
|
850
904
|
let t = components[0];
|
|
851
905
|
// @ts-ignore
|
|
@@ -925,7 +979,7 @@ function srgbvalues(token) {
|
|
|
925
979
|
return null;
|
|
926
980
|
}
|
|
927
981
|
function rgb2srgb(token) {
|
|
928
|
-
return getComponents(token)
|
|
982
|
+
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;
|
|
929
983
|
}
|
|
930
984
|
function hex2srgb(token) {
|
|
931
985
|
const value = expandHexValue(token.kin == 'lit' ? COLORS_NAMES[token.val.toLowerCase()] : token.val);
|
|
@@ -940,7 +994,10 @@ function xyz2srgb(x, y, z) {
|
|
|
940
994
|
return lsrgb2srgbvalues(...XYZ_to_lin_sRGB(x, y, z));
|
|
941
995
|
}
|
|
942
996
|
function hwb2srgb(token) {
|
|
943
|
-
const { h: hue, s: white, l: black, a: alpha } = hslvalues(token);
|
|
997
|
+
const { h: hue, s: white, l: black, a: alpha } = hslvalues(token) ?? {};
|
|
998
|
+
if (hue == null || white == null || black == null) {
|
|
999
|
+
return [];
|
|
1000
|
+
}
|
|
944
1001
|
const rgb = hsl2srgbvalues(hue, 1, .5);
|
|
945
1002
|
for (let i = 0; i < 3; i++) {
|
|
946
1003
|
rgb[i] *= (1 - white - black);
|
|
@@ -952,11 +1009,17 @@ function hwb2srgb(token) {
|
|
|
952
1009
|
return rgb;
|
|
953
1010
|
}
|
|
954
1011
|
function hsl2srgb(token) {
|
|
955
|
-
let { h, s, l, a } = hslvalues(token);
|
|
1012
|
+
let { h, s, l, a } = hslvalues(token) ?? {};
|
|
1013
|
+
if (h == null || s == null || l == null) {
|
|
1014
|
+
return null;
|
|
1015
|
+
}
|
|
956
1016
|
return hsl2srgbvalues(h, s, l, a);
|
|
957
1017
|
}
|
|
958
1018
|
function cmyk2srgb(token) {
|
|
959
1019
|
const components = getComponents(token);
|
|
1020
|
+
if (components == null) {
|
|
1021
|
+
return null;
|
|
1022
|
+
}
|
|
960
1023
|
// @ts-ignore
|
|
961
1024
|
let t = components[0];
|
|
962
1025
|
// @ts-ignore
|
|
@@ -988,7 +1051,10 @@ function cmyk2srgb(token) {
|
|
|
988
1051
|
return rgb;
|
|
989
1052
|
}
|
|
990
1053
|
function oklab2srgb(token) {
|
|
991
|
-
const [l, a, b, alpha] = getOKLABComponents(token);
|
|
1054
|
+
const [l, a, b, alpha] = getOKLABComponents(token) ?? [];
|
|
1055
|
+
if (l == null || a == null || b == null) {
|
|
1056
|
+
return null;
|
|
1057
|
+
}
|
|
992
1058
|
const rgb = OKLab_to_sRGB(l, a, b);
|
|
993
1059
|
if (alpha != null && alpha != 1) {
|
|
994
1060
|
rgb.push(alpha);
|
|
@@ -996,7 +1062,10 @@ function oklab2srgb(token) {
|
|
|
996
1062
|
return rgb;
|
|
997
1063
|
}
|
|
998
1064
|
function oklch2srgb(token) {
|
|
999
|
-
const [l, c, h, alpha] = getOKLCHComponents(token);
|
|
1065
|
+
const [l, c, h, alpha] = getOKLCHComponents(token) ?? [];
|
|
1066
|
+
if (l == null || c == null || h == null) {
|
|
1067
|
+
return null;
|
|
1068
|
+
}
|
|
1000
1069
|
// @ts-ignore
|
|
1001
1070
|
const rgb = OKLab_to_sRGB(...lch2labvalues(l, c, h));
|
|
1002
1071
|
if (alpha != 1) {
|
|
@@ -1006,6 +1075,9 @@ function oklch2srgb(token) {
|
|
|
1006
1075
|
}
|
|
1007
1076
|
function hslvalues(token) {
|
|
1008
1077
|
const components = getComponents(token);
|
|
1078
|
+
if (components == null) {
|
|
1079
|
+
return null;
|
|
1080
|
+
}
|
|
1009
1081
|
let t;
|
|
1010
1082
|
// @ts-ignore
|
|
1011
1083
|
let h = getAngle(components[0]);
|
|
@@ -1080,7 +1152,10 @@ function hsl2srgbvalues(h, s, l, a = null) {
|
|
|
1080
1152
|
return values;
|
|
1081
1153
|
}
|
|
1082
1154
|
function lab2srgb(token) {
|
|
1083
|
-
const [l, a, b, alpha] = getLABComponents(token);
|
|
1155
|
+
const [l, a, b, alpha] = getLABComponents(token) ?? [];
|
|
1156
|
+
if (l == null || a == null || b == null) {
|
|
1157
|
+
return null;
|
|
1158
|
+
}
|
|
1084
1159
|
const rgb = Lab_to_sRGB(l, a, b);
|
|
1085
1160
|
if (alpha != null && alpha != 1) {
|
|
1086
1161
|
rgb.push(alpha);
|
|
@@ -1090,6 +1165,9 @@ function lab2srgb(token) {
|
|
|
1090
1165
|
function lch2srgb(token) {
|
|
1091
1166
|
// @ts-ignore
|
|
1092
1167
|
const [l, a, b, alpha] = lch2labvalues(...getLCHComponents(token));
|
|
1168
|
+
if (l == null || a == null || b == null) {
|
|
1169
|
+
return null;
|
|
1170
|
+
}
|
|
1093
1171
|
// https://www.w3.org/TR/css-color-4/#lab-to-lch
|
|
1094
1172
|
const rgb = Lab_to_sRGB(l, a, b);
|
|
1095
1173
|
if (alpha != 1) {
|
|
@@ -1149,26 +1227,29 @@ function hex2rgb(token) {
|
|
|
1149
1227
|
return rgb;
|
|
1150
1228
|
}
|
|
1151
1229
|
function hwb2rgb(token) {
|
|
1152
|
-
return hwb2srgb(token)
|
|
1230
|
+
return hwb2srgb(token)?.map?.(srgb2rgb) ?? null;
|
|
1153
1231
|
}
|
|
1154
1232
|
function hsl2rgb(token) {
|
|
1155
|
-
let { h, s, l, a } = hslvalues(token);
|
|
1233
|
+
let { h, s, l, a } = hslvalues(token) ?? {};
|
|
1234
|
+
if (h == null || s == null || l == null) {
|
|
1235
|
+
return null;
|
|
1236
|
+
}
|
|
1156
1237
|
return hsl2srgbvalues(h, s, l, a).map((t) => minmax(Math.round(t * 255), 0, 255));
|
|
1157
1238
|
}
|
|
1158
1239
|
function cmyk2rgb(token) {
|
|
1159
|
-
return cmyk2srgb(token)
|
|
1240
|
+
return cmyk2srgb(token)?.map?.(srgb2rgb) ?? null;
|
|
1160
1241
|
}
|
|
1161
1242
|
function oklab2rgb(token) {
|
|
1162
|
-
return oklab2srgb(token)
|
|
1243
|
+
return oklab2srgb(token)?.map?.(srgb2rgb) ?? null;
|
|
1163
1244
|
}
|
|
1164
1245
|
function oklch2rgb(token) {
|
|
1165
|
-
return oklch2srgb(token)
|
|
1246
|
+
return oklch2srgb(token)?.map?.(srgb2rgb) ?? null;
|
|
1166
1247
|
}
|
|
1167
1248
|
function lab2rgb(token) {
|
|
1168
|
-
return lab2srgb(token)
|
|
1249
|
+
return lab2srgb(token)?.map?.(srgb2rgb) ?? null;
|
|
1169
1250
|
}
|
|
1170
1251
|
function lch2rgb(token) {
|
|
1171
|
-
return lch2srgb(token)
|
|
1252
|
+
return lch2srgb(token)?.map?.(srgb2rgb) ?? null;
|
|
1172
1253
|
}
|
|
1173
1254
|
|
|
1174
1255
|
function hwb2hsv(h, w, b, a) {
|
|
@@ -1196,6 +1277,9 @@ function hex2hsl(token) {
|
|
|
1196
1277
|
}
|
|
1197
1278
|
function rgb2hsl(token) {
|
|
1198
1279
|
const chi = getComponents(token);
|
|
1280
|
+
if (chi == null) {
|
|
1281
|
+
return null;
|
|
1282
|
+
}
|
|
1199
1283
|
// @ts-ignore
|
|
1200
1284
|
let t = chi[0];
|
|
1201
1285
|
// @ts-ignore
|
|
@@ -1254,12 +1338,14 @@ function lch2hsl(token) {
|
|
|
1254
1338
|
return rgb2hslvalues(...lch2rgb(token));
|
|
1255
1339
|
}
|
|
1256
1340
|
function oklab2hsl(token) {
|
|
1341
|
+
const t = oklab2rgb(token);
|
|
1257
1342
|
// @ts-ignore
|
|
1258
|
-
return rgb2hslvalues(...
|
|
1343
|
+
return t == null ? null : rgb2hslvalues(...t);
|
|
1259
1344
|
}
|
|
1260
1345
|
function oklch2hsl(token) {
|
|
1346
|
+
const t = oklch2rgb(token);
|
|
1261
1347
|
// @ts-ignore
|
|
1262
|
-
return rgb2hslvalues(...
|
|
1348
|
+
return t == null ? null : rgb2hslvalues(...t);
|
|
1263
1349
|
}
|
|
1264
1350
|
function rgb2hslvalues(r, g, b, a = null) {
|
|
1265
1351
|
return srgb2hsl(r / 255, g / 255, b / 255, a);
|
|
@@ -1609,10 +1695,15 @@ function convert(token, to) {
|
|
|
1609
1695
|
}
|
|
1610
1696
|
let values = [];
|
|
1611
1697
|
if (to == 'hsl') {
|
|
1698
|
+
let t;
|
|
1612
1699
|
switch (token.kin) {
|
|
1613
1700
|
case 'rgb':
|
|
1614
1701
|
case 'rgba':
|
|
1615
|
-
|
|
1702
|
+
t = rgb2hsl(token);
|
|
1703
|
+
if (t == null) {
|
|
1704
|
+
return null;
|
|
1705
|
+
}
|
|
1706
|
+
values.push(...t);
|
|
1616
1707
|
break;
|
|
1617
1708
|
case 'hex':
|
|
1618
1709
|
case 'lit':
|
|
@@ -1622,10 +1713,18 @@ function convert(token, to) {
|
|
|
1622
1713
|
values.push(...hwb2hsl(token));
|
|
1623
1714
|
break;
|
|
1624
1715
|
case 'oklab':
|
|
1625
|
-
|
|
1716
|
+
t = oklab2hsl(token);
|
|
1717
|
+
if (t == null) {
|
|
1718
|
+
return null;
|
|
1719
|
+
}
|
|
1720
|
+
values.push(...t);
|
|
1626
1721
|
break;
|
|
1627
1722
|
case 'oklch':
|
|
1628
|
-
|
|
1723
|
+
t = oklch2hsl(token);
|
|
1724
|
+
if (t == null) {
|
|
1725
|
+
return null;
|
|
1726
|
+
}
|
|
1727
|
+
values.push(...t);
|
|
1629
1728
|
break;
|
|
1630
1729
|
case 'lab':
|
|
1631
1730
|
values.push(...lab2hsl(token));
|
|
@@ -1674,28 +1773,53 @@ function convert(token, to) {
|
|
|
1674
1773
|
}
|
|
1675
1774
|
}
|
|
1676
1775
|
else if (to == 'rgb') {
|
|
1776
|
+
let t;
|
|
1677
1777
|
switch (token.kin) {
|
|
1678
1778
|
case 'hex':
|
|
1679
1779
|
case 'lit':
|
|
1680
1780
|
values.push(...hex2rgb(token));
|
|
1681
1781
|
break;
|
|
1682
1782
|
case 'hsl':
|
|
1683
|
-
|
|
1783
|
+
t = hsl2rgb(token);
|
|
1784
|
+
if (t == null) {
|
|
1785
|
+
return null;
|
|
1786
|
+
}
|
|
1787
|
+
values.push(...t);
|
|
1684
1788
|
break;
|
|
1685
1789
|
case 'hwb':
|
|
1686
|
-
|
|
1790
|
+
t = hwb2rgb(token);
|
|
1791
|
+
if (t == null) {
|
|
1792
|
+
return null;
|
|
1793
|
+
}
|
|
1794
|
+
values.push(...t);
|
|
1687
1795
|
break;
|
|
1688
1796
|
case 'oklab':
|
|
1689
|
-
|
|
1797
|
+
t = oklab2rgb(token);
|
|
1798
|
+
if (t == null) {
|
|
1799
|
+
return null;
|
|
1800
|
+
}
|
|
1801
|
+
values.push(...t);
|
|
1690
1802
|
break;
|
|
1691
1803
|
case 'oklch':
|
|
1692
|
-
|
|
1804
|
+
t = oklch2rgb(token);
|
|
1805
|
+
if (t == null) {
|
|
1806
|
+
return null;
|
|
1807
|
+
}
|
|
1808
|
+
values.push(...t);
|
|
1693
1809
|
break;
|
|
1694
1810
|
case 'lab':
|
|
1695
|
-
|
|
1811
|
+
t = lab2rgb(token);
|
|
1812
|
+
if (t == null) {
|
|
1813
|
+
return null;
|
|
1814
|
+
}
|
|
1815
|
+
values.push(...t);
|
|
1696
1816
|
break;
|
|
1697
1817
|
case 'lch':
|
|
1698
|
-
|
|
1818
|
+
t = lch2rgb(token);
|
|
1819
|
+
if (t == null) {
|
|
1820
|
+
return null;
|
|
1821
|
+
}
|
|
1822
|
+
values.push(...t);
|
|
1699
1823
|
break;
|
|
1700
1824
|
case 'color':
|
|
1701
1825
|
// @ts-ignore
|
|
@@ -1881,6 +2005,7 @@ function convert(token, to) {
|
|
|
1881
2005
|
}
|
|
1882
2006
|
}
|
|
1883
2007
|
else if (colorFuncColorSpace.includes(to)) {
|
|
2008
|
+
let t;
|
|
1884
2009
|
switch (token.kin) {
|
|
1885
2010
|
case 'hex':
|
|
1886
2011
|
case 'lit':
|
|
@@ -1888,30 +2013,60 @@ function convert(token, to) {
|
|
|
1888
2013
|
break;
|
|
1889
2014
|
case 'rgb':
|
|
1890
2015
|
case 'rgba':
|
|
1891
|
-
|
|
2016
|
+
t = rgb2srgb(token);
|
|
2017
|
+
if (t == null) {
|
|
2018
|
+
return null;
|
|
2019
|
+
}
|
|
2020
|
+
values.push(...t);
|
|
1892
2021
|
break;
|
|
1893
2022
|
case 'hsl':
|
|
1894
2023
|
case 'hsla':
|
|
1895
|
-
|
|
2024
|
+
t = hsl2srgb(token);
|
|
2025
|
+
if (t == null) {
|
|
2026
|
+
return null;
|
|
2027
|
+
}
|
|
2028
|
+
values.push(...t);
|
|
1896
2029
|
break;
|
|
1897
2030
|
case 'hwb':
|
|
1898
|
-
|
|
2031
|
+
t = hwb2srgb(token);
|
|
2032
|
+
if (t == null) {
|
|
2033
|
+
return null;
|
|
2034
|
+
}
|
|
2035
|
+
values.push(...t);
|
|
1899
2036
|
break;
|
|
1900
2037
|
case 'lab':
|
|
1901
|
-
|
|
2038
|
+
t = lab2srgb(token);
|
|
2039
|
+
if (t == null) {
|
|
2040
|
+
return null;
|
|
2041
|
+
}
|
|
2042
|
+
values.push(...t);
|
|
1902
2043
|
break;
|
|
1903
2044
|
case 'oklab':
|
|
1904
|
-
|
|
2045
|
+
t = oklab2srgb(token);
|
|
2046
|
+
if (t == null) {
|
|
2047
|
+
return null;
|
|
2048
|
+
}
|
|
2049
|
+
values.push(...t);
|
|
1905
2050
|
break;
|
|
1906
2051
|
case 'lch':
|
|
1907
|
-
|
|
2052
|
+
t = lch2srgb(token);
|
|
2053
|
+
if (t == null) {
|
|
2054
|
+
return null;
|
|
2055
|
+
}
|
|
2056
|
+
values.push(...t);
|
|
1908
2057
|
break;
|
|
1909
2058
|
case 'oklch':
|
|
1910
|
-
|
|
1911
|
-
|
|
2059
|
+
t = color2srgbvalues(token);
|
|
2060
|
+
if (t == null) {
|
|
2061
|
+
return null;
|
|
2062
|
+
}
|
|
2063
|
+
values.push(...t);
|
|
1912
2064
|
break;
|
|
1913
2065
|
case 'color':
|
|
1914
2066
|
const val = color2srgbvalues(token);
|
|
2067
|
+
if (val == null) {
|
|
2068
|
+
return null;
|
|
2069
|
+
}
|
|
1915
2070
|
switch (to) {
|
|
1916
2071
|
case 'srgb':
|
|
1917
2072
|
values.push(...val);
|
|
@@ -1965,6 +2120,9 @@ function minmax(value, min, max) {
|
|
|
1965
2120
|
}
|
|
1966
2121
|
function color2srgbvalues(token) {
|
|
1967
2122
|
const components = getComponents(token);
|
|
2123
|
+
if (components == null) {
|
|
2124
|
+
return null;
|
|
2125
|
+
}
|
|
1968
2126
|
const colorSpace = components.shift();
|
|
1969
2127
|
let values = components.map((val) => getNumber(val));
|
|
1970
2128
|
switch (colorSpace.val) {
|
|
@@ -2107,6 +2265,10 @@ function getNumber(token) {
|
|
|
2107
2265
|
// @ts-ignore
|
|
2108
2266
|
return token.typ == exports.EnumToken.PercentageTokenType ? token.val / 100 : +token.val;
|
|
2109
2267
|
}
|
|
2268
|
+
/**
|
|
2269
|
+
* convert angle to turn
|
|
2270
|
+
* @param token
|
|
2271
|
+
*/
|
|
2110
2272
|
function getAngle(token) {
|
|
2111
2273
|
if (token.typ == exports.EnumToken.IdenTokenType) {
|
|
2112
2274
|
if (token.val == 'none') {
|
|
@@ -2167,6 +2329,9 @@ function interpolateHue(interpolationMethod, h1, h2) {
|
|
|
2167
2329
|
return [h1, h2];
|
|
2168
2330
|
}
|
|
2169
2331
|
function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color2, percentage2) {
|
|
2332
|
+
if (color1.val == 'currentcolor' || color2.val == 'currentcolor') {
|
|
2333
|
+
return null;
|
|
2334
|
+
}
|
|
2170
2335
|
if (hueInterpolationMethod != null && isRectangularOrthogonalColorspace(colorSpace)) {
|
|
2171
2336
|
return null;
|
|
2172
2337
|
}
|
|
@@ -2220,6 +2385,9 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
|
|
|
2220
2385
|
}
|
|
2221
2386
|
const components1 = getComponents(color1);
|
|
2222
2387
|
const components2 = getComponents(color2);
|
|
2388
|
+
if (components1 == null || components2 == null) {
|
|
2389
|
+
return null;
|
|
2390
|
+
}
|
|
2223
2391
|
if ((components1[3] != null && components1[3].typ == exports.EnumToken.IdenTokenType && components1[3].val == 'none') && values2.length == 4) {
|
|
2224
2392
|
values1[3] = values2[3];
|
|
2225
2393
|
}
|
|
@@ -2448,9 +2616,20 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
|
|
|
2448
2616
|
function gcd(x, y) {
|
|
2449
2617
|
x = Math.abs(x);
|
|
2450
2618
|
y = Math.abs(y);
|
|
2619
|
+
if (x == y) {
|
|
2620
|
+
return x;
|
|
2621
|
+
}
|
|
2451
2622
|
let t;
|
|
2452
|
-
if (x == 0
|
|
2453
|
-
return
|
|
2623
|
+
if (x == 0) {
|
|
2624
|
+
return y;
|
|
2625
|
+
}
|
|
2626
|
+
if (y == 0) {
|
|
2627
|
+
return x;
|
|
2628
|
+
}
|
|
2629
|
+
if (y > x) {
|
|
2630
|
+
t = x;
|
|
2631
|
+
x = y;
|
|
2632
|
+
y = t;
|
|
2454
2633
|
}
|
|
2455
2634
|
while (y) {
|
|
2456
2635
|
t = y;
|
|
@@ -2459,7 +2638,7 @@ function gcd(x, y) {
|
|
|
2459
2638
|
}
|
|
2460
2639
|
return x;
|
|
2461
2640
|
}
|
|
2462
|
-
function compute(a, b, op) {
|
|
2641
|
+
function compute$1(a, b, op) {
|
|
2463
2642
|
if (typeof a == 'number' && typeof b == 'number') {
|
|
2464
2643
|
switch (op) {
|
|
2465
2644
|
case exports.EnumToken.Add:
|
|
@@ -2520,6 +2699,7 @@ function compute(a, b, op) {
|
|
|
2520
2699
|
r2 = l1.r.val * r1.l.val;
|
|
2521
2700
|
break;
|
|
2522
2701
|
}
|
|
2702
|
+
// @ts-ignore
|
|
2523
2703
|
const a2 = simplify(l2, r2);
|
|
2524
2704
|
if (a2[1] == 1) {
|
|
2525
2705
|
return a2[0];
|
|
@@ -2578,14 +2758,19 @@ function evaluate(tokens) {
|
|
|
2578
2758
|
return tokens;
|
|
2579
2759
|
}
|
|
2580
2760
|
if (nodes.length <= 1) {
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2761
|
+
if (nodes.length == 1) {
|
|
2762
|
+
if (nodes[0].typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
2763
|
+
return inlineExpression(nodes[0]);
|
|
2764
|
+
}
|
|
2765
|
+
// @ts-ignore
|
|
2766
|
+
if (nodes[0].typ == exports.EnumToken.IdenTokenType && typeof Math[nodes[0].val.toUpperCase()] == 'number') {
|
|
2767
|
+
return [{
|
|
2768
|
+
...nodes[0],
|
|
2769
|
+
// @ts-ignore
|
|
2770
|
+
val: '' + Math[nodes[0].val.toUpperCase()],
|
|
2771
|
+
typ: exports.EnumToken.NumberTokenType
|
|
2772
|
+
}];
|
|
2773
|
+
}
|
|
2589
2774
|
}
|
|
2590
2775
|
return nodes;
|
|
2591
2776
|
}
|
|
@@ -2705,8 +2890,7 @@ function doEvaluate(l, r, op) {
|
|
|
2705
2890
|
}
|
|
2706
2891
|
}
|
|
2707
2892
|
// @ts-ignore
|
|
2708
|
-
const val = compute(v1, v2, op);
|
|
2709
|
-
// typ = typeof val == 'number' ? EnumToken.NumberTokenType : EnumToken.FractionTokenType;
|
|
2893
|
+
const val = compute$1(v1, v2, op);
|
|
2710
2894
|
const token = {
|
|
2711
2895
|
...(l.typ == exports.EnumToken.NumberTokenType ? r : l),
|
|
2712
2896
|
typ,
|
|
@@ -3185,30 +3369,19 @@ function computeComponentValue(expr, converted, values) {
|
|
|
3185
3369
|
return expr;
|
|
3186
3370
|
}
|
|
3187
3371
|
function replaceValue(parent, value, newValue) {
|
|
3188
|
-
|
|
3189
|
-
if (
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
parent.r = newValue;
|
|
3194
|
-
}
|
|
3195
|
-
}
|
|
3196
|
-
else {
|
|
3197
|
-
for (let i = 0; i < parent.chi.length; i++) {
|
|
3198
|
-
if (parent.chi[i] == value) {
|
|
3199
|
-
parent.chi.splice(i, 1, newValue);
|
|
3200
|
-
break;
|
|
3201
|
-
}
|
|
3202
|
-
if (parent.chi[i].typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
3203
|
-
if (parent.chi[i].l == value) {
|
|
3204
|
-
parent.chi[i].l = newValue;
|
|
3205
|
-
break;
|
|
3372
|
+
for (const { value: val, parent: pr } of walkValues([parent])) {
|
|
3373
|
+
if (val.typ == value.typ && val.val == value.val) {
|
|
3374
|
+
if (pr.typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
3375
|
+
if (pr.l == val) {
|
|
3376
|
+
pr.l = newValue;
|
|
3206
3377
|
}
|
|
3207
|
-
else
|
|
3208
|
-
|
|
3209
|
-
break;
|
|
3378
|
+
else {
|
|
3379
|
+
pr.r = newValue;
|
|
3210
3380
|
}
|
|
3211
3381
|
}
|
|
3382
|
+
else {
|
|
3383
|
+
pr.chi.splice(pr.chi.indexOf(val), 1, newValue);
|
|
3384
|
+
}
|
|
3212
3385
|
}
|
|
3213
3386
|
}
|
|
3214
3387
|
}
|
|
@@ -3402,7 +3575,7 @@ function doRender(data, options = {}) {
|
|
|
3402
3575
|
return result;
|
|
3403
3576
|
}
|
|
3404
3577
|
function updateSourceMap(node, options, cache, sourcemap, position, str) {
|
|
3405
|
-
if ([exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyFrameRuleNodeType].includes(node.typ)) {
|
|
3578
|
+
if ([exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyFrameRuleNodeType, exports.EnumToken.KeyframeAtRuleNodeType].includes(node.typ)) {
|
|
3406
3579
|
let src = node.loc?.src ?? '';
|
|
3407
3580
|
let output = options.output ?? '';
|
|
3408
3581
|
if (!(src in cache)) {
|
|
@@ -3445,7 +3618,7 @@ function renderAstNode(data, options, sourcemap, position, errors, reducer, cach
|
|
|
3445
3618
|
const indentSub = indents[level + 1];
|
|
3446
3619
|
switch (data.typ) {
|
|
3447
3620
|
case exports.EnumToken.DeclarationNodeType:
|
|
3448
|
-
return `${data.nam}:${options.indent}${data.val.reduce(reducer, '')}`;
|
|
3621
|
+
return `${data.nam}:${options.indent}${(options.minify ? filterValues(data.val) : data.val).reduce(reducer, '')}`;
|
|
3449
3622
|
case exports.EnumToken.CommentNodeType:
|
|
3450
3623
|
case exports.EnumToken.CDOCOMMNodeType:
|
|
3451
3624
|
if (data.val.startsWith('/*# sourceMappingURL=')) {
|
|
@@ -3474,7 +3647,8 @@ function renderAstNode(data, options, sourcemap, position, errors, reducer, cach
|
|
|
3474
3647
|
case exports.EnumToken.AtRuleNodeType:
|
|
3475
3648
|
case exports.EnumToken.RuleNodeType:
|
|
3476
3649
|
case exports.EnumToken.KeyFrameRuleNodeType:
|
|
3477
|
-
|
|
3650
|
+
case exports.EnumToken.KeyframeAtRuleNodeType:
|
|
3651
|
+
if ([exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyframeAtRuleNodeType].includes(data.typ) && !('chi' in data)) {
|
|
3478
3652
|
return `${indent}@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val};`;
|
|
3479
3653
|
}
|
|
3480
3654
|
// @ts-ignore
|
|
@@ -3484,7 +3658,7 @@ function renderAstNode(data, options, sourcemap, position, errors, reducer, cach
|
|
|
3484
3658
|
str = options.removeComments && (!options.preserveLicense || !node.val.startsWith('/*!')) ? '' : node.val;
|
|
3485
3659
|
}
|
|
3486
3660
|
else if (node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
3487
|
-
if (node.val.length == 0) {
|
|
3661
|
+
if (!node.nam.startsWith('--') && node.val.length == 0) {
|
|
3488
3662
|
// @ts-ignore
|
|
3489
3663
|
errors.push({
|
|
3490
3664
|
action: 'ignore',
|
|
@@ -3493,7 +3667,7 @@ function renderAstNode(data, options, sourcemap, position, errors, reducer, cach
|
|
|
3493
3667
|
});
|
|
3494
3668
|
return '';
|
|
3495
3669
|
}
|
|
3496
|
-
str = `${node.nam}:${options.indent}${node.val.reduce(reducer, '').trimEnd()};`;
|
|
3670
|
+
str = `${node.nam}:${options.indent}${(options.minify ? filterValues(node.val) : node.val).reduce(reducer, '').trimEnd()};`;
|
|
3497
3671
|
}
|
|
3498
3672
|
else if (node.typ == exports.EnumToken.AtRuleNodeType && !('chi' in node)) {
|
|
3499
3673
|
str = `${data.val === '' ? '' : options.indent || ' '}${data.val};`;
|
|
@@ -3515,7 +3689,7 @@ function renderAstNode(data, options, sourcemap, position, errors, reducer, cach
|
|
|
3515
3689
|
if (children.endsWith(';')) {
|
|
3516
3690
|
children = children.slice(0, -1);
|
|
3517
3691
|
}
|
|
3518
|
-
if (
|
|
3692
|
+
if ([exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyframeAtRuleNodeType].includes(data.typ)) {
|
|
3519
3693
|
return `@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val}${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
|
|
3520
3694
|
}
|
|
3521
3695
|
return data.sel + `${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
|
|
@@ -3551,20 +3725,25 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
3551
3725
|
if (isColor(token)) {
|
|
3552
3726
|
// @ts-ignore
|
|
3553
3727
|
token.typ = exports.EnumToken.ColorTokenType;
|
|
3728
|
+
// @ts-ignore
|
|
3554
3729
|
if (token.chi[0].typ == exports.EnumToken.IdenTokenType && token.chi[0].val == 'from') {
|
|
3555
3730
|
// @ts-ignore
|
|
3556
3731
|
token.cal = 'rel';
|
|
3557
3732
|
}
|
|
3558
|
-
else
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3733
|
+
else { // @ts-ignore
|
|
3734
|
+
if (token.val == 'color-mix' && token.chi[0].typ == exports.EnumToken.IdenTokenType && token.chi[0].val == 'in') {
|
|
3735
|
+
// @ts-ignore
|
|
3736
|
+
token.cal = 'mix';
|
|
3737
|
+
}
|
|
3738
|
+
else {
|
|
3739
|
+
// @ts-ignore
|
|
3740
|
+
if (token.val == 'color') {
|
|
3741
|
+
// @ts-ignore
|
|
3742
|
+
token.cal = 'col';
|
|
3743
|
+
}
|
|
3564
3744
|
// @ts-ignore
|
|
3565
|
-
token.
|
|
3745
|
+
token.chi = token.chi.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommaTokenType, exports.EnumToken.CommentTokenType].includes(t.typ));
|
|
3566
3746
|
}
|
|
3567
|
-
token.chi = token.chi.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommaTokenType, exports.EnumToken.CommentTokenType].includes(t.typ));
|
|
3568
3747
|
}
|
|
3569
3748
|
}
|
|
3570
3749
|
}
|
|
@@ -3631,22 +3810,36 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
3631
3810
|
if (value != null) {
|
|
3632
3811
|
token = value;
|
|
3633
3812
|
}
|
|
3813
|
+
else if (!token.chi.some(t => t.typ == exports.EnumToken.CommaTokenType)) {
|
|
3814
|
+
token.chi = children.reduce((acc, curr, index) => {
|
|
3815
|
+
if (acc.length > 0) {
|
|
3816
|
+
acc.push({ typ: exports.EnumToken.CommaTokenType });
|
|
3817
|
+
}
|
|
3818
|
+
acc.push(...curr);
|
|
3819
|
+
return acc;
|
|
3820
|
+
}, []);
|
|
3821
|
+
}
|
|
3634
3822
|
}
|
|
3635
3823
|
if (token.cal == 'rel' && ['rgb', 'hsl', 'hwb', 'lab', 'lch', 'oklab', 'oklch', 'color'].includes(token.val)) {
|
|
3636
3824
|
const chi = getComponents(token);
|
|
3637
3825
|
const offset = token.val == 'color' ? 2 : 1;
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3826
|
+
if (chi != null) {
|
|
3827
|
+
// @ts-ignore
|
|
3828
|
+
const color = chi[1];
|
|
3829
|
+
const components = parseRelativeColor(token.val == 'color' ? chi[offset].val : token.val, color, chi[offset + 1], chi[offset + 2], chi[offset + 3], chi[offset + 4]);
|
|
3830
|
+
if (components != null) {
|
|
3831
|
+
token.chi = [...(token.val == 'color' ? [chi[offset]] : []), ...Object.values(components)];
|
|
3832
|
+
delete token.cal;
|
|
3833
|
+
}
|
|
3644
3834
|
}
|
|
3645
3835
|
}
|
|
3646
3836
|
if (token.val == 'color') {
|
|
3647
3837
|
if (token.chi[0].typ == exports.EnumToken.IdenTokenType && colorFuncColorSpace.includes(token.chi[0].val.toLowerCase())) {
|
|
3648
|
-
|
|
3649
|
-
|
|
3838
|
+
const values = color2srgbvalues(token);
|
|
3839
|
+
if (Array.isArray(values) && values.every(t => !Number.isNaN(t))) {
|
|
3840
|
+
// @ts-ignore
|
|
3841
|
+
return reduceHexValue(srgb2hexvalues(...values));
|
|
3842
|
+
}
|
|
3650
3843
|
}
|
|
3651
3844
|
}
|
|
3652
3845
|
if (token.cal != null) {
|
|
@@ -3703,7 +3896,7 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
3703
3896
|
else if (token.val == 'lch') {
|
|
3704
3897
|
value = lch2hex(token);
|
|
3705
3898
|
}
|
|
3706
|
-
if (value !== '') {
|
|
3899
|
+
if (value !== '' && value != null) {
|
|
3707
3900
|
return reduceHexValue(value);
|
|
3708
3901
|
}
|
|
3709
3902
|
}
|
|
@@ -3893,7 +4086,11 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
3893
4086
|
if (!('original' in token)) {
|
|
3894
4087
|
// do not modify original token
|
|
3895
4088
|
token = { ...token };
|
|
3896
|
-
Object.defineProperty(token, 'original', {
|
|
4089
|
+
Object.defineProperty(token, 'original', {
|
|
4090
|
+
enumerable: false,
|
|
4091
|
+
writable: false,
|
|
4092
|
+
value: token.val
|
|
4093
|
+
});
|
|
3897
4094
|
}
|
|
3898
4095
|
// @ts-ignore
|
|
3899
4096
|
if (!(token.original in cache)) {
|
|
@@ -3926,7 +4123,7 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
3926
4123
|
case exports.EnumToken.InvalidClassSelectorTokenType:
|
|
3927
4124
|
return token.val;
|
|
3928
4125
|
case exports.EnumToken.DeclarationNodeType:
|
|
3929
|
-
return token.nam + ':' + token.val.reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
4126
|
+
return token.nam + ':' + (options.minify ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
3930
4127
|
case exports.EnumToken.MediaQueryConditionTokenType:
|
|
3931
4128
|
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), '');
|
|
3932
4129
|
case exports.EnumToken.MediaFeatureTokenType:
|
|
@@ -3939,12 +4136,25 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
3939
4136
|
return 'and';
|
|
3940
4137
|
case exports.EnumToken.MediaFeatureOrTokenType:
|
|
3941
4138
|
return 'or';
|
|
3942
|
-
default:
|
|
3943
|
-
|
|
4139
|
+
// default:
|
|
4140
|
+
//
|
|
4141
|
+
// throw new Error(`render: unexpected token ${JSON.stringify(token, null, 1)}`);
|
|
3944
4142
|
}
|
|
3945
4143
|
errors?.push({ action: 'ignore', message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
|
|
3946
4144
|
return '';
|
|
3947
4145
|
}
|
|
4146
|
+
function filterValues(values) {
|
|
4147
|
+
let i = 0;
|
|
4148
|
+
for (; i < values.length; i++) {
|
|
4149
|
+
if (values[i].typ == exports.EnumToken.ImportantTokenType && values[i - 1]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
4150
|
+
values.splice(i - 1, 1);
|
|
4151
|
+
}
|
|
4152
|
+
else if (funcLike.includes(values[i].typ) && !['var', 'calc'].includes(values[i].val) && values[i + 1]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
4153
|
+
values.splice(i + 1, 1);
|
|
4154
|
+
}
|
|
4155
|
+
}
|
|
4156
|
+
return values;
|
|
4157
|
+
}
|
|
3948
4158
|
|
|
3949
4159
|
// https://www.w3.org/TR/CSS21/syndata.html#syntax
|
|
3950
4160
|
// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token
|
|
@@ -3959,6 +4169,14 @@ const dimensionUnits = new Set([
|
|
|
3959
4169
|
const fontFormat = ['collection', 'embedded-opentype', 'opentype', 'svg', 'truetype', 'woff', 'woff2'];
|
|
3960
4170
|
const colorFontTech = ['color-colrv0', 'color-colrv1', 'color-svg', 'color-sbix', 'color-cbdt'];
|
|
3961
4171
|
const fontFeaturesTech = ['features-opentype', 'features-aat', 'features-graphite', 'incremental-patch', 'incremental-range', 'incremental-auto', 'variations', 'palettes'];
|
|
4172
|
+
const transformFunctions = [
|
|
4173
|
+
'translate', 'scale', 'rotate', 'skew', 'perspective',
|
|
4174
|
+
'translateX', 'translateY', 'translateZ',
|
|
4175
|
+
'scaleX', 'scaleY', 'scaleZ',
|
|
4176
|
+
'rotateX', 'rotateY', 'rotateZ',
|
|
4177
|
+
'skewX', 'skewY',
|
|
4178
|
+
'rotate3d', 'translate3d', 'scale3d', 'matrix', 'matrix3d'
|
|
4179
|
+
];
|
|
3962
4180
|
// https://drafts.csswg.org/mediaqueries/#media-types
|
|
3963
4181
|
const mediaTypes = ['all', 'print', 'screen',
|
|
3964
4182
|
/* deprecated */
|
|
@@ -4350,7 +4568,9 @@ function isColor(token) {
|
|
|
4350
4568
|
}
|
|
4351
4569
|
let isLegacySyntax = false;
|
|
4352
4570
|
if (token.typ == exports.EnumToken.FunctionTokenType && token.chi.length > 0 && colorsFunc.includes(token.val)) {
|
|
4571
|
+
// @ts-ignore
|
|
4353
4572
|
if (token.val == 'light-dark') {
|
|
4573
|
+
// @ts-ignore
|
|
4354
4574
|
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));
|
|
4355
4575
|
if (children.length != 2) {
|
|
4356
4576
|
return false;
|
|
@@ -4359,7 +4579,9 @@ function isColor(token) {
|
|
|
4359
4579
|
return true;
|
|
4360
4580
|
}
|
|
4361
4581
|
}
|
|
4582
|
+
// @ts-ignore
|
|
4362
4583
|
if (token.val == 'color') {
|
|
4584
|
+
// @ts-ignore
|
|
4363
4585
|
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));
|
|
4364
4586
|
const isRelative = children[0].typ == exports.EnumToken.IdenTokenType && children[0].val == 'from';
|
|
4365
4587
|
if (children.length < 4 || children.length > 8) {
|
|
@@ -4408,73 +4630,79 @@ function isColor(token) {
|
|
|
4408
4630
|
}
|
|
4409
4631
|
return true;
|
|
4410
4632
|
}
|
|
4411
|
-
else
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
if (![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ)) {
|
|
4418
|
-
acc[acc.length - 1].push(t);
|
|
4633
|
+
else { // @ts-ignore
|
|
4634
|
+
if (token.val == 'color-mix') {
|
|
4635
|
+
// @ts-ignore
|
|
4636
|
+
const children = token.chi.reduce((acc, t) => {
|
|
4637
|
+
if (t.typ == exports.EnumToken.CommaTokenType) {
|
|
4638
|
+
acc.push([]);
|
|
4419
4639
|
}
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
if (children[0].length > 3 ||
|
|
4425
|
-
children[0][0].typ != exports.EnumToken.IdenTokenType ||
|
|
4426
|
-
children[0][0].val != 'in' ||
|
|
4427
|
-
!isColorspace(children[0][1]) ||
|
|
4428
|
-
(children[0].length == 3 && !isHueInterpolationMethod(children[0][2])) ||
|
|
4429
|
-
children[1].length > 2 ||
|
|
4430
|
-
children[1][0].typ != exports.EnumToken.ColorTokenType ||
|
|
4431
|
-
children[2].length > 2 ||
|
|
4432
|
-
children[2][0].typ != exports.EnumToken.ColorTokenType) {
|
|
4433
|
-
return false;
|
|
4434
|
-
}
|
|
4435
|
-
if (children[1].length == 2) {
|
|
4436
|
-
if (!(children[1][1].typ == exports.EnumToken.PercentageTokenType || (children[1][1].typ == exports.EnumToken.NumberTokenType && children[1][1].val == '0'))) {
|
|
4437
|
-
return false;
|
|
4640
|
+
else {
|
|
4641
|
+
if (![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ)) {
|
|
4642
|
+
acc[acc.length - 1].push(t);
|
|
4643
|
+
}
|
|
4438
4644
|
}
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4645
|
+
return acc;
|
|
4646
|
+
}, [[]]);
|
|
4647
|
+
if (children.length == 3) {
|
|
4648
|
+
if (children[0].length > 3 ||
|
|
4649
|
+
children[0][0].typ != exports.EnumToken.IdenTokenType ||
|
|
4650
|
+
children[0][0].val != 'in' ||
|
|
4651
|
+
!isColorspace(children[0][1]) ||
|
|
4652
|
+
(children[0].length == 3 && !isHueInterpolationMethod(children[0][2])) ||
|
|
4653
|
+
children[1].length > 2 ||
|
|
4654
|
+
children[1][0].typ != exports.EnumToken.ColorTokenType ||
|
|
4655
|
+
children[2].length > 2 ||
|
|
4656
|
+
children[2][0].typ != exports.EnumToken.ColorTokenType) {
|
|
4442
4657
|
return false;
|
|
4443
4658
|
}
|
|
4659
|
+
if (children[1].length == 2) {
|
|
4660
|
+
if (!(children[1][1].typ == exports.EnumToken.PercentageTokenType || (children[1][1].typ == exports.EnumToken.NumberTokenType && children[1][1].val == '0'))) {
|
|
4661
|
+
return false;
|
|
4662
|
+
}
|
|
4663
|
+
}
|
|
4664
|
+
if (children[2].length == 2) {
|
|
4665
|
+
if (!(children[2][1].typ == exports.EnumToken.PercentageTokenType || (children[2][1].typ == exports.EnumToken.NumberTokenType && children[2][1].val == '0'))) {
|
|
4666
|
+
return false;
|
|
4667
|
+
}
|
|
4668
|
+
}
|
|
4669
|
+
return true;
|
|
4444
4670
|
}
|
|
4445
|
-
return
|
|
4446
|
-
}
|
|
4447
|
-
return false;
|
|
4448
|
-
}
|
|
4449
|
-
else {
|
|
4450
|
-
const keywords = ['from', 'none'];
|
|
4451
|
-
if (['rgb', 'hsl', 'hwb', 'lab', 'lch', 'oklab', 'oklch'].includes(token.val)) {
|
|
4452
|
-
keywords.push('alpha', ...token.val.slice(-3).split(''));
|
|
4671
|
+
return false;
|
|
4453
4672
|
}
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4673
|
+
else {
|
|
4674
|
+
const keywords = ['from', 'none'];
|
|
4675
|
+
// @ts-ignore
|
|
4676
|
+
if (['rgb', 'hsl', 'hwb', 'lab', 'lch', 'oklab', 'oklch'].includes(token.val)) {
|
|
4677
|
+
// @ts-ignore
|
|
4678
|
+
keywords.push('alpha', ...token.val.slice(-3).split(''));
|
|
4458
4679
|
}
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4680
|
+
// @ts-ignore
|
|
4681
|
+
for (const v of token.chi) {
|
|
4682
|
+
if (v.typ == exports.EnumToken.CommaTokenType) {
|
|
4683
|
+
isLegacySyntax = true;
|
|
4462
4684
|
}
|
|
4463
|
-
if (
|
|
4464
|
-
if (
|
|
4685
|
+
if (v.typ == exports.EnumToken.IdenTokenType) {
|
|
4686
|
+
if (!(keywords.includes(v.val) || v.val.toLowerCase() in COLORS_NAMES)) {
|
|
4465
4687
|
return false;
|
|
4466
4688
|
}
|
|
4467
|
-
if (
|
|
4468
|
-
|
|
4689
|
+
if (keywords.includes(v.val)) {
|
|
4690
|
+
if (isLegacySyntax) {
|
|
4691
|
+
return false;
|
|
4692
|
+
}
|
|
4693
|
+
// @ts-ignore
|
|
4694
|
+
if (v.val == 'from' && ['rgba', 'hsla'].includes(token.val)) {
|
|
4695
|
+
return false;
|
|
4696
|
+
}
|
|
4469
4697
|
}
|
|
4698
|
+
continue;
|
|
4699
|
+
}
|
|
4700
|
+
if (v.typ == exports.EnumToken.FunctionTokenType && (mathFuncs.includes(v.val) || v.val == 'var' || colorsFunc.includes(v.val))) {
|
|
4701
|
+
continue;
|
|
4702
|
+
}
|
|
4703
|
+
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)) {
|
|
4704
|
+
return false;
|
|
4470
4705
|
}
|
|
4471
|
-
continue;
|
|
4472
|
-
}
|
|
4473
|
-
if (v.typ == exports.EnumToken.FunctionTokenType && (mathFuncs.includes(v.val) || v.val == 'var' || colorsFunc.includes(v.val))) {
|
|
4474
|
-
continue;
|
|
4475
|
-
}
|
|
4476
|
-
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)) {
|
|
4477
|
-
return false;
|
|
4478
4706
|
}
|
|
4479
4707
|
}
|
|
4480
4708
|
}
|
|
@@ -6258,7 +6486,7 @@ function parseDeclarationNode(node, errors, src, position) {
|
|
|
6258
6486
|
while (node.val[0]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
6259
6487
|
node.val.shift();
|
|
6260
6488
|
}
|
|
6261
|
-
if (node.val.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ)).length == 0) {
|
|
6489
|
+
if (!node.nam.startsWith('--') && node.val.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ)).length == 0) {
|
|
6262
6490
|
errors.push({
|
|
6263
6491
|
action: 'drop',
|
|
6264
6492
|
message: 'doParse: invalid declaration',
|
|
@@ -10881,7 +11109,7 @@ function parseSyntax(syntax) {
|
|
|
10881
11109
|
chi: []
|
|
10882
11110
|
}, 'pos', { ...objectProperties, value: { ind: 0, lin: 1, col: 0 } });
|
|
10883
11111
|
// return minify(doParseSyntax(syntaxes, tokenize(syntaxes), root)) as ValidationRootToken;
|
|
10884
|
-
return minify$
|
|
11112
|
+
return minify$2(transform$1(doParseSyntax(syntax, tokenize(syntax), root)));
|
|
10885
11113
|
}
|
|
10886
11114
|
function matchParens(syntax, iterator) {
|
|
10887
11115
|
let item;
|
|
@@ -11132,12 +11360,12 @@ function matchAtRule(syntax, iterator) {
|
|
|
11132
11360
|
const t = { typ: ValidationTokenEnum.Root, chi: token.prelude };
|
|
11133
11361
|
doParseSyntax(syntax, t.chi[Symbol.iterator](), t);
|
|
11134
11362
|
token.prelude = t.chi;
|
|
11135
|
-
minify$
|
|
11363
|
+
minify$2(token.prelude);
|
|
11136
11364
|
}
|
|
11137
11365
|
}
|
|
11138
11366
|
// @ts-ignore
|
|
11139
11367
|
if (token?.chi?.length > 0) {
|
|
11140
|
-
minify$
|
|
11368
|
+
minify$2(doParseSyntax(syntax, token.chi[Symbol.iterator](), token));
|
|
11141
11369
|
}
|
|
11142
11370
|
}
|
|
11143
11371
|
else {
|
|
@@ -11590,7 +11818,7 @@ function move(position, chr) {
|
|
|
11590
11818
|
}
|
|
11591
11819
|
return position;
|
|
11592
11820
|
}
|
|
11593
|
-
function minify$
|
|
11821
|
+
function minify$2(ast) {
|
|
11594
11822
|
if (Array.isArray(ast)) {
|
|
11595
11823
|
// @ts-ignore
|
|
11596
11824
|
while (ast.length > 0 && ast[0].typ == ValidationTokenEnum.Whitespace) {
|
|
@@ -11603,7 +11831,7 @@ function minify$1(ast) {
|
|
|
11603
11831
|
for (let i = 0; i < ast.length; i++) {
|
|
11604
11832
|
// if ([ValidationTokenEnum.ColumnToken, ValidationTokenEnum.PipeToken, ValidationTokenEnum.AmpersandToken].includes(ast[i].typ)) {
|
|
11605
11833
|
// for (const j of (ast[i] as ValidationPipeToken | ValidationColumnToken | ValidationAmpersandToken).l) {
|
|
11606
|
-
minify$
|
|
11834
|
+
minify$2(ast[i]);
|
|
11607
11835
|
// }
|
|
11608
11836
|
// for (const j of (ast[i] as ValidationPipeToken | ValidationColumnToken | ValidationAmpersandToken).r) {
|
|
11609
11837
|
//
|
|
@@ -11635,18 +11863,18 @@ function minify$1(ast) {
|
|
|
11635
11863
|
// if ([ValidationTokenEnum.ColumnToken, ValidationTokenEnum.PipeToken, ValidationTokenEnum.AmpersandToken].includes(ast.typ)) {
|
|
11636
11864
|
// for (const j of (ast as ValidationPipeToken | ValidationColumnToken | ValidationAmpersandToken).l) {
|
|
11637
11865
|
if ('l' in ast) {
|
|
11638
|
-
minify$
|
|
11866
|
+
minify$2(ast.l);
|
|
11639
11867
|
}
|
|
11640
11868
|
// }
|
|
11641
11869
|
// for (const j of (ast as ValidationPipeToken | ValidationColumnToken | ValidationAmpersandToken).r) {
|
|
11642
11870
|
if ('r' in ast) {
|
|
11643
|
-
minify$
|
|
11871
|
+
minify$2(ast.r);
|
|
11644
11872
|
}
|
|
11645
11873
|
if ('chi' in ast) {
|
|
11646
|
-
minify$
|
|
11874
|
+
minify$2(ast.chi);
|
|
11647
11875
|
}
|
|
11648
11876
|
if ('prelude' in ast) {
|
|
11649
|
-
minify$
|
|
11877
|
+
minify$2(ast.prelude);
|
|
11650
11878
|
}
|
|
11651
11879
|
return ast;
|
|
11652
11880
|
}
|
|
@@ -11787,6 +12015,23 @@ function consumeWhitespace(tokens) {
|
|
|
11787
12015
|
return true;
|
|
11788
12016
|
}
|
|
11789
12017
|
|
|
12018
|
+
function stripCommaToken(tokenList) {
|
|
12019
|
+
let result = [];
|
|
12020
|
+
let last = null;
|
|
12021
|
+
for (let i = 0; i < tokenList.length; i++) {
|
|
12022
|
+
if (tokenList[i].typ == exports.EnumToken.CommaTokenType && last != null && last.typ == exports.EnumToken.CommaTokenType) {
|
|
12023
|
+
return null;
|
|
12024
|
+
}
|
|
12025
|
+
if (tokenList[i].typ != exports.EnumToken.WhitespaceTokenType) {
|
|
12026
|
+
last = tokenList[i];
|
|
12027
|
+
}
|
|
12028
|
+
if (tokenList[i].typ == exports.EnumToken.CommentTokenType || tokenList[i].typ == exports.EnumToken.CommaTokenType) {
|
|
12029
|
+
continue;
|
|
12030
|
+
}
|
|
12031
|
+
result.push(tokenList[i]);
|
|
12032
|
+
}
|
|
12033
|
+
return result;
|
|
12034
|
+
}
|
|
11790
12035
|
function splitTokenList(tokenList, split = [exports.EnumToken.CommaTokenType]) {
|
|
11791
12036
|
return tokenList.reduce((acc, curr) => {
|
|
11792
12037
|
if (curr.typ == exports.EnumToken.CommentTokenType) {
|
|
@@ -12143,19 +12388,20 @@ const validateSelector$1 = validateComplexSelector;
|
|
|
12143
12388
|
function validateRelativeSelector(tokens, root, options) {
|
|
12144
12389
|
tokens = tokens.slice();
|
|
12145
12390
|
consumeWhitespace(tokens);
|
|
12146
|
-
if (tokens.length == 0) {
|
|
12147
|
-
|
|
12148
|
-
|
|
12149
|
-
|
|
12150
|
-
|
|
12151
|
-
|
|
12152
|
-
|
|
12153
|
-
|
|
12154
|
-
|
|
12155
|
-
|
|
12156
|
-
|
|
12157
|
-
|
|
12158
|
-
}
|
|
12391
|
+
// if (tokens.length == 0) {
|
|
12392
|
+
//
|
|
12393
|
+
// // @ts-ignore
|
|
12394
|
+
// return {
|
|
12395
|
+
// valid: ValidationLevel.Drop,
|
|
12396
|
+
// matches: [],
|
|
12397
|
+
// // @ts-ignore
|
|
12398
|
+
// node: root,
|
|
12399
|
+
// // @ts-ignore
|
|
12400
|
+
// syntax: null,
|
|
12401
|
+
// error: 'expected selector',
|
|
12402
|
+
// tokens
|
|
12403
|
+
// }
|
|
12404
|
+
// }
|
|
12159
12405
|
// , EnumToken.DescendantCombinatorTokenType
|
|
12160
12406
|
if (combinatorsTokens.includes(tokens[0].typ)) {
|
|
12161
12407
|
tokens.shift();
|
|
@@ -12242,126 +12488,46 @@ function validateComplexSelectorList(tokens, root, options) {
|
|
|
12242
12488
|
};
|
|
12243
12489
|
}
|
|
12244
12490
|
|
|
12245
|
-
function validateKeyframeSelector(tokens,
|
|
12491
|
+
function validateKeyframeSelector(tokens, options) {
|
|
12246
12492
|
consumeWhitespace(tokens);
|
|
12247
12493
|
if (tokens.length == 0) {
|
|
12248
12494
|
// @ts-ignore
|
|
12249
12495
|
return {
|
|
12250
12496
|
valid: ValidationLevel.Drop,
|
|
12251
12497
|
matches: [],
|
|
12252
|
-
node:
|
|
12498
|
+
node: null,
|
|
12253
12499
|
syntax: null,
|
|
12254
12500
|
error: 'expected keyframe selector',
|
|
12255
12501
|
tokens
|
|
12256
12502
|
};
|
|
12257
12503
|
}
|
|
12258
|
-
|
|
12259
|
-
|
|
12260
|
-
consumeWhitespace(tokens);
|
|
12261
|
-
if (tokens.length == 0) {
|
|
12262
|
-
// @ts-ignore
|
|
12504
|
+
for (const t of splitTokenList(tokens)) {
|
|
12505
|
+
if (t.length != 1) {
|
|
12263
12506
|
return {
|
|
12264
|
-
valid: ValidationLevel.
|
|
12507
|
+
valid: ValidationLevel.Drop,
|
|
12265
12508
|
matches: [],
|
|
12266
|
-
node:
|
|
12509
|
+
node: t[0] ?? null,
|
|
12267
12510
|
syntax: null,
|
|
12268
|
-
error: '',
|
|
12511
|
+
error: 'unexpected token',
|
|
12512
|
+
tokens
|
|
12513
|
+
};
|
|
12514
|
+
}
|
|
12515
|
+
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))) {
|
|
12516
|
+
return {
|
|
12517
|
+
valid: ValidationLevel.Drop,
|
|
12518
|
+
matches: [],
|
|
12519
|
+
node: t[0],
|
|
12520
|
+
syntax: null,
|
|
12521
|
+
error: 'expected keyframe selector',
|
|
12269
12522
|
tokens
|
|
12270
12523
|
};
|
|
12271
12524
|
}
|
|
12272
|
-
|
|
12273
|
-
|
|
12274
|
-
|
|
12275
|
-
|
|
12276
|
-
|
|
12277
|
-
|
|
12278
|
-
error: 'unexpected token',
|
|
12279
|
-
tokens
|
|
12280
|
-
};
|
|
12281
|
-
}
|
|
12282
|
-
if (tokens[0].typ != exports.EnumToken.IdenTokenType) {
|
|
12283
|
-
// @ts-ignore
|
|
12284
|
-
return {
|
|
12285
|
-
valid: ValidationLevel.Drop,
|
|
12286
|
-
matches: [],
|
|
12287
|
-
node: tokens[0],
|
|
12288
|
-
// @ts-ignore
|
|
12289
|
-
syntax: null,
|
|
12290
|
-
error: 'expected keyframe selector',
|
|
12291
|
-
tokens
|
|
12292
|
-
};
|
|
12293
|
-
}
|
|
12294
|
-
if (['from', 'to'].includes(tokens[0].val)) {
|
|
12295
|
-
tokens.shift();
|
|
12296
|
-
consumeWhitespace(tokens);
|
|
12297
|
-
if (tokens.length > 0) {
|
|
12298
|
-
// @ts-ignore
|
|
12299
|
-
return {
|
|
12300
|
-
valid: ValidationLevel.Drop,
|
|
12301
|
-
matches: [],
|
|
12302
|
-
node: tokens[0],
|
|
12303
|
-
syntax: null,
|
|
12304
|
-
error: 'unexpected token',
|
|
12305
|
-
tokens
|
|
12306
|
-
};
|
|
12307
|
-
}
|
|
12308
|
-
// @ts-ignore
|
|
12309
|
-
return {
|
|
12310
|
-
valid: ValidationLevel.Valid,
|
|
12311
|
-
matches: [],
|
|
12312
|
-
node: null,
|
|
12313
|
-
// @ts-ignore
|
|
12314
|
-
syntax: null,
|
|
12315
|
-
error: '',
|
|
12316
|
-
tokens
|
|
12317
|
-
};
|
|
12318
|
-
}
|
|
12319
|
-
if (!['cover', 'contain', 'entry', 'exit', 'entry-crossing', 'exit-crossing'].includes(tokens[0].val)) {
|
|
12320
|
-
// @ts-ignore
|
|
12321
|
-
return {
|
|
12322
|
-
valid: ValidationLevel.Drop,
|
|
12323
|
-
matches: [],
|
|
12324
|
-
node: tokens[0],
|
|
12325
|
-
// @ts-ignore
|
|
12326
|
-
syntax: null,
|
|
12327
|
-
error: 'unexpected token',
|
|
12328
|
-
tokens
|
|
12329
|
-
};
|
|
12330
|
-
}
|
|
12331
|
-
tokens.shift();
|
|
12332
|
-
consumeWhitespace(tokens);
|
|
12333
|
-
// @ts-ignore
|
|
12334
|
-
if (tokens.length == 0 || tokens[0].typ != exports.EnumToken.PercentageTokenType) {
|
|
12335
|
-
// @ts-ignore
|
|
12336
|
-
return {
|
|
12337
|
-
valid: ValidationLevel.Drop,
|
|
12338
|
-
matches: [],
|
|
12339
|
-
node: tokens[0],
|
|
12340
|
-
// @ts-ignore
|
|
12341
|
-
syntax: null,
|
|
12342
|
-
error: 'expecting percentage token',
|
|
12343
|
-
tokens
|
|
12344
|
-
};
|
|
12345
|
-
}
|
|
12346
|
-
tokens.shift();
|
|
12347
|
-
consumeWhitespace(tokens);
|
|
12348
|
-
if (tokens.length > 0) {
|
|
12349
|
-
// @ts-ignore
|
|
12350
|
-
return {
|
|
12351
|
-
valid: ValidationLevel.Drop,
|
|
12352
|
-
matches: [],
|
|
12353
|
-
node: tokens[0],
|
|
12354
|
-
// @ts-ignore
|
|
12355
|
-
syntax: null,
|
|
12356
|
-
error: 'unexpected token',
|
|
12357
|
-
tokens
|
|
12358
|
-
};
|
|
12359
|
-
}
|
|
12360
|
-
// @ts-ignore
|
|
12361
|
-
return {
|
|
12362
|
-
valid: ValidationLevel.Valid,
|
|
12363
|
-
matches: [],
|
|
12364
|
-
node: null,
|
|
12525
|
+
}
|
|
12526
|
+
// @ts-ignore
|
|
12527
|
+
return {
|
|
12528
|
+
valid: ValidationLevel.Valid,
|
|
12529
|
+
matches: [],
|
|
12530
|
+
node: null,
|
|
12365
12531
|
// @ts-ignore
|
|
12366
12532
|
syntax: null,
|
|
12367
12533
|
error: '',
|
|
@@ -12375,7 +12541,7 @@ function validateKeyframeBlockList(tokens, atRule, options) {
|
|
|
12375
12541
|
let result = null;
|
|
12376
12542
|
while (i + 1 < tokens.length) {
|
|
12377
12543
|
if (tokens[++i].typ == exports.EnumToken.CommaTokenType) {
|
|
12378
|
-
result = validateKeyframeSelector(tokens.slice(j, i)
|
|
12544
|
+
result = validateKeyframeSelector(tokens.slice(j, i));
|
|
12379
12545
|
if (result.valid == ValidationLevel.Drop) {
|
|
12380
12546
|
return result;
|
|
12381
12547
|
}
|
|
@@ -12383,7 +12549,7 @@ function validateKeyframeBlockList(tokens, atRule, options) {
|
|
|
12383
12549
|
i = j;
|
|
12384
12550
|
}
|
|
12385
12551
|
}
|
|
12386
|
-
return validateKeyframeSelector(i == j ? tokens.slice(i) : tokens.slice(j, i + 1)
|
|
12552
|
+
return validateKeyframeSelector(i == j ? tokens.slice(i) : tokens.slice(j, i + 1));
|
|
12387
12553
|
}
|
|
12388
12554
|
|
|
12389
12555
|
const matchUrl = /^(https?:)?\/\//;
|
|
@@ -12559,7 +12725,7 @@ function validateSelector(selector, options, root) {
|
|
|
12559
12725
|
}
|
|
12560
12726
|
// @ts-ignore
|
|
12561
12727
|
if (root.typ == exports.EnumToken.AtRuleNodeType && root.nam.match(/^(-[a-z]+-)?keyframes$/)) {
|
|
12562
|
-
return validateKeyframeBlockList(selector
|
|
12728
|
+
return validateKeyframeBlockList(selector);
|
|
12563
12729
|
}
|
|
12564
12730
|
let isNested = root.typ == exports.EnumToken.RuleNodeType ? 1 : 0;
|
|
12565
12731
|
let currentRoot = root.parent;
|
|
@@ -12575,7 +12741,10 @@ function validateSelector(selector, options, root) {
|
|
|
12575
12741
|
}
|
|
12576
12742
|
const nestedSelector = isNested > 0;
|
|
12577
12743
|
// @ts-ignore
|
|
12578
|
-
return nestedSelector ? validateRelativeSelectorList(selector, root, {
|
|
12744
|
+
return nestedSelector ? validateRelativeSelectorList(selector, root, {
|
|
12745
|
+
...(options ?? {}),
|
|
12746
|
+
nestedSelector
|
|
12747
|
+
}) : validateSelectorList(selector, root, { ...(options ?? {}), nestedSelector });
|
|
12579
12748
|
}
|
|
12580
12749
|
|
|
12581
12750
|
function validateAtRuleMedia(atRule, options, root) {
|
|
@@ -12811,7 +12980,6 @@ function validateMediaCondition(token, atRule) {
|
|
|
12811
12980
|
if (chi[0].typ == exports.EnumToken.MediaQueryConditionTokenType) {
|
|
12812
12981
|
return chi[0].l.typ == exports.EnumToken.IdenTokenType;
|
|
12813
12982
|
}
|
|
12814
|
-
console.error(chi[0].parent);
|
|
12815
12983
|
return false;
|
|
12816
12984
|
}
|
|
12817
12985
|
function validateMediaFeature(token) {
|
|
@@ -13658,7 +13826,7 @@ function validateAtRuleDocument(atRule, options, root) {
|
|
|
13658
13826
|
}
|
|
13659
13827
|
if (t[0].typ == exports.EnumToken.UrlFunctionTokenType) {
|
|
13660
13828
|
result = validateURL(t[0]);
|
|
13661
|
-
if (result
|
|
13829
|
+
if (result?.valid == ValidationLevel.Drop) {
|
|
13662
13830
|
return result;
|
|
13663
13831
|
}
|
|
13664
13832
|
continue;
|
|
@@ -13697,7 +13865,7 @@ function validateAtRuleKeyframes(atRule, options, root) {
|
|
|
13697
13865
|
valid: ValidationLevel.Drop,
|
|
13698
13866
|
matches: [],
|
|
13699
13867
|
node: atRule,
|
|
13700
|
-
syntax: '@
|
|
13868
|
+
syntax: '@keyframes',
|
|
13701
13869
|
error: 'expecting at-rule prelude',
|
|
13702
13870
|
tokens: []
|
|
13703
13871
|
};
|
|
@@ -14004,10 +14172,10 @@ function validateAtRuleContainerQueryList(tokens, atRule) {
|
|
|
14004
14172
|
break;
|
|
14005
14173
|
}
|
|
14006
14174
|
token = queries[0];
|
|
14007
|
-
if (token
|
|
14175
|
+
if (token?.typ == exports.EnumToken.MediaFeatureNotTokenType) {
|
|
14008
14176
|
token = token.val;
|
|
14009
14177
|
}
|
|
14010
|
-
if (token
|
|
14178
|
+
if (token?.typ != exports.EnumToken.ParensTokenType && (token?.typ != exports.EnumToken.FunctionTokenType || !['scroll-state', 'style'].includes(token.val))) {
|
|
14011
14179
|
return {
|
|
14012
14180
|
valid: ValidationLevel.Drop,
|
|
14013
14181
|
matches: [],
|
|
@@ -14017,7 +14185,7 @@ function validateAtRuleContainerQueryList(tokens, atRule) {
|
|
|
14017
14185
|
tokens
|
|
14018
14186
|
};
|
|
14019
14187
|
}
|
|
14020
|
-
if (token
|
|
14188
|
+
if (token?.typ == exports.EnumToken.ParensTokenType) {
|
|
14021
14189
|
result = validateContainerSizeFeature(token.chi, atRule);
|
|
14022
14190
|
}
|
|
14023
14191
|
else if (token.val == 'scroll-state') {
|
|
@@ -14035,7 +14203,7 @@ function validateAtRuleContainerQueryList(tokens, atRule) {
|
|
|
14035
14203
|
break;
|
|
14036
14204
|
}
|
|
14037
14205
|
token = queries[0];
|
|
14038
|
-
if (token
|
|
14206
|
+
if (token?.typ != exports.EnumToken.MediaFeatureAndTokenType && token?.typ != exports.EnumToken.MediaFeatureOrTokenType) {
|
|
14039
14207
|
return {
|
|
14040
14208
|
valid: ValidationLevel.Drop,
|
|
14041
14209
|
matches: [],
|
|
@@ -14046,9 +14214,9 @@ function validateAtRuleContainerQueryList(tokens, atRule) {
|
|
|
14046
14214
|
};
|
|
14047
14215
|
}
|
|
14048
14216
|
if (tokenType == null) {
|
|
14049
|
-
tokenType = token
|
|
14217
|
+
tokenType = token?.typ;
|
|
14050
14218
|
}
|
|
14051
|
-
if (tokenType != token
|
|
14219
|
+
if (tokenType == null || tokenType != token?.typ) {
|
|
14052
14220
|
return {
|
|
14053
14221
|
valid: ValidationLevel.Drop,
|
|
14054
14222
|
matches: [],
|
|
@@ -14310,9 +14478,6 @@ function validateAtRule(atRule, options, root) {
|
|
|
14310
14478
|
error: ''
|
|
14311
14479
|
};
|
|
14312
14480
|
}
|
|
14313
|
-
if (atRule.nam == 'keyframes') {
|
|
14314
|
-
return validateAtRuleKeyframes(atRule);
|
|
14315
|
-
}
|
|
14316
14481
|
if (['font-face', 'view-transition', 'starting-style'].includes(atRule.nam)) {
|
|
14317
14482
|
return {
|
|
14318
14483
|
valid: ValidationLevel.Valid,
|
|
@@ -14495,12 +14660,13 @@ async function doParse(iterator, options = {}) {
|
|
|
14495
14660
|
minify: true,
|
|
14496
14661
|
pass: 1,
|
|
14497
14662
|
parseColor: true,
|
|
14498
|
-
nestingRules:
|
|
14663
|
+
nestingRules: true,
|
|
14499
14664
|
resolveImport: false,
|
|
14500
14665
|
resolveUrls: false,
|
|
14501
14666
|
removeCharset: true,
|
|
14502
14667
|
removeEmpty: true,
|
|
14503
14668
|
removeDuplicateDeclarations: true,
|
|
14669
|
+
computeTransform: true,
|
|
14504
14670
|
computeShorthand: true,
|
|
14505
14671
|
computeCalcExpression: true,
|
|
14506
14672
|
inlineCssVariables: false,
|
|
@@ -14569,11 +14735,13 @@ async function doParse(iterator, options = {}) {
|
|
|
14569
14735
|
}
|
|
14570
14736
|
else if (item.token == '{') {
|
|
14571
14737
|
let inBlock = 1;
|
|
14738
|
+
tokens = [item];
|
|
14572
14739
|
do {
|
|
14573
14740
|
item = iter.next().value;
|
|
14574
14741
|
if (item == null) {
|
|
14575
14742
|
break;
|
|
14576
14743
|
}
|
|
14744
|
+
tokens.push(item);
|
|
14577
14745
|
if (item.token == '{') {
|
|
14578
14746
|
inBlock++;
|
|
14579
14747
|
}
|
|
@@ -14581,6 +14749,13 @@ async function doParse(iterator, options = {}) {
|
|
|
14581
14749
|
inBlock--;
|
|
14582
14750
|
}
|
|
14583
14751
|
} while (inBlock != 0);
|
|
14752
|
+
if (tokens.length > 0) {
|
|
14753
|
+
errors.push({
|
|
14754
|
+
action: 'drop',
|
|
14755
|
+
message: 'invalid block',
|
|
14756
|
+
rawTokens: tokens.slice()
|
|
14757
|
+
});
|
|
14758
|
+
}
|
|
14584
14759
|
}
|
|
14585
14760
|
tokens = [];
|
|
14586
14761
|
map = new Map;
|
|
@@ -14613,6 +14788,7 @@ async function doParse(iterator, options = {}) {
|
|
|
14613
14788
|
await parseNode(tokens, context, stats, options, errors, src, map, rawTokens);
|
|
14614
14789
|
rawTokens.length = 0;
|
|
14615
14790
|
if (context != null && context.typ == exports.EnumToken.InvalidRuleTokenType) {
|
|
14791
|
+
// @ts-ignore
|
|
14616
14792
|
const index = context.chi.findIndex((node) => node == context);
|
|
14617
14793
|
if (index > -1) {
|
|
14618
14794
|
context.chi.splice(index, 1);
|
|
@@ -14912,9 +15088,11 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
14912
15088
|
acc.push(renderToken(curr, { removeComments: true }));
|
|
14913
15089
|
return acc;
|
|
14914
15090
|
}, []);
|
|
15091
|
+
const nam = renderToken(atRule, { removeComments: true });
|
|
15092
|
+
// @ts-ignore
|
|
14915
15093
|
const node = {
|
|
14916
|
-
typ: exports.EnumToken.AtRuleNodeType,
|
|
14917
|
-
nam
|
|
15094
|
+
typ: /^(-[a-z]+-)?keyframes$/.test(nam) ? exports.EnumToken.KeyframeAtRuleNodeType : exports.EnumToken.AtRuleNodeType,
|
|
15095
|
+
nam,
|
|
14918
15096
|
// tokens: t,
|
|
14919
15097
|
val: raw.join('')
|
|
14920
15098
|
};
|
|
@@ -14945,7 +15123,7 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
14945
15123
|
isValid = false;
|
|
14946
15124
|
}
|
|
14947
15125
|
}
|
|
14948
|
-
const valid = isValid ? validateAtRule(node, options, context) : {
|
|
15126
|
+
const valid = isValid ? (node.typ == exports.EnumToken.KeyframeAtRuleNodeType ? validateAtRuleKeyframes(node) : validateAtRule(node, options, context)) : {
|
|
14949
15127
|
valid: ValidationLevel.Drop,
|
|
14950
15128
|
node,
|
|
14951
15129
|
syntax: '@' + node.nam,
|
|
@@ -14961,7 +15139,10 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
14961
15139
|
node.typ = exports.EnumToken.InvalidAtRuleTokenType;
|
|
14962
15140
|
}
|
|
14963
15141
|
else {
|
|
14964
|
-
node.val = node.tokens.reduce((acc, curr) => acc + renderToken(curr, {
|
|
15142
|
+
node.val = node.tokens.reduce((acc, curr) => acc + renderToken(curr, {
|
|
15143
|
+
minify: false,
|
|
15144
|
+
removeComments: true
|
|
15145
|
+
}), '');
|
|
14965
15146
|
}
|
|
14966
15147
|
}
|
|
14967
15148
|
// @ts-ignore
|
|
@@ -14974,72 +15155,79 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
14974
15155
|
if (delim.typ == exports.EnumToken.BlockStartTokenType) {
|
|
14975
15156
|
const position = map.get(tokens[0]);
|
|
14976
15157
|
const uniq = new Map;
|
|
14977
|
-
parseTokens(tokens, { minify: true })
|
|
14978
|
-
|
|
14979
|
-
return acc;
|
|
14980
|
-
}
|
|
14981
|
-
if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
14982
|
-
if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
|
|
14983
|
-
trimWhiteSpace.includes(array[index + 1]?.typ) ||
|
|
14984
|
-
combinators.includes(array[index - 1]?.val) ||
|
|
14985
|
-
combinators.includes(array[index + 1]?.val)) {
|
|
14986
|
-
return acc;
|
|
14987
|
-
}
|
|
14988
|
-
}
|
|
14989
|
-
let t = renderToken(curr, { minify: false });
|
|
14990
|
-
if (t == ',') {
|
|
14991
|
-
acc.push([]);
|
|
14992
|
-
// uniqTokens.push([]);
|
|
14993
|
-
}
|
|
14994
|
-
else {
|
|
14995
|
-
acc[acc.length - 1].push(t);
|
|
14996
|
-
// uniqTokens[uniqTokens.length - 1].push(curr);
|
|
14997
|
-
}
|
|
14998
|
-
return acc;
|
|
14999
|
-
}, [[]]).reduce((acc, curr) => {
|
|
15000
|
-
let i = 0;
|
|
15001
|
-
for (; i < curr.length; i++) {
|
|
15002
|
-
if (i + 1 < curr.length && curr[i] == '*') {
|
|
15003
|
-
if (curr[i] == '*') {
|
|
15004
|
-
let index = curr[i + 1] == ' ' ? 2 : 1;
|
|
15005
|
-
if (!['>', '~', '+'].includes(curr[index])) {
|
|
15006
|
-
curr.splice(i, index);
|
|
15007
|
-
}
|
|
15008
|
-
}
|
|
15009
|
-
}
|
|
15010
|
-
}
|
|
15011
|
-
acc.set(curr.join(''), curr);
|
|
15012
|
-
return acc;
|
|
15013
|
-
}, uniq);
|
|
15014
|
-
const ruleType = context.typ == exports.EnumToken.AtRuleNodeType && context.nam == 'keyframes' ? exports.EnumToken.KeyFrameRuleNodeType : exports.EnumToken.RuleNodeType;
|
|
15158
|
+
parseTokens(tokens, { minify: true });
|
|
15159
|
+
const ruleType = context.typ == exports.EnumToken.KeyframeAtRuleNodeType ? exports.EnumToken.KeyFrameRuleNodeType : exports.EnumToken.RuleNodeType;
|
|
15015
15160
|
if (ruleType == exports.EnumToken.RuleNodeType) {
|
|
15016
15161
|
parseSelector(tokens);
|
|
15017
|
-
|
|
15018
|
-
|
|
15019
|
-
|
|
15020
|
-
|
|
15021
|
-
|
|
15022
|
-
|
|
15023
|
-
|
|
15024
|
-
|
|
15025
|
-
|
|
15026
|
-
|
|
15027
|
-
|
|
15028
|
-
|
|
15029
|
-
|
|
15030
|
-
// @ts-ignore
|
|
15031
|
-
location: { src, ...(map.get(valid.node) ?? position) }
|
|
15032
|
-
});
|
|
15162
|
+
}
|
|
15163
|
+
if (options.validation) {
|
|
15164
|
+
// @ts-ignore
|
|
15165
|
+
const valid = ruleType == exports.EnumToken.KeyFrameRuleNodeType ? validateKeyframeSelector(tokens) : validateSelector(tokens, options, context);
|
|
15166
|
+
if (valid.valid != ValidationLevel.Valid) {
|
|
15167
|
+
const node = {
|
|
15168
|
+
typ: exports.EnumToken.InvalidRuleTokenType,
|
|
15169
|
+
sel: tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), ''),
|
|
15170
|
+
chi: []
|
|
15171
|
+
};
|
|
15172
|
+
errors.push({
|
|
15173
|
+
action: 'drop',
|
|
15174
|
+
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), '') + '"',
|
|
15033
15175
|
// @ts-ignore
|
|
15034
|
-
|
|
15035
|
-
|
|
15036
|
-
|
|
15037
|
-
|
|
15176
|
+
location: { src, ...(map.get(valid.node) ?? position) }
|
|
15177
|
+
});
|
|
15178
|
+
// @ts-ignore
|
|
15179
|
+
context.chi.push(node);
|
|
15180
|
+
Object.defineProperty(node, 'parent', { ...definedPropertySettings, value: context });
|
|
15181
|
+
return node;
|
|
15038
15182
|
}
|
|
15039
15183
|
}
|
|
15040
15184
|
const node = {
|
|
15041
15185
|
typ: ruleType,
|
|
15042
|
-
sel: [...
|
|
15186
|
+
sel: [...tokens.reduce((acc, curr, index, array) => {
|
|
15187
|
+
if (curr.typ == exports.EnumToken.CommentTokenType) {
|
|
15188
|
+
return acc;
|
|
15189
|
+
}
|
|
15190
|
+
if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
15191
|
+
if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
|
|
15192
|
+
trimWhiteSpace.includes(array[index + 1]?.typ) ||
|
|
15193
|
+
combinators.includes(array[index - 1]?.val) ||
|
|
15194
|
+
combinators.includes(array[index + 1]?.val)) {
|
|
15195
|
+
return acc;
|
|
15196
|
+
}
|
|
15197
|
+
}
|
|
15198
|
+
if (ruleType == exports.EnumToken.KeyFrameRuleNodeType) {
|
|
15199
|
+
if (curr.typ == exports.EnumToken.IdenTokenType && curr.val == 'from') {
|
|
15200
|
+
Object.assign(curr, { typ: exports.EnumToken.PercentageTokenType, val: '0' });
|
|
15201
|
+
}
|
|
15202
|
+
else if (curr.typ == exports.EnumToken.PercentageTokenType && curr.val == '100') {
|
|
15203
|
+
Object.assign(curr, { typ: exports.EnumToken.IdenTokenType, val: 'to' });
|
|
15204
|
+
}
|
|
15205
|
+
}
|
|
15206
|
+
let t = renderToken(curr, { minify: false });
|
|
15207
|
+
if (t == ',') {
|
|
15208
|
+
acc.push([]);
|
|
15209
|
+
// uniqTokens.push([]);
|
|
15210
|
+
}
|
|
15211
|
+
else {
|
|
15212
|
+
acc[acc.length - 1].push(t);
|
|
15213
|
+
// uniqTokens[uniqTokens.length - 1].push(curr);
|
|
15214
|
+
}
|
|
15215
|
+
return acc;
|
|
15216
|
+
}, [[]]).reduce((acc, curr) => {
|
|
15217
|
+
let i = 0;
|
|
15218
|
+
for (; i < curr.length; i++) {
|
|
15219
|
+
if (i + 1 < curr.length && curr[i] == '*') {
|
|
15220
|
+
if (curr[i] == '*') {
|
|
15221
|
+
let index = curr[i + 1] == ' ' ? 2 : 1;
|
|
15222
|
+
if (!['>', '~', '+'].includes(curr[index])) {
|
|
15223
|
+
curr.splice(i, index);
|
|
15224
|
+
}
|
|
15225
|
+
}
|
|
15226
|
+
}
|
|
15227
|
+
}
|
|
15228
|
+
acc.set(curr.join(''), curr);
|
|
15229
|
+
return acc;
|
|
15230
|
+
}, uniq).keys()].join(','),
|
|
15043
15231
|
chi: []
|
|
15044
15232
|
};
|
|
15045
15233
|
Object.defineProperty(node, 'tokens', {
|
|
@@ -15124,7 +15312,8 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
15124
15312
|
}
|
|
15125
15313
|
}
|
|
15126
15314
|
}
|
|
15127
|
-
|
|
15315
|
+
const nam = renderToken(name.shift(), { removeComments: true });
|
|
15316
|
+
if (value == null || (!nam.startsWith('--') && value.length == 0)) {
|
|
15128
15317
|
errors.push({
|
|
15129
15318
|
action: 'drop',
|
|
15130
15319
|
message: 'doParse: invalid declaration',
|
|
@@ -15132,33 +15321,30 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
15132
15321
|
});
|
|
15133
15322
|
return null;
|
|
15134
15323
|
}
|
|
15324
|
+
for (const { value: token } of walkValues(value, null, {
|
|
15325
|
+
fn: (node) => node.typ == exports.EnumToken.FunctionTokenType && node.val == 'calc' ? WalkerOptionEnum.IgnoreChildren : null,
|
|
15326
|
+
type: exports.EnumToken.FunctionTokenType
|
|
15327
|
+
})) {
|
|
15328
|
+
if (token.typ == exports.EnumToken.FunctionTokenType && token.val == 'calc') {
|
|
15329
|
+
for (const { value: node, parent } of walkValues(token.chi, token)) {
|
|
15330
|
+
// fix expressions starting with '/' or '*' such as '/4' in (1 + 1)/4
|
|
15331
|
+
if (node.typ == exports.EnumToken.LiteralTokenType && node.val.length > 0) {
|
|
15332
|
+
if (node.val[0] == '/' || node.val[0] == '*') {
|
|
15333
|
+
parent.chi.splice(parent.chi.indexOf(node), 1, { typ: node.val[0] == '/' ? exports.EnumToken.Div : exports.EnumToken.Mul }, ...parseString(node.val.slice(1)));
|
|
15334
|
+
}
|
|
15335
|
+
}
|
|
15336
|
+
}
|
|
15337
|
+
}
|
|
15338
|
+
}
|
|
15135
15339
|
const node = {
|
|
15136
15340
|
typ: exports.EnumToken.DeclarationNodeType,
|
|
15137
15341
|
// @ts-ignore
|
|
15138
|
-
nam
|
|
15342
|
+
nam,
|
|
15139
15343
|
// @ts-ignore
|
|
15140
15344
|
val: value
|
|
15141
15345
|
};
|
|
15142
15346
|
const result = parseDeclarationNode(node, errors, src, position);
|
|
15143
15347
|
if (result != null) {
|
|
15144
|
-
// if (options.validation) {
|
|
15145
|
-
//
|
|
15146
|
-
// const valid: ValidationResult = validateDeclaration(result, options, context);
|
|
15147
|
-
//
|
|
15148
|
-
// // console.error({valid});
|
|
15149
|
-
//
|
|
15150
|
-
// if (valid.valid == ValidationLevel.Drop) {
|
|
15151
|
-
//
|
|
15152
|
-
// errors.push({
|
|
15153
|
-
// action: 'drop',
|
|
15154
|
-
// message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, {minify: false}), '') + '"',
|
|
15155
|
-
// // @ts-ignore
|
|
15156
|
-
// location: {src, ...(map.get(valid.node) ?? position)}
|
|
15157
|
-
// });
|
|
15158
|
-
//
|
|
15159
|
-
// return null;
|
|
15160
|
-
// }
|
|
15161
|
-
// }
|
|
15162
15348
|
// @ts-ignore
|
|
15163
15349
|
context.chi.push(result);
|
|
15164
15350
|
Object.defineProperty(result, 'parent', { ...definedPropertySettings, value: context });
|
|
@@ -15241,8 +15427,6 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
15241
15427
|
}
|
|
15242
15428
|
}
|
|
15243
15429
|
if (value.typ == exports.EnumToken.ParensTokenType || (value.typ == exports.EnumToken.FunctionTokenType && ['media', 'supports', 'style', 'scroll-state'].includes(value.val))) {
|
|
15244
|
-
// @todo parse range and declarations
|
|
15245
|
-
// parseDeclaration(parent.chi);
|
|
15246
15430
|
let i;
|
|
15247
15431
|
let nameIndex = -1;
|
|
15248
15432
|
let valueIndex = -1;
|
|
@@ -15806,7 +15990,7 @@ function parseTokens(tokens, options = {}) {
|
|
|
15806
15990
|
upper++;
|
|
15807
15991
|
}
|
|
15808
15992
|
if (upper < t.chi.length &&
|
|
15809
|
-
t.chi[upper].typ == exports.EnumToken.
|
|
15993
|
+
t.chi[upper].typ == exports.EnumToken.IdenTokenType &&
|
|
15810
15994
|
['i', 's'].includes(t.chi[upper].val.toLowerCase())) {
|
|
15811
15995
|
t.chi[m].attr = t.chi[upper].val;
|
|
15812
15996
|
t.chi.splice(upper, 1);
|
|
@@ -16022,6 +16206,13 @@ function eq(a, b) {
|
|
|
16022
16206
|
return true;
|
|
16023
16207
|
}
|
|
16024
16208
|
|
|
16209
|
+
var WalkerOptionEnum;
|
|
16210
|
+
(function (WalkerOptionEnum) {
|
|
16211
|
+
WalkerOptionEnum[WalkerOptionEnum["Ignore"] = 0] = "Ignore";
|
|
16212
|
+
WalkerOptionEnum[WalkerOptionEnum["Stop"] = 1] = "Stop";
|
|
16213
|
+
WalkerOptionEnum[WalkerOptionEnum["Children"] = 2] = "Children";
|
|
16214
|
+
WalkerOptionEnum[WalkerOptionEnum["IgnoreChildren"] = 3] = "IgnoreChildren";
|
|
16215
|
+
})(WalkerOptionEnum || (WalkerOptionEnum = {}));
|
|
16025
16216
|
var WalkerValueEvent;
|
|
16026
16217
|
(function (WalkerValueEvent) {
|
|
16027
16218
|
WalkerValueEvent[WalkerValueEvent["Enter"] = 0] = "Enter";
|
|
@@ -16040,10 +16231,10 @@ function* walk(node, filter) {
|
|
|
16040
16231
|
let option = null;
|
|
16041
16232
|
if (filter != null) {
|
|
16042
16233
|
option = filter(node);
|
|
16043
|
-
if (option ===
|
|
16234
|
+
if (option === WalkerOptionEnum.Ignore) {
|
|
16044
16235
|
continue;
|
|
16045
16236
|
}
|
|
16046
|
-
if (option ===
|
|
16237
|
+
if (option === WalkerOptionEnum.Stop) {
|
|
16047
16238
|
break;
|
|
16048
16239
|
}
|
|
16049
16240
|
}
|
|
@@ -16052,7 +16243,7 @@ function* walk(node, filter) {
|
|
|
16052
16243
|
// @ts-ignore
|
|
16053
16244
|
yield { node, parent: map.get(node), root };
|
|
16054
16245
|
}
|
|
16055
|
-
if (option !==
|
|
16246
|
+
if (option !== WalkerOptionEnum.IgnoreChildren && 'chi' in node) {
|
|
16056
16247
|
parents.unshift(...node.chi);
|
|
16057
16248
|
for (const child of node.chi.slice()) {
|
|
16058
16249
|
map.set(child, node);
|
|
@@ -16084,19 +16275,20 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
16084
16275
|
event: WalkerValueEvent.Enter
|
|
16085
16276
|
};
|
|
16086
16277
|
}
|
|
16278
|
+
const eventType = filter.event ?? WalkerValueEvent.Enter;
|
|
16087
16279
|
while (stack.length > 0) {
|
|
16088
16280
|
let value = reverse ? stack.pop() : stack.shift();
|
|
16089
16281
|
let option = null;
|
|
16090
|
-
if (filter.fn != null &&
|
|
16282
|
+
if (filter.fn != null && eventType == WalkerValueEvent.Enter) {
|
|
16091
16283
|
const isValid = filter.type == null || value.typ == filter.type ||
|
|
16092
16284
|
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
16093
16285
|
(typeof filter.type == 'function' && filter.type(value));
|
|
16094
16286
|
if (isValid) {
|
|
16095
|
-
option = filter.fn(value, map.get(value) ?? root
|
|
16096
|
-
if (option ===
|
|
16287
|
+
option = filter.fn(value, map.get(value) ?? root);
|
|
16288
|
+
if (option === WalkerOptionEnum.Ignore) {
|
|
16097
16289
|
continue;
|
|
16098
16290
|
}
|
|
16099
|
-
if (option ===
|
|
16291
|
+
if (option === WalkerOptionEnum.Stop) {
|
|
16100
16292
|
break;
|
|
16101
16293
|
}
|
|
16102
16294
|
// @ts-ignore
|
|
@@ -16105,8 +16297,7 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
16105
16297
|
}
|
|
16106
16298
|
}
|
|
16107
16299
|
}
|
|
16108
|
-
|
|
16109
|
-
if (filter.event == WalkerValueEvent.Enter && option !== 'children') {
|
|
16300
|
+
if (eventType == WalkerValueEvent.Enter && option !== WalkerOptionEnum.Children) {
|
|
16110
16301
|
yield {
|
|
16111
16302
|
value,
|
|
16112
16303
|
parent: map.get(value) ?? root,
|
|
@@ -16116,7 +16307,7 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
16116
16307
|
root: root ?? null
|
|
16117
16308
|
};
|
|
16118
16309
|
}
|
|
16119
|
-
if (option !==
|
|
16310
|
+
if (option !== WalkerOptionEnum.IgnoreChildren && 'chi' in value) {
|
|
16120
16311
|
const sliced = value.chi.slice();
|
|
16121
16312
|
for (const child of sliced) {
|
|
16122
16313
|
map.set(child, value);
|
|
@@ -16129,24 +16320,23 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
16129
16320
|
}
|
|
16130
16321
|
}
|
|
16131
16322
|
else if (value.typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
16132
|
-
map.set(value.l,
|
|
16133
|
-
map.set(value.r,
|
|
16323
|
+
map.set(value.l, value);
|
|
16324
|
+
map.set(value.r, value);
|
|
16134
16325
|
stack.unshift(value.l, value.r);
|
|
16135
16326
|
}
|
|
16136
|
-
if (
|
|
16327
|
+
if (eventType == WalkerValueEvent.Leave && filter.fn != null) {
|
|
16137
16328
|
const isValid = filter.type == null || value.typ == filter.type ||
|
|
16138
16329
|
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
16139
16330
|
(typeof filter.type == 'function' && filter.type(value));
|
|
16140
16331
|
if (isValid) {
|
|
16141
|
-
option = filter.fn(value, map.get(value)
|
|
16332
|
+
option = filter.fn(value, map.get(value));
|
|
16142
16333
|
// @ts-ignore
|
|
16143
16334
|
if (option != null && 'typ' in option) {
|
|
16144
16335
|
map.set(option, map.get(value) ?? root);
|
|
16145
16336
|
}
|
|
16146
16337
|
}
|
|
16147
16338
|
}
|
|
16148
|
-
|
|
16149
|
-
if (filter.event == WalkerValueEvent.Leave && option !== 'children') {
|
|
16339
|
+
if (eventType == WalkerValueEvent.Leave && option !== WalkerOptionEnum.Children) {
|
|
16150
16340
|
yield {
|
|
16151
16341
|
value,
|
|
16152
16342
|
parent: map.get(value) ?? root,
|
|
@@ -16434,11 +16624,6 @@ class ComputePrefixFeature {
|
|
|
16434
16624
|
}
|
|
16435
16625
|
static register(options) {
|
|
16436
16626
|
if (options.removePrefix) {
|
|
16437
|
-
for (const feature of options.features) {
|
|
16438
|
-
if (feature instanceof ComputePrefixFeature) {
|
|
16439
|
-
return;
|
|
16440
|
-
}
|
|
16441
|
-
}
|
|
16442
16627
|
// @ts-ignore
|
|
16443
16628
|
options.features.push(new ComputePrefixFeature(options));
|
|
16444
16629
|
}
|
|
@@ -16465,9 +16650,9 @@ class ComputePrefixFeature {
|
|
|
16465
16650
|
for (const { value } of walkValues(node.val)) {
|
|
16466
16651
|
if (value.typ == exports.EnumToken.IdenTokenType && value.val.charAt(0) == '-' && value.val.charAt(1) != '-') {
|
|
16467
16652
|
// @ts-ignore
|
|
16468
|
-
const values = config$1.declarations[node.nam].ast
|
|
16653
|
+
const values = config$1.declarations[node.nam].ast?.slice?.();
|
|
16469
16654
|
const match = value.val.match(/^-(.*?)-(.*)$/);
|
|
16470
|
-
if (match != null) {
|
|
16655
|
+
if (values != null && match != null) {
|
|
16471
16656
|
const val = matchToken({ ...value, val: match[2] }, values);
|
|
16472
16657
|
if (val != null) {
|
|
16473
16658
|
// @ts-ignore
|
|
@@ -16569,11 +16754,6 @@ class InlineCssVariablesFeature {
|
|
|
16569
16754
|
}
|
|
16570
16755
|
static register(options) {
|
|
16571
16756
|
if (options.inlineCssVariables) {
|
|
16572
|
-
for (const feature of options.features) {
|
|
16573
|
-
if (feature instanceof InlineCssVariablesFeature) {
|
|
16574
|
-
return;
|
|
16575
|
-
}
|
|
16576
|
-
}
|
|
16577
16757
|
// @ts-ignore
|
|
16578
16758
|
options.features.push(new InlineCssVariablesFeature());
|
|
16579
16759
|
}
|
|
@@ -17565,15 +17745,10 @@ class PropertyList {
|
|
|
17565
17745
|
|
|
17566
17746
|
class ComputeShorthandFeature {
|
|
17567
17747
|
static get ordering() {
|
|
17568
|
-
return
|
|
17748
|
+
return 3;
|
|
17569
17749
|
}
|
|
17570
17750
|
static register(options) {
|
|
17571
17751
|
if (options.computeShorthand) {
|
|
17572
|
-
for (const feature of options.features) {
|
|
17573
|
-
if (feature instanceof ComputeShorthandFeature) {
|
|
17574
|
-
return;
|
|
17575
|
-
}
|
|
17576
|
-
}
|
|
17577
17752
|
// @ts-ignore
|
|
17578
17753
|
options.features.push(new ComputeShorthandFeature(options));
|
|
17579
17754
|
}
|
|
@@ -17583,18 +17758,20 @@ class ComputeShorthandFeature {
|
|
|
17583
17758
|
const j = ast.chi.length;
|
|
17584
17759
|
let k = 0;
|
|
17585
17760
|
let properties = new PropertyList(options);
|
|
17761
|
+
const rules = [];
|
|
17586
17762
|
// @ts-ignore
|
|
17587
17763
|
for (; k < j; k++) {
|
|
17588
17764
|
// @ts-ignore
|
|
17589
17765
|
const node = ast.chi[k];
|
|
17590
17766
|
if (node.typ == exports.EnumToken.CommentNodeType || node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
17591
17767
|
properties.add(node);
|
|
17592
|
-
continue;
|
|
17593
17768
|
}
|
|
17594
|
-
|
|
17769
|
+
else {
|
|
17770
|
+
rules.push(node);
|
|
17771
|
+
}
|
|
17595
17772
|
}
|
|
17596
17773
|
// @ts-ignore
|
|
17597
|
-
ast.chi = [...properties]
|
|
17774
|
+
ast.chi = [...properties, ...rules];
|
|
17598
17775
|
return ast;
|
|
17599
17776
|
}
|
|
17600
17777
|
}
|
|
@@ -17605,11 +17782,6 @@ class ComputeCalcExpressionFeature {
|
|
|
17605
17782
|
}
|
|
17606
17783
|
static register(options) {
|
|
17607
17784
|
if (options.computeCalcExpression) {
|
|
17608
|
-
for (const feature of options.features) {
|
|
17609
|
-
if (feature instanceof ComputeCalcExpressionFeature) {
|
|
17610
|
-
return;
|
|
17611
|
-
}
|
|
17612
|
-
}
|
|
17613
17785
|
// @ts-ignore
|
|
17614
17786
|
options.features.push(new ComputeCalcExpressionFeature());
|
|
17615
17787
|
}
|
|
@@ -17618,7 +17790,6 @@ class ComputeCalcExpressionFeature {
|
|
|
17618
17790
|
if (!('chi' in ast)) {
|
|
17619
17791
|
return;
|
|
17620
17792
|
}
|
|
17621
|
-
// @ts-ignore
|
|
17622
17793
|
for (const node of ast.chi) {
|
|
17623
17794
|
if (node.typ != exports.EnumToken.DeclarationNodeType) {
|
|
17624
17795
|
continue;
|
|
@@ -17626,15 +17797,18 @@ class ComputeCalcExpressionFeature {
|
|
|
17626
17797
|
const set = new Set;
|
|
17627
17798
|
for (const { value, parent } of walkValues(node.val, node, {
|
|
17628
17799
|
event: WalkerValueEvent.Enter,
|
|
17629
|
-
|
|
17800
|
+
// @ts-ignore
|
|
17801
|
+
fn(node, parent) {
|
|
17630
17802
|
if (parent != null &&
|
|
17803
|
+
// @ts-ignore
|
|
17631
17804
|
parent.typ == exports.EnumToken.DeclarationNodeType &&
|
|
17805
|
+
// @ts-ignore
|
|
17632
17806
|
parent.val.length == 1 &&
|
|
17633
17807
|
node.typ == exports.EnumToken.FunctionTokenType &&
|
|
17634
17808
|
mathFuncs.includes(node.val) &&
|
|
17635
17809
|
node.chi.length == 1 &&
|
|
17636
17810
|
node.chi[0].typ == exports.EnumToken.IdenTokenType) {
|
|
17637
|
-
return
|
|
17811
|
+
return WalkerOptionEnum.Ignore;
|
|
17638
17812
|
}
|
|
17639
17813
|
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))) {
|
|
17640
17814
|
return null;
|
|
@@ -17656,7 +17830,7 @@ class ComputeCalcExpressionFeature {
|
|
|
17656
17830
|
// @ts-ignore
|
|
17657
17831
|
node[key] = values;
|
|
17658
17832
|
}
|
|
17659
|
-
return
|
|
17833
|
+
return WalkerOptionEnum.Ignore;
|
|
17660
17834
|
}
|
|
17661
17835
|
return null;
|
|
17662
17836
|
}
|
|
@@ -17718,78 +17892,1180 @@ class ComputeCalcExpressionFeature {
|
|
|
17718
17892
|
}
|
|
17719
17893
|
}
|
|
17720
17894
|
|
|
17721
|
-
|
|
17722
|
-
|
|
17723
|
-
|
|
17724
|
-
|
|
17725
|
-
|
|
17726
|
-
|
|
17727
|
-
|
|
17728
|
-
|
|
17729
|
-
|
|
17730
|
-
const
|
|
17731
|
-
const
|
|
17732
|
-
|
|
17733
|
-
|
|
17734
|
-
|
|
17735
|
-
|
|
17736
|
-
*
|
|
17737
|
-
* @param options
|
|
17738
|
-
* @param recursive
|
|
17739
|
-
* @param errors
|
|
17740
|
-
* @param nestingContent
|
|
17741
|
-
* @param context
|
|
17742
|
-
*/
|
|
17743
|
-
function minify(ast, options = {}, recursive = false, errors, nestingContent, context = {}) {
|
|
17744
|
-
if (!('nodes' in context)) {
|
|
17745
|
-
context.nodes = new Set;
|
|
17895
|
+
const epsilon = 1e-5;
|
|
17896
|
+
function identity() {
|
|
17897
|
+
return [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
|
|
17898
|
+
}
|
|
17899
|
+
function pLength(point) {
|
|
17900
|
+
// Calcul de la norme euclidienne
|
|
17901
|
+
return Math.sqrt(point[0] * point[0] + point[1] * point[1] + point[2] * point[2]);
|
|
17902
|
+
}
|
|
17903
|
+
function normalize(point) {
|
|
17904
|
+
const [x, y, z] = point;
|
|
17905
|
+
const norm = Math.sqrt(point[0] * point[0] + point[1] * point[1] + point[2] * point[2]);
|
|
17906
|
+
return norm === 0 ? [0, 0, 0] : [x / norm, y / norm, z / norm];
|
|
17907
|
+
}
|
|
17908
|
+
function dot(point1, point2) {
|
|
17909
|
+
if (point1.length === 4 && point2.length === 4) {
|
|
17910
|
+
return point1[0] * point2[0] + point1[1] * point2[1] + point1[2] * point2[2] + point1[3] * point2[3];
|
|
17746
17911
|
}
|
|
17747
|
-
|
|
17748
|
-
|
|
17912
|
+
return point1[0] * point2[0] + point1[1] * point2[1] + point1[2] * point2[2];
|
|
17913
|
+
}
|
|
17914
|
+
function multiply(matrixA, matrixB) {
|
|
17915
|
+
let result = Array(4).fill(0).map(() => Array(4).fill(0));
|
|
17916
|
+
for (let i = 0; i < 4; i++) {
|
|
17917
|
+
for (let j = 0; j < 4; j++) {
|
|
17918
|
+
for (let k = 0; k < 4; k++) {
|
|
17919
|
+
result[j][i] += matrixA[k][i] * matrixB[j][k];
|
|
17920
|
+
}
|
|
17921
|
+
}
|
|
17749
17922
|
}
|
|
17750
|
-
|
|
17751
|
-
|
|
17752
|
-
|
|
17753
|
-
|
|
17754
|
-
|
|
17755
|
-
|
|
17756
|
-
|
|
17757
|
-
|
|
17758
|
-
|
|
17759
|
-
|
|
17760
|
-
|
|
17761
|
-
|
|
17762
|
-
|
|
17923
|
+
return result;
|
|
17924
|
+
}
|
|
17925
|
+
function round(number) {
|
|
17926
|
+
return Math.abs(number) < epsilon ? 0 : +number.toPrecision(6);
|
|
17927
|
+
}
|
|
17928
|
+
// translate3d(25.9808px, 0, 15px ) rotateY(60deg) skewX(49.9999deg) scale(1, 1.2)
|
|
17929
|
+
// translate → rotate → skew → scale
|
|
17930
|
+
function decompose(original) {
|
|
17931
|
+
const matrix = original.flat();
|
|
17932
|
+
// Normalize last row
|
|
17933
|
+
if (matrix[15] === 0) {
|
|
17934
|
+
return null;
|
|
17935
|
+
}
|
|
17936
|
+
for (let i = 0; i < 16; i++)
|
|
17937
|
+
matrix[i] /= matrix[15];
|
|
17938
|
+
// Perspective extraction
|
|
17939
|
+
const perspective = [0, 0, 0, 1];
|
|
17940
|
+
if (matrix[3] !== 0 || matrix[7] !== 0 || matrix[11] !== 0) {
|
|
17941
|
+
const rightHandSide = [matrix[3], matrix[7], matrix[11], matrix[15]];
|
|
17942
|
+
const perspectiveMatrix = matrix.slice();
|
|
17943
|
+
perspectiveMatrix[3] = 0;
|
|
17944
|
+
perspectiveMatrix[7] = 0;
|
|
17945
|
+
perspectiveMatrix[11] = 0;
|
|
17946
|
+
perspectiveMatrix[15] = 1;
|
|
17947
|
+
const inverse = invertMatrix4(perspectiveMatrix);
|
|
17948
|
+
if (!inverse) {
|
|
17949
|
+
return null;
|
|
17763
17950
|
}
|
|
17951
|
+
const transposedInverse = transposeMatrix4(inverse);
|
|
17952
|
+
perspective[0] = dot(rightHandSide, transposedInverse.slice(0, 4));
|
|
17953
|
+
perspective[1] = dot(rightHandSide, transposedInverse.slice(4, 8));
|
|
17954
|
+
perspective[2] = dot(rightHandSide, transposedInverse.slice(8, 12));
|
|
17955
|
+
perspective[3] = dot(rightHandSide, transposedInverse.slice(12, 16));
|
|
17956
|
+
// Clear perspective from matrix
|
|
17957
|
+
matrix[3] = 0;
|
|
17958
|
+
matrix[7] = 0;
|
|
17959
|
+
matrix[11] = 0;
|
|
17960
|
+
matrix[15] = 1;
|
|
17961
|
+
}
|
|
17962
|
+
// Translation
|
|
17963
|
+
const translate = [matrix[12], matrix[13], matrix[14]];
|
|
17964
|
+
matrix[12] = matrix[13] = matrix[14] = 0;
|
|
17965
|
+
// Build the 3x3 matrix
|
|
17966
|
+
const row0 = [matrix[0], matrix[1], matrix[2]];
|
|
17967
|
+
const row1 = [matrix[4], matrix[5], matrix[6]];
|
|
17968
|
+
const row2 = [matrix[8], matrix[9], matrix[10]];
|
|
17969
|
+
// Compute scale
|
|
17970
|
+
const scaleX = pLength(row0);
|
|
17971
|
+
const row0Norm = normalize(row0);
|
|
17972
|
+
const skewXY = dot(row0Norm, row1);
|
|
17973
|
+
const row1Proj = [
|
|
17974
|
+
row1[0] - skewXY * row0Norm[0],
|
|
17975
|
+
row1[1] - skewXY * row0Norm[1],
|
|
17976
|
+
row1[2] - skewXY * row0Norm[2]
|
|
17977
|
+
];
|
|
17978
|
+
const scaleY = pLength(row1Proj);
|
|
17979
|
+
const row1Norm = normalize(row1Proj);
|
|
17980
|
+
const skewXZ = dot(row0Norm, row2);
|
|
17981
|
+
const skewYZ = dot(row1Norm, row2);
|
|
17982
|
+
const row2Proj = [
|
|
17983
|
+
row2[0] - skewXZ * row0Norm[0] - skewYZ * row1Norm[0],
|
|
17984
|
+
row2[1] - skewXZ * row0Norm[1] - skewYZ * row1Norm[1],
|
|
17985
|
+
row2[2] - skewXZ * row0Norm[2] - skewYZ * row1Norm[2]
|
|
17986
|
+
];
|
|
17987
|
+
const scaleZ = pLength(row2Proj);
|
|
17988
|
+
const row2Norm = normalize(row2Proj);
|
|
17989
|
+
// Build rotation matrix from orthonormalized vectors
|
|
17990
|
+
const r00 = row0Norm[0], r01 = row1Norm[0], r02 = row2Norm[0];
|
|
17991
|
+
const r10 = row0Norm[1], r11 = row1Norm[1], r12 = row2Norm[1];
|
|
17992
|
+
const r20 = row0Norm[2], r21 = row1Norm[2], r22 = row2Norm[2];
|
|
17993
|
+
// Convert to quaternion
|
|
17994
|
+
const trace = r00 + r11 + r22;
|
|
17995
|
+
let qw, qx, qy, qz;
|
|
17996
|
+
if (trace > 0) {
|
|
17997
|
+
const s = 0.5 / Math.sqrt(trace + 1.0);
|
|
17998
|
+
qw = 0.25 / s;
|
|
17999
|
+
qx = (r21 - r12) * s;
|
|
18000
|
+
qy = (r02 - r20) * s;
|
|
18001
|
+
qz = (r10 - r01) * s;
|
|
18002
|
+
}
|
|
18003
|
+
else if (r00 > r11 && r00 > r22) {
|
|
18004
|
+
const s = 2.0 * Math.sqrt(1.0 + r00 - r11 - r22);
|
|
18005
|
+
qw = (r21 - r12) / s;
|
|
18006
|
+
qx = 0.25 * s;
|
|
18007
|
+
qy = (r01 + r10) / s;
|
|
18008
|
+
qz = (r02 + r20) / s;
|
|
18009
|
+
}
|
|
18010
|
+
else if (r11 > r22) {
|
|
18011
|
+
const s = 2.0 * Math.sqrt(1.0 + r11 - r00 - r22);
|
|
18012
|
+
qw = (r02 - r20) / s;
|
|
18013
|
+
qx = (r01 + r10) / s;
|
|
18014
|
+
qy = 0.25 * s;
|
|
18015
|
+
qz = (r12 + r21) / s;
|
|
17764
18016
|
}
|
|
17765
|
-
|
|
17766
|
-
|
|
17767
|
-
|
|
17768
|
-
|
|
18017
|
+
else {
|
|
18018
|
+
const s = 2.0 * Math.sqrt(1.0 + r22 - r00 - r11);
|
|
18019
|
+
qw = (r10 - r01) / s;
|
|
18020
|
+
qx = (r02 + r20) / s;
|
|
18021
|
+
qy = (r12 + r21) / s;
|
|
18022
|
+
qz = 0.25 * s;
|
|
18023
|
+
}
|
|
18024
|
+
[qx, qy, qz] = toZero([qx, qy, qz]);
|
|
18025
|
+
// const q = gcd(qx, gcd(qy, qz));
|
|
18026
|
+
let q = [Math.abs(qx), Math.abs(qy), Math.abs(qz)].reduce((acc, curr) => {
|
|
18027
|
+
if (acc == 0 || (curr > 0 && curr < acc)) {
|
|
18028
|
+
acc = curr;
|
|
17769
18029
|
}
|
|
17770
|
-
|
|
17771
|
-
|
|
17772
|
-
|
|
17773
|
-
|
|
17774
|
-
|
|
17775
|
-
|
|
17776
|
-
|
|
18030
|
+
return acc;
|
|
18031
|
+
}, 0);
|
|
18032
|
+
if (q > 0) {
|
|
18033
|
+
qx /= q;
|
|
18034
|
+
qy /= q;
|
|
18035
|
+
qz /= q;
|
|
18036
|
+
}
|
|
18037
|
+
const rotate = [qx, qy, qz, Object.is(qw, 0) ? 0 : 2 * Math.acos(qw) * 180 / Math.PI];
|
|
18038
|
+
const scale = [scaleX, scaleY, scaleZ];
|
|
18039
|
+
const skew = [skewXY, skewXZ, skewYZ];
|
|
18040
|
+
return {
|
|
18041
|
+
translate,
|
|
18042
|
+
scale,
|
|
18043
|
+
rotate,
|
|
18044
|
+
skew,
|
|
18045
|
+
perspective
|
|
18046
|
+
};
|
|
18047
|
+
}
|
|
18048
|
+
function transposeMatrix4(m) {
|
|
18049
|
+
return [
|
|
18050
|
+
m[0], m[4], m[8], m[12],
|
|
18051
|
+
m[1], m[5], m[9], m[13],
|
|
18052
|
+
m[2], m[6], m[10], m[14],
|
|
18053
|
+
m[3], m[7], m[11], m[15],
|
|
18054
|
+
];
|
|
18055
|
+
}
|
|
18056
|
+
function invertMatrix4(m) {
|
|
18057
|
+
new Array(16);
|
|
18058
|
+
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]
|
|
18059
|
+
- m[0] * m[13] * m[10] * m[7] - m[0] * m[9] * m[6] * m[15] - m[0] * m[5] * m[14] * m[11];
|
|
18060
|
+
if (det === 0)
|
|
18061
|
+
return null;
|
|
18062
|
+
// For brevity, not implementing full inverse here — you'd normally use gl-matrix or similar.
|
|
18063
|
+
// Just use a trusted library or expand this if needed.
|
|
18064
|
+
return null; // placeholder
|
|
18065
|
+
}
|
|
18066
|
+
function toZero(v) {
|
|
18067
|
+
for (let i = 0; i < v.length; i++) {
|
|
18068
|
+
if (Math.abs(v[i]) <= epsilon) {
|
|
18069
|
+
v[i] = 0;
|
|
17777
18070
|
}
|
|
17778
|
-
else
|
|
17779
|
-
|
|
18071
|
+
else {
|
|
18072
|
+
v[i] = +v[i].toPrecision(6);
|
|
17780
18073
|
}
|
|
17781
|
-
acc.push(curr.join(''));
|
|
17782
|
-
return acc;
|
|
17783
18074
|
}
|
|
17784
|
-
|
|
17785
|
-
|
|
17786
|
-
|
|
17787
|
-
|
|
17788
|
-
|
|
17789
|
-
|
|
17790
|
-
|
|
18075
|
+
return v;
|
|
18076
|
+
}
|
|
18077
|
+
// https://drafts.csswg.org/css-transforms-1/#2d-matrix
|
|
18078
|
+
function is2DMatrix(matrix) {
|
|
18079
|
+
// m13,m14, m23, m24, m31, m32, m34, m43 are all 0
|
|
18080
|
+
return matrix[0][2] === 0 &&
|
|
18081
|
+
matrix[0][3] === 0 &&
|
|
18082
|
+
matrix[1][2] === 0 &&
|
|
18083
|
+
matrix[1][3] === 0 &&
|
|
18084
|
+
matrix[2][0] === 0 &&
|
|
18085
|
+
matrix[2][1] === 0 &&
|
|
18086
|
+
matrix[2][3] === 0 &&
|
|
18087
|
+
matrix[3][2] === 0 &&
|
|
18088
|
+
matrix[2][2] === 1 &&
|
|
18089
|
+
matrix[3][3] === 1;
|
|
18090
|
+
}
|
|
18091
|
+
|
|
18092
|
+
// https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Values_and_units#absolute_length_units
|
|
18093
|
+
function length2Px(value) {
|
|
18094
|
+
if (value.typ == exports.EnumToken.NumberTokenType) {
|
|
18095
|
+
return +value.val;
|
|
18096
|
+
}
|
|
18097
|
+
switch (value.unit) {
|
|
18098
|
+
case 'cm':
|
|
18099
|
+
// @ts-ignore
|
|
18100
|
+
return value.val * 37.8;
|
|
18101
|
+
case 'mm':
|
|
18102
|
+
// @ts-ignore
|
|
18103
|
+
return value.val * 3.78;
|
|
18104
|
+
case 'Q':
|
|
18105
|
+
// @ts-ignore
|
|
18106
|
+
return value.val * 37.8 / 40;
|
|
18107
|
+
case 'in':
|
|
18108
|
+
// @ts-ignore
|
|
18109
|
+
return value.val / 96;
|
|
18110
|
+
case 'pc':
|
|
18111
|
+
// @ts-ignore
|
|
18112
|
+
return value.val / 16;
|
|
18113
|
+
case 'pt':
|
|
18114
|
+
// @ts-ignore
|
|
18115
|
+
return value.val * 4 / 3;
|
|
18116
|
+
case 'px':
|
|
18117
|
+
return +value.val;
|
|
18118
|
+
}
|
|
18119
|
+
return null;
|
|
18120
|
+
}
|
|
18121
|
+
|
|
18122
|
+
function translateX(x, from) {
|
|
18123
|
+
const matrix = identity();
|
|
18124
|
+
matrix[3][0] = x;
|
|
18125
|
+
return multiply(from, matrix);
|
|
18126
|
+
}
|
|
18127
|
+
function translateY(y, from) {
|
|
18128
|
+
const matrix = identity();
|
|
18129
|
+
matrix[3][1] = y;
|
|
18130
|
+
return multiply(from, matrix);
|
|
18131
|
+
}
|
|
18132
|
+
function translateZ(z, from) {
|
|
18133
|
+
const matrix = identity();
|
|
18134
|
+
matrix[3][2] = z;
|
|
18135
|
+
return multiply(from, matrix);
|
|
18136
|
+
}
|
|
18137
|
+
function translate(translate, from) {
|
|
18138
|
+
const matrix = identity();
|
|
18139
|
+
matrix[3][0] = translate[0];
|
|
18140
|
+
matrix[3][1] = translate[1] ?? 0;
|
|
18141
|
+
return multiply(from, matrix);
|
|
18142
|
+
}
|
|
18143
|
+
function translate3d(translate, from) {
|
|
18144
|
+
const matrix = identity();
|
|
18145
|
+
matrix[3][0] = translate[0];
|
|
18146
|
+
matrix[3][1] = translate[1];
|
|
18147
|
+
matrix[3][2] = translate[2];
|
|
18148
|
+
return multiply(from, matrix);
|
|
18149
|
+
}
|
|
18150
|
+
|
|
18151
|
+
/**
|
|
18152
|
+
* angle in radian
|
|
18153
|
+
* @param angle
|
|
18154
|
+
* @param x
|
|
18155
|
+
* @param y
|
|
18156
|
+
* @param z
|
|
18157
|
+
* @param from
|
|
18158
|
+
*/
|
|
18159
|
+
function rotate3D(angle, x, y, z, from) {
|
|
18160
|
+
const matrix = identity();
|
|
18161
|
+
const sc = Math.sin(angle / 2) * Math.cos(angle / 2);
|
|
18162
|
+
const sq = Math.sin(angle / 2) * Math.sin(angle / 2);
|
|
18163
|
+
const norm = Math.sqrt(x * x + y * y + z * z);
|
|
18164
|
+
const unit = norm === 0 ? 0 : 1 / norm;
|
|
18165
|
+
x *= unit;
|
|
18166
|
+
y *= unit;
|
|
18167
|
+
z *= unit;
|
|
18168
|
+
matrix[0][0] = 1 - 2 * (y * y + z * z) * sq;
|
|
18169
|
+
matrix[0][1] = 2 * (x * y * sq + z * sc);
|
|
18170
|
+
matrix[0][2] = 2 * (x * z * sq - y * sc);
|
|
18171
|
+
matrix[1][0] = 2 * (x * y * sq - z * sc);
|
|
18172
|
+
matrix[1][1] = 1 - 2 * (x * x + z * z) * sq;
|
|
18173
|
+
matrix[1][2] = 2 * (y * z * sq + x * sc);
|
|
18174
|
+
matrix[2][0] = 2 * (x * z * sq + y * sc);
|
|
18175
|
+
matrix[2][1] = 2 * (y * z * sq - x * sc);
|
|
18176
|
+
matrix[2][2] = 1 - 2 * (x * x + y * y) * sq;
|
|
18177
|
+
return multiply(from, matrix);
|
|
18178
|
+
}
|
|
18179
|
+
function rotate(angle, from) {
|
|
18180
|
+
const matrix = identity();
|
|
18181
|
+
matrix[0][0] = Math.cos(angle);
|
|
18182
|
+
matrix[0][1] = Math.sin(angle);
|
|
18183
|
+
matrix[1][0] = -Math.sin(angle);
|
|
18184
|
+
matrix[1][1] = Math.cos(angle);
|
|
18185
|
+
return multiply(from, matrix);
|
|
18186
|
+
}
|
|
18187
|
+
|
|
18188
|
+
function scaleX(x, from) {
|
|
18189
|
+
const matrix = identity();
|
|
18190
|
+
matrix[0][0] = x;
|
|
18191
|
+
return multiply(from, matrix);
|
|
18192
|
+
}
|
|
18193
|
+
function scaleY(y, from) {
|
|
18194
|
+
const matrix = identity();
|
|
18195
|
+
matrix[1][1] = y;
|
|
18196
|
+
return multiply(from, matrix);
|
|
18197
|
+
}
|
|
18198
|
+
function scaleZ(z, from) {
|
|
18199
|
+
const matrix = identity();
|
|
18200
|
+
matrix[2][2] = z;
|
|
18201
|
+
return multiply(from, matrix);
|
|
18202
|
+
}
|
|
18203
|
+
function scale(x, y, from) {
|
|
18204
|
+
const matrix = identity();
|
|
18205
|
+
matrix[0][0] = x;
|
|
18206
|
+
matrix[1][1] = y;
|
|
18207
|
+
return multiply(from, matrix);
|
|
18208
|
+
}
|
|
18209
|
+
function scale3d(x, y, z, from) {
|
|
18210
|
+
const matrix = identity();
|
|
18211
|
+
matrix[0][0] = x;
|
|
18212
|
+
matrix[1][1] = y;
|
|
18213
|
+
matrix[2][2] = z;
|
|
18214
|
+
return multiply(from, matrix);
|
|
18215
|
+
}
|
|
18216
|
+
|
|
18217
|
+
function parseMatrix(mat) {
|
|
18218
|
+
if (mat.typ == exports.EnumToken.IdenTokenType) {
|
|
18219
|
+
return mat.val == 'none' ? identity() : null;
|
|
18220
|
+
}
|
|
18221
|
+
const children = mat.chi.filter((t) => t.typ == exports.EnumToken.NumberTokenType || t.typ == exports.EnumToken.IdenTokenType);
|
|
18222
|
+
const values = [];
|
|
18223
|
+
for (const child of children) {
|
|
18224
|
+
if (child.typ != exports.EnumToken.NumberTokenType) {
|
|
18225
|
+
return null;
|
|
18226
|
+
}
|
|
18227
|
+
// @ts-ignore
|
|
18228
|
+
values.push(getNumber(child));
|
|
18229
|
+
}
|
|
18230
|
+
// @ts-ignore
|
|
18231
|
+
return matrix(values);
|
|
18232
|
+
}
|
|
18233
|
+
// use column-major order
|
|
18234
|
+
function matrix(values) {
|
|
18235
|
+
const matrix = identity();
|
|
18236
|
+
if (values.length === 6) {
|
|
18237
|
+
matrix[0][0] = values[0];
|
|
18238
|
+
matrix[0][1] = values[1];
|
|
18239
|
+
matrix[1][0] = values[2];
|
|
18240
|
+
matrix[1][1] = values[3];
|
|
18241
|
+
matrix[3][0] = values[4];
|
|
18242
|
+
matrix[3][1] = values[5];
|
|
18243
|
+
}
|
|
18244
|
+
else if (values.length === 16) {
|
|
18245
|
+
matrix[0][0] = values[0];
|
|
18246
|
+
matrix[0][1] = values[1];
|
|
18247
|
+
matrix[0][2] = values[2];
|
|
18248
|
+
matrix[0][3] = values[3];
|
|
18249
|
+
matrix[1][0] = values[4];
|
|
18250
|
+
matrix[1][1] = values[5];
|
|
18251
|
+
matrix[1][2] = values[6];
|
|
18252
|
+
matrix[1][3] = values[7];
|
|
18253
|
+
matrix[2][0] = values[8];
|
|
18254
|
+
matrix[2][1] = values[9];
|
|
18255
|
+
matrix[2][2] = values[10];
|
|
18256
|
+
matrix[2][3] = values[11];
|
|
18257
|
+
matrix[3][0] = values[12];
|
|
18258
|
+
matrix[3][1] = values[13];
|
|
18259
|
+
matrix[3][2] = values[14];
|
|
18260
|
+
matrix[3][3] = values[15];
|
|
18261
|
+
}
|
|
18262
|
+
else {
|
|
18263
|
+
return null;
|
|
18264
|
+
}
|
|
18265
|
+
return matrix;
|
|
18266
|
+
}
|
|
18267
|
+
function serialize(matrix) {
|
|
18268
|
+
matrix = matrix.map(t => toZero(t.slice()));
|
|
18269
|
+
// @ts-ignore
|
|
18270
|
+
if (eq(matrix, identity())) {
|
|
18271
|
+
return {
|
|
18272
|
+
typ: exports.EnumToken.IdenTokenType,
|
|
18273
|
+
val: 'none'
|
|
18274
|
+
};
|
|
18275
|
+
}
|
|
18276
|
+
if (is2DMatrix(matrix)) {
|
|
18277
|
+
// https://drafts.csswg.org/css-transforms-2/#two-dimensional-subset
|
|
18278
|
+
return {
|
|
18279
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18280
|
+
val: 'matrix',
|
|
18281
|
+
chi: [
|
|
18282
|
+
matrix[0][0],
|
|
18283
|
+
matrix[0][1],
|
|
18284
|
+
matrix[1][0],
|
|
18285
|
+
matrix[1][1],
|
|
18286
|
+
matrix[3][0],
|
|
18287
|
+
matrix[3][1]
|
|
18288
|
+
].reduce((acc, t) => {
|
|
18289
|
+
if (acc.length > 0) {
|
|
18290
|
+
acc.push({ typ: exports.EnumToken.CommaTokenType });
|
|
18291
|
+
}
|
|
18292
|
+
acc.push({
|
|
18293
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18294
|
+
val: reduceNumber(t)
|
|
18295
|
+
});
|
|
18296
|
+
return acc;
|
|
18297
|
+
}, [])
|
|
18298
|
+
};
|
|
18299
|
+
}
|
|
18300
|
+
return {
|
|
18301
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18302
|
+
val: 'matrix3d',
|
|
18303
|
+
chi: matrix.flat().reduce((acc, curr) => {
|
|
18304
|
+
if (acc.length > 0) {
|
|
18305
|
+
acc.push({ typ: exports.EnumToken.CommaTokenType });
|
|
18306
|
+
}
|
|
18307
|
+
acc.push({
|
|
18308
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18309
|
+
val: reduceNumber(curr)
|
|
18310
|
+
});
|
|
18311
|
+
return acc;
|
|
18312
|
+
}, [])
|
|
18313
|
+
};
|
|
18314
|
+
}
|
|
18315
|
+
|
|
18316
|
+
// translate → rotate → skew → scale
|
|
18317
|
+
function minify$1(matrix) {
|
|
18318
|
+
const decomposed = decompose(matrix);
|
|
18319
|
+
if (decomposed == null) {
|
|
18320
|
+
return null;
|
|
18321
|
+
}
|
|
18322
|
+
const transforms = new Set(['translate', 'scale', 'skew', 'perspective', 'rotate']);
|
|
18323
|
+
const scales = new Set(['x', 'y', 'z']);
|
|
18324
|
+
const skew = new Set(['x', 'y']);
|
|
18325
|
+
let result = [];
|
|
18326
|
+
// check identity
|
|
18327
|
+
if (round(decomposed.translate[0]) == 0 && round(decomposed.translate[1]) == 0 && round(decomposed.translate[2]) == 0) {
|
|
18328
|
+
transforms.delete('translate');
|
|
18329
|
+
}
|
|
18330
|
+
if (round(decomposed.scale[0]) == 1 && round(decomposed.scale[1]) == 1 && round(decomposed.scale[2]) == 1) {
|
|
18331
|
+
transforms.delete('scale');
|
|
18332
|
+
}
|
|
18333
|
+
if (round(decomposed.skew[0]) == 0 && round(decomposed.skew[1]) == 0) {
|
|
18334
|
+
transforms.delete('skew');
|
|
18335
|
+
}
|
|
18336
|
+
if (round(decomposed.perspective[2]) == 0) {
|
|
18337
|
+
transforms.delete('perspective');
|
|
18338
|
+
}
|
|
18339
|
+
if (round(decomposed.rotate[3]) == 0) {
|
|
18340
|
+
transforms.delete('rotate');
|
|
18341
|
+
}
|
|
18342
|
+
if (transforms.has('translate')) {
|
|
18343
|
+
let coordinates = new Set(['x', 'y', 'z']);
|
|
18344
|
+
for (let i = 0; i < 3; i++) {
|
|
18345
|
+
if (round(decomposed.translate[i]) == 0) {
|
|
18346
|
+
coordinates.delete(i == 0 ? 'x' : i == 1 ? 'y' : 'z');
|
|
18347
|
+
}
|
|
18348
|
+
}
|
|
18349
|
+
if (coordinates.size == 3) {
|
|
18350
|
+
result.push({
|
|
18351
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18352
|
+
val: 'translate3d',
|
|
18353
|
+
chi: [
|
|
18354
|
+
{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[0]) + '', unit: 'px' },
|
|
18355
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18356
|
+
{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[1]) + '', unit: 'px' },
|
|
18357
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18358
|
+
{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[2]) + '', unit: 'px' }
|
|
18359
|
+
]
|
|
18360
|
+
});
|
|
18361
|
+
}
|
|
18362
|
+
else if (coordinates.size == 1) {
|
|
18363
|
+
if (coordinates.has('x')) {
|
|
18364
|
+
result.push({
|
|
18365
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18366
|
+
val: 'translate',
|
|
18367
|
+
chi: [{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[0]) + '', unit: 'px' }]
|
|
18368
|
+
});
|
|
18369
|
+
}
|
|
18370
|
+
else {
|
|
18371
|
+
let axis = coordinates.has('y') ? 'y' : 'z';
|
|
18372
|
+
let index = axis == 'y' ? 1 : 2;
|
|
18373
|
+
result.push({
|
|
18374
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18375
|
+
val: 'translate' + axis.toUpperCase(),
|
|
18376
|
+
chi: [{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[index]) + '', unit: 'px' }]
|
|
18377
|
+
});
|
|
18378
|
+
}
|
|
18379
|
+
}
|
|
18380
|
+
else if (coordinates.has('z')) {
|
|
18381
|
+
result.push({
|
|
18382
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18383
|
+
val: 'translate3d',
|
|
18384
|
+
chi: [
|
|
18385
|
+
decomposed.translate[0] == 0 ? {
|
|
18386
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18387
|
+
'val': '0'
|
|
18388
|
+
} : { typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[0]) + '', unit: 'px' },
|
|
18389
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18390
|
+
decomposed.translate[1] == 0 ? {
|
|
18391
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18392
|
+
'val': '0'
|
|
18393
|
+
} : { typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[1]) + '', unit: 'px' },
|
|
18394
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18395
|
+
{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[2]) + '', unit: 'px' }
|
|
18396
|
+
]
|
|
18397
|
+
});
|
|
18398
|
+
}
|
|
18399
|
+
else {
|
|
18400
|
+
result.push({
|
|
18401
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18402
|
+
val: 'translate',
|
|
18403
|
+
chi: [
|
|
18404
|
+
decomposed.translate[0] == 0 ? {
|
|
18405
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18406
|
+
'val': '0'
|
|
18407
|
+
} : { typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[0]) + '', unit: 'px' },
|
|
18408
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18409
|
+
decomposed.translate[1] == 0 ? {
|
|
18410
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18411
|
+
'val': '0'
|
|
18412
|
+
} : { typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[1]) + '', unit: 'px' }
|
|
18413
|
+
]
|
|
18414
|
+
});
|
|
18415
|
+
}
|
|
18416
|
+
}
|
|
18417
|
+
if (transforms.has('rotate')) {
|
|
18418
|
+
const [x, y, z, angle] = decomposed.rotate;
|
|
18419
|
+
if (y == 0 && z == 0) {
|
|
18420
|
+
result.push({
|
|
18421
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18422
|
+
val: 'rotateX',
|
|
18423
|
+
chi: [
|
|
18424
|
+
{
|
|
18425
|
+
typ: exports.EnumToken.AngleTokenType,
|
|
18426
|
+
val: '' + round(angle),
|
|
18427
|
+
unit: 'deg'
|
|
18428
|
+
}
|
|
18429
|
+
]
|
|
18430
|
+
});
|
|
18431
|
+
}
|
|
18432
|
+
else if (x == 0 && z == 0) {
|
|
18433
|
+
result.push({
|
|
18434
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18435
|
+
val: 'rotateY',
|
|
18436
|
+
chi: [
|
|
18437
|
+
{
|
|
18438
|
+
typ: exports.EnumToken.AngleTokenType,
|
|
18439
|
+
val: '' + round(angle),
|
|
18440
|
+
unit: 'deg'
|
|
18441
|
+
}
|
|
18442
|
+
]
|
|
18443
|
+
});
|
|
18444
|
+
}
|
|
18445
|
+
else if (x == 0 && y == 0) {
|
|
18446
|
+
result.push({
|
|
18447
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18448
|
+
val: 'rotate',
|
|
18449
|
+
chi: [
|
|
18450
|
+
{
|
|
18451
|
+
typ: exports.EnumToken.AngleTokenType,
|
|
18452
|
+
val: '' + round(angle),
|
|
18453
|
+
unit: 'deg'
|
|
18454
|
+
}
|
|
18455
|
+
]
|
|
18456
|
+
});
|
|
18457
|
+
}
|
|
18458
|
+
else {
|
|
18459
|
+
result.push({
|
|
18460
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18461
|
+
val: 'rotate3d',
|
|
18462
|
+
chi: [
|
|
18463
|
+
{
|
|
18464
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18465
|
+
val: '' + round(x)
|
|
18466
|
+
},
|
|
18467
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18468
|
+
{
|
|
18469
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18470
|
+
val: '' + round(y)
|
|
18471
|
+
},
|
|
18472
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18473
|
+
{
|
|
18474
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
18475
|
+
val: '' + round(z)
|
|
18476
|
+
},
|
|
18477
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18478
|
+
{
|
|
18479
|
+
typ: exports.EnumToken.AngleTokenType,
|
|
18480
|
+
val: '' + round(angle),
|
|
18481
|
+
unit: 'deg'
|
|
18482
|
+
}
|
|
18483
|
+
]
|
|
18484
|
+
});
|
|
18485
|
+
}
|
|
18486
|
+
}
|
|
18487
|
+
if (transforms.has('skew')) {
|
|
18488
|
+
if (round(decomposed.skew[0]) == 0) {
|
|
18489
|
+
skew.delete('x');
|
|
18490
|
+
}
|
|
18491
|
+
if (round(decomposed.skew[1]) == 0) {
|
|
18492
|
+
skew.delete('y');
|
|
18493
|
+
}
|
|
18494
|
+
for (let i = 0; i < 2; i++) {
|
|
18495
|
+
decomposed.skew[i] = round(Math.atan(decomposed.skew[i]) * 180 / Math.PI);
|
|
18496
|
+
}
|
|
18497
|
+
if (skew.size == 1) {
|
|
18498
|
+
result.push({
|
|
18499
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18500
|
+
val: 'skew' + (skew.has('x') ? '' : 'Y'),
|
|
18501
|
+
chi: [
|
|
18502
|
+
{ typ: exports.EnumToken.AngleTokenType, val: '' + round(decomposed.skew[0]), unit: 'deg' }
|
|
18503
|
+
]
|
|
18504
|
+
});
|
|
18505
|
+
}
|
|
18506
|
+
else {
|
|
18507
|
+
result.push({
|
|
18508
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18509
|
+
val: 'skew',
|
|
18510
|
+
chi: [
|
|
18511
|
+
{ typ: exports.EnumToken.AngleTokenType, val: '' + round(decomposed.skew[0]), unit: 'deg' },
|
|
18512
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18513
|
+
{ typ: exports.EnumToken.AngleTokenType, val: '' + round(decomposed.skew[1]), unit: 'deg' }
|
|
18514
|
+
]
|
|
18515
|
+
});
|
|
18516
|
+
}
|
|
18517
|
+
}
|
|
18518
|
+
if (transforms.has('scale')) {
|
|
18519
|
+
const [sx, sy, sz] = toZero(decomposed.scale);
|
|
18520
|
+
if (sz == 1) {
|
|
18521
|
+
scales.delete('z');
|
|
18522
|
+
}
|
|
18523
|
+
if (sy == 1) {
|
|
18524
|
+
scales.delete('y');
|
|
18525
|
+
}
|
|
18526
|
+
if (sx == 1) {
|
|
18527
|
+
scales.delete('x');
|
|
18528
|
+
}
|
|
18529
|
+
if (scales.size == 1) {
|
|
18530
|
+
let prefix = scales.has('x') ? '' : scales.has('y') ? 'Y' : 'Z';
|
|
18531
|
+
result.push({
|
|
18532
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18533
|
+
val: 'scale' + prefix,
|
|
18534
|
+
chi: [
|
|
18535
|
+
{ typ: exports.EnumToken.NumberTokenType, val: '' + round(prefix == 'Z' ? sz : prefix == 'Y' ? sy : sx) }
|
|
18536
|
+
]
|
|
18537
|
+
});
|
|
18538
|
+
}
|
|
18539
|
+
else if (!scales.has('z')) {
|
|
18540
|
+
result.push({
|
|
18541
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18542
|
+
val: 'scale',
|
|
18543
|
+
chi: [
|
|
18544
|
+
{ typ: exports.EnumToken.NumberTokenType, val: '' + round(sx) },
|
|
18545
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18546
|
+
{ typ: exports.EnumToken.NumberTokenType, val: '' + round(sy) },
|
|
18547
|
+
]
|
|
18548
|
+
});
|
|
18549
|
+
}
|
|
18550
|
+
else {
|
|
18551
|
+
result.push({
|
|
18552
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18553
|
+
val: 'scale3d',
|
|
18554
|
+
chi: [
|
|
18555
|
+
{ typ: exports.EnumToken.NumberTokenType, val: '' + round(sx) },
|
|
18556
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18557
|
+
{ typ: exports.EnumToken.NumberTokenType, val: '' + round(sy) },
|
|
18558
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
18559
|
+
{ typ: exports.EnumToken.NumberTokenType, val: '' + round(sz) }
|
|
18560
|
+
]
|
|
18561
|
+
});
|
|
18562
|
+
}
|
|
18563
|
+
}
|
|
18564
|
+
if (transforms.has('perspective')) {
|
|
18565
|
+
result.push({
|
|
18566
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
18567
|
+
val: 'perspective',
|
|
18568
|
+
chi: [
|
|
18569
|
+
{ typ: exports.EnumToken.Length, val: '' + round(1 / decomposed.perspective[2]), unit: 'px' },
|
|
18570
|
+
]
|
|
18571
|
+
});
|
|
18572
|
+
}
|
|
18573
|
+
// identity
|
|
18574
|
+
return result.length == 0 || (result.length == 1 && eqMatrix(identity(), result)) ? [
|
|
18575
|
+
{
|
|
18576
|
+
typ: exports.EnumToken.IdenTokenType,
|
|
18577
|
+
val: 'none'
|
|
18578
|
+
}
|
|
18579
|
+
] : result;
|
|
18580
|
+
}
|
|
18581
|
+
function eqMatrix(a, b) {
|
|
18582
|
+
let mat = identity();
|
|
18583
|
+
let tmp = identity();
|
|
18584
|
+
// @ts-ignore
|
|
18585
|
+
const data = Array.isArray(a) ? a : parseMatrix(a);
|
|
18586
|
+
for (const transform of b) {
|
|
18587
|
+
tmp = computeMatrix([transform], identity());
|
|
18588
|
+
if (tmp == null) {
|
|
18589
|
+
return false;
|
|
18590
|
+
}
|
|
18591
|
+
mat = multiply(mat, tmp);
|
|
18592
|
+
}
|
|
18593
|
+
if (mat == null) {
|
|
18594
|
+
return false;
|
|
18595
|
+
}
|
|
18596
|
+
for (let i = 0; i < 4; i++) {
|
|
18597
|
+
for (let j = 0; j < 4; j++) {
|
|
18598
|
+
if (Math.abs(mat[i][j] - data[i][j]) > epsilon) {
|
|
18599
|
+
return false;
|
|
18600
|
+
}
|
|
18601
|
+
}
|
|
18602
|
+
}
|
|
18603
|
+
return true;
|
|
18604
|
+
}
|
|
18605
|
+
|
|
18606
|
+
function skewX(x, from) {
|
|
18607
|
+
const matrix = identity();
|
|
18608
|
+
matrix[1][0] = Math.tan(x);
|
|
18609
|
+
return multiply(from, matrix);
|
|
18610
|
+
}
|
|
18611
|
+
function skewY(y, from) {
|
|
18612
|
+
const matrix = identity();
|
|
18613
|
+
matrix[0][1] = Math.tan(y);
|
|
18614
|
+
return multiply(from, matrix);
|
|
18615
|
+
}
|
|
18616
|
+
// convert angle to radian
|
|
18617
|
+
function skew(values, from) {
|
|
18618
|
+
const matrix = identity();
|
|
18619
|
+
matrix[1][0] = Math.tan(values[0]);
|
|
18620
|
+
if (values.length > 1) {
|
|
18621
|
+
matrix[0][1] = Math.tan(values[1]);
|
|
18622
|
+
}
|
|
18623
|
+
return multiply(from, matrix);
|
|
18624
|
+
}
|
|
18625
|
+
|
|
18626
|
+
function perspective(x, from) {
|
|
18627
|
+
const matrix = identity();
|
|
18628
|
+
// @ts-ignore
|
|
18629
|
+
matrix[2][3] = typeof x == 'object' && x.val == 'none' ? 0 : x == 0 ? Number.NEGATIVE_INFINITY : -1 / x;
|
|
18630
|
+
return multiply(from, matrix);
|
|
18631
|
+
}
|
|
18632
|
+
|
|
18633
|
+
function compute(transformLists) {
|
|
18634
|
+
transformLists = transformLists.slice();
|
|
18635
|
+
stripCommaToken(transformLists);
|
|
18636
|
+
if (transformLists.length == 0) {
|
|
18637
|
+
return null;
|
|
18638
|
+
}
|
|
18639
|
+
let matrix = identity();
|
|
18640
|
+
let mat;
|
|
18641
|
+
const cumulative = [];
|
|
18642
|
+
for (const transformList of splitTransformList(transformLists)) {
|
|
18643
|
+
mat = computeMatrix(transformList, identity());
|
|
18644
|
+
if (mat == null) {
|
|
18645
|
+
return null;
|
|
18646
|
+
}
|
|
18647
|
+
matrix = multiply(matrix, mat);
|
|
18648
|
+
cumulative.push(...(minify$1(mat) ?? transformList));
|
|
18649
|
+
}
|
|
18650
|
+
const serialized = serialize(matrix);
|
|
18651
|
+
if (cumulative.length > 0) {
|
|
18652
|
+
for (let i = 0; i < cumulative.length; i++) {
|
|
18653
|
+
if (cumulative[i].typ == exports.EnumToken.IdenTokenType && cumulative[i].val == 'none') {
|
|
18654
|
+
cumulative.splice(i--, 1);
|
|
18655
|
+
}
|
|
18656
|
+
}
|
|
18657
|
+
if (cumulative.length == 0) {
|
|
18658
|
+
cumulative.push({
|
|
18659
|
+
typ: exports.EnumToken.IdenTokenType, val: 'none'
|
|
18660
|
+
});
|
|
18661
|
+
}
|
|
18662
|
+
}
|
|
18663
|
+
return {
|
|
18664
|
+
matrix: serialize(matrix),
|
|
18665
|
+
cumulative,
|
|
18666
|
+
minified: minify$1(matrix) ?? [serialized]
|
|
18667
|
+
};
|
|
18668
|
+
}
|
|
18669
|
+
function computeMatrix(transformList, matrixVar) {
|
|
18670
|
+
let values = [];
|
|
18671
|
+
let val;
|
|
18672
|
+
let i = 0;
|
|
18673
|
+
for (; i < transformList.length; i++) {
|
|
18674
|
+
if (transformList[i].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18675
|
+
continue;
|
|
18676
|
+
}
|
|
18677
|
+
if (transformList[i].typ != exports.EnumToken.FunctionTokenType || !transformFunctions.includes(transformList[i].val)) {
|
|
18678
|
+
return null;
|
|
18679
|
+
}
|
|
18680
|
+
switch (transformList[i].val) {
|
|
18681
|
+
case 'translate':
|
|
18682
|
+
case 'translateX':
|
|
18683
|
+
case 'translateY':
|
|
18684
|
+
case 'translateZ':
|
|
18685
|
+
case 'translate3d':
|
|
18686
|
+
{
|
|
18687
|
+
values.length = 0;
|
|
18688
|
+
const children = stripCommaToken(transformList[i].chi.slice());
|
|
18689
|
+
if (children == null || children.length == 0) {
|
|
18690
|
+
return null;
|
|
18691
|
+
}
|
|
18692
|
+
const valCount = transformList[i].val == 'translate3d' || transformList[i].val == 'translate' ? 3 : 1;
|
|
18693
|
+
if (children.length == 1 && children[0].typ == exports.EnumToken.IdenTokenType && children[0].val == 'none') {
|
|
18694
|
+
values.fill(0, 0, valCount);
|
|
18695
|
+
}
|
|
18696
|
+
else {
|
|
18697
|
+
for (let j = 0; j < children.length; j++) {
|
|
18698
|
+
if (children[j].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18699
|
+
continue;
|
|
18700
|
+
}
|
|
18701
|
+
val = length2Px(children[j]);
|
|
18702
|
+
if (typeof val != 'number' || Number.isNaN(val)) {
|
|
18703
|
+
return null;
|
|
18704
|
+
}
|
|
18705
|
+
values.push(val);
|
|
18706
|
+
}
|
|
18707
|
+
}
|
|
18708
|
+
if (values.length == 0 || values.length > valCount) {
|
|
18709
|
+
return null;
|
|
18710
|
+
}
|
|
18711
|
+
if (transformList[i].val == 'translateX') {
|
|
18712
|
+
matrixVar = translateX(values[0], matrixVar);
|
|
18713
|
+
}
|
|
18714
|
+
else if (transformList[i].val == 'translateY') {
|
|
18715
|
+
matrixVar = translateY(values[0], matrixVar);
|
|
18716
|
+
}
|
|
18717
|
+
else if (transformList[i].val == 'translateZ') {
|
|
18718
|
+
matrixVar = translateZ(values[0], matrixVar);
|
|
18719
|
+
}
|
|
18720
|
+
else if (transformList[i].val == 'translate') {
|
|
18721
|
+
matrixVar = translate(values, matrixVar);
|
|
18722
|
+
}
|
|
18723
|
+
else {
|
|
18724
|
+
// @ts-ignore
|
|
18725
|
+
matrixVar = translate3d(values, matrixVar);
|
|
18726
|
+
}
|
|
18727
|
+
}
|
|
18728
|
+
break;
|
|
18729
|
+
case 'rotate':
|
|
18730
|
+
case 'rotateX':
|
|
18731
|
+
case 'rotateY':
|
|
18732
|
+
case 'rotateZ':
|
|
18733
|
+
case 'rotate3d':
|
|
18734
|
+
{
|
|
18735
|
+
let x = 0;
|
|
18736
|
+
let y = 0;
|
|
18737
|
+
let z = 0;
|
|
18738
|
+
let angle;
|
|
18739
|
+
let values = [];
|
|
18740
|
+
let valuesCount = transformList[i].val == 'rotate3d' ? 4 : 1;
|
|
18741
|
+
for (const child of stripCommaToken(transformList[i].chi.slice())) {
|
|
18742
|
+
if (child.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18743
|
+
continue;
|
|
18744
|
+
}
|
|
18745
|
+
values.push(child);
|
|
18746
|
+
if (transformList[i].val == 'rotateX') {
|
|
18747
|
+
x = 1;
|
|
18748
|
+
}
|
|
18749
|
+
else if (transformList[i].val == 'rotateY') {
|
|
18750
|
+
y = 1;
|
|
18751
|
+
}
|
|
18752
|
+
else if (transformList[i].val == 'rotate' || transformList[i].val == 'rotateZ') {
|
|
18753
|
+
z = 1;
|
|
18754
|
+
}
|
|
18755
|
+
}
|
|
18756
|
+
if (values.length != valuesCount) {
|
|
18757
|
+
return null;
|
|
18758
|
+
}
|
|
18759
|
+
if (transformList[i].val == 'rotate3d') {
|
|
18760
|
+
x = getNumber(values[0]);
|
|
18761
|
+
y = getNumber(values[1]);
|
|
18762
|
+
z = getNumber(values[2]);
|
|
18763
|
+
}
|
|
18764
|
+
angle = getAngle(values.at(-1));
|
|
18765
|
+
if ([x, y, z, angle].some(t => typeof t != 'number' || Number.isNaN(+t))) {
|
|
18766
|
+
return null;
|
|
18767
|
+
}
|
|
18768
|
+
if (transformList[i].val == 'rotate' || transformList[i].val == 'rotateZ') {
|
|
18769
|
+
matrixVar = rotate(angle * 2 * Math.PI, matrixVar);
|
|
18770
|
+
}
|
|
18771
|
+
else {
|
|
18772
|
+
matrixVar = rotate3D(angle * 2 * Math.PI, x, y, z, matrixVar);
|
|
18773
|
+
}
|
|
18774
|
+
}
|
|
18775
|
+
break;
|
|
18776
|
+
case 'scale':
|
|
18777
|
+
case 'scaleX':
|
|
18778
|
+
case 'scaleY':
|
|
18779
|
+
case 'scaleZ':
|
|
18780
|
+
case 'scale3d':
|
|
18781
|
+
{
|
|
18782
|
+
values.length = 0;
|
|
18783
|
+
let child;
|
|
18784
|
+
const children = stripCommaToken(transformList[i].chi.slice());
|
|
18785
|
+
for (let k = 0; k < children.length; k++) {
|
|
18786
|
+
child = children[k];
|
|
18787
|
+
if (child.typ == exports.EnumToken.CommentTokenType || child.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18788
|
+
continue;
|
|
18789
|
+
}
|
|
18790
|
+
if (child.typ != exports.EnumToken.NumberTokenType) {
|
|
18791
|
+
return null;
|
|
18792
|
+
}
|
|
18793
|
+
values.push(getNumber(child));
|
|
18794
|
+
}
|
|
18795
|
+
if (values.length == 0) {
|
|
18796
|
+
return null;
|
|
18797
|
+
}
|
|
18798
|
+
if (transformList[i].val == 'scale3d') {
|
|
18799
|
+
if (values.length != 3) {
|
|
18800
|
+
return null;
|
|
18801
|
+
}
|
|
18802
|
+
matrixVar = scale3d(...values, matrixVar);
|
|
18803
|
+
break;
|
|
18804
|
+
}
|
|
18805
|
+
if (transformList[i].val == 'scale') {
|
|
18806
|
+
if (values.length != 1 && values.length != 2) {
|
|
18807
|
+
return null;
|
|
18808
|
+
}
|
|
18809
|
+
matrixVar = scale(values[0], values[1] ?? values[0], matrixVar);
|
|
18810
|
+
break;
|
|
18811
|
+
}
|
|
18812
|
+
if (values.length != 1) {
|
|
18813
|
+
return null;
|
|
18814
|
+
}
|
|
18815
|
+
else if (transformList[i].val == 'scaleX') {
|
|
18816
|
+
matrixVar = scaleX(values[0], matrixVar);
|
|
18817
|
+
}
|
|
18818
|
+
else if (transformList[i].val == 'scaleY') {
|
|
18819
|
+
matrixVar = scaleY(values[0], matrixVar);
|
|
18820
|
+
}
|
|
18821
|
+
else if (transformList[i].val == 'scaleZ') {
|
|
18822
|
+
matrixVar = scaleZ(values[0], matrixVar);
|
|
18823
|
+
}
|
|
18824
|
+
}
|
|
18825
|
+
break;
|
|
18826
|
+
case 'skew':
|
|
18827
|
+
case 'skewX':
|
|
18828
|
+
case 'skewY':
|
|
18829
|
+
{
|
|
18830
|
+
values.length = 0;
|
|
18831
|
+
let child;
|
|
18832
|
+
let value;
|
|
18833
|
+
for (let k = 0; k < transformList[i].chi.length; k++) {
|
|
18834
|
+
child = transformList[i].chi[k];
|
|
18835
|
+
if (child.typ == exports.EnumToken.CommentTokenType || child.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18836
|
+
continue;
|
|
18837
|
+
}
|
|
18838
|
+
value = getAngle(child);
|
|
18839
|
+
if (value == null) {
|
|
18840
|
+
return null;
|
|
18841
|
+
}
|
|
18842
|
+
values.push(value * 2 * Math.PI);
|
|
18843
|
+
}
|
|
18844
|
+
if (values.length == 0 || (values.length > (transformList[i].val == 'skew' ? 2 : 1))) {
|
|
18845
|
+
return null;
|
|
18846
|
+
}
|
|
18847
|
+
if (transformList[i].val == 'skew') {
|
|
18848
|
+
matrixVar = skew(values, matrixVar);
|
|
18849
|
+
}
|
|
18850
|
+
else {
|
|
18851
|
+
matrixVar = transformList[i].val == 'skewX' ? skewX(values[0], matrixVar) : skewY(values[0], matrixVar);
|
|
18852
|
+
}
|
|
18853
|
+
}
|
|
18854
|
+
break;
|
|
18855
|
+
case 'perspective':
|
|
18856
|
+
{
|
|
18857
|
+
const values = [];
|
|
18858
|
+
let child;
|
|
18859
|
+
let value;
|
|
18860
|
+
for (let k = 0; k < transformList[i].chi.length; k++) {
|
|
18861
|
+
child = transformList[i].chi[k];
|
|
18862
|
+
if (child.typ == exports.EnumToken.CommentTokenType || child.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18863
|
+
continue;
|
|
18864
|
+
}
|
|
18865
|
+
if (child.typ == exports.EnumToken.IdenTokenType && child.val == 'none') {
|
|
18866
|
+
values.push(child);
|
|
18867
|
+
continue;
|
|
18868
|
+
}
|
|
18869
|
+
value = length2Px(child);
|
|
18870
|
+
if (value == null) {
|
|
18871
|
+
return null;
|
|
18872
|
+
}
|
|
18873
|
+
values.push(value);
|
|
18874
|
+
}
|
|
18875
|
+
if (values.length != 1) {
|
|
18876
|
+
return null;
|
|
18877
|
+
}
|
|
18878
|
+
matrixVar = perspective(values[0], matrixVar);
|
|
18879
|
+
}
|
|
18880
|
+
break;
|
|
18881
|
+
case 'matrix3d':
|
|
18882
|
+
// return null;
|
|
18883
|
+
case 'matrix':
|
|
18884
|
+
{
|
|
18885
|
+
const values = [];
|
|
18886
|
+
let value;
|
|
18887
|
+
for (const token of transformList[i].chi) {
|
|
18888
|
+
if ([exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType, exports.EnumToken.CommaTokenType].includes(token.typ)) {
|
|
18889
|
+
continue;
|
|
18890
|
+
}
|
|
18891
|
+
value = getNumber(token);
|
|
18892
|
+
if (value == null) {
|
|
18893
|
+
return null;
|
|
18894
|
+
}
|
|
18895
|
+
values.push(value);
|
|
18896
|
+
}
|
|
18897
|
+
if (transformList[i].val == 'matrix') {
|
|
18898
|
+
if (values.length != 6) {
|
|
18899
|
+
return null;
|
|
18900
|
+
}
|
|
18901
|
+
}
|
|
18902
|
+
else if (values.length != 16) {
|
|
18903
|
+
return null;
|
|
18904
|
+
}
|
|
18905
|
+
matrixVar = multiply(matrixVar, matrix(values));
|
|
18906
|
+
}
|
|
18907
|
+
break;
|
|
18908
|
+
default:
|
|
18909
|
+
return null;
|
|
18910
|
+
}
|
|
18911
|
+
}
|
|
18912
|
+
return matrixVar;
|
|
18913
|
+
}
|
|
18914
|
+
function splitTransformList(transformList) {
|
|
18915
|
+
let pattern = null;
|
|
18916
|
+
const tokens = [];
|
|
18917
|
+
for (let i = 0; i < transformList.length; i++) {
|
|
18918
|
+
if (transformList[i].typ == exports.EnumToken.CommentTokenType || transformList[i].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18919
|
+
continue;
|
|
18920
|
+
}
|
|
18921
|
+
if (pattern == null || (transformList[i].typ == exports.EnumToken.FunctionTokenType && !transformList[i].val.startsWith(pattern))) {
|
|
18922
|
+
if (transformList[i].typ == exports.EnumToken.FunctionTokenType) {
|
|
18923
|
+
if (transformList[i].val.startsWith('scale')) {
|
|
18924
|
+
pattern = 'scale';
|
|
18925
|
+
}
|
|
18926
|
+
else if (transformList[i].val.startsWith('rotate')) {
|
|
18927
|
+
pattern = 'rotate';
|
|
18928
|
+
}
|
|
18929
|
+
else if (transformList[i].val.startsWith('translate')) {
|
|
18930
|
+
pattern = 'translate';
|
|
18931
|
+
}
|
|
18932
|
+
else {
|
|
18933
|
+
pattern = null;
|
|
18934
|
+
}
|
|
18935
|
+
tokens.push([transformList[i]]);
|
|
18936
|
+
continue;
|
|
18937
|
+
}
|
|
18938
|
+
}
|
|
18939
|
+
if (pattern != null && transformList[i].typ == exports.EnumToken.FunctionTokenType && transformList[i].val.startsWith(pattern)) {
|
|
18940
|
+
tokens[tokens.length - 1].push(transformList[i]);
|
|
18941
|
+
continue;
|
|
18942
|
+
}
|
|
18943
|
+
tokens.push([transformList[i]]);
|
|
18944
|
+
}
|
|
18945
|
+
return tokens;
|
|
18946
|
+
}
|
|
18947
|
+
|
|
18948
|
+
class TransformCssFeature {
|
|
18949
|
+
static get ordering() {
|
|
18950
|
+
return 4;
|
|
18951
|
+
}
|
|
18952
|
+
static register(options) {
|
|
18953
|
+
// @ts-ignore
|
|
18954
|
+
if (options.computeTransform) {
|
|
18955
|
+
// @ts-ignore
|
|
18956
|
+
options.features.push(new TransformCssFeature());
|
|
18957
|
+
}
|
|
18958
|
+
}
|
|
18959
|
+
run(ast) {
|
|
18960
|
+
if (!('chi' in ast)) {
|
|
18961
|
+
return;
|
|
18962
|
+
}
|
|
18963
|
+
let i = 0;
|
|
18964
|
+
let node;
|
|
18965
|
+
// @ts-ignore
|
|
18966
|
+
for (; i < ast.chi.length; i++) {
|
|
18967
|
+
// @ts-ignore
|
|
18968
|
+
node = ast.chi[i];
|
|
18969
|
+
if (node.typ != exports.EnumToken.DeclarationNodeType || !node.nam.match(/^(-[a-z]+-)?transform$/)) {
|
|
18970
|
+
continue;
|
|
18971
|
+
}
|
|
18972
|
+
const children = node.val.slice();
|
|
18973
|
+
consumeWhitespace(children);
|
|
18974
|
+
let { matrix, cumulative, minified } = compute(children) ?? {};
|
|
18975
|
+
if (matrix == null || cumulative == null || minified == null) {
|
|
18976
|
+
return;
|
|
18977
|
+
}
|
|
18978
|
+
let r = [filterValues(node.val.slice())];
|
|
18979
|
+
if (eqMatrix(matrix, cumulative)) {
|
|
18980
|
+
r.push(cumulative);
|
|
18981
|
+
}
|
|
18982
|
+
if (eqMatrix(matrix, minified)) {
|
|
18983
|
+
r.push(minified);
|
|
18984
|
+
}
|
|
18985
|
+
const l = renderToken(matrix).length;
|
|
18986
|
+
node.val = r.reduce((acc, curr) => {
|
|
18987
|
+
if (curr.reduce((acc, t) => acc + renderToken(t), '').length < l) {
|
|
18988
|
+
return curr;
|
|
18989
|
+
}
|
|
18990
|
+
return acc;
|
|
18991
|
+
}, [matrix]);
|
|
18992
|
+
}
|
|
18993
|
+
}
|
|
18994
|
+
}
|
|
18995
|
+
|
|
18996
|
+
var allFeatures = /*#__PURE__*/Object.freeze({
|
|
18997
|
+
__proto__: null,
|
|
18998
|
+
ComputeCalcExpressionFeature: ComputeCalcExpressionFeature,
|
|
18999
|
+
ComputePrefixFeature: ComputePrefixFeature,
|
|
19000
|
+
ComputeShorthandFeature: ComputeShorthandFeature,
|
|
19001
|
+
InlineCssVariablesFeature: InlineCssVariablesFeature,
|
|
19002
|
+
TransformCssFeature: TransformCssFeature
|
|
19003
|
+
});
|
|
19004
|
+
|
|
19005
|
+
const combinators = ['+', '>', '~', '||', '|'];
|
|
19006
|
+
const definedPropertySettings = { configurable: true, enumerable: false, writable: true };
|
|
19007
|
+
const notEndingWith = ['(', '['].concat(combinators);
|
|
19008
|
+
// @ts-ignore
|
|
19009
|
+
const features = Object.values(allFeatures).sort((a, b) => a.ordering - b.ordering);
|
|
19010
|
+
/**
|
|
19011
|
+
* minify ast
|
|
19012
|
+
* @param ast
|
|
19013
|
+
* @param options
|
|
19014
|
+
* @param recursive
|
|
19015
|
+
* @param errors
|
|
19016
|
+
* @param nestingContent
|
|
19017
|
+
* @param context
|
|
19018
|
+
*/
|
|
19019
|
+
function minify(ast, options = {}, recursive = false, errors, nestingContent, context = {}) {
|
|
19020
|
+
if (!('nodes' in context)) {
|
|
19021
|
+
context.nodes = new Set;
|
|
19022
|
+
}
|
|
19023
|
+
if (context.nodes.has(ast)) {
|
|
19024
|
+
return ast;
|
|
19025
|
+
}
|
|
19026
|
+
context.nodes.add(ast);
|
|
19027
|
+
if (!('features' in options)) {
|
|
19028
|
+
// @ts-ignore
|
|
19029
|
+
options = {
|
|
19030
|
+
removeDuplicateDeclarations: true,
|
|
19031
|
+
computeShorthand: true,
|
|
19032
|
+
computeCalcExpression: true,
|
|
19033
|
+
removePrefix: false,
|
|
19034
|
+
features: [], ...options
|
|
19035
|
+
};
|
|
19036
|
+
// @ts-ignore
|
|
19037
|
+
for (const feature of features) {
|
|
19038
|
+
feature.register(options);
|
|
19039
|
+
}
|
|
19040
|
+
}
|
|
19041
|
+
function reducer(acc, curr, index, array) {
|
|
19042
|
+
// trim :is()
|
|
19043
|
+
if (array.length == 1 && array[0][0] == ':is(' && array[0].at(-1) == ')') {
|
|
19044
|
+
curr = curr.slice(1, -1);
|
|
19045
|
+
}
|
|
19046
|
+
if (curr[0] == '&') {
|
|
19047
|
+
if (curr[1] == ' ' && !isIdent(curr[2]) && !isFunction(curr[2])) {
|
|
19048
|
+
curr.splice(0, 2);
|
|
19049
|
+
}
|
|
19050
|
+
else if (combinators.includes(curr[1])) {
|
|
19051
|
+
curr.shift();
|
|
19052
|
+
}
|
|
19053
|
+
}
|
|
19054
|
+
else if (ast.typ == exports.EnumToken.RuleNodeType && (isIdent(curr[0]) || isFunction(curr[0]))) {
|
|
19055
|
+
curr.unshift('&', ' ');
|
|
19056
|
+
}
|
|
19057
|
+
acc.push(curr.join(''));
|
|
19058
|
+
return acc;
|
|
19059
|
+
}
|
|
19060
|
+
// @ts-ignore
|
|
19061
|
+
if ('chi' in ast && ast.chi.length > 0) {
|
|
19062
|
+
if (!nestingContent) {
|
|
19063
|
+
nestingContent = options.nestingRules && ast.typ == exports.EnumToken.RuleNodeType;
|
|
19064
|
+
}
|
|
19065
|
+
let i = 0;
|
|
19066
|
+
let previous = null;
|
|
17791
19067
|
let node;
|
|
17792
|
-
let nodeIndex;
|
|
19068
|
+
let nodeIndex = -1;
|
|
17793
19069
|
// @ts-ignore
|
|
17794
19070
|
for (; i < ast.chi.length; i++) {
|
|
17795
19071
|
// @ts-ignore
|
|
@@ -17801,13 +19077,50 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
|
|
|
17801
19077
|
// @ts-ignore
|
|
17802
19078
|
if (previous == node) {
|
|
17803
19079
|
// @ts-ignore
|
|
17804
|
-
ast.chi.splice(i
|
|
17805
|
-
i--;
|
|
19080
|
+
ast.chi.splice(i--, 1);
|
|
17806
19081
|
continue;
|
|
17807
19082
|
}
|
|
17808
19083
|
if (node.typ == exports.EnumToken.AtRuleNodeType && node.nam == 'font-face') {
|
|
17809
19084
|
continue;
|
|
17810
19085
|
}
|
|
19086
|
+
if (node.typ == exports.EnumToken.KeyframeAtRuleNodeType) {
|
|
19087
|
+
if (previous?.typ == exports.EnumToken.KeyframeAtRuleNodeType &&
|
|
19088
|
+
node.nam == previous.nam &&
|
|
19089
|
+
node.val == previous.val) {
|
|
19090
|
+
ast.chi?.splice(nodeIndex--, 1);
|
|
19091
|
+
previous = ast?.chi?.[nodeIndex] ?? null;
|
|
19092
|
+
i = nodeIndex;
|
|
19093
|
+
continue;
|
|
19094
|
+
}
|
|
19095
|
+
if (node.chi.length > 0) {
|
|
19096
|
+
minify(node, options, true, errors, nestingContent, context);
|
|
19097
|
+
}
|
|
19098
|
+
}
|
|
19099
|
+
if (node.typ == exports.EnumToken.KeyFrameRuleNodeType) {
|
|
19100
|
+
if (previous?.typ == exports.EnumToken.KeyFrameRuleNodeType &&
|
|
19101
|
+
node.sel == previous.sel) {
|
|
19102
|
+
previous.chi.push(...node.chi);
|
|
19103
|
+
// @ts-ignore
|
|
19104
|
+
ast.chi.splice(i--, 1);
|
|
19105
|
+
continue;
|
|
19106
|
+
}
|
|
19107
|
+
let k;
|
|
19108
|
+
for (k = 0; k < node.chi.length; k++) {
|
|
19109
|
+
if (node.chi[k].typ == exports.EnumToken.DeclarationNodeType) {
|
|
19110
|
+
let l = node.chi[k].val.length;
|
|
19111
|
+
while (l--) {
|
|
19112
|
+
if (node.chi[k].val[l].typ == exports.EnumToken.ImportantTokenType) {
|
|
19113
|
+
node.chi.splice(k--, 1);
|
|
19114
|
+
break;
|
|
19115
|
+
}
|
|
19116
|
+
if ([exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(node.chi[k].val[l].typ)) {
|
|
19117
|
+
continue;
|
|
19118
|
+
}
|
|
19119
|
+
break;
|
|
19120
|
+
}
|
|
19121
|
+
}
|
|
19122
|
+
}
|
|
19123
|
+
}
|
|
17811
19124
|
if (node.typ == exports.EnumToken.AtRuleNodeType) {
|
|
17812
19125
|
// @ts-ignore
|
|
17813
19126
|
if (node.nam == 'media' && ['all', '', null].includes(node.val)) {
|
|
@@ -18058,6 +19371,10 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
|
|
|
18058
19371
|
}
|
|
18059
19372
|
}
|
|
18060
19373
|
}
|
|
19374
|
+
// else if ('chi' in node) {
|
|
19375
|
+
//
|
|
19376
|
+
// minify(node, options, recursive, errors, nestingContent, context);
|
|
19377
|
+
// }
|
|
18061
19378
|
if (!nestingContent &&
|
|
18062
19379
|
// @ts-ignore
|
|
18063
19380
|
previous != null &&
|
|
@@ -18072,7 +19389,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
|
|
|
18072
19389
|
// @ts-ignore
|
|
18073
19390
|
if (recursive && node != null && ('chi' in node)) {
|
|
18074
19391
|
// @ts-ignore
|
|
18075
|
-
if (!node.chi.some(n => n.typ == exports.EnumToken.DeclarationNodeType)) {
|
|
19392
|
+
if (node.typ == exports.EnumToken.KeyframeAtRuleNodeType || !node.chi.some(n => n.typ == exports.EnumToken.DeclarationNodeType)) {
|
|
18076
19393
|
// @ts-ignore
|
|
18077
19394
|
if (!(node.typ == exports.EnumToken.AtRuleNodeType && node.nam != 'font-face')) {
|
|
18078
19395
|
minify(node, options, recursive, errors, nestingContent, context);
|
|
@@ -18733,7 +20050,7 @@ function parseResponse(response) {
|
|
|
18733
20050
|
}
|
|
18734
20051
|
return response.text();
|
|
18735
20052
|
}
|
|
18736
|
-
async function load(url, currentFile) {
|
|
20053
|
+
async function load(url, currentFile = '.') {
|
|
18737
20054
|
const resolved = resolve(url, currentFile);
|
|
18738
20055
|
return matchUrl.test(resolved.absolute) ? fetch(resolved.absolute).then(parseResponse) : promises.readFile(resolved.absolute, { encoding: 'utf-8' });
|
|
18739
20056
|
}
|