@tbela99/css-parser 1.4.9 → 1.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/dist/index-umd-web.js +89 -129
- package/dist/index.cjs +89 -129
- package/dist/index.d.ts +1684 -1684
- package/dist/lib/ast/math/math.js +2 -1
- package/dist/lib/ast/transform/compute.js +2 -1
- package/dist/lib/ast/types.js +1 -66
- package/dist/lib/renderer/render.js +6 -47
- package/dist/lib/syntax/color/color.js +3 -21
- package/dist/lib/syntax/color/utils/distance.js +2 -1
- package/dist/lib/syntax/syntax.js +86 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[](https://tbela99.github.io/css-parser/playground/) [](https://www.npmjs.com/package/@tbela99/css-parser) [](https://jsr.io/@tbela99/css-parser) [](https://jsr.io/@tbela99/css-parser) [](https://github.com/tbela99/css-parser/actions) [](https://tbela99.github.io/css-parser/docs) [](https://www.npmjs.com/package/@tbela99/css-parser) [](https://www.npmjs.com/package/@tbela99/css-parser)
|
|
4
4
|
|
|
5
5
|
# css-parser
|
|
6
6
|
|
package/dist/index-umd-web.js
CHANGED
|
@@ -982,71 +982,6 @@
|
|
|
982
982
|
*/
|
|
983
983
|
ModuleScopeEnumOptions[ModuleScopeEnumOptions["Shortest"] = 512] = "Shortest";
|
|
984
984
|
})(exports.ModuleScopeEnumOptions || (exports.ModuleScopeEnumOptions = {}));
|
|
985
|
-
// https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Values_and_units#absolute_length_units
|
|
986
|
-
/**
|
|
987
|
-
* Convert length to px
|
|
988
|
-
* @param value
|
|
989
|
-
* @returns
|
|
990
|
-
*/
|
|
991
|
-
function length2Px(value) {
|
|
992
|
-
let result = null;
|
|
993
|
-
if (value.typ == exports.EnumToken.NumberTokenType) {
|
|
994
|
-
result = +value.val;
|
|
995
|
-
}
|
|
996
|
-
else {
|
|
997
|
-
switch (value.unit) {
|
|
998
|
-
case "cm":
|
|
999
|
-
// @ts-ignore
|
|
1000
|
-
result = value.val * 37.8;
|
|
1001
|
-
break;
|
|
1002
|
-
case "mm":
|
|
1003
|
-
// @ts-ignore
|
|
1004
|
-
result = value.val * 3.78;
|
|
1005
|
-
break;
|
|
1006
|
-
case "Q":
|
|
1007
|
-
// @ts-ignore
|
|
1008
|
-
result = (value.val * 37.8) / 40;
|
|
1009
|
-
break;
|
|
1010
|
-
case "in":
|
|
1011
|
-
// @ts-ignore
|
|
1012
|
-
result = value.val / 96;
|
|
1013
|
-
break;
|
|
1014
|
-
case "pc":
|
|
1015
|
-
// @ts-ignore
|
|
1016
|
-
result = value.val / 16;
|
|
1017
|
-
break;
|
|
1018
|
-
case "pt":
|
|
1019
|
-
// @ts-ignore
|
|
1020
|
-
result = (value.val * 4) / 3;
|
|
1021
|
-
break;
|
|
1022
|
-
case "px":
|
|
1023
|
-
result = +value.val;
|
|
1024
|
-
break;
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
return isNaN(result) ? null : result;
|
|
1028
|
-
}
|
|
1029
|
-
/**
|
|
1030
|
-
* minify number
|
|
1031
|
-
* @param val
|
|
1032
|
-
*/
|
|
1033
|
-
function minifyNumber(val) {
|
|
1034
|
-
val = String(val);
|
|
1035
|
-
if (val === "0") {
|
|
1036
|
-
return "0";
|
|
1037
|
-
}
|
|
1038
|
-
const chr = val.charAt(0);
|
|
1039
|
-
if (chr == "-") {
|
|
1040
|
-
const slice = val.slice(0, 2);
|
|
1041
|
-
if (slice == "-0") {
|
|
1042
|
-
return val.length == 2 ? "0" : "-" + val.slice(2);
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
if (chr == "0") {
|
|
1046
|
-
return val.slice(1);
|
|
1047
|
-
}
|
|
1048
|
-
return val;
|
|
1049
|
-
}
|
|
1050
985
|
|
|
1051
986
|
var declarations = {
|
|
1052
987
|
"-ms-accelerator": {
|
|
@@ -9006,7 +8941,7 @@
|
|
|
9006
8941
|
// @ts-ignore
|
|
9007
8942
|
return lp32p3(...xyz2lp3(...srgb2xyz(r, g, b, alpha)));
|
|
9008
8943
|
}
|
|
9009
|
-
function srgb2lp3values
|
|
8944
|
+
function srgb2lp3values(r, g, b, alpha) {
|
|
9010
8945
|
// @ts-ignore
|
|
9011
8946
|
return xyz2lp3(...srgb2xyz(r, g, b, alpha));
|
|
9012
8947
|
}
|
|
@@ -9165,7 +9100,7 @@
|
|
|
9165
9100
|
break;
|
|
9166
9101
|
case "display-p3-linear":
|
|
9167
9102
|
// @ts-ignore
|
|
9168
|
-
values = srgb2lp3values
|
|
9103
|
+
values = srgb2lp3values(...values);
|
|
9169
9104
|
break;
|
|
9170
9105
|
case "a98-rgb":
|
|
9171
9106
|
// @ts-ignore
|
|
@@ -14852,24 +14787,6 @@
|
|
|
14852
14787
|
// @ts-ignore
|
|
14853
14788
|
return token.val / 360;
|
|
14854
14789
|
}
|
|
14855
|
-
function toPrecisionValue(value, precision = colorPrecision) {
|
|
14856
|
-
const div = Math.pow(10, precision);
|
|
14857
|
-
value = Math.round(value * div) / div;
|
|
14858
|
-
return Math.abs(value) < epsilon ? 0 : value;
|
|
14859
|
-
}
|
|
14860
|
-
function toPrecisionAngle(angle, precision = colorPrecision, correctValue = true) {
|
|
14861
|
-
angle = toPrecisionValue(angle, precision);
|
|
14862
|
-
if (correctValue && Math.abs(angle) >= 360) {
|
|
14863
|
-
angle %= 360;
|
|
14864
|
-
}
|
|
14865
|
-
if (Math.abs(angle) < anglePrecision) {
|
|
14866
|
-
angle = 0;
|
|
14867
|
-
}
|
|
14868
|
-
if (correctValue && angle < 0) {
|
|
14869
|
-
angle += 360;
|
|
14870
|
-
}
|
|
14871
|
-
return angle;
|
|
14872
|
-
}
|
|
14873
14790
|
|
|
14874
14791
|
/**
|
|
14875
14792
|
* Calculate the distance between two okLab colors.
|
|
@@ -16148,6 +16065,90 @@
|
|
|
16148
16065
|
codepoint == 0x2028 ||
|
|
16149
16066
|
codepoint == 0x2029);
|
|
16150
16067
|
}
|
|
16068
|
+
// https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Values_and_units#absolute_length_units
|
|
16069
|
+
/**
|
|
16070
|
+
* Convert length to px
|
|
16071
|
+
* @param value
|
|
16072
|
+
* @returns
|
|
16073
|
+
*/
|
|
16074
|
+
function length2Px(value) {
|
|
16075
|
+
let result = null;
|
|
16076
|
+
if (value.typ == exports.EnumToken.NumberTokenType) {
|
|
16077
|
+
result = +value.val;
|
|
16078
|
+
}
|
|
16079
|
+
else {
|
|
16080
|
+
switch (value.unit) {
|
|
16081
|
+
case "cm":
|
|
16082
|
+
// @ts-ignore
|
|
16083
|
+
result = value.val * 37.8;
|
|
16084
|
+
break;
|
|
16085
|
+
case "mm":
|
|
16086
|
+
// @ts-ignore
|
|
16087
|
+
result = value.val * 3.78;
|
|
16088
|
+
break;
|
|
16089
|
+
case "Q":
|
|
16090
|
+
// @ts-ignore
|
|
16091
|
+
result = (value.val * 37.8) / 40;
|
|
16092
|
+
break;
|
|
16093
|
+
case "in":
|
|
16094
|
+
// @ts-ignore
|
|
16095
|
+
result = value.val / 96;
|
|
16096
|
+
break;
|
|
16097
|
+
case "pc":
|
|
16098
|
+
// @ts-ignore
|
|
16099
|
+
result = value.val / 16;
|
|
16100
|
+
break;
|
|
16101
|
+
case "pt":
|
|
16102
|
+
// @ts-ignore
|
|
16103
|
+
result = (value.val * 4) / 3;
|
|
16104
|
+
break;
|
|
16105
|
+
case "px":
|
|
16106
|
+
result = +value.val;
|
|
16107
|
+
break;
|
|
16108
|
+
}
|
|
16109
|
+
}
|
|
16110
|
+
return isNaN(result) ? null : result;
|
|
16111
|
+
}
|
|
16112
|
+
/**
|
|
16113
|
+
* minify number
|
|
16114
|
+
* @param val
|
|
16115
|
+
*/
|
|
16116
|
+
function minifyNumber(val) {
|
|
16117
|
+
val = String(toPrecisionValue(val));
|
|
16118
|
+
if (val === "0") {
|
|
16119
|
+
return "0";
|
|
16120
|
+
}
|
|
16121
|
+
const chr = val.charAt(0);
|
|
16122
|
+
if (chr == "-") {
|
|
16123
|
+
const slice = val.slice(0, 2);
|
|
16124
|
+
if (slice == "-0") {
|
|
16125
|
+
return val.length == 2 ? "0" : "-" + val.slice(2);
|
|
16126
|
+
}
|
|
16127
|
+
}
|
|
16128
|
+
if (chr == "0") {
|
|
16129
|
+
return val.slice(1);
|
|
16130
|
+
}
|
|
16131
|
+
return val;
|
|
16132
|
+
}
|
|
16133
|
+
function toPrecisionValue(value, precision = colorPrecision) {
|
|
16134
|
+
const div = Math.pow(10, precision);
|
|
16135
|
+
// @ts-ignore
|
|
16136
|
+
value = Math.round(value * div) / div;
|
|
16137
|
+
return Math.abs(value) < epsilon ? 0 : value;
|
|
16138
|
+
}
|
|
16139
|
+
function toPrecisionAngle(angle, precision = colorPrecision, correctValue = true) {
|
|
16140
|
+
angle = toPrecisionValue(angle, precision);
|
|
16141
|
+
if (correctValue && Math.abs(angle) >= 360) {
|
|
16142
|
+
angle %= 360;
|
|
16143
|
+
}
|
|
16144
|
+
if (Math.abs(angle) < anglePrecision) {
|
|
16145
|
+
angle = 0;
|
|
16146
|
+
}
|
|
16147
|
+
if (correctValue && angle < 0) {
|
|
16148
|
+
angle += 360;
|
|
16149
|
+
}
|
|
16150
|
+
return angle;
|
|
16151
|
+
}
|
|
16151
16152
|
|
|
16152
16153
|
function eq(a, b) {
|
|
16153
16154
|
if (a == null || b == null) {
|
|
@@ -24444,10 +24445,10 @@
|
|
|
24444
24445
|
let srcId = node[LOC]?.srcId ?? 0;
|
|
24445
24446
|
let sourceFileName = options.sourcesMap?.get(srcId)?.getFileName?.() || null;
|
|
24446
24447
|
if (sourceFileName != null && options.output != null) {
|
|
24447
|
-
if (
|
|
24448
|
-
cache
|
|
24448
|
+
if (cache[sourceFileName] == null) {
|
|
24449
|
+
cache[sourceFileName] = options.resolve(sourceFileName, dirname(options.output)).relative;
|
|
24449
24450
|
}
|
|
24450
|
-
sourceFileName = cache
|
|
24451
|
+
sourceFileName = cache[sourceFileName];
|
|
24451
24452
|
}
|
|
24452
24453
|
// @ts-ignore
|
|
24453
24454
|
sourcemap.add(...linesMap.getOffsets(sourceLocation.end), srcId,
|
|
@@ -24648,46 +24649,6 @@
|
|
|
24648
24649
|
return acc + renderValue(curr, options, cache, reducer, errors);
|
|
24649
24650
|
};
|
|
24650
24651
|
}
|
|
24651
|
-
// if (token.typ == EnumToken.FunctionTokenType && colorsFunc.includes((token as FunctionToken).val)) {
|
|
24652
|
-
// if (isColor(token)) {
|
|
24653
|
-
// // @ts-ignore
|
|
24654
|
-
// token.typ = EnumToken.ColorTokenType;
|
|
24655
|
-
// if (
|
|
24656
|
-
// // @ts-ignore
|
|
24657
|
-
// (token as ColorToken)!.chi[0]!.typ == EnumToken.IdenTokenType &&
|
|
24658
|
-
// // @ts-ignore
|
|
24659
|
-
// ((token as ColorToken)!.chi[0] as IdentToken).val == "from"
|
|
24660
|
-
// ) {
|
|
24661
|
-
// // @ts-ignore
|
|
24662
|
-
// (<ColorToken>token).cal = "rel";
|
|
24663
|
-
// } else {
|
|
24664
|
-
// // @ts-ignore
|
|
24665
|
-
// if (
|
|
24666
|
-
// (token as ColorToken).val == "color-mix" &&
|
|
24667
|
-
// (token as ColorToken).chi?.[0]?.typ == EnumToken.IdenTokenType &&
|
|
24668
|
-
// ((token as ColorToken).chi?.[0] as IdentToken).val == "in"
|
|
24669
|
-
// ) {
|
|
24670
|
-
// // @ts-ignore
|
|
24671
|
-
// (<ColorToken>token).cal = "mix";
|
|
24672
|
-
// } else {
|
|
24673
|
-
// // @ts-ignore
|
|
24674
|
-
// if ((token as ColorToken).val == "color") {
|
|
24675
|
-
// // @ts-ignore
|
|
24676
|
-
// token.cal = "col";
|
|
24677
|
-
// }
|
|
24678
|
-
// // @ts-ignore
|
|
24679
|
-
// (token as ColorToken).chi = (token as ColorToken).chi!.filter(
|
|
24680
|
-
// (t: Token) =>
|
|
24681
|
-
// ![
|
|
24682
|
-
// EnumToken.WhitespaceTokenType,
|
|
24683
|
-
// EnumToken.CommaTokenType,
|
|
24684
|
-
// EnumToken.CommentTokenType,
|
|
24685
|
-
// ].includes(t.typ),
|
|
24686
|
-
// );
|
|
24687
|
-
// }
|
|
24688
|
-
// }
|
|
24689
|
-
// }
|
|
24690
|
-
// }
|
|
24691
24652
|
switch (token.typ) {
|
|
24692
24653
|
case exports.EnumToken.FunctionTokenDefType:
|
|
24693
24654
|
case exports.EnumToken.UrlFunctionTokenDefType:
|
|
@@ -25482,7 +25443,6 @@
|
|
|
25482
25443
|
if (token.typ == exports.EnumToken.ResolutionTokenType && unit == "dppx") {
|
|
25483
25444
|
unit = "x";
|
|
25484
25445
|
}
|
|
25485
|
-
// @ts-ignore
|
|
25486
25446
|
return val.includes("/") ? val.replace("/", unit + "/") : minifyNumber(toPrecisionValue(val)) + unit;
|
|
25487
25447
|
case exports.EnumToken.FlexTokenType:
|
|
25488
25448
|
case exports.EnumToken.PercentageTokenType:
|
package/dist/index.cjs
CHANGED
|
@@ -985,71 +985,6 @@ exports.ModuleScopeEnumOptions = void 0;
|
|
|
985
985
|
*/
|
|
986
986
|
ModuleScopeEnumOptions[ModuleScopeEnumOptions["Shortest"] = 512] = "Shortest";
|
|
987
987
|
})(exports.ModuleScopeEnumOptions || (exports.ModuleScopeEnumOptions = {}));
|
|
988
|
-
// https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Values_and_units#absolute_length_units
|
|
989
|
-
/**
|
|
990
|
-
* Convert length to px
|
|
991
|
-
* @param value
|
|
992
|
-
* @returns
|
|
993
|
-
*/
|
|
994
|
-
function length2Px(value) {
|
|
995
|
-
let result = null;
|
|
996
|
-
if (value.typ == exports.EnumToken.NumberTokenType) {
|
|
997
|
-
result = +value.val;
|
|
998
|
-
}
|
|
999
|
-
else {
|
|
1000
|
-
switch (value.unit) {
|
|
1001
|
-
case "cm":
|
|
1002
|
-
// @ts-ignore
|
|
1003
|
-
result = value.val * 37.8;
|
|
1004
|
-
break;
|
|
1005
|
-
case "mm":
|
|
1006
|
-
// @ts-ignore
|
|
1007
|
-
result = value.val * 3.78;
|
|
1008
|
-
break;
|
|
1009
|
-
case "Q":
|
|
1010
|
-
// @ts-ignore
|
|
1011
|
-
result = (value.val * 37.8) / 40;
|
|
1012
|
-
break;
|
|
1013
|
-
case "in":
|
|
1014
|
-
// @ts-ignore
|
|
1015
|
-
result = value.val / 96;
|
|
1016
|
-
break;
|
|
1017
|
-
case "pc":
|
|
1018
|
-
// @ts-ignore
|
|
1019
|
-
result = value.val / 16;
|
|
1020
|
-
break;
|
|
1021
|
-
case "pt":
|
|
1022
|
-
// @ts-ignore
|
|
1023
|
-
result = (value.val * 4) / 3;
|
|
1024
|
-
break;
|
|
1025
|
-
case "px":
|
|
1026
|
-
result = +value.val;
|
|
1027
|
-
break;
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
return isNaN(result) ? null : result;
|
|
1031
|
-
}
|
|
1032
|
-
/**
|
|
1033
|
-
* minify number
|
|
1034
|
-
* @param val
|
|
1035
|
-
*/
|
|
1036
|
-
function minifyNumber(val) {
|
|
1037
|
-
val = String(val);
|
|
1038
|
-
if (val === "0") {
|
|
1039
|
-
return "0";
|
|
1040
|
-
}
|
|
1041
|
-
const chr = val.charAt(0);
|
|
1042
|
-
if (chr == "-") {
|
|
1043
|
-
const slice = val.slice(0, 2);
|
|
1044
|
-
if (slice == "-0") {
|
|
1045
|
-
return val.length == 2 ? "0" : "-" + val.slice(2);
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
if (chr == "0") {
|
|
1049
|
-
return val.slice(1);
|
|
1050
|
-
}
|
|
1051
|
-
return val;
|
|
1052
|
-
}
|
|
1053
988
|
|
|
1054
989
|
var declarations = {
|
|
1055
990
|
"-ms-accelerator": {
|
|
@@ -9009,7 +8944,7 @@ function srgb2p3values(r, g, b, alpha) {
|
|
|
9009
8944
|
// @ts-ignore
|
|
9010
8945
|
return lp32p3(...xyz2lp3(...srgb2xyz(r, g, b, alpha)));
|
|
9011
8946
|
}
|
|
9012
|
-
function srgb2lp3values
|
|
8947
|
+
function srgb2lp3values(r, g, b, alpha) {
|
|
9013
8948
|
// @ts-ignore
|
|
9014
8949
|
return xyz2lp3(...srgb2xyz(r, g, b, alpha));
|
|
9015
8950
|
}
|
|
@@ -9168,7 +9103,7 @@ function colorMix(...args) {
|
|
|
9168
9103
|
break;
|
|
9169
9104
|
case "display-p3-linear":
|
|
9170
9105
|
// @ts-ignore
|
|
9171
|
-
values = srgb2lp3values
|
|
9106
|
+
values = srgb2lp3values(...values);
|
|
9172
9107
|
break;
|
|
9173
9108
|
case "a98-rgb":
|
|
9174
9109
|
// @ts-ignore
|
|
@@ -14855,24 +14790,6 @@ function getAngle(token) {
|
|
|
14855
14790
|
// @ts-ignore
|
|
14856
14791
|
return token.val / 360;
|
|
14857
14792
|
}
|
|
14858
|
-
function toPrecisionValue(value, precision = colorPrecision) {
|
|
14859
|
-
const div = Math.pow(10, precision);
|
|
14860
|
-
value = Math.round(value * div) / div;
|
|
14861
|
-
return Math.abs(value) < epsilon ? 0 : value;
|
|
14862
|
-
}
|
|
14863
|
-
function toPrecisionAngle(angle, precision = colorPrecision, correctValue = true) {
|
|
14864
|
-
angle = toPrecisionValue(angle, precision);
|
|
14865
|
-
if (correctValue && Math.abs(angle) >= 360) {
|
|
14866
|
-
angle %= 360;
|
|
14867
|
-
}
|
|
14868
|
-
if (Math.abs(angle) < anglePrecision) {
|
|
14869
|
-
angle = 0;
|
|
14870
|
-
}
|
|
14871
|
-
if (correctValue && angle < 0) {
|
|
14872
|
-
angle += 360;
|
|
14873
|
-
}
|
|
14874
|
-
return angle;
|
|
14875
|
-
}
|
|
14876
14793
|
|
|
14877
14794
|
/**
|
|
14878
14795
|
* Calculate the distance between two okLab colors.
|
|
@@ -16151,6 +16068,90 @@ function isWhiteSpace(codepoint) {
|
|
|
16151
16068
|
codepoint == 0x2028 ||
|
|
16152
16069
|
codepoint == 0x2029);
|
|
16153
16070
|
}
|
|
16071
|
+
// https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Values_and_units#absolute_length_units
|
|
16072
|
+
/**
|
|
16073
|
+
* Convert length to px
|
|
16074
|
+
* @param value
|
|
16075
|
+
* @returns
|
|
16076
|
+
*/
|
|
16077
|
+
function length2Px(value) {
|
|
16078
|
+
let result = null;
|
|
16079
|
+
if (value.typ == exports.EnumToken.NumberTokenType) {
|
|
16080
|
+
result = +value.val;
|
|
16081
|
+
}
|
|
16082
|
+
else {
|
|
16083
|
+
switch (value.unit) {
|
|
16084
|
+
case "cm":
|
|
16085
|
+
// @ts-ignore
|
|
16086
|
+
result = value.val * 37.8;
|
|
16087
|
+
break;
|
|
16088
|
+
case "mm":
|
|
16089
|
+
// @ts-ignore
|
|
16090
|
+
result = value.val * 3.78;
|
|
16091
|
+
break;
|
|
16092
|
+
case "Q":
|
|
16093
|
+
// @ts-ignore
|
|
16094
|
+
result = (value.val * 37.8) / 40;
|
|
16095
|
+
break;
|
|
16096
|
+
case "in":
|
|
16097
|
+
// @ts-ignore
|
|
16098
|
+
result = value.val / 96;
|
|
16099
|
+
break;
|
|
16100
|
+
case "pc":
|
|
16101
|
+
// @ts-ignore
|
|
16102
|
+
result = value.val / 16;
|
|
16103
|
+
break;
|
|
16104
|
+
case "pt":
|
|
16105
|
+
// @ts-ignore
|
|
16106
|
+
result = (value.val * 4) / 3;
|
|
16107
|
+
break;
|
|
16108
|
+
case "px":
|
|
16109
|
+
result = +value.val;
|
|
16110
|
+
break;
|
|
16111
|
+
}
|
|
16112
|
+
}
|
|
16113
|
+
return isNaN(result) ? null : result;
|
|
16114
|
+
}
|
|
16115
|
+
/**
|
|
16116
|
+
* minify number
|
|
16117
|
+
* @param val
|
|
16118
|
+
*/
|
|
16119
|
+
function minifyNumber(val) {
|
|
16120
|
+
val = String(toPrecisionValue(val));
|
|
16121
|
+
if (val === "0") {
|
|
16122
|
+
return "0";
|
|
16123
|
+
}
|
|
16124
|
+
const chr = val.charAt(0);
|
|
16125
|
+
if (chr == "-") {
|
|
16126
|
+
const slice = val.slice(0, 2);
|
|
16127
|
+
if (slice == "-0") {
|
|
16128
|
+
return val.length == 2 ? "0" : "-" + val.slice(2);
|
|
16129
|
+
}
|
|
16130
|
+
}
|
|
16131
|
+
if (chr == "0") {
|
|
16132
|
+
return val.slice(1);
|
|
16133
|
+
}
|
|
16134
|
+
return val;
|
|
16135
|
+
}
|
|
16136
|
+
function toPrecisionValue(value, precision = colorPrecision) {
|
|
16137
|
+
const div = Math.pow(10, precision);
|
|
16138
|
+
// @ts-ignore
|
|
16139
|
+
value = Math.round(value * div) / div;
|
|
16140
|
+
return Math.abs(value) < epsilon ? 0 : value;
|
|
16141
|
+
}
|
|
16142
|
+
function toPrecisionAngle(angle, precision = colorPrecision, correctValue = true) {
|
|
16143
|
+
angle = toPrecisionValue(angle, precision);
|
|
16144
|
+
if (correctValue && Math.abs(angle) >= 360) {
|
|
16145
|
+
angle %= 360;
|
|
16146
|
+
}
|
|
16147
|
+
if (Math.abs(angle) < anglePrecision) {
|
|
16148
|
+
angle = 0;
|
|
16149
|
+
}
|
|
16150
|
+
if (correctValue && angle < 0) {
|
|
16151
|
+
angle += 360;
|
|
16152
|
+
}
|
|
16153
|
+
return angle;
|
|
16154
|
+
}
|
|
16154
16155
|
|
|
16155
16156
|
function eq(a, b) {
|
|
16156
16157
|
if (a == null || b == null) {
|
|
@@ -24447,10 +24448,10 @@ function updateSourceMap(node, options, cache, sourcemap, sourceLocation, linesM
|
|
|
24447
24448
|
let srcId = node[LOC]?.srcId ?? 0;
|
|
24448
24449
|
let sourceFileName = options.sourcesMap?.get(srcId)?.getFileName?.() || null;
|
|
24449
24450
|
if (sourceFileName != null && options.output != null) {
|
|
24450
|
-
if (
|
|
24451
|
-
cache
|
|
24451
|
+
if (cache[sourceFileName] == null) {
|
|
24452
|
+
cache[sourceFileName] = options.resolve(sourceFileName, dirname(options.output)).relative;
|
|
24452
24453
|
}
|
|
24453
|
-
sourceFileName = cache
|
|
24454
|
+
sourceFileName = cache[sourceFileName];
|
|
24454
24455
|
}
|
|
24455
24456
|
// @ts-ignore
|
|
24456
24457
|
sourcemap.add(...linesMap.getOffsets(sourceLocation.end), srcId,
|
|
@@ -24651,46 +24652,6 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
|
|
|
24651
24652
|
return acc + renderValue(curr, options, cache, reducer, errors);
|
|
24652
24653
|
};
|
|
24653
24654
|
}
|
|
24654
|
-
// if (token.typ == EnumToken.FunctionTokenType && colorsFunc.includes((token as FunctionToken).val)) {
|
|
24655
|
-
// if (isColor(token)) {
|
|
24656
|
-
// // @ts-ignore
|
|
24657
|
-
// token.typ = EnumToken.ColorTokenType;
|
|
24658
|
-
// if (
|
|
24659
|
-
// // @ts-ignore
|
|
24660
|
-
// (token as ColorToken)!.chi[0]!.typ == EnumToken.IdenTokenType &&
|
|
24661
|
-
// // @ts-ignore
|
|
24662
|
-
// ((token as ColorToken)!.chi[0] as IdentToken).val == "from"
|
|
24663
|
-
// ) {
|
|
24664
|
-
// // @ts-ignore
|
|
24665
|
-
// (<ColorToken>token).cal = "rel";
|
|
24666
|
-
// } else {
|
|
24667
|
-
// // @ts-ignore
|
|
24668
|
-
// if (
|
|
24669
|
-
// (token as ColorToken).val == "color-mix" &&
|
|
24670
|
-
// (token as ColorToken).chi?.[0]?.typ == EnumToken.IdenTokenType &&
|
|
24671
|
-
// ((token as ColorToken).chi?.[0] as IdentToken).val == "in"
|
|
24672
|
-
// ) {
|
|
24673
|
-
// // @ts-ignore
|
|
24674
|
-
// (<ColorToken>token).cal = "mix";
|
|
24675
|
-
// } else {
|
|
24676
|
-
// // @ts-ignore
|
|
24677
|
-
// if ((token as ColorToken).val == "color") {
|
|
24678
|
-
// // @ts-ignore
|
|
24679
|
-
// token.cal = "col";
|
|
24680
|
-
// }
|
|
24681
|
-
// // @ts-ignore
|
|
24682
|
-
// (token as ColorToken).chi = (token as ColorToken).chi!.filter(
|
|
24683
|
-
// (t: Token) =>
|
|
24684
|
-
// ![
|
|
24685
|
-
// EnumToken.WhitespaceTokenType,
|
|
24686
|
-
// EnumToken.CommaTokenType,
|
|
24687
|
-
// EnumToken.CommentTokenType,
|
|
24688
|
-
// ].includes(t.typ),
|
|
24689
|
-
// );
|
|
24690
|
-
// }
|
|
24691
|
-
// }
|
|
24692
|
-
// }
|
|
24693
|
-
// }
|
|
24694
24655
|
switch (token.typ) {
|
|
24695
24656
|
case exports.EnumToken.FunctionTokenDefType:
|
|
24696
24657
|
case exports.EnumToken.UrlFunctionTokenDefType:
|
|
@@ -25485,7 +25446,6 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
|
|
|
25485
25446
|
if (token.typ == exports.EnumToken.ResolutionTokenType && unit == "dppx") {
|
|
25486
25447
|
unit = "x";
|
|
25487
25448
|
}
|
|
25488
|
-
// @ts-ignore
|
|
25489
25449
|
return val.includes("/") ? val.replace("/", unit + "/") : minifyNumber(toPrecisionValue(val)) + unit;
|
|
25490
25450
|
case exports.EnumToken.FlexTokenType:
|
|
25491
25451
|
case exports.EnumToken.PercentageTokenType:
|