@tbela99/css-parser 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +2 -2
- package/dist/index-umd-web.js +483 -849
- package/dist/index.cjs +483 -849
- package/dist/index.d.ts +107 -11
- package/dist/lib/ast/features/calc.js +1 -25
- package/dist/lib/ast/features/inlinecssvariables.js +0 -19
- package/dist/lib/ast/features/transform.js +2 -2
- package/dist/lib/ast/math/expression.js +26 -149
- package/dist/lib/ast/math/math.js +8 -8
- package/dist/lib/ast/transform/compute.js +4 -37
- package/dist/lib/ast/transform/matrix.js +33 -34
- package/dist/lib/ast/transform/minify.js +32 -51
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.js +13 -13
- package/dist/lib/ast/transform/scale.js +8 -8
- package/dist/lib/ast/transform/skew.js +4 -4
- package/dist/lib/ast/transform/translate.js +8 -8
- package/dist/lib/ast/transform/utils.js +31 -39
- package/dist/lib/ast/types.js +91 -2
- package/dist/lib/parser/declaration/set.js +2 -2
- package/dist/lib/parser/parse.js +34 -12
- package/dist/lib/parser/tokenize.js +28 -40
- package/dist/lib/parser/utils/type.js +1 -1
- package/dist/lib/renderer/render.js +36 -27
- package/dist/lib/syntax/color/cmyk.js +2 -2
- package/dist/lib/syntax/color/color-mix.js +11 -12
- package/dist/lib/syntax/color/color.js +7 -7
- package/dist/lib/syntax/color/hsl.js +4 -4
- package/dist/lib/syntax/color/hwb.js +27 -8
- package/dist/lib/syntax/color/lab.js +4 -4
- package/dist/lib/syntax/color/lch.js +4 -4
- package/dist/lib/syntax/color/oklab.js +4 -4
- package/dist/lib/syntax/color/oklch.js +4 -4
- package/dist/lib/syntax/color/relativecolor.js +1 -1
- package/dist/lib/syntax/color/rgb.js +4 -4
- package/dist/lib/syntax/color/utils/components.js +15 -3
- package/dist/lib/syntax/color/utils/distance.js +11 -1
- package/dist/lib/syntax/syntax.js +8 -17
- package/dist/lib/syntax/utils.js +1 -1
- package/dist/lib/validation/at-rules/document.js +1 -1
- package/dist/lib/validation/at-rules/import.js +4 -4
- package/dist/lib/validation/at-rules/keyframes.js +0 -11
- package/dist/lib/validation/at-rules/supports.js +6 -6
- package/dist/lib/validation/config.js +0 -4
- package/dist/lib/validation/parser/parse.js +0 -8
- package/dist/lib/validation/selector.js +0 -9
- package/dist/lib/validation/syntax.js +14 -134
- package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -11
- package/dist/lib/validation/syntaxes/family-name.js +0 -32
- package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -11
- package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -26
- package/dist/lib/validation/syntaxes/url.js +0 -33
- package/dist/lib/validation/utils/list.js +0 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3,11 +3,17 @@
|
|
|
3
3
|
var process = require('node:process');
|
|
4
4
|
var promises = require('node:fs/promises');
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* syntax validation enum
|
|
8
|
+
*/
|
|
6
9
|
var SyntaxValidationResult;
|
|
7
10
|
(function (SyntaxValidationResult) {
|
|
11
|
+
/** valid syntax */
|
|
8
12
|
SyntaxValidationResult[SyntaxValidationResult["Valid"] = 0] = "Valid";
|
|
13
|
+
/** drop invalid syntax */
|
|
9
14
|
SyntaxValidationResult[SyntaxValidationResult["Drop"] = 1] = "Drop";
|
|
10
|
-
|
|
15
|
+
/** preserve unknown at-rules, declarations and pseudo-classes */
|
|
16
|
+
SyntaxValidationResult[SyntaxValidationResult["Lenient"] = 2] = "Lenient";
|
|
11
17
|
})(SyntaxValidationResult || (SyntaxValidationResult = {}));
|
|
12
18
|
/**
|
|
13
19
|
* validation level enum
|
|
@@ -159,35 +165,118 @@ exports.EnumToken = void 0;
|
|
|
159
165
|
EnumToken[EnumToken["TimingFunction"] = 17] = "TimingFunction";
|
|
160
166
|
EnumToken[EnumToken["TimelineFunction"] = 16] = "TimelineFunction";
|
|
161
167
|
})(exports.EnumToken || (exports.EnumToken = {}));
|
|
162
|
-
|
|
168
|
+
/**
|
|
169
|
+
* color types enum
|
|
170
|
+
*/
|
|
163
171
|
exports.ColorType = void 0;
|
|
164
172
|
(function (ColorType) {
|
|
173
|
+
/**
|
|
174
|
+
* system colors
|
|
175
|
+
*/
|
|
165
176
|
ColorType[ColorType["SYS"] = 0] = "SYS";
|
|
177
|
+
/**
|
|
178
|
+
* deprecated system colors
|
|
179
|
+
*/
|
|
166
180
|
ColorType[ColorType["DPSYS"] = 1] = "DPSYS";
|
|
181
|
+
/**
|
|
182
|
+
* colors as literals
|
|
183
|
+
*/
|
|
167
184
|
ColorType[ColorType["LIT"] = 2] = "LIT";
|
|
185
|
+
/**
|
|
186
|
+
* colors as hex values
|
|
187
|
+
*/
|
|
168
188
|
ColorType[ColorType["HEX"] = 3] = "HEX";
|
|
189
|
+
/**
|
|
190
|
+
* colors as rgb values
|
|
191
|
+
*/
|
|
169
192
|
ColorType[ColorType["RGBA"] = 4] = "RGBA";
|
|
193
|
+
/**
|
|
194
|
+
* colors as hsl values
|
|
195
|
+
*/
|
|
170
196
|
ColorType[ColorType["HSLA"] = 5] = "HSLA";
|
|
197
|
+
/**
|
|
198
|
+
* colors as hwb values
|
|
199
|
+
*/
|
|
171
200
|
ColorType[ColorType["HWB"] = 6] = "HWB";
|
|
201
|
+
/**
|
|
202
|
+
* colors as cmyk values
|
|
203
|
+
*/
|
|
172
204
|
ColorType[ColorType["CMYK"] = 7] = "CMYK";
|
|
205
|
+
/**
|
|
206
|
+
* colors as oklab values
|
|
207
|
+
* */
|
|
173
208
|
ColorType[ColorType["OKLAB"] = 8] = "OKLAB";
|
|
209
|
+
/**
|
|
210
|
+
* colors as oklch values
|
|
211
|
+
* */
|
|
174
212
|
ColorType[ColorType["OKLCH"] = 9] = "OKLCH";
|
|
213
|
+
/**
|
|
214
|
+
* colors as lab values
|
|
215
|
+
*/
|
|
175
216
|
ColorType[ColorType["LAB"] = 10] = "LAB";
|
|
217
|
+
/**
|
|
218
|
+
* colors as lch values
|
|
219
|
+
*/
|
|
176
220
|
ColorType[ColorType["LCH"] = 11] = "LCH";
|
|
221
|
+
/**
|
|
222
|
+
* colors using color() function
|
|
223
|
+
*/
|
|
177
224
|
ColorType[ColorType["COLOR"] = 12] = "COLOR";
|
|
225
|
+
/**
|
|
226
|
+
* color using srgb values
|
|
227
|
+
*/
|
|
178
228
|
ColorType[ColorType["SRGB"] = 13] = "SRGB";
|
|
229
|
+
/**
|
|
230
|
+
* color using prophoto-rgb values
|
|
231
|
+
*/
|
|
179
232
|
ColorType[ColorType["PROPHOTO_RGB"] = 14] = "PROPHOTO_RGB";
|
|
233
|
+
/**
|
|
234
|
+
* color using a98-rgb values
|
|
235
|
+
*/
|
|
180
236
|
ColorType[ColorType["A98_RGB"] = 15] = "A98_RGB";
|
|
237
|
+
/**
|
|
238
|
+
* color using rec2020 values
|
|
239
|
+
*/
|
|
181
240
|
ColorType[ColorType["REC2020"] = 16] = "REC2020";
|
|
241
|
+
/**
|
|
242
|
+
* color using display-p3 values
|
|
243
|
+
*/
|
|
182
244
|
ColorType[ColorType["DISPLAY_P3"] = 17] = "DISPLAY_P3";
|
|
245
|
+
/**
|
|
246
|
+
* color using srgb-linear values
|
|
247
|
+
*/
|
|
183
248
|
ColorType[ColorType["SRGB_LINEAR"] = 18] = "SRGB_LINEAR";
|
|
249
|
+
/**
|
|
250
|
+
* color using xyz-d50 values
|
|
251
|
+
*/
|
|
184
252
|
ColorType[ColorType["XYZ_D50"] = 19] = "XYZ_D50";
|
|
253
|
+
/**
|
|
254
|
+
* color using xyz-d65 values
|
|
255
|
+
*/
|
|
185
256
|
ColorType[ColorType["XYZ_D65"] = 20] = "XYZ_D65";
|
|
257
|
+
/**
|
|
258
|
+
* light-dark() color function
|
|
259
|
+
*/
|
|
186
260
|
ColorType[ColorType["LIGHT_DARK"] = 21] = "LIGHT_DARK";
|
|
261
|
+
/**
|
|
262
|
+
* color-mix() color function
|
|
263
|
+
*/
|
|
187
264
|
ColorType[ColorType["COLOR_MIX"] = 22] = "COLOR_MIX";
|
|
265
|
+
/**
|
|
266
|
+
* alias for rgba
|
|
267
|
+
*/
|
|
188
268
|
ColorType[ColorType["RGB"] = 4] = "RGB";
|
|
269
|
+
/**
|
|
270
|
+
* alias for hsl
|
|
271
|
+
*/
|
|
189
272
|
ColorType[ColorType["HSL"] = 5] = "HSL";
|
|
273
|
+
/**
|
|
274
|
+
* alias for xyz-d65
|
|
275
|
+
*/
|
|
190
276
|
ColorType[ColorType["XYZ"] = 20] = "XYZ";
|
|
277
|
+
/**
|
|
278
|
+
* alias for cmyk
|
|
279
|
+
*/
|
|
191
280
|
ColorType[ColorType["DEVICE_CMYK"] = 7] = "DEVICE_CMYK";
|
|
192
281
|
})(exports.ColorType || (exports.ColorType = {}));
|
|
193
282
|
|
|
@@ -496,12 +585,12 @@ function color2lchToken(token) {
|
|
|
496
585
|
function lchToken(values) {
|
|
497
586
|
values[2] = toPrecisionAngle(values[2]);
|
|
498
587
|
const chi = [
|
|
499
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
500
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
501
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
588
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
589
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[1] },
|
|
590
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[2] },
|
|
502
591
|
];
|
|
503
592
|
if (values.length == 4) {
|
|
504
|
-
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: '/' }, { typ: exports.EnumToken.PercentageTokenType, val:
|
|
593
|
+
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: '/' }, { typ: exports.EnumToken.PercentageTokenType, val: values[3] * 100 });
|
|
505
594
|
}
|
|
506
595
|
return {
|
|
507
596
|
typ: exports.EnumToken.ColorTokenType,
|
|
@@ -764,14 +853,14 @@ function color2oklchToken(token) {
|
|
|
764
853
|
function oklchToken(values) {
|
|
765
854
|
values[2] = toPrecisionAngle(values[2]);
|
|
766
855
|
const chi = [
|
|
767
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
768
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
769
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
856
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
857
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[1] },
|
|
858
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[2] },
|
|
770
859
|
];
|
|
771
860
|
if (values.length == 4) {
|
|
772
861
|
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: '/' }, {
|
|
773
862
|
typ: exports.EnumToken.PercentageTokenType,
|
|
774
|
-
val:
|
|
863
|
+
val: values[3] * 100
|
|
775
864
|
});
|
|
776
865
|
}
|
|
777
866
|
return {
|
|
@@ -916,14 +1005,14 @@ function color2oklabToken(token) {
|
|
|
916
1005
|
}
|
|
917
1006
|
function oklabToken(values) {
|
|
918
1007
|
const chi = [
|
|
919
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
920
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
921
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
1008
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
1009
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[1] },
|
|
1010
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[2] },
|
|
922
1011
|
];
|
|
923
1012
|
if (values.length == 4) {
|
|
924
1013
|
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: '/' }, {
|
|
925
1014
|
typ: exports.EnumToken.PercentageTokenType,
|
|
926
|
-
val:
|
|
1015
|
+
val: values[3] * 100
|
|
927
1016
|
});
|
|
928
1017
|
}
|
|
929
1018
|
return {
|
|
@@ -1134,14 +1223,14 @@ function color2labToken(token) {
|
|
|
1134
1223
|
}
|
|
1135
1224
|
function labToken(values) {
|
|
1136
1225
|
const chi = [
|
|
1137
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
1138
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
1139
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
1226
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
1227
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[1] },
|
|
1228
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[2] },
|
|
1140
1229
|
];
|
|
1141
1230
|
if (values.length == 4) {
|
|
1142
1231
|
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: '/' }, {
|
|
1143
1232
|
typ: exports.EnumToken.PercentageTokenType,
|
|
1144
|
-
val:
|
|
1233
|
+
val: values[3] * 100
|
|
1145
1234
|
});
|
|
1146
1235
|
}
|
|
1147
1236
|
return {
|
|
@@ -1765,7 +1854,7 @@ function getComponents(token) {
|
|
|
1765
1854
|
const value = expandHexValue(token.kin == exports.ColorType.LIT ? COLORS_NAMES[token.val.toLowerCase()] : token.val);
|
|
1766
1855
|
// @ts-ignore
|
|
1767
1856
|
return value.slice(1).match(/([a-fA-F0-9]{2})/g).map((t, index) => {
|
|
1768
|
-
return { typ: exports.EnumToken.Number, val:
|
|
1857
|
+
return { typ: exports.EnumToken.Number, val: index < 3 ? parseInt(t, 16) : parseInt(t, 16) / 255 };
|
|
1769
1858
|
});
|
|
1770
1859
|
}
|
|
1771
1860
|
const result = [];
|
|
@@ -1775,7 +1864,19 @@ function getComponents(token) {
|
|
|
1775
1864
|
].includes(child.typ)) {
|
|
1776
1865
|
continue;
|
|
1777
1866
|
}
|
|
1778
|
-
if (child.typ == exports.EnumToken.
|
|
1867
|
+
if (child.typ == exports.EnumToken.FunctionTokenType) {
|
|
1868
|
+
if ('var' == child.val.toLowerCase()) {
|
|
1869
|
+
return null;
|
|
1870
|
+
}
|
|
1871
|
+
else {
|
|
1872
|
+
for (const { value } of walkValues(child.chi)) {
|
|
1873
|
+
if (value.typ == exports.EnumToken.FunctionTokenType && 'var' === value.val.toLowerCase()) {
|
|
1874
|
+
return null;
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
if (child.typ == exports.EnumToken.ColorTokenType && 'currentcolor' === child.val.toLowerCase()) {
|
|
1779
1880
|
return null;
|
|
1780
1881
|
}
|
|
1781
1882
|
result.push(child);
|
|
@@ -1783,13 +1884,23 @@ function getComponents(token) {
|
|
|
1783
1884
|
return result;
|
|
1784
1885
|
}
|
|
1785
1886
|
|
|
1887
|
+
/**
|
|
1888
|
+
* Calculate the distance between two okLab colors.
|
|
1889
|
+
* @param okLab1
|
|
1890
|
+
* @param okLab2
|
|
1891
|
+
*/
|
|
1786
1892
|
function okLabDistance(okLab1, okLab2) {
|
|
1787
1893
|
return Math.sqrt(Math.pow(okLab1[0] - okLab2[0], 2) + Math.pow(okLab1[1] - okLab2[1], 2) + Math.pow(okLab1[2] - okLab2[2], 2));
|
|
1788
1894
|
}
|
|
1895
|
+
/**
|
|
1896
|
+
* Check if two colors are close.
|
|
1897
|
+
* @param color1
|
|
1898
|
+
* @param color2
|
|
1899
|
+
* @param threshold
|
|
1900
|
+
*/
|
|
1789
1901
|
function isOkLabClose(color1, color2, threshold = .01) {
|
|
1790
1902
|
color1 = convertColor(color1, exports.ColorType.OKLAB);
|
|
1791
1903
|
color2 = convertColor(color2, exports.ColorType.OKLAB);
|
|
1792
|
-
// console.error(JSON.stringify({color1, color2}, null, 1));
|
|
1793
1904
|
if (color1 == null || color2 == null) {
|
|
1794
1905
|
return false;
|
|
1795
1906
|
}
|
|
@@ -1865,12 +1976,12 @@ function color2RgbToken(token) {
|
|
|
1865
1976
|
}
|
|
1866
1977
|
function rgb2RgbToken(values) {
|
|
1867
1978
|
const chi = [
|
|
1868
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
1869
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
1870
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
1979
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
1980
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[1] },
|
|
1981
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[2] },
|
|
1871
1982
|
];
|
|
1872
1983
|
if (values.length == 4) {
|
|
1873
|
-
chi.push({ typ: exports.EnumToken.PercentageTokenType, val:
|
|
1984
|
+
chi.push({ typ: exports.EnumToken.PercentageTokenType, val: values[3] * 100 });
|
|
1874
1985
|
}
|
|
1875
1986
|
return {
|
|
1876
1987
|
typ: exports.EnumToken.ColorTokenType,
|
|
@@ -2011,12 +2122,12 @@ function color2HslToken(token) {
|
|
|
2011
2122
|
function hslToken(values) {
|
|
2012
2123
|
values[0] = toPrecisionAngle(values[0] * 360);
|
|
2013
2124
|
const chi = [
|
|
2014
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
2015
|
-
{ typ: exports.EnumToken.PercentageTokenType, val:
|
|
2016
|
-
{ typ: exports.EnumToken.PercentageTokenType, val:
|
|
2125
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
2126
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[1] * 100 },
|
|
2127
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[2] * 100 },
|
|
2017
2128
|
];
|
|
2018
2129
|
if (values.length == 4 && values[3] != 1) {
|
|
2019
|
-
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: '/' }, { typ: exports.EnumToken.PercentageTokenType, val:
|
|
2130
|
+
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: '/' }, { typ: exports.EnumToken.PercentageTokenType, val: values[3] * 100 });
|
|
2020
2131
|
}
|
|
2021
2132
|
return {
|
|
2022
2133
|
typ: exports.EnumToken.ColorTokenType,
|
|
@@ -2192,12 +2303,15 @@ function color2hwbToken(token) {
|
|
|
2192
2303
|
function hwbToken(values) {
|
|
2193
2304
|
values[0] = toPrecisionAngle(values[0] * 360);
|
|
2194
2305
|
const chi = [
|
|
2195
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
2196
|
-
{ typ: exports.EnumToken.PercentageTokenType, val:
|
|
2197
|
-
{ typ: exports.EnumToken.PercentageTokenType, val:
|
|
2306
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
2307
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[1] * 100 },
|
|
2308
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[2] * 100 },
|
|
2198
2309
|
];
|
|
2199
2310
|
if (values.length == 4) {
|
|
2200
|
-
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: '/' }, {
|
|
2311
|
+
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: '/' }, {
|
|
2312
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
2313
|
+
val: values[3] * 100
|
|
2314
|
+
});
|
|
2201
2315
|
}
|
|
2202
2316
|
return {
|
|
2203
2317
|
typ: exports.EnumToken.ColorTokenType,
|
|
@@ -2232,16 +2346,28 @@ function hsl2hwbvalues(token) {
|
|
|
2232
2346
|
}));
|
|
2233
2347
|
}
|
|
2234
2348
|
function lab2hwbvalues(token) {
|
|
2349
|
+
const values = lab2srgbvalues(token);
|
|
2350
|
+
if (values == null) {
|
|
2351
|
+
return null;
|
|
2352
|
+
}
|
|
2235
2353
|
// @ts-ignore
|
|
2236
|
-
return srgb2hwb(...
|
|
2354
|
+
return srgb2hwb(...values);
|
|
2237
2355
|
}
|
|
2238
2356
|
function lch2hwbvalues(token) {
|
|
2357
|
+
const values = lch2srgbvalues(token);
|
|
2358
|
+
if (values == null) {
|
|
2359
|
+
return null;
|
|
2360
|
+
}
|
|
2239
2361
|
// @ts-ignore
|
|
2240
|
-
return srgb2hwb(...
|
|
2362
|
+
return srgb2hwb(...values);
|
|
2241
2363
|
}
|
|
2242
2364
|
function oklab2hwbvalues(token) {
|
|
2365
|
+
const values = oklab2srgbvalues(token);
|
|
2366
|
+
if (values == null) {
|
|
2367
|
+
return null;
|
|
2368
|
+
}
|
|
2243
2369
|
// @ts-ignore
|
|
2244
|
-
return srgb2hwb(...
|
|
2370
|
+
return srgb2hwb(...values);
|
|
2245
2371
|
}
|
|
2246
2372
|
function oklch2hwbvalues(token) {
|
|
2247
2373
|
const values = oklch2srgbvalues(token);
|
|
@@ -2275,8 +2401,12 @@ function rgb2whiteness(r, g, b) {
|
|
|
2275
2401
|
return Math.min(r, g, b);
|
|
2276
2402
|
}
|
|
2277
2403
|
function color2hwbvalues(token) {
|
|
2404
|
+
const values = color2srgbvalues(token);
|
|
2405
|
+
if (values == null) {
|
|
2406
|
+
return null;
|
|
2407
|
+
}
|
|
2278
2408
|
// @ts-ignore
|
|
2279
|
-
return srgb2hwb(...
|
|
2409
|
+
return srgb2hwb(...values);
|
|
2280
2410
|
}
|
|
2281
2411
|
function srgb2hwb(r, g, b, a = null, fallback = 0) {
|
|
2282
2412
|
r *= 100;
|
|
@@ -2497,7 +2627,7 @@ function interpolateHue(interpolationMethod, h1, h2) {
|
|
|
2497
2627
|
return [h1, h2];
|
|
2498
2628
|
}
|
|
2499
2629
|
function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color2, percentage2) {
|
|
2500
|
-
if (color1.val == 'currentcolor' || color2.val == 'currentcolor') {
|
|
2630
|
+
if (color1.val.toLowerCase() == 'currentcolor' || color2.val == 'currentcolor'.toLowerCase()) {
|
|
2501
2631
|
return null;
|
|
2502
2632
|
}
|
|
2503
2633
|
if (hueInterpolationMethod != null && isRectangularOrthogonalColorspace(colorSpace)) {
|
|
@@ -2509,20 +2639,19 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
|
|
|
2509
2639
|
if (percentage1 == null) {
|
|
2510
2640
|
if (percentage2 == null) {
|
|
2511
2641
|
// @ts-ignore
|
|
2512
|
-
percentage1 = { typ: exports.EnumToken.NumberTokenType, val:
|
|
2642
|
+
percentage1 = { typ: exports.EnumToken.NumberTokenType, val: .5 };
|
|
2513
2643
|
// @ts-ignore
|
|
2514
|
-
percentage2 = { typ: exports.EnumToken.NumberTokenType, val:
|
|
2644
|
+
percentage2 = { typ: exports.EnumToken.NumberTokenType, val: .5 };
|
|
2515
2645
|
}
|
|
2516
2646
|
else {
|
|
2517
2647
|
if (+percentage2.val <= 0) {
|
|
2518
2648
|
return null;
|
|
2519
2649
|
}
|
|
2520
2650
|
if (+percentage2.val >= 100) {
|
|
2521
|
-
|
|
2522
|
-
percentage2 = { typ: exports.EnumToken.NumberTokenType, val: '1' };
|
|
2651
|
+
percentage2 = { typ: exports.EnumToken.NumberTokenType, val: 1 };
|
|
2523
2652
|
}
|
|
2524
2653
|
// @ts-ignore
|
|
2525
|
-
percentage1 = { typ: exports.EnumToken.NumberTokenType, val:
|
|
2654
|
+
percentage1 = { typ: exports.EnumToken.NumberTokenType, val: 1 - percentage2.val / 100 };
|
|
2526
2655
|
}
|
|
2527
2656
|
}
|
|
2528
2657
|
else {
|
|
@@ -2534,10 +2663,10 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
|
|
|
2534
2663
|
// @ts-ignore
|
|
2535
2664
|
if (percentage1.val >= 100) {
|
|
2536
2665
|
// @ts-ignore
|
|
2537
|
-
percentage1 = { typ: exports.EnumToken.NumberTokenType, val:
|
|
2666
|
+
percentage1 = { typ: exports.EnumToken.NumberTokenType, val: 1 };
|
|
2538
2667
|
}
|
|
2539
2668
|
// @ts-ignore
|
|
2540
|
-
percentage2 = { typ: exports.EnumToken.NumberTokenType, val:
|
|
2669
|
+
percentage2 = { typ: exports.EnumToken.NumberTokenType, val: 1 - percentage1.val / 100 };
|
|
2541
2670
|
}
|
|
2542
2671
|
else {
|
|
2543
2672
|
// @ts-ignore
|
|
@@ -2715,7 +2844,7 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
|
|
|
2715
2844
|
chi: values.map(v => {
|
|
2716
2845
|
return {
|
|
2717
2846
|
typ: exports.EnumToken.NumberTokenType,
|
|
2718
|
-
val:
|
|
2847
|
+
val: v
|
|
2719
2848
|
};
|
|
2720
2849
|
}),
|
|
2721
2850
|
kin: exports.ColorType.LCH
|
|
@@ -2772,11 +2901,11 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
|
|
|
2772
2901
|
};
|
|
2773
2902
|
if (colorSpace.val == 'hsl' || colorSpace.val == 'hwb') {
|
|
2774
2903
|
// @ts-ignore
|
|
2775
|
-
result.chi[0] = { typ: exports.EnumToken.AngleTokenType, val:
|
|
2904
|
+
result.chi[0] = { typ: exports.EnumToken.AngleTokenType, val: result.chi[0].val * 360 };
|
|
2776
2905
|
// @ts-ignore
|
|
2777
|
-
result.chi[1] = { typ: exports.EnumToken.PercentageTokenType, val:
|
|
2906
|
+
result.chi[1] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[1].val * 100 };
|
|
2778
2907
|
// @ts-ignore
|
|
2779
|
-
result.chi[2] = { typ: exports.EnumToken.PercentageTokenType, val:
|
|
2908
|
+
result.chi[2] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[2].val * 100 };
|
|
2780
2909
|
}
|
|
2781
2910
|
return result;
|
|
2782
2911
|
}
|
|
@@ -2827,20 +2956,20 @@ function compute$1(a, b, op) {
|
|
|
2827
2956
|
const r2 = minifyNumber(r[0]) + '/' + minifyNumber(r[1]);
|
|
2828
2957
|
return minifyNumber(result).length < r2.length ? result : {
|
|
2829
2958
|
typ: exports.EnumToken.FractionTokenType,
|
|
2830
|
-
l: { typ: exports.EnumToken.NumberTokenType, val:
|
|
2831
|
-
r: { typ: exports.EnumToken.NumberTokenType, val:
|
|
2959
|
+
l: { typ: exports.EnumToken.NumberTokenType, val: r[0] },
|
|
2960
|
+
r: { typ: exports.EnumToken.NumberTokenType, val: r[1] }
|
|
2832
2961
|
};
|
|
2833
2962
|
}
|
|
2834
2963
|
}
|
|
2835
2964
|
let l1 = typeof a == 'number' ? {
|
|
2836
2965
|
typ: exports.EnumToken.FractionTokenType,
|
|
2837
|
-
l: { typ: exports.EnumToken.NumberTokenType, val:
|
|
2838
|
-
r: { typ: exports.EnumToken.NumberTokenType, val:
|
|
2966
|
+
l: { typ: exports.EnumToken.NumberTokenType, val: a },
|
|
2967
|
+
r: { typ: exports.EnumToken.NumberTokenType, val: 1 }
|
|
2839
2968
|
} : a;
|
|
2840
2969
|
let r1 = typeof b == 'number' ? {
|
|
2841
2970
|
typ: exports.EnumToken.FractionTokenType,
|
|
2842
|
-
l: { typ: exports.EnumToken.NumberTokenType, val:
|
|
2843
|
-
r: { typ: exports.EnumToken.NumberTokenType, val:
|
|
2971
|
+
l: { typ: exports.EnumToken.NumberTokenType, val: b },
|
|
2972
|
+
r: { typ: exports.EnumToken.NumberTokenType, val: 1 }
|
|
2844
2973
|
} : b;
|
|
2845
2974
|
let l2;
|
|
2846
2975
|
let r2;
|
|
@@ -2878,8 +3007,8 @@ function compute$1(a, b, op) {
|
|
|
2878
3007
|
const result = a2[0] / a2[1];
|
|
2879
3008
|
return minifyNumber(result).length <= minifyNumber(a2[0]).length + 1 + minifyNumber(a2[1]).length ? result : {
|
|
2880
3009
|
typ: exports.EnumToken.FractionTokenType,
|
|
2881
|
-
l: { typ: exports.EnumToken.NumberTokenType, val:
|
|
2882
|
-
r: { typ: exports.EnumToken.NumberTokenType, val:
|
|
3010
|
+
l: { typ: exports.EnumToken.NumberTokenType, val: a2[0] },
|
|
3011
|
+
r: { typ: exports.EnumToken.NumberTokenType, val: a2[1] }
|
|
2883
3012
|
};
|
|
2884
3013
|
}
|
|
2885
3014
|
function rem(...a) {
|
|
@@ -2922,12 +3051,7 @@ function evaluate(tokens) {
|
|
|
2922
3051
|
});
|
|
2923
3052
|
return evaluateFunc(tokens[0]);
|
|
2924
3053
|
}
|
|
2925
|
-
// try {
|
|
2926
3054
|
nodes = inlineExpression$1(evaluateExpression(buildExpression(tokens)));
|
|
2927
|
-
// } catch (e) {
|
|
2928
|
-
//
|
|
2929
|
-
// return tokens;
|
|
2930
|
-
// }
|
|
2931
3055
|
if (nodes.length <= 1) {
|
|
2932
3056
|
if (nodes.length == 1) {
|
|
2933
3057
|
if (nodes[0].typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
@@ -2938,7 +3062,7 @@ function evaluate(tokens) {
|
|
|
2938
3062
|
return [{
|
|
2939
3063
|
...nodes[0],
|
|
2940
3064
|
// @ts-ignore
|
|
2941
|
-
val:
|
|
3065
|
+
val: Math[nodes[0].val.toUpperCase()],
|
|
2942
3066
|
typ: exports.EnumToken.NumberTokenType
|
|
2943
3067
|
}];
|
|
2944
3068
|
}
|
|
@@ -2958,7 +3082,7 @@ function evaluate(tokens) {
|
|
|
2958
3082
|
token = { typ: exports.EnumToken.ListToken, chi: [nodes[i], nodes[i + 1]] };
|
|
2959
3083
|
}
|
|
2960
3084
|
else {
|
|
2961
|
-
token = doEvaluate(nodes[i + 1], { typ: exports.EnumToken.NumberTokenType, val:
|
|
3085
|
+
token = doEvaluate(nodes[i + 1], { typ: exports.EnumToken.NumberTokenType, val: -1 }, exports.EnumToken.Mul);
|
|
2962
3086
|
}
|
|
2963
3087
|
i++;
|
|
2964
3088
|
}
|
|
@@ -2973,7 +3097,7 @@ function evaluate(tokens) {
|
|
|
2973
3097
|
const token = curr[1].reduce((acc, curr) => doEvaluate(acc, curr, exports.EnumToken.Add));
|
|
2974
3098
|
if (token.typ != exports.EnumToken.BinaryExpressionTokenType) {
|
|
2975
3099
|
if ('val' in token && +token.val < 0) {
|
|
2976
|
-
acc.push({ typ: exports.EnumToken.Sub }, { ...token, val:
|
|
3100
|
+
acc.push({ typ: exports.EnumToken.Sub }, { ...token, val: -token.val });
|
|
2977
3101
|
return acc;
|
|
2978
3102
|
}
|
|
2979
3103
|
}
|
|
@@ -3000,73 +3124,37 @@ function doEvaluate(l, r, op) {
|
|
|
3000
3124
|
if (!isScalarToken(l) || !isScalarToken(r) || (l.typ == r.typ && 'unit' in l && 'unit' in r && l.unit != r.unit)) {
|
|
3001
3125
|
return defaultReturn;
|
|
3002
3126
|
}
|
|
3003
|
-
// if (l.typ == EnumToken.FunctionTokenType) {
|
|
3004
|
-
//
|
|
3005
|
-
// const val: Token[] = evaluateFunc(l as FunctionToken);
|
|
3006
|
-
//
|
|
3007
|
-
// if (val.length == 1) {
|
|
3008
|
-
//
|
|
3009
|
-
// l = val[0];
|
|
3010
|
-
// } else {
|
|
3011
|
-
//
|
|
3012
|
-
// return defaultReturn;
|
|
3013
|
-
// }
|
|
3014
|
-
// }
|
|
3015
3127
|
if (r.typ == exports.EnumToken.FunctionTokenType) {
|
|
3016
3128
|
const val = evaluateFunc(r);
|
|
3017
3129
|
if (val.length == 1) {
|
|
3018
3130
|
r = val[0];
|
|
3019
3131
|
}
|
|
3020
|
-
// else {
|
|
3021
|
-
//
|
|
3022
|
-
// return defaultReturn;
|
|
3023
|
-
// }
|
|
3024
3132
|
}
|
|
3025
|
-
// if (l.typ == EnumToken.FunctionTokenType) {
|
|
3026
|
-
//
|
|
3027
|
-
// const val = evaluateFunc(l as FunctionToken);
|
|
3028
|
-
//
|
|
3029
|
-
// if (val.length == 1) {
|
|
3030
|
-
//
|
|
3031
|
-
// l = val[0];
|
|
3032
|
-
// }
|
|
3033
|
-
// }
|
|
3034
3133
|
if ((op == exports.EnumToken.Add || op == exports.EnumToken.Sub)) {
|
|
3035
3134
|
// @ts-ignore
|
|
3036
3135
|
if (l.typ != r.typ) {
|
|
3037
3136
|
return defaultReturn;
|
|
3038
3137
|
}
|
|
3039
3138
|
}
|
|
3040
|
-
// else if (
|
|
3041
|
-
// op == EnumToken.Mul &&
|
|
3042
|
-
// ![EnumToken.NumberTokenType, EnumToken.PercentageTokenType].includes(l.typ) &&
|
|
3043
|
-
// ![EnumToken.NumberTokenType, EnumToken.PercentageTokenType].includes(r.typ)) {
|
|
3044
|
-
//
|
|
3045
|
-
// return defaultReturn;
|
|
3046
|
-
// }
|
|
3047
3139
|
let typ = l.typ == exports.EnumToken.NumberTokenType ? r.typ : (r.typ == exports.EnumToken.NumberTokenType ? l.typ : (l.typ == exports.EnumToken.PercentageTokenType ? r.typ : l.typ));
|
|
3048
3140
|
// @ts-ignore
|
|
3049
3141
|
let v1 = l.val?.typ == exports.EnumToken.FractionTokenType ? l.val : getValue$1(l);
|
|
3050
3142
|
// @ts-ignore
|
|
3051
3143
|
let v2 = r.val?.typ == exports.EnumToken.FractionTokenType ? r.val : getValue$1(r);
|
|
3052
|
-
// if (v1 == null || v2 == null) {
|
|
3053
|
-
//
|
|
3054
|
-
// return defaultReturn;
|
|
3055
|
-
// }
|
|
3056
3144
|
if (op == exports.EnumToken.Mul) {
|
|
3057
3145
|
if (l.typ != exports.EnumToken.NumberTokenType && r.typ != exports.EnumToken.NumberTokenType) {
|
|
3058
3146
|
if (typeof v1 == 'number' && l.typ == exports.EnumToken.PercentageTokenType) {
|
|
3059
3147
|
v1 = {
|
|
3060
3148
|
typ: exports.EnumToken.FractionTokenType,
|
|
3061
|
-
l: { typ: exports.EnumToken.NumberTokenType, val:
|
|
3062
|
-
r: { typ: exports.EnumToken.NumberTokenType, val:
|
|
3149
|
+
l: { typ: exports.EnumToken.NumberTokenType, val: v1 },
|
|
3150
|
+
r: { typ: exports.EnumToken.NumberTokenType, val: 100 }
|
|
3063
3151
|
};
|
|
3064
3152
|
}
|
|
3065
3153
|
else if (typeof v2 == 'number' && r.typ == exports.EnumToken.PercentageTokenType) {
|
|
3066
3154
|
v2 = {
|
|
3067
3155
|
typ: exports.EnumToken.FractionTokenType,
|
|
3068
|
-
l: { typ: exports.EnumToken.NumberTokenType, val:
|
|
3069
|
-
r: { typ: exports.EnumToken.NumberTokenType, val:
|
|
3156
|
+
l: { typ: exports.EnumToken.NumberTokenType, val: v2 },
|
|
3157
|
+
r: { typ: exports.EnumToken.NumberTokenType, val: 100 }
|
|
3070
3158
|
};
|
|
3071
3159
|
}
|
|
3072
3160
|
}
|
|
@@ -3076,7 +3164,7 @@ function doEvaluate(l, r, op) {
|
|
|
3076
3164
|
const token = {
|
|
3077
3165
|
...(l.typ == exports.EnumToken.NumberTokenType ? r : l),
|
|
3078
3166
|
typ,
|
|
3079
|
-
val: typeof val == 'number' ? minifyNumber(val) : val
|
|
3167
|
+
val /* : typeof val == 'number' ? minifyNumber(val) : val */
|
|
3080
3168
|
};
|
|
3081
3169
|
if (token.typ == exports.EnumToken.IdenTokenType) {
|
|
3082
3170
|
// @ts-ignore
|
|
@@ -3085,26 +3173,10 @@ function doEvaluate(l, r, op) {
|
|
|
3085
3173
|
return token;
|
|
3086
3174
|
}
|
|
3087
3175
|
function getValue$1(t) {
|
|
3088
|
-
// if (t.typ == EnumToken.FunctionTokenType) {
|
|
3089
|
-
//
|
|
3090
|
-
// v1 = evaluateFunc(t as FunctionToken);
|
|
3091
|
-
//
|
|
3092
|
-
// if (v1.length != 1 || v1[0].typ == EnumToken.BinaryExpressionTokenType) {
|
|
3093
|
-
//
|
|
3094
|
-
// return null;
|
|
3095
|
-
// }
|
|
3096
|
-
//
|
|
3097
|
-
// t = v1[0] as NumberToken | IdentToken;
|
|
3098
|
-
// }
|
|
3099
3176
|
if (t.typ == exports.EnumToken.IdenTokenType) {
|
|
3100
3177
|
// @ts-ignore
|
|
3101
3178
|
return Math[t.val.toUpperCase()];
|
|
3102
3179
|
}
|
|
3103
|
-
// if ((t.val as FractionToken).typ == EnumToken.FractionTokenType) {
|
|
3104
|
-
//
|
|
3105
|
-
// // @ts-ignore
|
|
3106
|
-
// return (t.val as FractionToken).l.val / (t.val as FractionToken).r.val;
|
|
3107
|
-
// }
|
|
3108
3180
|
// @ts-ignore
|
|
3109
3181
|
return t.typ == exports.EnumToken.FractionTokenType ? t.l.val / t.r.val : +t.val;
|
|
3110
3182
|
}
|
|
@@ -3122,15 +3194,11 @@ function evaluateFunc(token) {
|
|
|
3122
3194
|
case 'sqrt':
|
|
3123
3195
|
case 'exp': {
|
|
3124
3196
|
const value = evaluate(values);
|
|
3125
|
-
// if (value.length != 1 || (value[0].typ != EnumToken.NumberTokenType && value[0].typ != EnumToken.FractionTokenType) || (value[0].typ == EnumToken.FractionTokenType && (+(value[0] as FractionToken).r.val == 0 || !Number.isFinite(+(value[0] as FractionToken).l.val) || !Number.isFinite(+(value[0] as FractionToken).r.val)))) {
|
|
3126
|
-
//
|
|
3127
|
-
// return value;
|
|
3128
|
-
// }
|
|
3129
3197
|
// @ts-ignore
|
|
3130
3198
|
let val = value[0].typ == exports.EnumToken.NumberTokenType ? +value[0].val : value[0].l.val / value[0].r.val;
|
|
3131
3199
|
return [{
|
|
3132
3200
|
typ: exports.EnumToken.NumberTokenType,
|
|
3133
|
-
val:
|
|
3201
|
+
val: Math[token.val](val)
|
|
3134
3202
|
}];
|
|
3135
3203
|
}
|
|
3136
3204
|
case 'hypot': {
|
|
@@ -3138,29 +3206,16 @@ function evaluateFunc(token) {
|
|
|
3138
3206
|
let all = [];
|
|
3139
3207
|
let ref = chi[0];
|
|
3140
3208
|
let value = 0;
|
|
3141
|
-
// if (![EnumToken.NumberTokenType, EnumToken.PercentageTokenType].includes(ref.typ) && !('unit' in ref)) {
|
|
3142
|
-
//
|
|
3143
|
-
// return [token];
|
|
3144
|
-
// }
|
|
3145
3209
|
for (let i = 0; i < chi.length; i++) {
|
|
3146
|
-
// @ts-ignore
|
|
3147
|
-
// if (chi[i].typ != ref.typ || ('unit' in chi[i] && 'unit' in ref && chi[i].unit != ref.unit)) {
|
|
3148
|
-
//
|
|
3149
|
-
// return [token];
|
|
3150
|
-
// }
|
|
3151
3210
|
// @ts-ignore
|
|
3152
3211
|
const val = getValue$1(chi[i]);
|
|
3153
|
-
// if (val == null) {
|
|
3154
|
-
//
|
|
3155
|
-
// return [token];
|
|
3156
|
-
// }
|
|
3157
3212
|
all.push(val);
|
|
3158
3213
|
value += val * val;
|
|
3159
3214
|
}
|
|
3160
3215
|
return [
|
|
3161
3216
|
{
|
|
3162
3217
|
...ref,
|
|
3163
|
-
val: Math.sqrt(value).toFixed(rem(...all))
|
|
3218
|
+
val: +(Math.sqrt(value).toFixed(rem(...all)))
|
|
3164
3219
|
}
|
|
3165
3220
|
];
|
|
3166
3221
|
}
|
|
@@ -3169,48 +3224,18 @@ function evaluateFunc(token) {
|
|
|
3169
3224
|
case 'rem':
|
|
3170
3225
|
case 'mod': {
|
|
3171
3226
|
const chi = values.filter(t => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ));
|
|
3172
|
-
// if (chi.length != 3 || chi[1].typ != EnumToken.CommaTokenType) {
|
|
3173
|
-
//
|
|
3174
|
-
// return [token];
|
|
3175
|
-
// }
|
|
3176
|
-
// if (token.val == 'pow' && (chi[0].typ != EnumToken.NumberTokenType || chi[2].typ != EnumToken.NumberTokenType)) {
|
|
3177
|
-
//
|
|
3178
|
-
// return [token];
|
|
3179
|
-
// }
|
|
3180
|
-
// if (['rem', 'mod'].includes(token.val) &&
|
|
3181
|
-
// (
|
|
3182
|
-
// chi[0].typ != chi[2].typ) || (
|
|
3183
|
-
// 'unit' in chi[0] && 'unit' in chi[2] &&
|
|
3184
|
-
// chi[0].unit != chi[2].unit
|
|
3185
|
-
// )) {
|
|
3186
|
-
//
|
|
3187
|
-
// return [token];
|
|
3188
|
-
// }
|
|
3189
3227
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/mod
|
|
3190
3228
|
const v1 = evaluate([chi[0]]);
|
|
3191
3229
|
const v2 = evaluate([chi[2]]);
|
|
3192
|
-
[exports.EnumToken.PercentageTokenType, exports.EnumToken.DimensionTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.NumberTokenType, exports.EnumToken.LengthTokenType, exports.EnumToken.TimeTokenType, exports.EnumToken.FrequencyTokenType, exports.EnumToken.ResolutionTokenType];
|
|
3193
|
-
// if (v1.length != 1 || v2.length != 1 || !types.includes(v1[0].typ) || !types.includes(v2[0].typ) || (v1[0] as DimensionToken).unit != (v2[0] as DimensionToken).unit) {
|
|
3194
|
-
//
|
|
3195
|
-
// return [token];
|
|
3196
|
-
// }
|
|
3197
3230
|
// @ts-ignore
|
|
3198
3231
|
const val1 = getValue$1(v1[0]);
|
|
3199
3232
|
// @ts-ignore
|
|
3200
3233
|
const val2 = getValue$1(v2[0]);
|
|
3201
|
-
// if (val1 == null || val2 == null || (v1[0].typ != v2[0].typ && val1 != 0 && val2 != 0)) {
|
|
3202
|
-
//
|
|
3203
|
-
// return [token];
|
|
3204
|
-
// }
|
|
3205
3234
|
if (token.val == 'rem') {
|
|
3206
|
-
// if (val2 == 0) {
|
|
3207
|
-
//
|
|
3208
|
-
// return [token];
|
|
3209
|
-
// }
|
|
3210
3235
|
return [
|
|
3211
3236
|
{
|
|
3212
3237
|
...v1[0],
|
|
3213
|
-
val: (val1 % val2).toFixed(rem(val1, val2))
|
|
3238
|
+
val: +((val1 % val2).toFixed(rem(val1, val2)))
|
|
3214
3239
|
}
|
|
3215
3240
|
];
|
|
3216
3241
|
}
|
|
@@ -3218,7 +3243,7 @@ function evaluateFunc(token) {
|
|
|
3218
3243
|
return [
|
|
3219
3244
|
{
|
|
3220
3245
|
...v1[0],
|
|
3221
|
-
val:
|
|
3246
|
+
val: Math.pow(val1, val2)
|
|
3222
3247
|
}
|
|
3223
3248
|
];
|
|
3224
3249
|
}
|
|
@@ -3226,14 +3251,14 @@ function evaluateFunc(token) {
|
|
|
3226
3251
|
return [
|
|
3227
3252
|
{
|
|
3228
3253
|
...{}, ...v1[0],
|
|
3229
|
-
val:
|
|
3254
|
+
val: Math.atan2(val1, val2)
|
|
3230
3255
|
}
|
|
3231
3256
|
];
|
|
3232
3257
|
}
|
|
3233
3258
|
return [
|
|
3234
3259
|
{
|
|
3235
3260
|
...v1[0],
|
|
3236
|
-
val:
|
|
3261
|
+
val: val2 == 0 ? val1 : val1 - (Math.floor(val1 / val2) * val2)
|
|
3237
3262
|
}
|
|
3238
3263
|
];
|
|
3239
3264
|
}
|
|
@@ -3251,10 +3276,6 @@ function evaluateFunc(token) {
|
|
|
3251
3276
|
continue;
|
|
3252
3277
|
}
|
|
3253
3278
|
const result = evaluate([curr]);
|
|
3254
|
-
// if (result.length != 1 || result[0].typ == EnumToken.FunctionTokenType) {
|
|
3255
|
-
//
|
|
3256
|
-
// return [token];
|
|
3257
|
-
// }
|
|
3258
3279
|
const key = result[0].typ + ('unit' in result[0] ? result[0].unit : '');
|
|
3259
3280
|
if (!valuesMap.has(key)) {
|
|
3260
3281
|
valuesMap.set(key, []);
|
|
@@ -3264,24 +3285,12 @@ function evaluateFunc(token) {
|
|
|
3264
3285
|
if (valuesMap.size == 1) {
|
|
3265
3286
|
const values = valuesMap.values().next().value;
|
|
3266
3287
|
if (token.val == 'log') {
|
|
3267
|
-
// if (values[0].typ != EnumToken.NumberTokenType || values.length > 2) {
|
|
3268
|
-
//
|
|
3269
|
-
// return [token];
|
|
3270
|
-
// }
|
|
3271
3288
|
const val1 = getValue$1(values[0]);
|
|
3272
3289
|
const val2 = values.length == 2 ? getValue$1(values[1]) : null;
|
|
3273
|
-
// if (values.length == 1) {
|
|
3274
|
-
//
|
|
3275
|
-
// return [
|
|
3276
|
-
// {
|
|
3277
|
-
// ...values[0],
|
|
3278
|
-
// val: String(Math.log(val1))
|
|
3279
|
-
// } as DimensionToken | AngleToken | NumberToken | LengthToken | TimeToken | FrequencyToken | ResolutionToken];
|
|
3280
|
-
// }
|
|
3281
3290
|
return [
|
|
3282
3291
|
{
|
|
3283
3292
|
...values[0],
|
|
3284
|
-
val:
|
|
3293
|
+
val: Math.log(val1) / Math.log(val2)
|
|
3285
3294
|
}
|
|
3286
3295
|
];
|
|
3287
3296
|
}
|
|
@@ -3305,10 +3314,6 @@ function evaluateFunc(token) {
|
|
|
3305
3314
|
if (token.val == 'round') {
|
|
3306
3315
|
let val = getValue$1(values[0]);
|
|
3307
3316
|
let val2 = getValue$1(values[1]);
|
|
3308
|
-
// if (Number.isNaN(val) || Number.isNaN(val2)) {
|
|
3309
|
-
//
|
|
3310
|
-
// return [token];
|
|
3311
|
-
// }
|
|
3312
3317
|
if (strategy == null || strategy == 'down') {
|
|
3313
3318
|
val = val - (val % val2);
|
|
3314
3319
|
}
|
|
@@ -3316,11 +3321,10 @@ function evaluateFunc(token) {
|
|
|
3316
3321
|
val = strategy == 'to-zero' ? Math.trunc(val / val2) * val2 : (strategy == 'nearest' ? Math.round(val / val2) * val2 : Math.ceil(val / val2) * val2);
|
|
3317
3322
|
}
|
|
3318
3323
|
// @ts-ignore
|
|
3319
|
-
return [{ ...values[0], val
|
|
3324
|
+
return [{ ...values[0], val }];
|
|
3320
3325
|
}
|
|
3321
3326
|
}
|
|
3322
3327
|
}
|
|
3323
|
-
// return [token];
|
|
3324
3328
|
}
|
|
3325
3329
|
return [token];
|
|
3326
3330
|
}
|
|
@@ -3330,10 +3334,6 @@ function evaluateFunc(token) {
|
|
|
3330
3334
|
*/
|
|
3331
3335
|
function inlineExpression$1(token) {
|
|
3332
3336
|
const result = [];
|
|
3333
|
-
// if (token.typ == EnumToken.ParensTokenType && (token as ParensToken).chi.length == 1) {
|
|
3334
|
-
//
|
|
3335
|
-
// result.push((token as ParensToken).chi[0]);
|
|
3336
|
-
// } else
|
|
3337
3337
|
if (token.typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
3338
3338
|
if ([exports.EnumToken.Mul, exports.EnumToken.Div].includes(token.op)) {
|
|
3339
3339
|
result.push(token);
|
|
@@ -3372,7 +3372,7 @@ function isScalarToken(token) {
|
|
|
3372
3372
|
}
|
|
3373
3373
|
/**
|
|
3374
3374
|
*
|
|
3375
|
-
* generate binary expression tree
|
|
3375
|
+
* generate a binary expression tree
|
|
3376
3376
|
* @param tokens
|
|
3377
3377
|
*/
|
|
3378
3378
|
function buildExpression(tokens) {
|
|
@@ -3392,7 +3392,7 @@ function getArithmeticOperation(op) {
|
|
|
3392
3392
|
}
|
|
3393
3393
|
/**
|
|
3394
3394
|
*
|
|
3395
|
-
* generate binary expression tree
|
|
3395
|
+
* generate a binary expression tree
|
|
3396
3396
|
* @param token
|
|
3397
3397
|
*/
|
|
3398
3398
|
function factorToken(token) {
|
|
@@ -3407,7 +3407,7 @@ function factorToken(token) {
|
|
|
3407
3407
|
return token;
|
|
3408
3408
|
}
|
|
3409
3409
|
/**
|
|
3410
|
-
* generate binary expression tree
|
|
3410
|
+
* generate a binary expression tree
|
|
3411
3411
|
* @param tokens
|
|
3412
3412
|
* @param ops
|
|
3413
3413
|
*/
|
|
@@ -3498,7 +3498,7 @@ function getValue(t, converted, component) {
|
|
|
3498
3498
|
}
|
|
3499
3499
|
return {
|
|
3500
3500
|
typ: exports.EnumToken.NumberTokenType,
|
|
3501
|
-
val:
|
|
3501
|
+
val: value
|
|
3502
3502
|
};
|
|
3503
3503
|
}
|
|
3504
3504
|
return t;
|
|
@@ -3688,11 +3688,11 @@ function cmyktoken(values) {
|
|
|
3688
3688
|
chi: values.reduce((acc, curr, index) => index < 4 ? [...acc, {
|
|
3689
3689
|
typ: exports.EnumToken.PercentageTokenType,
|
|
3690
3690
|
// @ts-ignore
|
|
3691
|
-
val:
|
|
3691
|
+
val: curr * 100
|
|
3692
3692
|
}] : [...acc, {
|
|
3693
3693
|
typ: exports.EnumToken.LiteralTokenType,
|
|
3694
3694
|
val: '/'
|
|
3695
|
-
}, { typ: exports.EnumToken.PercentageTokenType, val:
|
|
3695
|
+
}, { typ: exports.EnumToken.PercentageTokenType, val: curr * 100 }], []),
|
|
3696
3696
|
kin: exports.ColorType.DEVICE_CMYK
|
|
3697
3697
|
};
|
|
3698
3698
|
}
|
|
@@ -3752,7 +3752,7 @@ function xyz2la98rgb(x, y, z, a = null) {
|
|
|
3752
3752
|
}
|
|
3753
3753
|
|
|
3754
3754
|
/**
|
|
3755
|
-
* Converts a color
|
|
3755
|
+
* Converts a color to another color space
|
|
3756
3756
|
* @param token
|
|
3757
3757
|
* @param to
|
|
3758
3758
|
*/
|
|
@@ -3760,7 +3760,7 @@ function convertColor(token, to) {
|
|
|
3760
3760
|
if (token.kin == exports.ColorType.SYS ||
|
|
3761
3761
|
token.kin == exports.ColorType.DPSYS ||
|
|
3762
3762
|
(isIdentColor(token) &&
|
|
3763
|
-
|
|
3763
|
+
'currentcolor' == token.val.toLowerCase())) {
|
|
3764
3764
|
return token;
|
|
3765
3765
|
}
|
|
3766
3766
|
if (token.kin == exports.ColorType.COLOR_MIX && to != exports.ColorType.COLOR_MIX) {
|
|
@@ -4229,14 +4229,14 @@ function color2srgbvalues(token) {
|
|
|
4229
4229
|
function values2colortoken(values, to) {
|
|
4230
4230
|
values = srgb2srgbcolorspace(values, to);
|
|
4231
4231
|
const chi = [
|
|
4232
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
4233
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
4234
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
4232
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
4233
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[1] },
|
|
4234
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[2] },
|
|
4235
4235
|
];
|
|
4236
4236
|
if (values.length == 4) {
|
|
4237
4237
|
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
|
|
4238
4238
|
typ: exports.EnumToken.PercentageTokenType,
|
|
4239
|
-
val:
|
|
4239
|
+
val: values[3] * 100
|
|
4240
4240
|
});
|
|
4241
4241
|
}
|
|
4242
4242
|
const colorSpace = exports.ColorType[to].toLowerCase().replaceAll('_', '-');
|
|
@@ -4257,7 +4257,7 @@ function getNumber(token) {
|
|
|
4257
4257
|
return 0;
|
|
4258
4258
|
}
|
|
4259
4259
|
// @ts-ignore
|
|
4260
|
-
return token.typ == exports.EnumToken.PercentageTokenType ? token.val / 100 :
|
|
4260
|
+
return token.typ == exports.EnumToken.PercentageTokenType ? token.val / 100 : token.val;
|
|
4261
4261
|
}
|
|
4262
4262
|
/**
|
|
4263
4263
|
* convert angle to turn
|
|
@@ -4710,7 +4710,7 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
4710
4710
|
if (Array.isArray(token.chi)) {
|
|
4711
4711
|
const isLegacy = ['rgb', 'rgba', 'hsl', 'hsla'].includes(token.val.toLowerCase());
|
|
4712
4712
|
const useAlpha = (['rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'oklab', 'oklch', 'lab', 'lch'].includes(token.val.toLowerCase()) && token.chi.length == 4) ||
|
|
4713
|
-
('color'
|
|
4713
|
+
('color' == token.val.toLowerCase() && token.chi.length == 5);
|
|
4714
4714
|
return (token.val.endsWith('a') ? token.val.slice(0, -1) : token.val) + '(' + token.chi.reduce((acc, curr, index, array) => {
|
|
4715
4715
|
if (/[,/]\s*$/.test(acc)) {
|
|
4716
4716
|
if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
@@ -4907,32 +4907,41 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
4907
4907
|
return token.val.slice(1);
|
|
4908
4908
|
}
|
|
4909
4909
|
case exports.EnumToken.UrlTokenTokenType:
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4910
|
+
// if (token.typ == EnumToken.UrlTokenTokenType) {
|
|
4911
|
+
//
|
|
4912
|
+
// if (options.output != null) {
|
|
4913
|
+
//
|
|
4914
|
+
// if (!('original' in token)) {
|
|
4915
|
+
//
|
|
4916
|
+
// // do not modify original token
|
|
4917
|
+
// token = {...token};
|
|
4918
|
+
// Object.defineProperty(token, 'original', {
|
|
4919
|
+
// enumerable: false,
|
|
4920
|
+
// writable: false,
|
|
4921
|
+
// value: (token as UrlToken).val
|
|
4922
|
+
// })
|
|
4923
|
+
// }
|
|
4924
|
+
//
|
|
4925
|
+
// // @ts-ignore
|
|
4926
|
+
// if (!(token.original in cache)) {
|
|
4927
|
+
//
|
|
4928
|
+
// let output: string = <string>options.output ?? '';
|
|
4929
|
+
// const key = output + 'abs';
|
|
4930
|
+
//
|
|
4931
|
+
// if (!(key in cache)) {
|
|
4932
|
+
//
|
|
4933
|
+
// // @ts-ignore
|
|
4934
|
+
// cache[key] = options.dirname(options.resolve(output, options.cwd).absolute);
|
|
4935
|
+
// }
|
|
4936
|
+
//
|
|
4937
|
+
// // @ts-ignore
|
|
4938
|
+
// cache[token.original] = options.resolve(token.original, cache[key]).relative;
|
|
4939
|
+
// }
|
|
4940
|
+
//
|
|
4941
|
+
// // @ts-ignore
|
|
4942
|
+
// token.val = cache[token.original];
|
|
4943
|
+
// }
|
|
4944
|
+
// }
|
|
4936
4945
|
case exports.EnumToken.HashTokenType:
|
|
4937
4946
|
case exports.EnumToken.IdenTokenType:
|
|
4938
4947
|
case exports.EnumToken.AtRuleTokenType:
|
|
@@ -5470,18 +5479,18 @@ function isPolarColorspace(token) {
|
|
|
5470
5479
|
}
|
|
5471
5480
|
function isHueInterpolationMethod(token) {
|
|
5472
5481
|
if (!Array.isArray(token)) {
|
|
5473
|
-
return token.typ == exports.EnumToken.IdenTokenType && 'hue'
|
|
5482
|
+
return token.typ == exports.EnumToken.IdenTokenType && 'hue' === token.val?.toLowerCase?.();
|
|
5474
5483
|
}
|
|
5475
5484
|
if (token.length != 2 || token[0].typ != exports.EnumToken.IdenTokenType || token[1].typ != exports.EnumToken.IdenTokenType) {
|
|
5476
5485
|
return false;
|
|
5477
5486
|
}
|
|
5478
|
-
return ['shorter', 'longer', 'increasing', 'decreasing'].includes(token[0].val) && 'hue'
|
|
5487
|
+
return ['shorter', 'longer', 'increasing', 'decreasing'].includes(token[0].val?.toLowerCase?.()) && 'hue' === token[1].val?.toLowerCase?.();
|
|
5479
5488
|
}
|
|
5480
5489
|
function isIdentColor(token) {
|
|
5481
5490
|
return token.typ == exports.EnumToken.ColorTokenType && [exports.ColorType.SYS, exports.ColorType.DPSYS, exports.ColorType.LIT].includes(token.kin) && isIdent(token.val);
|
|
5482
5491
|
}
|
|
5483
5492
|
function isPercentageToken(token) {
|
|
5484
|
-
return token.typ == exports.EnumToken.PercentageTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val ==
|
|
5493
|
+
return token.typ == exports.EnumToken.PercentageTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val == 0);
|
|
5485
5494
|
}
|
|
5486
5495
|
function isColor(token) {
|
|
5487
5496
|
if (token.typ == exports.EnumToken.ColorTokenType) {
|
|
@@ -5592,7 +5601,7 @@ function isColor(token) {
|
|
|
5592
5601
|
if (children.length == 3) {
|
|
5593
5602
|
if (children[0].length > 4 ||
|
|
5594
5603
|
children[0][0].typ != exports.EnumToken.IdenTokenType ||
|
|
5595
|
-
'in'
|
|
5604
|
+
'in' !== children[0][0].val?.toLowerCase?.() ||
|
|
5596
5605
|
!isColorspace(children[0][1]) ||
|
|
5597
5606
|
(children[0].length >= 3 && !isHueInterpolationMethod(children[0].slice(2))) ||
|
|
5598
5607
|
children[1].length > 2 ||
|
|
@@ -5604,12 +5613,12 @@ function isColor(token) {
|
|
|
5604
5613
|
return false;
|
|
5605
5614
|
}
|
|
5606
5615
|
if (children[1].length == 2) {
|
|
5607
|
-
if (!(children[1][1].typ == exports.EnumToken.PercentageTokenType || (children[1][1].typ == exports.EnumToken.NumberTokenType && children[1][1].val ==
|
|
5616
|
+
if (!(children[1][1].typ == exports.EnumToken.PercentageTokenType || (children[1][1].typ == exports.EnumToken.NumberTokenType && children[1][1].val == 0))) {
|
|
5608
5617
|
return false;
|
|
5609
5618
|
}
|
|
5610
5619
|
}
|
|
5611
5620
|
if (children[2].length == 2) {
|
|
5612
|
-
if (!(children[2][1].typ == exports.EnumToken.PercentageTokenType || (children[2][1].typ == exports.EnumToken.NumberTokenType && children[2][1].val ==
|
|
5621
|
+
if (!(children[2][1].typ == exports.EnumToken.PercentageTokenType || (children[2][1].typ == exports.EnumToken.NumberTokenType && children[2][1].val == 0))) {
|
|
5613
5622
|
return false;
|
|
5614
5623
|
}
|
|
5615
5624
|
}
|
|
@@ -5753,15 +5762,6 @@ function isIdent(name) {
|
|
|
5753
5762
|
}
|
|
5754
5763
|
return true;
|
|
5755
5764
|
}
|
|
5756
|
-
function isNonPrintable(codepoint) {
|
|
5757
|
-
// null -> backspace
|
|
5758
|
-
return (codepoint >= 0 && codepoint <= 0x8) ||
|
|
5759
|
-
// tab
|
|
5760
|
-
codepoint == 0xb ||
|
|
5761
|
-
// delete
|
|
5762
|
-
codepoint == 0x7f ||
|
|
5763
|
-
(codepoint >= 0xe && codepoint <= 0x1f);
|
|
5764
|
-
}
|
|
5765
5765
|
function isPseudo(name) {
|
|
5766
5766
|
return name.charAt(0) == ':' &&
|
|
5767
5767
|
((name.endsWith('(') && isIdent(name.charAt(1) == ':' ? name.slice(2, -1) : name.slice(1, -1))) ||
|
|
@@ -5868,7 +5868,7 @@ function parseDimension(name) {
|
|
|
5868
5868
|
}
|
|
5869
5869
|
const dimension = {
|
|
5870
5870
|
typ: exports.EnumToken.DimensionTokenType,
|
|
5871
|
-
val: name.slice(0, index),
|
|
5871
|
+
val: +name.slice(0, index),
|
|
5872
5872
|
unit: name.slice(index)
|
|
5873
5873
|
};
|
|
5874
5874
|
if (isAngle(dimension)) {
|
|
@@ -5971,7 +5971,7 @@ function length2Px(value) {
|
|
|
5971
5971
|
* @param val
|
|
5972
5972
|
*/
|
|
5973
5973
|
function minifyNumber(val) {
|
|
5974
|
-
val = String(
|
|
5974
|
+
val = String(val);
|
|
5975
5975
|
if (val === '0') {
|
|
5976
5976
|
return '0';
|
|
5977
5977
|
}
|
|
@@ -7472,7 +7472,7 @@ function matchType(val, properties) {
|
|
|
7472
7472
|
(properties.types.some((t) => exports.EnumToken[t] == val.typ))) {
|
|
7473
7473
|
return true;
|
|
7474
7474
|
}
|
|
7475
|
-
if (val.typ == exports.EnumToken.NumberTokenType && val.val ==
|
|
7475
|
+
if (val.typ == exports.EnumToken.NumberTokenType && val.val == 0) {
|
|
7476
7476
|
// @ts-ignore
|
|
7477
7477
|
return properties.types.some((type) => {
|
|
7478
7478
|
// @ts-ignore
|
|
@@ -7965,8 +7965,6 @@ function* tokenize$1(stream) {
|
|
|
7965
7965
|
value = peek(parseInfo);
|
|
7966
7966
|
// let cp: number;
|
|
7967
7967
|
let whitespace = '';
|
|
7968
|
-
let hasWhiteSpace = false;
|
|
7969
|
-
let errorState = false;
|
|
7970
7968
|
if (value == '"' || value == "'") {
|
|
7971
7969
|
const quote = value;
|
|
7972
7970
|
let inquote = true;
|
|
@@ -8006,7 +8004,6 @@ function* tokenize$1(stream) {
|
|
|
8006
8004
|
if (isWhiteSpace(charCode)) {
|
|
8007
8005
|
whitespace += value;
|
|
8008
8006
|
while (value = peek(parseInfo)) {
|
|
8009
|
-
hasWhiteSpace = true;
|
|
8010
8007
|
if (isWhiteSpace(value?.charCodeAt(0))) {
|
|
8011
8008
|
whitespace += next(parseInfo);
|
|
8012
8009
|
continue;
|
|
@@ -8062,42 +8059,33 @@ function* tokenize$1(stream) {
|
|
|
8062
8059
|
buffer = '';
|
|
8063
8060
|
break;
|
|
8064
8061
|
}
|
|
8065
|
-
if (
|
|
8066
|
-
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
if (
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
|
|
8078
|
-
|
|
8079
|
-
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
|
|
8083
|
-
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
|
|
8092
|
-
if (charCode == 0x29) {
|
|
8093
|
-
break;
|
|
8094
|
-
}
|
|
8095
|
-
buffer += next(parseInfo);
|
|
8096
|
-
}
|
|
8097
|
-
yield pushToken(buffer, parseInfo, exports.EnumToken.BadUrlTokenType);
|
|
8098
|
-
buffer = '';
|
|
8099
|
-
break;
|
|
8100
|
-
}
|
|
8062
|
+
// if (errorState) {
|
|
8063
|
+
//
|
|
8064
|
+
// buffer += whitespace + value;
|
|
8065
|
+
//
|
|
8066
|
+
// while (value = peek(parseInfo)) {
|
|
8067
|
+
//
|
|
8068
|
+
// charCode = value.charCodeAt(0);
|
|
8069
|
+
//
|
|
8070
|
+
// if (charCode == 0x5c) {
|
|
8071
|
+
//
|
|
8072
|
+
// buffer += next(parseInfo, 2);
|
|
8073
|
+
// continue;
|
|
8074
|
+
// }
|
|
8075
|
+
//
|
|
8076
|
+
// // ')'
|
|
8077
|
+
// if (charCode == 0x29) {
|
|
8078
|
+
//
|
|
8079
|
+
// break;
|
|
8080
|
+
// }
|
|
8081
|
+
//
|
|
8082
|
+
// buffer += next(parseInfo);
|
|
8083
|
+
// }
|
|
8084
|
+
//
|
|
8085
|
+
// yield pushToken(buffer, parseInfo, EnumToken.BadUrlTokenType);
|
|
8086
|
+
// buffer = '';
|
|
8087
|
+
// break;
|
|
8088
|
+
// }
|
|
8101
8089
|
buffer += value;
|
|
8102
8090
|
}
|
|
8103
8091
|
}
|
|
@@ -12607,7 +12595,6 @@ function parseSyntax(syntax) {
|
|
|
12607
12595
|
typ: ValidationTokenEnum.Root,
|
|
12608
12596
|
chi: []
|
|
12609
12597
|
}, 'pos', { ...objectProperties, value: { ind: 0, lin: 1, col: 0 } });
|
|
12610
|
-
// return minify(doParseSyntax(syntaxes, tokenize(syntaxes), root)) as ValidationRootToken;
|
|
12611
12598
|
return minify$2(doParseSyntax(syntax, tokenize(syntax), root));
|
|
12612
12599
|
}
|
|
12613
12600
|
function matchParens(syntax, iterator) {
|
|
@@ -12783,10 +12770,6 @@ function matchAtRule(syntax, iterator) {
|
|
|
12783
12770
|
token.typ = ValidationTokenEnum.AtRule;
|
|
12784
12771
|
break;
|
|
12785
12772
|
}
|
|
12786
|
-
// if (item.value.typ != ValidationTokenEnum.Whitespace) {
|
|
12787
|
-
//
|
|
12788
|
-
// console.error('unexpected token', item.value);
|
|
12789
|
-
// }
|
|
12790
12773
|
item = iterator.next();
|
|
12791
12774
|
if (item.done) {
|
|
12792
12775
|
break;
|
|
@@ -13403,9 +13386,6 @@ function renderSyntax(token, parent) {
|
|
|
13403
13386
|
return '{' + token.chi.reduce((acc, t) => acc + renderSyntax(t), '') + '}';
|
|
13404
13387
|
case ValidationTokenEnum.DeclarationDefinitionToken:
|
|
13405
13388
|
return token.nam + ': ' + renderSyntax(token.val);
|
|
13406
|
-
// case ValidationTokenEnum.ColumnArrayToken:
|
|
13407
|
-
//
|
|
13408
|
-
// return (token as ValidationColumnArrayToken).chi.reduce((acc: string, curr: ValidationToken) => acc + (acc.trim().length > 0 ? '||' : '') + renderSyntax(curr), '');
|
|
13409
13389
|
default:
|
|
13410
13390
|
throw new Error('Unhandled token: ' + JSON.stringify({ token }, null, 1));
|
|
13411
13391
|
}
|
|
@@ -13499,10 +13479,6 @@ function getSyntax(group, key) {
|
|
|
13499
13479
|
key = matches[1] + matches[3];
|
|
13500
13480
|
}
|
|
13501
13481
|
}
|
|
13502
|
-
// if (!(key in obj)) {
|
|
13503
|
-
//
|
|
13504
|
-
// return null;
|
|
13505
|
-
// }
|
|
13506
13482
|
}
|
|
13507
13483
|
// @ts-ignore
|
|
13508
13484
|
obj = obj[key];
|
|
@@ -13604,10 +13580,6 @@ function consumeWhitespace(tokens) {
|
|
|
13604
13580
|
function stripCommaToken(tokenList) {
|
|
13605
13581
|
let result = [];
|
|
13606
13582
|
for (let i = 0; i < tokenList.length; i++) {
|
|
13607
|
-
// if (tokenList[i].typ == EnumToken.CommaTokenType && last != null && last.typ == EnumToken.CommaTokenType) {
|
|
13608
|
-
//
|
|
13609
|
-
// return null;
|
|
13610
|
-
// }
|
|
13611
13583
|
if (tokenList[i].typ != exports.EnumToken.WhitespaceTokenType) {
|
|
13612
13584
|
tokenList[i];
|
|
13613
13585
|
}
|
|
@@ -13620,10 +13592,6 @@ function stripCommaToken(tokenList) {
|
|
|
13620
13592
|
}
|
|
13621
13593
|
function splitTokenList(tokenList, split = [exports.EnumToken.CommaTokenType]) {
|
|
13622
13594
|
return tokenList.reduce((acc, curr) => {
|
|
13623
|
-
// if (curr.typ == EnumToken.CommentTokenType) {
|
|
13624
|
-
//
|
|
13625
|
-
// return acc;
|
|
13626
|
-
// }
|
|
13627
13595
|
if (split.includes(curr.typ)) {
|
|
13628
13596
|
acc.push([]);
|
|
13629
13597
|
}
|
|
@@ -13638,18 +13606,6 @@ function validateFamilyName(tokens, atRule) {
|
|
|
13638
13606
|
let node;
|
|
13639
13607
|
tokens = tokens.slice();
|
|
13640
13608
|
consumeWhitespace(tokens);
|
|
13641
|
-
// if (tokens.length == 0) {
|
|
13642
|
-
//
|
|
13643
|
-
// // @ts-ignore
|
|
13644
|
-
// return {
|
|
13645
|
-
// valid: SyntaxValidationResult.Drop,
|
|
13646
|
-
// matches: [],
|
|
13647
|
-
// node: atRule,
|
|
13648
|
-
// syntax: null,
|
|
13649
|
-
// error: 'expected at-rule prelude',
|
|
13650
|
-
// tokens
|
|
13651
|
-
// } as ValidationSyntaxResult;
|
|
13652
|
-
// }
|
|
13653
13609
|
if (tokens.length == 0 || tokens[0].typ == exports.EnumToken.CommaTokenType) {
|
|
13654
13610
|
// @ts-ignore
|
|
13655
13611
|
return {
|
|
@@ -13662,26 +13618,6 @@ function validateFamilyName(tokens, atRule) {
|
|
|
13662
13618
|
};
|
|
13663
13619
|
}
|
|
13664
13620
|
while (tokens.length > 0) {
|
|
13665
|
-
// @ts-ignore
|
|
13666
|
-
// if (tokens[0].typ == EnumToken.CommaTokenType) {
|
|
13667
|
-
//
|
|
13668
|
-
// node = tokens.shift() as Token;
|
|
13669
|
-
//
|
|
13670
|
-
// consumeWhitespace(tokens);
|
|
13671
|
-
//
|
|
13672
|
-
// if (tokens.length == 0) {
|
|
13673
|
-
//
|
|
13674
|
-
// // @ts-ignore
|
|
13675
|
-
// return {
|
|
13676
|
-
// valid: SyntaxValidationResult.Drop,
|
|
13677
|
-
// matches: [],
|
|
13678
|
-
// node,
|
|
13679
|
-
// syntax: null,
|
|
13680
|
-
// error: 'unexpected token',
|
|
13681
|
-
// tokens
|
|
13682
|
-
// } as ValidationSyntaxResult;
|
|
13683
|
-
// }
|
|
13684
|
-
// }
|
|
13685
13621
|
node = tokens[0];
|
|
13686
13622
|
if (![exports.EnumToken.IdenTokenType, exports.EnumToken.StringTokenType].includes(node.typ)) {
|
|
13687
13623
|
// @ts-ignore
|
|
@@ -13965,33 +13901,7 @@ function validateRelativeSelector(tokens, root, options) {
|
|
|
13965
13901
|
function validateRelativeSelectorList(tokens, root, options) {
|
|
13966
13902
|
tokens = tokens.slice();
|
|
13967
13903
|
consumeWhitespace(tokens);
|
|
13968
|
-
// if (tokens.length == 0) {
|
|
13969
|
-
//
|
|
13970
|
-
// return {
|
|
13971
|
-
// valid: SyntaxValidationResult.Drop,
|
|
13972
|
-
// matches: [],
|
|
13973
|
-
// // @ts-ignore
|
|
13974
|
-
// node: root,
|
|
13975
|
-
// // @ts-ignore
|
|
13976
|
-
// syntax: null,
|
|
13977
|
-
// error: 'expecting relative selector list',
|
|
13978
|
-
// tokens
|
|
13979
|
-
// }
|
|
13980
|
-
// }
|
|
13981
13904
|
for (const t of splitTokenList(tokens)) {
|
|
13982
|
-
// if (t.length == 0) {
|
|
13983
|
-
//
|
|
13984
|
-
// return {
|
|
13985
|
-
// valid: SyntaxValidationResult.Drop,
|
|
13986
|
-
// matches: [],
|
|
13987
|
-
// // @ts-ignore
|
|
13988
|
-
// node: root,
|
|
13989
|
-
// // @ts-ignore
|
|
13990
|
-
// syntax: null,
|
|
13991
|
-
// error: 'unexpected comma',
|
|
13992
|
-
// tokens
|
|
13993
|
-
// }
|
|
13994
|
-
// }
|
|
13995
13905
|
const result = validateRelativeSelector(t, root, options);
|
|
13996
13906
|
if (result.valid == SyntaxValidationResult.Drop) {
|
|
13997
13907
|
return result;
|
|
@@ -14012,17 +13922,6 @@ function validateRelativeSelectorList(tokens, root, options) {
|
|
|
14012
13922
|
function validateComplexSelectorList(tokens, root, options) {
|
|
14013
13923
|
tokens = tokens.slice();
|
|
14014
13924
|
consumeWhitespace(tokens);
|
|
14015
|
-
// if (tokens.length == 0) {
|
|
14016
|
-
//
|
|
14017
|
-
// return {
|
|
14018
|
-
// valid: SyntaxValidationResult.Drop,
|
|
14019
|
-
// context: [],
|
|
14020
|
-
// // @ts-ignore
|
|
14021
|
-
// node: root,
|
|
14022
|
-
// syntax: null,
|
|
14023
|
-
// error: 'expecting complex selector list'
|
|
14024
|
-
// }
|
|
14025
|
-
// }
|
|
14026
13925
|
let result = null;
|
|
14027
13926
|
for (const t of splitTokenList(tokens)) {
|
|
14028
13927
|
result = validateSelector$1(t, root, options);
|
|
@@ -14036,17 +13935,6 @@ function validateComplexSelectorList(tokens, root, options) {
|
|
|
14036
13935
|
|
|
14037
13936
|
function validateKeyframeSelector(tokens, options) {
|
|
14038
13937
|
consumeWhitespace(tokens);
|
|
14039
|
-
// if (tokens.length == 0) {
|
|
14040
|
-
//
|
|
14041
|
-
// // @ts-ignore
|
|
14042
|
-
// return {
|
|
14043
|
-
// valid: SyntaxValidationResult.Drop,
|
|
14044
|
-
// context: [],
|
|
14045
|
-
// node: null,
|
|
14046
|
-
// syntax: null,
|
|
14047
|
-
// error: 'expected keyframe selector'
|
|
14048
|
-
// }
|
|
14049
|
-
// }
|
|
14050
13938
|
for (const t of splitTokenList(tokens)) {
|
|
14051
13939
|
if (t.length != 1 || (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)))) {
|
|
14052
13940
|
return {
|
|
@@ -14196,15 +14084,8 @@ function createContext(input) {
|
|
|
14196
14084
|
},
|
|
14197
14085
|
consume(token, howMany) {
|
|
14198
14086
|
let newIndex = result.indexOf(token, this.index + 1);
|
|
14199
|
-
// if (newIndex == -1 || newIndex < this.index) {
|
|
14200
|
-
// return false;
|
|
14201
|
-
// }
|
|
14202
14087
|
howMany ??= 0;
|
|
14203
14088
|
let splice = 1;
|
|
14204
|
-
// if (result[newIndex - 1]?.typ == EnumToken.WhitespaceTokenType) {
|
|
14205
|
-
// splice++;
|
|
14206
|
-
// newIndex--;
|
|
14207
|
-
// }
|
|
14208
14089
|
result.splice(this.index + 1, 0, ...result.splice(newIndex, splice + howMany));
|
|
14209
14090
|
this.index += howMany + splice;
|
|
14210
14091
|
return true;
|
|
@@ -14226,10 +14107,6 @@ function createContext(input) {
|
|
|
14226
14107
|
this.index = index;
|
|
14227
14108
|
return result[this.index] ?? null;
|
|
14228
14109
|
},
|
|
14229
|
-
// tokens<Token>(): Token[] {
|
|
14230
|
-
//
|
|
14231
|
-
// return result as Token[];
|
|
14232
|
-
// },
|
|
14233
14110
|
slice() {
|
|
14234
14111
|
return result.slice(this.index + 1);
|
|
14235
14112
|
},
|
|
@@ -14237,16 +14114,7 @@ function createContext(input) {
|
|
|
14237
14114
|
const context = createContext(result.slice());
|
|
14238
14115
|
context.index = this.index;
|
|
14239
14116
|
return context;
|
|
14240
|
-
}
|
|
14241
|
-
// @ts-ignore
|
|
14242
|
-
// toJSON(): object {
|
|
14243
|
-
//
|
|
14244
|
-
// return {
|
|
14245
|
-
// index: this.index,
|
|
14246
|
-
// slice: this.slice(),
|
|
14247
|
-
// tokens: this.tokens()
|
|
14248
|
-
// }
|
|
14249
|
-
// }
|
|
14117
|
+
}
|
|
14250
14118
|
};
|
|
14251
14119
|
}
|
|
14252
14120
|
function evaluateSyntax(node, options) {
|
|
@@ -14280,10 +14148,6 @@ function evaluateSyntax(node, options) {
|
|
|
14280
14148
|
if (result.valid == SyntaxValidationResult.Valid && !result.context.done()) {
|
|
14281
14149
|
let token = null;
|
|
14282
14150
|
if ((token = result.context.next()) != null) {
|
|
14283
|
-
// if (token.typ == EnumToken.WhitespaceTokenType || token.typ == EnumToken.CommentTokenType) {
|
|
14284
|
-
//
|
|
14285
|
-
// continue;
|
|
14286
|
-
// }
|
|
14287
14151
|
return {
|
|
14288
14152
|
...result,
|
|
14289
14153
|
valid: SyntaxValidationResult.Drop,
|
|
@@ -14299,13 +14163,6 @@ function evaluateSyntax(node, options) {
|
|
|
14299
14163
|
};
|
|
14300
14164
|
}
|
|
14301
14165
|
break;
|
|
14302
|
-
// case EnumToken.RuleNodeType:
|
|
14303
|
-
// case EnumToken.AtRuleNodeType:
|
|
14304
|
-
// case EnumToken.KeyframeAtRuleNodeType:
|
|
14305
|
-
// case EnumToken.KeyFrameRuleNodeType:
|
|
14306
|
-
// default:
|
|
14307
|
-
//
|
|
14308
|
-
// throw new Error(`Not implemented: ${node.typ}`);
|
|
14309
14166
|
}
|
|
14310
14167
|
return {
|
|
14311
14168
|
valid: SyntaxValidationResult.Valid,
|
|
@@ -14347,8 +14204,6 @@ function doEvaluateSyntax(syntaxes, context, options) {
|
|
|
14347
14204
|
context
|
|
14348
14205
|
};
|
|
14349
14206
|
}
|
|
14350
|
-
// console.error(`>> ${syntaxes.reduce((acc, curr) => acc + renderSyntax(curr), '')}\n>> ${context.slice<Token>().reduce((acc, curr) => acc + renderToken(curr), '')}`);
|
|
14351
|
-
// console.error(new Error('doEvaluateSyntax'));
|
|
14352
14207
|
for (; i < syntaxes.length; i++) {
|
|
14353
14208
|
syntax = syntaxes[i];
|
|
14354
14209
|
if (context.done()) {
|
|
@@ -14359,7 +14214,7 @@ function doEvaluateSyntax(syntaxes, context, options) {
|
|
|
14359
14214
|
}
|
|
14360
14215
|
token = context.peek();
|
|
14361
14216
|
// if var() is the last token, then match the remaining syntax and return
|
|
14362
|
-
if (context.length == 1 && token.typ == exports.EnumToken.FunctionTokenType && 'var'
|
|
14217
|
+
if (context.length == 1 && token.typ == exports.EnumToken.FunctionTokenType && 'var' === token.val?.toLowerCase?.()) {
|
|
14363
14218
|
return doEvaluateSyntax(getParsedSyntax("functions" /* ValidationSyntaxGroupEnum.Functions */, 'var')?.[0]?.chi ?? [], createContext(token.chi), options);
|
|
14364
14219
|
}
|
|
14365
14220
|
if (syntax.typ == ValidationTokenEnum.Whitespace) {
|
|
@@ -14466,16 +14321,6 @@ function matchList(syntax, context, options) {
|
|
|
14466
14321
|
while (!con.done() && con.peek()?.typ != exports.EnumToken.CommaTokenType) {
|
|
14467
14322
|
tokens.push(con.next());
|
|
14468
14323
|
}
|
|
14469
|
-
// if (tokens.length == 0) {
|
|
14470
|
-
//
|
|
14471
|
-
// return {
|
|
14472
|
-
// valid: SyntaxValidationResult.Drop,
|
|
14473
|
-
// node: context.peek(),
|
|
14474
|
-
// syntax,
|
|
14475
|
-
// error: `could not match syntax: ${renderSyntax(syntax)}`,
|
|
14476
|
-
// context
|
|
14477
|
-
// }
|
|
14478
|
-
// }
|
|
14479
14324
|
result = doEvaluateSyntax([syntax], createContext(tokens), {
|
|
14480
14325
|
...options,
|
|
14481
14326
|
isList: false,
|
|
@@ -14560,22 +14405,6 @@ function match(syntax, context, options) {
|
|
|
14560
14405
|
};
|
|
14561
14406
|
}
|
|
14562
14407
|
}
|
|
14563
|
-
// if (token.typ == EnumToken.WhitespaceTokenType) {
|
|
14564
|
-
//
|
|
14565
|
-
// context.next();
|
|
14566
|
-
//
|
|
14567
|
-
// // @ts-ignore
|
|
14568
|
-
// if (syntax?.typ == ValidationTokenEnum.Whitespace) {
|
|
14569
|
-
//
|
|
14570
|
-
// return {
|
|
14571
|
-
// valid: SyntaxValidationResult.Valid,
|
|
14572
|
-
// node: null,
|
|
14573
|
-
// syntax,
|
|
14574
|
-
// error: '',
|
|
14575
|
-
// context
|
|
14576
|
-
// }
|
|
14577
|
-
// }
|
|
14578
|
-
// }
|
|
14579
14408
|
if (syntax.typ != ValidationTokenEnum.PropertyType && (token?.typ == exports.EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val))) {
|
|
14580
14409
|
const result = doEvaluateSyntax(getParsedSyntax("functions" /* ValidationSyntaxGroupEnum.Functions */, token.val)?.[0]?.chi ?? [], createContext(token.chi), {
|
|
14581
14410
|
...options,
|
|
@@ -14593,7 +14422,7 @@ function match(syntax, context, options) {
|
|
|
14593
14422
|
case ValidationTokenEnum.Keyword:
|
|
14594
14423
|
success = (token.typ == exports.EnumToken.IdenTokenType || token.typ == exports.EnumToken.DashedIdenTokenType || isIdentColor(token)) &&
|
|
14595
14424
|
(token.val == syntax.val ||
|
|
14596
|
-
syntax.val
|
|
14425
|
+
syntax.val === token.val?.toLowerCase?.() ||
|
|
14597
14426
|
// config.declarations.all
|
|
14598
14427
|
allValues.includes(token.val.toLowerCase()));
|
|
14599
14428
|
if (success) {
|
|
@@ -14621,7 +14450,6 @@ function match(syntax, context, options) {
|
|
|
14621
14450
|
};
|
|
14622
14451
|
}
|
|
14623
14452
|
result = match(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, syntax.val + '()')?.[0], context, options);
|
|
14624
|
-
// console.error(`>>[]
|
|
14625
14453
|
if (result.valid == SyntaxValidationResult.Valid) {
|
|
14626
14454
|
context.next();
|
|
14627
14455
|
result.context = context;
|
|
@@ -14636,49 +14464,12 @@ function match(syntax, context, options) {
|
|
|
14636
14464
|
occurence: null,
|
|
14637
14465
|
atLeastOnce: null
|
|
14638
14466
|
});
|
|
14639
|
-
// case ValidationTokenEnum.Parens:
|
|
14640
|
-
//
|
|
14641
|
-
// token = context.peek() as Token;
|
|
14642
|
-
// if (token.typ != EnumToken.ParensTokenType) {
|
|
14643
|
-
//
|
|
14644
|
-
// break;
|
|
14645
|
-
// }
|
|
14646
|
-
//
|
|
14647
|
-
// success = doEvaluateSyntax((syntax as ValidationParensToken).chi as ValidationToken[], createContext((token as ParensToken).chi), {
|
|
14648
|
-
// ...options,
|
|
14649
|
-
// isRepeatable: null,
|
|
14650
|
-
// isList: null,
|
|
14651
|
-
// occurence: null,
|
|
14652
|
-
// atLeastOnce: null
|
|
14653
|
-
// } as ValidationOptions).valid == SyntaxValidationResult.Valid;
|
|
14654
|
-
// break;
|
|
14655
14467
|
case ValidationTokenEnum.Comma:
|
|
14656
14468
|
success = context.peek()?.typ == exports.EnumToken.CommaTokenType;
|
|
14657
14469
|
if (success) {
|
|
14658
14470
|
context.next();
|
|
14659
14471
|
}
|
|
14660
14472
|
break;
|
|
14661
|
-
// case ValidationTokenEnum.Number:
|
|
14662
|
-
//
|
|
14663
|
-
// success = context.peek<Token>()?.typ == EnumToken.NumberTokenType;
|
|
14664
|
-
//
|
|
14665
|
-
// if (success) {
|
|
14666
|
-
//
|
|
14667
|
-
// context.next();
|
|
14668
|
-
// }
|
|
14669
|
-
//
|
|
14670
|
-
// break;
|
|
14671
|
-
//
|
|
14672
|
-
// case ValidationTokenEnum.Whitespace:
|
|
14673
|
-
//
|
|
14674
|
-
// success = context.peek<Token>()?.typ == EnumToken.WhitespaceTokenType;
|
|
14675
|
-
//
|
|
14676
|
-
// if (success) {
|
|
14677
|
-
//
|
|
14678
|
-
// context.next();
|
|
14679
|
-
// }
|
|
14680
|
-
//
|
|
14681
|
-
// break;
|
|
14682
14473
|
case ValidationTokenEnum.Separator:
|
|
14683
14474
|
{
|
|
14684
14475
|
const token = context.peek();
|
|
@@ -14694,14 +14485,7 @@ function match(syntax, context, options) {
|
|
|
14694
14485
|
break;
|
|
14695
14486
|
}
|
|
14696
14487
|
if (syntax.typ == ValidationTokenEnum.Function) {
|
|
14697
|
-
success = funcLike.includes(token.typ) && syntax.val.
|
|
14698
|
-
// console.error(`>> match: ${JSON.stringify({
|
|
14699
|
-
// syntax,
|
|
14700
|
-
// token,
|
|
14701
|
-
// // result,
|
|
14702
|
-
// tr2: syntax,
|
|
14703
|
-
// success
|
|
14704
|
-
// }, null, 1)}`);
|
|
14488
|
+
success = funcLike.includes(token.typ) && syntax.val.toLowerCase() === token.val?.toLowerCase?.() && doEvaluateSyntax(syntax.chi, createContext(token.chi), options).valid == SyntaxValidationResult.Valid;
|
|
14705
14489
|
if (success) {
|
|
14706
14490
|
context.next();
|
|
14707
14491
|
}
|
|
@@ -14720,7 +14504,6 @@ function match(syntax, context, options) {
|
|
|
14720
14504
|
}
|
|
14721
14505
|
break;
|
|
14722
14506
|
}
|
|
14723
|
-
// throw new Error(`Not implemented: ${ValidationTokenEnum[syntax.typ] ?? syntax.typ} : ${renderSyntax(syntax)} : ${renderToken(context.peek() as Token)} : ${JSON.stringify(syntax, null, 1)} | ${JSON.stringify(context.peek(), null, 1)}`);
|
|
14724
14507
|
}
|
|
14725
14508
|
if (!success && token.typ == exports.EnumToken.IdenTokenType && allValues.includes(token.val.toLowerCase())) {
|
|
14726
14509
|
success = true;
|
|
@@ -14833,7 +14616,7 @@ function matchPropertyType(syntax, context, options) {
|
|
|
14833
14616
|
token = context.peek();
|
|
14834
14617
|
continue;
|
|
14835
14618
|
}
|
|
14836
|
-
success = token.typ == exports.EnumToken.LengthTokenType || token.typ == exports.EnumToken.PercentageTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val ==
|
|
14619
|
+
success = token.typ == exports.EnumToken.LengthTokenType || token.typ == exports.EnumToken.PercentageTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val == 0);
|
|
14837
14620
|
if (!success) {
|
|
14838
14621
|
break;
|
|
14839
14622
|
}
|
|
@@ -14883,14 +14666,14 @@ function matchPropertyType(syntax, context, options) {
|
|
|
14883
14666
|
success = token.typ == exports.EnumToken.DashedIdenTokenType;
|
|
14884
14667
|
break;
|
|
14885
14668
|
case 'system-color':
|
|
14886
|
-
success = (token.typ == exports.EnumToken.ColorTokenType && token.kin == exports.ColorType.SYS) || (token.typ == exports.EnumToken.IdenTokenType && token.val.
|
|
14669
|
+
success = (token.typ == exports.EnumToken.ColorTokenType && token.kin == exports.ColorType.SYS) || (token.typ == exports.EnumToken.IdenTokenType && 'currentcolor' === token.val.toLowerCase()) || (token.typ == exports.EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
|
|
14887
14670
|
break;
|
|
14888
14671
|
case 'deprecated-system-color':
|
|
14889
|
-
success = (token.typ == exports.EnumToken.ColorTokenType && token.kin == exports.ColorType.DPSYS) || (token.typ == exports.EnumToken.IdenTokenType && token.val.
|
|
14672
|
+
success = (token.typ == exports.EnumToken.ColorTokenType && token.kin == exports.ColorType.DPSYS) || (token.typ == exports.EnumToken.IdenTokenType && 'currentcolor' === token.val.toLowerCase()) || (token.typ == exports.EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
|
|
14890
14673
|
break;
|
|
14891
14674
|
case 'color':
|
|
14892
14675
|
case 'color-base':
|
|
14893
|
-
success = token.typ == exports.EnumToken.ColorTokenType || (token.typ == exports.EnumToken.IdenTokenType && token.val.
|
|
14676
|
+
success = token.typ == exports.EnumToken.ColorTokenType || (token.typ == exports.EnumToken.IdenTokenType && 'currentcolor' === token.val.toLowerCase()) || (token.typ == exports.EnumToken.IdenTokenType && 'transparent' === token.val.toLowerCase()) || (token.typ == exports.EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
|
|
14894
14677
|
if (!success && token.typ == exports.EnumToken.FunctionTokenType && colorsFunc.includes(token.val)) {
|
|
14895
14678
|
success = doEvaluateSyntax(getParsedSyntax("functions" /* ValidationSyntaxGroupEnum.Functions */, token.val)?.[0]?.chi, createContext(token.chi), {
|
|
14896
14679
|
...options,
|
|
@@ -14931,19 +14714,19 @@ function matchPropertyType(syntax, context, options) {
|
|
|
14931
14714
|
}
|
|
14932
14715
|
break;
|
|
14933
14716
|
case 'angle':
|
|
14934
|
-
success = token.typ == exports.EnumToken.AngleTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val ==
|
|
14717
|
+
success = token.typ == exports.EnumToken.AngleTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val == 0) || (token.typ == exports.EnumToken.FunctionTokenType && token.val == 'calc');
|
|
14935
14718
|
break;
|
|
14936
14719
|
case 'length':
|
|
14937
|
-
success = token.typ == exports.EnumToken.LengthTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val ==
|
|
14720
|
+
success = token.typ == exports.EnumToken.LengthTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val == 0) || (token.typ == exports.EnumToken.FunctionTokenType && token.val == 'calc');
|
|
14938
14721
|
break;
|
|
14939
14722
|
case 'percentage':
|
|
14940
|
-
success = token.typ == exports.EnumToken.PercentageTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val ==
|
|
14723
|
+
success = token.typ == exports.EnumToken.PercentageTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val == 0) || (token.typ == exports.EnumToken.FunctionTokenType && token.val == 'calc');
|
|
14941
14724
|
break;
|
|
14942
14725
|
case 'length-percentage':
|
|
14943
|
-
success = token.typ == exports.EnumToken.LengthTokenType || token.typ == exports.EnumToken.PercentageTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val ==
|
|
14726
|
+
success = token.typ == exports.EnumToken.LengthTokenType || token.typ == exports.EnumToken.PercentageTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val == 0) || (token.typ == exports.EnumToken.FunctionTokenType && token.val == 'calc');
|
|
14944
14727
|
break;
|
|
14945
14728
|
case 'resolution':
|
|
14946
|
-
success = token.typ == exports.EnumToken.ResolutionTokenType || token.typ == exports.EnumToken.PercentageTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val ==
|
|
14729
|
+
success = token.typ == exports.EnumToken.ResolutionTokenType || token.typ == exports.EnumToken.PercentageTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val == 0) || (token.typ == exports.EnumToken.FunctionTokenType && token.val == 'calc');
|
|
14947
14730
|
break;
|
|
14948
14731
|
case 'hash-token':
|
|
14949
14732
|
success = token.typ == exports.EnumToken.HashTokenType;
|
|
@@ -14955,7 +14738,7 @@ function matchPropertyType(syntax, context, options) {
|
|
|
14955
14738
|
success = token.typ == exports.EnumToken.TimeTokenType || (token.typ == exports.EnumToken.FunctionTokenType && token.val == 'calc');
|
|
14956
14739
|
break;
|
|
14957
14740
|
case 'zero':
|
|
14958
|
-
success = token.val ==
|
|
14741
|
+
success = token.val == 0 || (token.typ == exports.EnumToken.FunctionTokenType && token.val == 'calc');
|
|
14959
14742
|
break;
|
|
14960
14743
|
case 'pseudo-element-selector':
|
|
14961
14744
|
success = token.typ == exports.EnumToken.PseudoElementTokenType;
|
|
@@ -14975,9 +14758,6 @@ function matchPropertyType(syntax, context, options) {
|
|
|
14975
14758
|
}
|
|
14976
14759
|
}
|
|
14977
14760
|
break;
|
|
14978
|
-
// default:
|
|
14979
|
-
//
|
|
14980
|
-
// throw new Error(`Not implemented: ${ValidationTokenEnum[syntax.typ] ?? syntax.typ} : ${renderSyntax(syntax)}\n${JSON.stringify(syntax, null, 1)}`);
|
|
14981
14761
|
}
|
|
14982
14762
|
if (!success &&
|
|
14983
14763
|
token.typ == exports.EnumToken.FunctionTokenType &&
|
|
@@ -15013,12 +14793,7 @@ function someOf(syntaxes, context, options) {
|
|
|
15013
14793
|
let success = false;
|
|
15014
14794
|
const matched = [];
|
|
15015
14795
|
for (i = 0; i < syntaxes.length; i++) {
|
|
15016
|
-
// if (context.peek<Token>()?.typ == EnumToken.WhitespaceTokenType) {
|
|
15017
|
-
//
|
|
15018
|
-
// context.next();
|
|
15019
|
-
// }
|
|
15020
14796
|
result = doEvaluateSyntax(syntaxes[i], context.clone(), options);
|
|
15021
|
-
// console.error(`>> someOf: ${JSON.stringify({result}, null, 1)}`);
|
|
15022
14797
|
if (result.valid == SyntaxValidationResult.Valid) {
|
|
15023
14798
|
success = true;
|
|
15024
14799
|
if (result.context.done()) {
|
|
@@ -15031,8 +14806,6 @@ function someOf(syntaxes, context, options) {
|
|
|
15031
14806
|
// pick the best match
|
|
15032
14807
|
matched.sort((a, b) => a.context.done() ? -1 : b.context.done() ? 1 : b.context.index - a.context.index);
|
|
15033
14808
|
}
|
|
15034
|
-
// console.error(JSON.stringify({matched}, null, 1));
|
|
15035
|
-
// console.error(new Error('someOf'));
|
|
15036
14809
|
return matched[0] ?? {
|
|
15037
14810
|
valid: SyntaxValidationResult.Drop,
|
|
15038
14811
|
node: context.peek(),
|
|
@@ -15088,10 +14861,6 @@ function allOf(syntax, context, options) {
|
|
|
15088
14861
|
for (i = 0; i < slice.length; i++) {
|
|
15089
14862
|
if (slice[i].typ == exports.EnumToken.FunctionTokenType && wildCardFuncs.includes(slice[i].val.toLowerCase())) {
|
|
15090
14863
|
vars.push(slice[i]);
|
|
15091
|
-
// if (slice[i + 1]?.typ == EnumToken.WhitespaceTokenType) {
|
|
15092
|
-
//
|
|
15093
|
-
// vars.push(slice[++i]);
|
|
15094
|
-
// }
|
|
15095
14864
|
continue;
|
|
15096
14865
|
}
|
|
15097
14866
|
if (slice[i].typ == exports.EnumToken.CommaTokenType || (slice[i].typ == exports.EnumToken.LiteralTokenType && slice[i].val == '/')) {
|
|
@@ -15118,7 +14887,6 @@ function allOf(syntax, context, options) {
|
|
|
15118
14887
|
}
|
|
15119
14888
|
while (!cp.done()) {
|
|
15120
14889
|
result = doEvaluateSyntax(syntax[i], cp.clone(), { ...options, isOptional: false });
|
|
15121
|
-
// console.error(`>> allOf: syntaxes[${i}]: ${syntax[i].length} ${syntax[i].reduce((acc, curr) => acc + renderSyntax(curr), '')}\n>> ${cp.slice<Token>().reduce((acc, curr) => acc + renderToken(curr), '')}\n>> ${JSON.stringify({result}, null, 1)}`);
|
|
15122
14890
|
if (result.valid == SyntaxValidationResult.Valid) {
|
|
15123
14891
|
let end = slice.indexOf(cp.current());
|
|
15124
14892
|
if (end == -1) {
|
|
@@ -15175,43 +14943,10 @@ function flatten(syntax) {
|
|
|
15175
14943
|
}
|
|
15176
14944
|
|
|
15177
14945
|
function validateURL(token) {
|
|
15178
|
-
// if (token.typ == EnumToken.UrlTokenTokenType) {
|
|
15179
|
-
//
|
|
15180
|
-
// // @ts-ignore
|
|
15181
|
-
// return {
|
|
15182
|
-
// valid: SyntaxValidationResult.Valid,
|
|
15183
|
-
// context: [],
|
|
15184
|
-
// node: token,
|
|
15185
|
-
// // @ts-ignore
|
|
15186
|
-
// syntax: 'url()',
|
|
15187
|
-
// error: ''
|
|
15188
|
-
// }
|
|
15189
|
-
// }
|
|
15190
|
-
// if (token.typ != EnumToken.UrlFunctionTokenType) {
|
|
15191
|
-
//
|
|
15192
|
-
// // @ts-ignore
|
|
15193
|
-
// return {
|
|
15194
|
-
// valid: SyntaxValidationResult.Drop,
|
|
15195
|
-
// context: [],
|
|
15196
|
-
// node: token,
|
|
15197
|
-
// // @ts-ignore
|
|
15198
|
-
// syntax: 'url()',
|
|
15199
|
-
// error: 'expected url()'
|
|
15200
|
-
// }
|
|
15201
|
-
// }
|
|
15202
14946
|
const children = token.chi.slice();
|
|
15203
14947
|
consumeWhitespace(children);
|
|
15204
14948
|
if (children.length > 0 && [exports.EnumToken.UrlTokenTokenType, exports.EnumToken.StringTokenType, exports.EnumToken.HashTokenType].includes(children[0].typ)) {
|
|
15205
14949
|
children.shift();
|
|
15206
|
-
// @ts-ignore
|
|
15207
|
-
// return {
|
|
15208
|
-
// valid: SyntaxValidationResult.Drop,
|
|
15209
|
-
// context: [],
|
|
15210
|
-
// node: children[0] ?? token,
|
|
15211
|
-
// // @ts-ignore
|
|
15212
|
-
// syntax: 'url()',
|
|
15213
|
-
// error: 'expected url-token'
|
|
15214
|
-
// }
|
|
15215
14950
|
}
|
|
15216
14951
|
consumeWhitespace(children);
|
|
15217
14952
|
if (children.length > 0) {
|
|
@@ -15239,15 +14974,6 @@ function validateURL(token) {
|
|
|
15239
14974
|
const validateSelectorList = validateComplexSelectorList;
|
|
15240
14975
|
|
|
15241
14976
|
function validateSelector(selector, options, root) {
|
|
15242
|
-
// if (root == null) {
|
|
15243
|
-
//
|
|
15244
|
-
// return validateSelectorList(selector, root, options);
|
|
15245
|
-
// }
|
|
15246
|
-
// @ts-ignore
|
|
15247
|
-
// if (root.typ == EnumToken.AtRuleNodeType && root.nam.match(/^(-[a-z]+-)?keyframes$/)) {
|
|
15248
|
-
//
|
|
15249
|
-
// return validateKeyframeBlockList(selector, root as AstAtRule, options);
|
|
15250
|
-
// }
|
|
15251
14977
|
let isNested = root.typ == exports.EnumToken.RuleNodeType ? 1 : 0;
|
|
15252
14978
|
let currentRoot = root.parent;
|
|
15253
14979
|
while (currentRoot != null && isNested == 0) {
|
|
@@ -15846,7 +15572,7 @@ function validateSupportCondition(atRule, token) {
|
|
|
15846
15572
|
if (token.typ == exports.EnumToken.MediaFeatureNotTokenType) {
|
|
15847
15573
|
return validateSupportCondition(atRule, token.val);
|
|
15848
15574
|
}
|
|
15849
|
-
if (token.typ == exports.EnumToken.FunctionTokenType && token.val.
|
|
15575
|
+
if (token.typ == exports.EnumToken.FunctionTokenType && 'selector' === token.val.toLowerCase()) {
|
|
15850
15576
|
return {
|
|
15851
15577
|
valid: SyntaxValidationResult.Valid,
|
|
15852
15578
|
context: [],
|
|
@@ -15903,7 +15629,7 @@ function validateSupportFeature(token) {
|
|
|
15903
15629
|
return validateSupportFeature(token.val);
|
|
15904
15630
|
}
|
|
15905
15631
|
if (token.typ == exports.EnumToken.FunctionTokenType) {
|
|
15906
|
-
if (token.val.
|
|
15632
|
+
if ('selector' === token.val.toLowerCase()) {
|
|
15907
15633
|
return {
|
|
15908
15634
|
valid: SyntaxValidationResult.Valid,
|
|
15909
15635
|
context: [],
|
|
@@ -15912,10 +15638,10 @@ function validateSupportFeature(token) {
|
|
|
15912
15638
|
error: ''
|
|
15913
15639
|
};
|
|
15914
15640
|
}
|
|
15915
|
-
if (
|
|
15641
|
+
if ('font-tech' === token.val.toLowerCase()) {
|
|
15916
15642
|
const chi = token.chi.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ));
|
|
15917
15643
|
// @ts-ignore
|
|
15918
|
-
return chi.length == 1 && chi[0].typ == exports.EnumToken.IdenTokenType && colorFontTech.concat(fontFeaturesTech).
|
|
15644
|
+
return chi.length == 1 && chi[0].typ == exports.EnumToken.IdenTokenType && colorFontTech.concat(fontFeaturesTech).includes(chi[0].val.toLowerCase()) ?
|
|
15919
15645
|
{
|
|
15920
15646
|
valid: SyntaxValidationResult.Valid,
|
|
15921
15647
|
context: [],
|
|
@@ -15931,10 +15657,10 @@ function validateSupportFeature(token) {
|
|
|
15931
15657
|
error: 'expected font-tech'
|
|
15932
15658
|
};
|
|
15933
15659
|
}
|
|
15934
|
-
if (
|
|
15660
|
+
if ('font-format' === token.val.toLowerCase()) {
|
|
15935
15661
|
const chi = token.chi.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ));
|
|
15936
15662
|
// @ts-ignore
|
|
15937
|
-
return chi.length == 1 && chi[0].typ == exports.EnumToken.IdenTokenType && fontFormat.
|
|
15663
|
+
return chi.length == 1 && chi[0].typ == exports.EnumToken.IdenTokenType && fontFormat.includes(chi[0].val, toLowerCase()) ?
|
|
15938
15664
|
{
|
|
15939
15665
|
valid: SyntaxValidationResult.Valid,
|
|
15940
15666
|
context: [],
|
|
@@ -16041,8 +15767,7 @@ function validateAtRuleImport(atRule, options, root) {
|
|
|
16041
15767
|
if (tokens.length > 0) {
|
|
16042
15768
|
// @ts-ignore
|
|
16043
15769
|
if (tokens[0].typ == exports.EnumToken.IdenTokenType) {
|
|
16044
|
-
|
|
16045
|
-
if ('layer'.localeCompare(tokens[0].val, undefined, { sensitivity: 'base' }) == 0) {
|
|
15770
|
+
if ('layer' === tokens[0].val.toLowerCase()) {
|
|
16046
15771
|
tokens.shift();
|
|
16047
15772
|
// @ts-ignore
|
|
16048
15773
|
if (!consumeWhitespace(tokens)) {
|
|
@@ -16060,7 +15785,7 @@ function validateAtRuleImport(atRule, options, root) {
|
|
|
16060
15785
|
// @ts-ignore
|
|
16061
15786
|
else if (tokens[0].typ == exports.EnumToken.FunctionTokenType) {
|
|
16062
15787
|
// @ts-ignore
|
|
16063
|
-
if ('layer'
|
|
15788
|
+
if ('layer' === tokens[0].val.toLowerCase()) {
|
|
16064
15789
|
const result = validateLayerName(tokens[0].chi);
|
|
16065
15790
|
if (result.valid == SyntaxValidationResult.Drop) {
|
|
16066
15791
|
return result;
|
|
@@ -16069,8 +15794,9 @@ function validateAtRuleImport(atRule, options, root) {
|
|
|
16069
15794
|
// @ts-ignore
|
|
16070
15795
|
consumeWhitespace(tokens);
|
|
16071
15796
|
}
|
|
15797
|
+
// tokens[0]?.val
|
|
16072
15798
|
// @ts-ignore
|
|
16073
|
-
if ('supports'
|
|
15799
|
+
if ('supports' === tokens[0]?.val?.toLowerCase?.()) {
|
|
16074
15800
|
const result = validateAtRuleSupportsConditions(atRule, tokens[0].chi);
|
|
16075
15801
|
if (result.valid == SyntaxValidationResult.Drop) {
|
|
16076
15802
|
return result;
|
|
@@ -16252,7 +15978,7 @@ function validateAtRuleDocument(atRule, options, root) {
|
|
|
16252
15978
|
};
|
|
16253
15979
|
}
|
|
16254
15980
|
// @ts-ignore
|
|
16255
|
-
if ((t[0].typ != exports.EnumToken.FunctionTokenType && t[0].typ != exports.EnumToken.UrlFunctionTokenType) || !['url', 'url-prefix', 'domain', 'media-document', 'regexp'].
|
|
15981
|
+
if ((t[0].typ != exports.EnumToken.FunctionTokenType && t[0].typ != exports.EnumToken.UrlFunctionTokenType) || !['url', 'url-prefix', 'domain', 'media-document', 'regexp'].includes(t[0].val?.toLowerCase?.())) {
|
|
16256
15982
|
return {
|
|
16257
15983
|
valid: SyntaxValidationResult.Drop,
|
|
16258
15984
|
context: [],
|
|
@@ -16306,17 +16032,6 @@ function validateAtRuleKeyframes(atRule, options, root) {
|
|
|
16306
16032
|
}
|
|
16307
16033
|
const tokens = atRule.tokens.filter((t) => t.typ != exports.EnumToken.CommentTokenType).slice();
|
|
16308
16034
|
consumeWhitespace(tokens);
|
|
16309
|
-
// if (tokens.length == 0) {
|
|
16310
|
-
//
|
|
16311
|
-
// // @ts-ignore
|
|
16312
|
-
// return {
|
|
16313
|
-
// valid: SyntaxValidationResult.Drop,
|
|
16314
|
-
// context: [],
|
|
16315
|
-
// node: atRule,
|
|
16316
|
-
// syntax: '@keyframes',
|
|
16317
|
-
// error: 'expecting at-rule prelude'
|
|
16318
|
-
// } as ValidationSyntaxResult;
|
|
16319
|
-
// }
|
|
16320
16035
|
if (tokens.length == 0 || ![exports.EnumToken.StringTokenType, exports.EnumToken.IdenTokenType].includes(tokens[0].typ)) {
|
|
16321
16036
|
// @ts-ignore
|
|
16322
16037
|
return {
|
|
@@ -17129,6 +16844,18 @@ async function doParse(iterator, options = {}) {
|
|
|
17129
16844
|
stats.bytesIn = item.bytesIn;
|
|
17130
16845
|
rawTokens.push(item);
|
|
17131
16846
|
if (item.hint != null && BadTokensTypes.includes(item.hint)) {
|
|
16847
|
+
const node = getTokenType(item.token, item.hint);
|
|
16848
|
+
errors.push({
|
|
16849
|
+
action: 'drop',
|
|
16850
|
+
message: 'Bad token',
|
|
16851
|
+
syntax: null,
|
|
16852
|
+
node,
|
|
16853
|
+
location: {
|
|
16854
|
+
src,
|
|
16855
|
+
sta: item.sta,
|
|
16856
|
+
end: item.end
|
|
16857
|
+
}
|
|
16858
|
+
});
|
|
17132
16859
|
// bad token
|
|
17133
16860
|
continue;
|
|
17134
16861
|
}
|
|
@@ -17173,7 +16900,12 @@ async function doParse(iterator, options = {}) {
|
|
|
17173
16900
|
errors.push({
|
|
17174
16901
|
action: 'drop',
|
|
17175
16902
|
message: 'invalid block',
|
|
17176
|
-
rawTokens: tokens.slice()
|
|
16903
|
+
rawTokens: tokens.slice(),
|
|
16904
|
+
location: {
|
|
16905
|
+
src,
|
|
16906
|
+
sta: tokens[0].sta,
|
|
16907
|
+
end: tokens[tokens.length - 1].end
|
|
16908
|
+
}
|
|
17177
16909
|
});
|
|
17178
16910
|
}
|
|
17179
16911
|
}
|
|
@@ -17341,6 +17073,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
17341
17073
|
errors.push({
|
|
17342
17074
|
action: 'drop',
|
|
17343
17075
|
message: `CDOCOMM not allowed here ${JSON.stringify(tokens[i], null, 1)}`,
|
|
17076
|
+
node: tokens[i],
|
|
17344
17077
|
location
|
|
17345
17078
|
});
|
|
17346
17079
|
continue;
|
|
@@ -17395,7 +17128,8 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
17395
17128
|
if (!(type == exports.EnumToken.InvalidAtRuleTokenType &&
|
|
17396
17129
|
// @ts-ignore
|
|
17397
17130
|
['charset', 'layer', 'import'].includes(context.chi[i].nam))) {
|
|
17398
|
-
|
|
17131
|
+
// @ts-ignore
|
|
17132
|
+
errors.push({ action: 'drop', message: 'invalid @import', location, rawTokens: [atRule, ...tokens] });
|
|
17399
17133
|
return null;
|
|
17400
17134
|
}
|
|
17401
17135
|
}
|
|
@@ -17471,7 +17205,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
17471
17205
|
action: 'drop',
|
|
17472
17206
|
message: '@charset must have only one space',
|
|
17473
17207
|
// @ts-ignore
|
|
17474
|
-
location
|
|
17208
|
+
location, rawTokens: [atRule, ...tokens]
|
|
17475
17209
|
});
|
|
17476
17210
|
return null;
|
|
17477
17211
|
}
|
|
@@ -17540,6 +17274,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
17540
17274
|
errors.push({
|
|
17541
17275
|
action: 'drop',
|
|
17542
17276
|
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), '') + '"',
|
|
17277
|
+
node,
|
|
17543
17278
|
// @ts-ignore
|
|
17544
17279
|
location: { src, ...(map.get(valid.node) ?? location) }
|
|
17545
17280
|
});
|
|
@@ -17588,7 +17323,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
17588
17323
|
if (curr.typ == exports.EnumToken.IdenTokenType && curr.val == 'from') {
|
|
17589
17324
|
Object.assign(curr, { typ: exports.EnumToken.PercentageTokenType, val: '0' });
|
|
17590
17325
|
}
|
|
17591
|
-
else if (curr.typ == exports.EnumToken.PercentageTokenType && curr.val ==
|
|
17326
|
+
else if (curr.typ == exports.EnumToken.PercentageTokenType && curr.val == 100) {
|
|
17592
17327
|
Object.assign(curr, { typ: exports.EnumToken.IdenTokenType, val: 'to' });
|
|
17593
17328
|
}
|
|
17594
17329
|
}
|
|
@@ -17641,6 +17376,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
17641
17376
|
errors.push({
|
|
17642
17377
|
action: 'drop',
|
|
17643
17378
|
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), '') + '"',
|
|
17379
|
+
node,
|
|
17644
17380
|
// @ts-ignore
|
|
17645
17381
|
location
|
|
17646
17382
|
});
|
|
@@ -17665,7 +17401,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
17665
17401
|
val: tokens[i].val.charAt(0)
|
|
17666
17402
|
}, {
|
|
17667
17403
|
typ: exports.EnumToken.NumberTokenType,
|
|
17668
|
-
val: tokens[i].val.slice(1)
|
|
17404
|
+
val: +tokens[i].val.slice(1)
|
|
17669
17405
|
});
|
|
17670
17406
|
}
|
|
17671
17407
|
else if (start == '/' && isFunction(val)) {
|
|
@@ -17866,9 +17602,10 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
17866
17602
|
}
|
|
17867
17603
|
}
|
|
17868
17604
|
}
|
|
17605
|
+
const val = value.typ == exports.EnumToken.IdenTokenType ? value.val.toLowerCase() : null;
|
|
17869
17606
|
if (value.typ == exports.EnumToken.IdenTokenType) {
|
|
17870
17607
|
if (parent == null && mediaTypes.some((t) => {
|
|
17871
|
-
if (
|
|
17608
|
+
if (val === t) {
|
|
17872
17609
|
// @ts-ignore
|
|
17873
17610
|
value.typ = exports.EnumToken.MediaFeatureTokenType;
|
|
17874
17611
|
return true;
|
|
@@ -17877,18 +17614,18 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
17877
17614
|
})) {
|
|
17878
17615
|
continue;
|
|
17879
17616
|
}
|
|
17880
|
-
if (value.typ == exports.EnumToken.IdenTokenType && 'and'
|
|
17617
|
+
if (value.typ == exports.EnumToken.IdenTokenType && 'and' === val) {
|
|
17881
17618
|
// @ts-ignore
|
|
17882
17619
|
value.typ = exports.EnumToken.MediaFeatureAndTokenType;
|
|
17883
17620
|
continue;
|
|
17884
17621
|
}
|
|
17885
|
-
if (value.typ == exports.EnumToken.IdenTokenType && 'or'
|
|
17622
|
+
if (value.typ == exports.EnumToken.IdenTokenType && 'or' === val) {
|
|
17886
17623
|
// @ts-ignore
|
|
17887
17624
|
value.typ = exports.EnumToken.MediaFeatureOrTokenType;
|
|
17888
17625
|
continue;
|
|
17889
17626
|
}
|
|
17890
17627
|
if (value.typ == exports.EnumToken.IdenTokenType &&
|
|
17891
|
-
['not', 'only'].some((t) =>
|
|
17628
|
+
['not', 'only'].some((t) => val === t)) {
|
|
17892
17629
|
// @ts-ignore
|
|
17893
17630
|
const array = parent?.chi ?? tokens;
|
|
17894
17631
|
const startIndex = array.indexOf(value);
|
|
@@ -18201,19 +17938,19 @@ function getTokenType(val, hint) {
|
|
|
18201
17938
|
if (isNumber(val)) {
|
|
18202
17939
|
return {
|
|
18203
17940
|
typ: exports.EnumToken.NumberTokenType,
|
|
18204
|
-
val
|
|
17941
|
+
val: +val
|
|
18205
17942
|
};
|
|
18206
17943
|
}
|
|
18207
17944
|
if (isPercentage(val)) {
|
|
18208
17945
|
return {
|
|
18209
17946
|
typ: exports.EnumToken.PercentageTokenType,
|
|
18210
|
-
val: val.slice(0, -1)
|
|
17947
|
+
val: +val.slice(0, -1)
|
|
18211
17948
|
};
|
|
18212
17949
|
}
|
|
18213
17950
|
if (isFlex(val)) {
|
|
18214
17951
|
return {
|
|
18215
17952
|
typ: exports.EnumToken.FlexTokenType,
|
|
18216
|
-
val: val.slice(0, -2)
|
|
17953
|
+
val: +val.slice(0, -2)
|
|
18217
17954
|
};
|
|
18218
17955
|
}
|
|
18219
17956
|
if (isDimension(val)) {
|
|
@@ -19007,25 +18744,6 @@ class InlineCssVariablesFeature {
|
|
|
19007
18744
|
replace(node, variableScope);
|
|
19008
18745
|
}
|
|
19009
18746
|
}
|
|
19010
|
-
// else {
|
|
19011
|
-
//
|
|
19012
|
-
// const info: VariableScopeInfo = <VariableScopeInfo>variableScope.get((<AstDeclaration>node).nam);
|
|
19013
|
-
//
|
|
19014
|
-
// info.globalScope = isRoot;
|
|
19015
|
-
//
|
|
19016
|
-
// if (!isRoot) {
|
|
19017
|
-
//
|
|
19018
|
-
// ++info.declarationCount;
|
|
19019
|
-
// }
|
|
19020
|
-
//
|
|
19021
|
-
// if (info.replaceable) {
|
|
19022
|
-
//
|
|
19023
|
-
// info.replaceable = isRoot && info.declarationCount == 1;
|
|
19024
|
-
// }
|
|
19025
|
-
//
|
|
19026
|
-
// info.parent.add(ast);
|
|
19027
|
-
// info.node = (<AstDeclaration>node);
|
|
19028
|
-
// }
|
|
19029
18747
|
}
|
|
19030
18748
|
else {
|
|
19031
18749
|
replace(node, variableScope);
|
|
@@ -19066,7 +18784,7 @@ function dedup(values) {
|
|
|
19066
18784
|
while (i-- > 1) {
|
|
19067
18785
|
const t = value[i];
|
|
19068
18786
|
const k = value[i == 1 ? 0 : i % 2];
|
|
19069
|
-
if (t.val == k.val && t.val ==
|
|
18787
|
+
if (t.val == k.val && t.val == 0) {
|
|
19070
18788
|
if ((t.typ == exports.EnumToken.NumberTokenType && isLength(k)) ||
|
|
19071
18789
|
(k.typ == exports.EnumToken.NumberTokenType && isLength(t)) ||
|
|
19072
18790
|
(isLength(k) || isLength(t))) {
|
|
@@ -19103,7 +18821,7 @@ class PropertySet {
|
|
|
19103
18821
|
// @ts-ignore
|
|
19104
18822
|
for (let token of this.declarations.get(this.config.shorthand).val) {
|
|
19105
18823
|
// @ts-ignore
|
|
19106
|
-
if (this.config.types.some(t => token.typ == exports.EnumToken[t]) || (token.typ == exports.EnumToken.NumberTokenType && token.val ==
|
|
18824
|
+
if (this.config.types.some(t => token.typ == exports.EnumToken[t]) || (token.typ == exports.EnumToken.NumberTokenType && token.val == 0 &&
|
|
19107
18825
|
(this.config.types.includes('Length') ||
|
|
19108
18826
|
this.config.types.includes('Angle') ||
|
|
19109
18827
|
this.config.types.includes('Dimension')))) {
|
|
@@ -20056,8 +19774,6 @@ class ComputeCalcExpressionFeature {
|
|
|
20056
19774
|
const slice = (node.typ == exports.EnumToken.FunctionTokenType ? node.chi : (node.typ == exports.EnumToken.DeclarationNodeType ? node.val : node.chi))?.slice();
|
|
20057
19775
|
if (slice != null && node.typ == exports.EnumToken.FunctionTokenType && mathFuncs.includes(node.val)) {
|
|
20058
19776
|
// @ts-ignore
|
|
20059
|
-
const cp = (node.typ == exports.EnumToken.FunctionTokenType && mathFuncs.includes(node.val) && node.val != 'calc' ? [node] : (node.typ == exports.EnumToken.DeclarationNodeType ? node.val : node.chi)).slice();
|
|
20060
|
-
evaluate(cp);
|
|
20061
19777
|
const key = 'chi' in node ? 'chi' : 'val';
|
|
20062
19778
|
const str1 = renderToken({ ...node, [key]: slice });
|
|
20063
19779
|
const str2 = renderToken(node); // values.reduce((acc: string, curr: Token): string => acc + renderToken(curr), '');
|
|
@@ -20065,11 +19781,6 @@ class ComputeCalcExpressionFeature {
|
|
|
20065
19781
|
// @ts-ignore
|
|
20066
19782
|
node[key] = slice;
|
|
20067
19783
|
}
|
|
20068
|
-
// else {
|
|
20069
|
-
//
|
|
20070
|
-
// // @ts-ignore
|
|
20071
|
-
// node[key] = values;
|
|
20072
|
-
// }
|
|
20073
19784
|
return WalkerOptionEnum.Ignore;
|
|
20074
19785
|
}
|
|
20075
19786
|
return null;
|
|
@@ -20085,20 +19796,9 @@ class ComputeCalcExpressionFeature {
|
|
|
20085
19796
|
// @ts-ignore
|
|
20086
19797
|
const children = parent.typ == exports.EnumToken.DeclarationNodeType ? parent.val : parent.chi;
|
|
20087
19798
|
if (values.length == 1 && values[0].typ != exports.EnumToken.BinaryExpressionTokenType) {
|
|
20088
|
-
// if (parent.typ == EnumToken.BinaryExpressionTokenType) {
|
|
20089
|
-
//
|
|
20090
|
-
// if ((parent as BinaryExpressionToken).l == value) {
|
|
20091
|
-
//
|
|
20092
|
-
// (parent as BinaryExpressionToken).l = values[0];
|
|
20093
|
-
// } else {
|
|
20094
|
-
//
|
|
20095
|
-
// (parent as BinaryExpressionToken).r = values[0];
|
|
20096
|
-
// }
|
|
20097
|
-
// } else {
|
|
20098
19799
|
for (let i = 0; i < children.length; i++) {
|
|
20099
19800
|
if (children[i] == value) {
|
|
20100
|
-
|
|
20101
|
-
children.splice(i, 1, !(parent.typ == exports.EnumToken.FunctionTokenType && parent.val == 'calc') && typeof values[0].val != 'string' ? {
|
|
19801
|
+
children.splice(i, 1, !(parent.typ == exports.EnumToken.FunctionTokenType && parent.val == 'calc') && (typeof values[0].val != 'number' && !(values[0].typ == exports.EnumToken.FunctionTokenType && mathFuncs.includes(values[0].val))) ? {
|
|
20102
19802
|
typ: exports.EnumToken.FunctionTokenType,
|
|
20103
19803
|
val: 'calc',
|
|
20104
19804
|
chi: values
|
|
@@ -20106,21 +19806,15 @@ class ComputeCalcExpressionFeature {
|
|
|
20106
19806
|
break;
|
|
20107
19807
|
}
|
|
20108
19808
|
}
|
|
20109
|
-
// }
|
|
20110
19809
|
}
|
|
20111
19810
|
else {
|
|
20112
19811
|
for (let i = 0; i < children.length; i++) {
|
|
20113
19812
|
if (children[i] == value) {
|
|
20114
|
-
// if (parent.typ == EnumToken.FunctionTokenType && (parent as FunctionToken).val == 'calc') {
|
|
20115
|
-
//
|
|
20116
|
-
// children.splice(i, 1, ...values);
|
|
20117
|
-
// } else {
|
|
20118
19813
|
children.splice(i, 1, {
|
|
20119
19814
|
typ: exports.EnumToken.FunctionTokenType,
|
|
20120
19815
|
val: 'calc',
|
|
20121
19816
|
chi: values
|
|
20122
19817
|
});
|
|
20123
|
-
// }
|
|
20124
19818
|
break;
|
|
20125
19819
|
}
|
|
20126
19820
|
}
|
|
@@ -20135,10 +19829,9 @@ class ComputeCalcExpressionFeature {
|
|
|
20135
19829
|
|
|
20136
19830
|
const epsilon = 1e-5;
|
|
20137
19831
|
function identity() {
|
|
20138
|
-
return [
|
|
19832
|
+
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
20139
19833
|
}
|
|
20140
19834
|
function pLength(point) {
|
|
20141
|
-
// Calcul de la norme euclidienne
|
|
20142
19835
|
return Math.sqrt(point[0] * point[0] + point[1] * point[1] + point[2] * point[2]);
|
|
20143
19836
|
}
|
|
20144
19837
|
function normalize(point) {
|
|
@@ -20147,23 +19840,19 @@ function normalize(point) {
|
|
|
20147
19840
|
return norm === 0 ? [0, 0, 0] : [x / norm, y / norm, z / norm];
|
|
20148
19841
|
}
|
|
20149
19842
|
function dot(point1, point2) {
|
|
20150
|
-
|
|
20151
|
-
|
|
20152
|
-
// return point1[0] * point2[0] + point1[1] * point2[1] + point1[2] * point2[2] + point1[3] * point2[3];
|
|
20153
|
-
// }
|
|
20154
|
-
let result = 0;
|
|
20155
|
-
for (let i = 0; i < point1.length; i++) {
|
|
20156
|
-
result += point1[i] * point2[i];
|
|
19843
|
+
if (point1.length === 4 && point2.length === 4) {
|
|
19844
|
+
return point1[0] * point2[0] + point1[1] * point2[1] + point1[2] * point2[2] + point1[3] * point2[3];
|
|
20157
19845
|
}
|
|
20158
|
-
return
|
|
20159
|
-
// return point1[0] * point2[0] + point1[1] * point2[1] + point1[2] * point2[2];
|
|
19846
|
+
return point1[0] * point2[0] + point1[1] * point2[1] + point1[2] * point2[2];
|
|
20160
19847
|
}
|
|
20161
19848
|
function multiply(matrixA, matrixB) {
|
|
20162
|
-
let result =
|
|
19849
|
+
let result = new Array(16).fill(0);
|
|
20163
19850
|
for (let i = 0; i < 4; i++) {
|
|
20164
19851
|
for (let j = 0; j < 4; j++) {
|
|
20165
19852
|
for (let k = 0; k < 4; k++) {
|
|
20166
|
-
|
|
19853
|
+
// Utiliser l'indexation linéaire pour accéder aux éléments
|
|
19854
|
+
// Pour une matrice 4x4, l'index est (row * 4 + col)
|
|
19855
|
+
result[j * 4 + i] += matrixA[k * 4 + i] * matrixB[j * 4 + k];
|
|
20167
19856
|
}
|
|
20168
19857
|
}
|
|
20169
19858
|
}
|
|
@@ -20171,20 +19860,17 @@ function multiply(matrixA, matrixB) {
|
|
|
20171
19860
|
}
|
|
20172
19861
|
function inverse(matrix) {
|
|
20173
19862
|
// Create augmented matrix [matrix | identity]
|
|
20174
|
-
let augmented =
|
|
20175
|
-
|
|
20176
|
-
|
|
20177
|
-
|
|
20178
|
-
i === 2 ? [0, 0, 1, 0] :
|
|
20179
|
-
[0, 0, 0, 1])
|
|
20180
|
-
]);
|
|
19863
|
+
let augmented = [
|
|
19864
|
+
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1,
|
|
19865
|
+
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1
|
|
19866
|
+
];
|
|
20181
19867
|
// Gaussian elimination with partial pivoting
|
|
20182
19868
|
for (let col = 0; col < 4; col++) {
|
|
20183
19869
|
// Find pivot row with maximum absolute value
|
|
20184
19870
|
let maxRow = col;
|
|
20185
|
-
let maxVal = Math.abs(augmented[col
|
|
19871
|
+
let maxVal = Math.abs(augmented[col * 4 + col]);
|
|
20186
19872
|
for (let row = col + 1; row < 4; row++) {
|
|
20187
|
-
let val = Math.abs(augmented[row
|
|
19873
|
+
let val = Math.abs(augmented[row * 4 + col]);
|
|
20188
19874
|
if (val > maxVal) {
|
|
20189
19875
|
maxVal = val;
|
|
20190
19876
|
maxRow = row;
|
|
@@ -20199,22 +19885,22 @@ function inverse(matrix) {
|
|
|
20199
19885
|
[augmented[col], augmented[maxRow]] = [augmented[maxRow], augmented[col]];
|
|
20200
19886
|
}
|
|
20201
19887
|
// Scale pivot row to make pivot element 1
|
|
20202
|
-
let pivot = augmented[col
|
|
19888
|
+
let pivot = augmented[col * 4 + col];
|
|
20203
19889
|
for (let j = 0; j < 8; j++) {
|
|
20204
|
-
augmented[col
|
|
19890
|
+
augmented[col * 4 + j] /= pivot;
|
|
20205
19891
|
}
|
|
20206
19892
|
// Eliminate column in other rows
|
|
20207
19893
|
for (let row = 0; row < 4; row++) {
|
|
20208
19894
|
if (row !== col) {
|
|
20209
|
-
let factor = augmented[row
|
|
19895
|
+
let factor = augmented[row * 4 + col];
|
|
20210
19896
|
for (let j = 0; j < 8; j++) {
|
|
20211
|
-
augmented[row
|
|
19897
|
+
augmented[row * 4 + j] -= factor * augmented[col * 4 + j];
|
|
20212
19898
|
}
|
|
20213
19899
|
}
|
|
20214
19900
|
}
|
|
20215
19901
|
}
|
|
20216
19902
|
// Extract the inverse from the right side of the augmented matrix
|
|
20217
|
-
return augmented.
|
|
19903
|
+
return augmented.slice(0, 16);
|
|
20218
19904
|
}
|
|
20219
19905
|
// function transpose(matrix: Matrix): Matrix {
|
|
20220
19906
|
// // Crée une nouvelle matrice vide 4x4
|
|
@@ -20238,7 +19924,7 @@ function round(number) {
|
|
|
20238
19924
|
// translate3d(25.9808px, 0, 15px ) rotateY(60deg) skewX(49.9999deg) scale(1, 1.2)
|
|
20239
19925
|
// translate → rotate → skew → scale
|
|
20240
19926
|
function decompose(original) {
|
|
20241
|
-
const matrix = original.
|
|
19927
|
+
const matrix = original.slice();
|
|
20242
19928
|
// Normalize last row
|
|
20243
19929
|
if (matrix[15] === 0) {
|
|
20244
19930
|
return null;
|
|
@@ -20255,7 +19941,7 @@ function decompose(original) {
|
|
|
20255
19941
|
perspectiveMatrix[11] = 0;
|
|
20256
19942
|
perspectiveMatrix[15] = 1;
|
|
20257
19943
|
// @ts-ignore
|
|
20258
|
-
const inverted = inverse(original.
|
|
19944
|
+
const inverted = inverse(original.slice());
|
|
20259
19945
|
if (!inverted) {
|
|
20260
19946
|
return null;
|
|
20261
19947
|
}
|
|
@@ -20378,44 +20064,44 @@ function toZero(v) {
|
|
|
20378
20064
|
// https://drafts.csswg.org/css-transforms-1/#2d-matrix
|
|
20379
20065
|
function is2DMatrix(matrix) {
|
|
20380
20066
|
// m13,m14, m23, m24, m31, m32, m34, m43 are all 0
|
|
20381
|
-
return matrix[0
|
|
20382
|
-
matrix[0
|
|
20383
|
-
matrix[1
|
|
20384
|
-
matrix[1
|
|
20385
|
-
matrix[2
|
|
20386
|
-
matrix[2
|
|
20387
|
-
matrix[2
|
|
20388
|
-
matrix[3
|
|
20389
|
-
matrix[2
|
|
20390
|
-
matrix[3
|
|
20067
|
+
return matrix[0 * 4 + 2] === 0 &&
|
|
20068
|
+
matrix[0 * 4 + 3] === 0 &&
|
|
20069
|
+
matrix[1 * 4 + 2] === 0 &&
|
|
20070
|
+
matrix[1 * 4 + 3] === 0 &&
|
|
20071
|
+
matrix[2 * 4 + 0] === 0 &&
|
|
20072
|
+
matrix[2 * 4 + 1] === 0 &&
|
|
20073
|
+
matrix[2 * 4 + 3] === 0 &&
|
|
20074
|
+
matrix[3 * 4 + 2] === 0 &&
|
|
20075
|
+
matrix[2 * 4 + 2] === 1 &&
|
|
20076
|
+
matrix[3 * 4 + 3] === 1;
|
|
20391
20077
|
}
|
|
20392
20078
|
|
|
20393
20079
|
function translateX(x, from) {
|
|
20394
20080
|
const matrix = identity();
|
|
20395
|
-
matrix[3
|
|
20081
|
+
matrix[3 * 4 + 0] = x;
|
|
20396
20082
|
return multiply(from, matrix);
|
|
20397
20083
|
}
|
|
20398
20084
|
function translateY(y, from) {
|
|
20399
20085
|
const matrix = identity();
|
|
20400
|
-
matrix[3
|
|
20086
|
+
matrix[3 * 4 + 1] = y;
|
|
20401
20087
|
return multiply(from, matrix);
|
|
20402
20088
|
}
|
|
20403
20089
|
function translateZ(z, from) {
|
|
20404
20090
|
const matrix = identity();
|
|
20405
|
-
matrix[3
|
|
20091
|
+
matrix[3 * 4 + 2] = z;
|
|
20406
20092
|
return multiply(from, matrix);
|
|
20407
20093
|
}
|
|
20408
20094
|
function translate(translate, from) {
|
|
20409
20095
|
const matrix = identity();
|
|
20410
|
-
matrix[3
|
|
20411
|
-
matrix[3
|
|
20096
|
+
matrix[3 * 4 + 0] = translate[0];
|
|
20097
|
+
matrix[3 * 4 + 1] = translate[1] ?? 0;
|
|
20412
20098
|
return multiply(from, matrix);
|
|
20413
20099
|
}
|
|
20414
20100
|
function translate3d(translate, from) {
|
|
20415
20101
|
const matrix = identity();
|
|
20416
|
-
matrix[3
|
|
20417
|
-
matrix[3
|
|
20418
|
-
matrix[3
|
|
20102
|
+
matrix[3 * 4 + 0] = translate[0];
|
|
20103
|
+
matrix[3 * 4 + 1] = translate[1];
|
|
20104
|
+
matrix[3 * 4 + 2] = translate[2];
|
|
20419
20105
|
return multiply(from, matrix);
|
|
20420
20106
|
}
|
|
20421
20107
|
|
|
@@ -20436,52 +20122,52 @@ function rotate3D(angle, x, y, z, from) {
|
|
|
20436
20122
|
x *= unit;
|
|
20437
20123
|
y *= unit;
|
|
20438
20124
|
z *= unit;
|
|
20439
|
-
matrix[0
|
|
20440
|
-
matrix[0
|
|
20441
|
-
matrix[0
|
|
20442
|
-
matrix[1
|
|
20443
|
-
matrix[1
|
|
20444
|
-
matrix[1
|
|
20445
|
-
matrix[2
|
|
20446
|
-
matrix[2
|
|
20447
|
-
matrix[2
|
|
20125
|
+
matrix[0 * 4 + 0] = 1 - 2 * (y * y + z * z) * sq;
|
|
20126
|
+
matrix[0 * 4 + 1] = 2 * (x * y * sq + z * sc);
|
|
20127
|
+
matrix[0 * 4 + 2] = 2 * (x * z * sq - y * sc);
|
|
20128
|
+
matrix[1 * 4 + 0] = 2 * (x * y * sq - z * sc);
|
|
20129
|
+
matrix[1 * 4 + 1] = 1 - 2 * (x * x + z * z) * sq;
|
|
20130
|
+
matrix[1 * 4 + 2] = 2 * (y * z * sq + x * sc);
|
|
20131
|
+
matrix[2 * 4 + 0] = 2 * (x * z * sq + y * sc);
|
|
20132
|
+
matrix[2 * 4 + 1] = 2 * (y * z * sq - x * sc);
|
|
20133
|
+
matrix[2 * 4 + 2] = 1 - 2 * (x * x + y * y) * sq;
|
|
20448
20134
|
return multiply(from, matrix);
|
|
20449
20135
|
}
|
|
20450
20136
|
function rotate(angle, from) {
|
|
20451
20137
|
const matrix = identity();
|
|
20452
|
-
matrix[0
|
|
20453
|
-
matrix[0
|
|
20454
|
-
matrix[1
|
|
20455
|
-
matrix[1
|
|
20138
|
+
matrix[0 * 4 + 0] = Math.cos(angle);
|
|
20139
|
+
matrix[0 * 4 + 1] = Math.sin(angle);
|
|
20140
|
+
matrix[1 * 4 + 0] = -Math.sin(angle);
|
|
20141
|
+
matrix[1 * 4 + 1] = Math.cos(angle);
|
|
20456
20142
|
return multiply(from, matrix);
|
|
20457
20143
|
}
|
|
20458
20144
|
|
|
20459
20145
|
function scaleX(x, from) {
|
|
20460
20146
|
const matrix = identity();
|
|
20461
|
-
matrix[0
|
|
20147
|
+
matrix[0 * 4 + 0] = x;
|
|
20462
20148
|
return multiply(from, matrix);
|
|
20463
20149
|
}
|
|
20464
20150
|
function scaleY(y, from) {
|
|
20465
20151
|
const matrix = identity();
|
|
20466
|
-
matrix[1
|
|
20152
|
+
matrix[1 * 4 + 1] = y;
|
|
20467
20153
|
return multiply(from, matrix);
|
|
20468
20154
|
}
|
|
20469
20155
|
function scaleZ(z, from) {
|
|
20470
20156
|
const matrix = identity();
|
|
20471
|
-
matrix[2
|
|
20157
|
+
matrix[2 * 4 + 2] = z;
|
|
20472
20158
|
return multiply(from, matrix);
|
|
20473
20159
|
}
|
|
20474
20160
|
function scale(x, y, from) {
|
|
20475
20161
|
const matrix = identity();
|
|
20476
|
-
matrix[0
|
|
20477
|
-
matrix[1
|
|
20162
|
+
matrix[0 * 4 + 0] = x;
|
|
20163
|
+
matrix[1 * 4 + 1] = y;
|
|
20478
20164
|
return multiply(from, matrix);
|
|
20479
20165
|
}
|
|
20480
20166
|
function scale3d(x, y, z, from) {
|
|
20481
20167
|
const matrix = identity();
|
|
20482
|
-
matrix[0
|
|
20483
|
-
matrix[1
|
|
20484
|
-
matrix[2
|
|
20168
|
+
matrix[0 * 4 + 0] = x;
|
|
20169
|
+
matrix[1 * 4 + 1] = y;
|
|
20170
|
+
matrix[2 * 4 + 2] = z;
|
|
20485
20171
|
return multiply(from, matrix);
|
|
20486
20172
|
}
|
|
20487
20173
|
|
|
@@ -20505,30 +20191,30 @@ function parseMatrix(mat) {
|
|
|
20505
20191
|
function matrix(values) {
|
|
20506
20192
|
const matrix = identity();
|
|
20507
20193
|
if (values.length === 6) {
|
|
20508
|
-
matrix[0
|
|
20509
|
-
matrix[0
|
|
20510
|
-
matrix[1
|
|
20511
|
-
matrix[1
|
|
20512
|
-
matrix[3
|
|
20513
|
-
matrix[3
|
|
20194
|
+
matrix[0 * 4 + 0] = values[0];
|
|
20195
|
+
matrix[0 * 4 + 1] = values[1];
|
|
20196
|
+
matrix[1 * 4 + 0] = values[2];
|
|
20197
|
+
matrix[1 * 4 + 1] = values[3];
|
|
20198
|
+
matrix[3 * 4 + 0] = values[4];
|
|
20199
|
+
matrix[3 * 4 + 1] = values[5];
|
|
20514
20200
|
}
|
|
20515
20201
|
else if (values.length === 16) {
|
|
20516
|
-
matrix[0
|
|
20517
|
-
matrix[0
|
|
20518
|
-
matrix[0
|
|
20519
|
-
matrix[0
|
|
20520
|
-
matrix[1
|
|
20521
|
-
matrix[1
|
|
20522
|
-
matrix[1
|
|
20523
|
-
matrix[1
|
|
20524
|
-
matrix[2
|
|
20525
|
-
matrix[2
|
|
20526
|
-
matrix[2
|
|
20527
|
-
matrix[2
|
|
20528
|
-
matrix[3
|
|
20529
|
-
matrix[3
|
|
20530
|
-
matrix[3
|
|
20531
|
-
matrix[3
|
|
20202
|
+
matrix[0 * 4 + 0] = values[0];
|
|
20203
|
+
matrix[0 * 4 + 1] = values[1];
|
|
20204
|
+
matrix[0 * 4 + 2] = values[2];
|
|
20205
|
+
matrix[0 * 4 + 3] = values[3];
|
|
20206
|
+
matrix[1 * 4 + 0] = values[4];
|
|
20207
|
+
matrix[1 * 4 + 1] = values[5];
|
|
20208
|
+
matrix[1 * 4 + 2] = values[6];
|
|
20209
|
+
matrix[1 * 4 + 3] = values[7];
|
|
20210
|
+
matrix[2 * 4 + 0] = values[8];
|
|
20211
|
+
matrix[2 * 4 + 1] = values[9];
|
|
20212
|
+
matrix[2 * 4 + 2] = values[10];
|
|
20213
|
+
matrix[2 * 4 + 3] = values[11];
|
|
20214
|
+
matrix[3 * 4 + 0] = values[12];
|
|
20215
|
+
matrix[3 * 4 + 1] = values[13];
|
|
20216
|
+
matrix[3 * 4 + 2] = values[14];
|
|
20217
|
+
matrix[3 * 4 + 3] = values[15];
|
|
20532
20218
|
}
|
|
20533
20219
|
else {
|
|
20534
20220
|
return null;
|
|
@@ -20536,7 +20222,7 @@ function matrix(values) {
|
|
|
20536
20222
|
return matrix;
|
|
20537
20223
|
}
|
|
20538
20224
|
function serialize(matrix) {
|
|
20539
|
-
matrix = matrix.
|
|
20225
|
+
matrix = matrix.slice();
|
|
20540
20226
|
// @ts-ignore
|
|
20541
20227
|
if (eq(matrix, identity())) {
|
|
20542
20228
|
return {
|
|
@@ -20550,19 +20236,19 @@ function serialize(matrix) {
|
|
|
20550
20236
|
typ: exports.EnumToken.FunctionTokenType,
|
|
20551
20237
|
val: 'matrix',
|
|
20552
20238
|
chi: [
|
|
20553
|
-
matrix[0
|
|
20554
|
-
matrix[0
|
|
20555
|
-
matrix[1
|
|
20556
|
-
matrix[1
|
|
20557
|
-
matrix[3
|
|
20558
|
-
matrix[3
|
|
20239
|
+
matrix[0 * 4 + 0],
|
|
20240
|
+
matrix[0 * 4 + 1],
|
|
20241
|
+
matrix[1 * 4 + 0],
|
|
20242
|
+
matrix[1 * 4 + 1],
|
|
20243
|
+
matrix[3 * 4 + 0],
|
|
20244
|
+
matrix[3 * 4 + 1]
|
|
20559
20245
|
].reduce((acc, t) => {
|
|
20560
20246
|
if (acc.length > 0) {
|
|
20561
20247
|
acc.push({ typ: exports.EnumToken.CommaTokenType });
|
|
20562
20248
|
}
|
|
20563
20249
|
acc.push({
|
|
20564
20250
|
typ: exports.EnumToken.NumberTokenType,
|
|
20565
|
-
val:
|
|
20251
|
+
val: t
|
|
20566
20252
|
});
|
|
20567
20253
|
return acc;
|
|
20568
20254
|
}, [])
|
|
@@ -20571,13 +20257,13 @@ function serialize(matrix) {
|
|
|
20571
20257
|
return {
|
|
20572
20258
|
typ: exports.EnumToken.FunctionTokenType,
|
|
20573
20259
|
val: 'matrix3d',
|
|
20574
|
-
chi: matrix.
|
|
20260
|
+
chi: matrix.reduce((acc, curr) => {
|
|
20575
20261
|
if (acc.length > 0) {
|
|
20576
20262
|
acc.push({ typ: exports.EnumToken.CommaTokenType });
|
|
20577
20263
|
}
|
|
20578
20264
|
acc.push({
|
|
20579
20265
|
typ: exports.EnumToken.NumberTokenType,
|
|
20580
|
-
val:
|
|
20266
|
+
val: curr
|
|
20581
20267
|
});
|
|
20582
20268
|
return acc;
|
|
20583
20269
|
}, [])
|
|
@@ -20617,26 +20303,12 @@ function minify$1(matrix) {
|
|
|
20617
20303
|
coordinates.delete(i == 0 ? 'x' : i == 1 ? 'y' : 'z');
|
|
20618
20304
|
}
|
|
20619
20305
|
}
|
|
20620
|
-
// if (coordinates.size == 3) {
|
|
20621
|
-
//
|
|
20622
|
-
// result.push({
|
|
20623
|
-
// typ: EnumToken.FunctionTokenType,
|
|
20624
|
-
// val: 'translate3d',
|
|
20625
|
-
// chi: [
|
|
20626
|
-
// {typ: EnumToken.LengthTokenType, val: round(decomposed.translate[0]) + '', unit: 'px'},
|
|
20627
|
-
// {typ: EnumToken.CommaTokenType},
|
|
20628
|
-
// {typ: EnumToken.LengthTokenType, val: round(decomposed.translate[1]) + '', unit: 'px'},
|
|
20629
|
-
// {typ: EnumToken.CommaTokenType},
|
|
20630
|
-
// {typ: EnumToken.LengthTokenType, val: round(decomposed.translate[2]) + '', unit: 'px'}
|
|
20631
|
-
// ]
|
|
20632
|
-
// })
|
|
20633
|
-
// } else
|
|
20634
20306
|
if (coordinates.size == 1) {
|
|
20635
20307
|
if (coordinates.has('x')) {
|
|
20636
20308
|
result.push({
|
|
20637
20309
|
typ: exports.EnumToken.FunctionTokenType,
|
|
20638
20310
|
val: 'translate',
|
|
20639
|
-
chi: [{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[0])
|
|
20311
|
+
chi: [{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: 'px' }]
|
|
20640
20312
|
});
|
|
20641
20313
|
}
|
|
20642
20314
|
else {
|
|
@@ -20645,7 +20317,7 @@ function minify$1(matrix) {
|
|
|
20645
20317
|
result.push({
|
|
20646
20318
|
typ: exports.EnumToken.FunctionTokenType,
|
|
20647
20319
|
val: 'translate' + axis.toUpperCase(),
|
|
20648
|
-
chi: [{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[index])
|
|
20320
|
+
chi: [{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[index]), unit: 'px' }]
|
|
20649
20321
|
});
|
|
20650
20322
|
}
|
|
20651
20323
|
}
|
|
@@ -20656,15 +20328,15 @@ function minify$1(matrix) {
|
|
|
20656
20328
|
chi: [
|
|
20657
20329
|
decomposed.translate[0] == 0 ? {
|
|
20658
20330
|
typ: exports.EnumToken.NumberTokenType,
|
|
20659
|
-
|
|
20660
|
-
} : { typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[0])
|
|
20331
|
+
val: 0
|
|
20332
|
+
} : { typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: 'px' },
|
|
20661
20333
|
{ typ: exports.EnumToken.CommaTokenType },
|
|
20662
20334
|
decomposed.translate[1] == 0 ? {
|
|
20663
20335
|
typ: exports.EnumToken.NumberTokenType,
|
|
20664
|
-
|
|
20665
|
-
} : { typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[1])
|
|
20336
|
+
val: 0
|
|
20337
|
+
} : { typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit: 'px' },
|
|
20666
20338
|
{ typ: exports.EnumToken.CommaTokenType },
|
|
20667
|
-
{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[2])
|
|
20339
|
+
{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[2]), unit: 'px' }
|
|
20668
20340
|
]
|
|
20669
20341
|
});
|
|
20670
20342
|
}
|
|
@@ -20673,9 +20345,9 @@ function minify$1(matrix) {
|
|
|
20673
20345
|
typ: exports.EnumToken.FunctionTokenType,
|
|
20674
20346
|
val: 'translate',
|
|
20675
20347
|
chi: [
|
|
20676
|
-
{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[0])
|
|
20348
|
+
{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[0]), unit: 'px' },
|
|
20677
20349
|
{ typ: exports.EnumToken.CommaTokenType },
|
|
20678
|
-
{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[1])
|
|
20350
|
+
{ typ: exports.EnumToken.LengthTokenType, val: round(decomposed.translate[1]), unit: 'px' }
|
|
20679
20351
|
]
|
|
20680
20352
|
});
|
|
20681
20353
|
}
|
|
@@ -20689,7 +20361,7 @@ function minify$1(matrix) {
|
|
|
20689
20361
|
chi: [
|
|
20690
20362
|
{
|
|
20691
20363
|
typ: exports.EnumToken.AngleTokenType,
|
|
20692
|
-
val:
|
|
20364
|
+
val: round(angle),
|
|
20693
20365
|
unit: 'deg'
|
|
20694
20366
|
}
|
|
20695
20367
|
]
|
|
@@ -20702,7 +20374,7 @@ function minify$1(matrix) {
|
|
|
20702
20374
|
chi: [
|
|
20703
20375
|
{
|
|
20704
20376
|
typ: exports.EnumToken.AngleTokenType,
|
|
20705
|
-
val:
|
|
20377
|
+
val: round(angle),
|
|
20706
20378
|
unit: 'deg'
|
|
20707
20379
|
}
|
|
20708
20380
|
]
|
|
@@ -20715,7 +20387,7 @@ function minify$1(matrix) {
|
|
|
20715
20387
|
chi: [
|
|
20716
20388
|
{
|
|
20717
20389
|
typ: exports.EnumToken.AngleTokenType,
|
|
20718
|
-
val:
|
|
20390
|
+
val: round(angle),
|
|
20719
20391
|
unit: 'deg'
|
|
20720
20392
|
}
|
|
20721
20393
|
]
|
|
@@ -20728,22 +20400,22 @@ function minify$1(matrix) {
|
|
|
20728
20400
|
chi: [
|
|
20729
20401
|
{
|
|
20730
20402
|
typ: exports.EnumToken.NumberTokenType,
|
|
20731
|
-
val:
|
|
20403
|
+
val: round(x)
|
|
20732
20404
|
},
|
|
20733
20405
|
{ typ: exports.EnumToken.CommaTokenType },
|
|
20734
20406
|
{
|
|
20735
20407
|
typ: exports.EnumToken.NumberTokenType,
|
|
20736
|
-
val:
|
|
20408
|
+
val: round(y)
|
|
20737
20409
|
},
|
|
20738
20410
|
{ typ: exports.EnumToken.CommaTokenType },
|
|
20739
20411
|
{
|
|
20740
20412
|
typ: exports.EnumToken.NumberTokenType,
|
|
20741
|
-
val:
|
|
20413
|
+
val: round(z)
|
|
20742
20414
|
},
|
|
20743
20415
|
{ typ: exports.EnumToken.CommaTokenType },
|
|
20744
20416
|
{
|
|
20745
20417
|
typ: exports.EnumToken.AngleTokenType,
|
|
20746
|
-
val:
|
|
20418
|
+
val: round(angle),
|
|
20747
20419
|
unit: 'deg'
|
|
20748
20420
|
}
|
|
20749
20421
|
]
|
|
@@ -20766,7 +20438,7 @@ function minify$1(matrix) {
|
|
|
20766
20438
|
typ: exports.EnumToken.FunctionTokenType,
|
|
20767
20439
|
val: 'skew' + (skew.has('x') ? '' : 'Y'),
|
|
20768
20440
|
chi: [
|
|
20769
|
-
{ typ: exports.EnumToken.AngleTokenType, val:
|
|
20441
|
+
{ typ: exports.EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: 'deg' }
|
|
20770
20442
|
]
|
|
20771
20443
|
});
|
|
20772
20444
|
}
|
|
@@ -20775,9 +20447,9 @@ function minify$1(matrix) {
|
|
|
20775
20447
|
typ: exports.EnumToken.FunctionTokenType,
|
|
20776
20448
|
val: 'skew',
|
|
20777
20449
|
chi: [
|
|
20778
|
-
{ typ: exports.EnumToken.AngleTokenType, val:
|
|
20450
|
+
{ typ: exports.EnumToken.AngleTokenType, val: round(decomposed.skew[0]), unit: 'deg' },
|
|
20779
20451
|
{ typ: exports.EnumToken.CommaTokenType },
|
|
20780
|
-
{ typ: exports.EnumToken.AngleTokenType, val:
|
|
20452
|
+
{ typ: exports.EnumToken.AngleTokenType, val: round(decomposed.skew[1]), unit: 'deg' }
|
|
20781
20453
|
]
|
|
20782
20454
|
});
|
|
20783
20455
|
}
|
|
@@ -20799,7 +20471,7 @@ function minify$1(matrix) {
|
|
|
20799
20471
|
typ: exports.EnumToken.FunctionTokenType,
|
|
20800
20472
|
val: 'scale' + prefix,
|
|
20801
20473
|
chi: [
|
|
20802
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
20474
|
+
{ typ: exports.EnumToken.NumberTokenType, val: round(prefix == 'Z' ? sz : prefix == 'Y' ? sy : sx) }
|
|
20803
20475
|
]
|
|
20804
20476
|
});
|
|
20805
20477
|
}
|
|
@@ -20808,9 +20480,9 @@ function minify$1(matrix) {
|
|
|
20808
20480
|
typ: exports.EnumToken.FunctionTokenType,
|
|
20809
20481
|
val: 'scale',
|
|
20810
20482
|
chi: [
|
|
20811
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
20483
|
+
{ typ: exports.EnumToken.NumberTokenType, val: round(sx) },
|
|
20812
20484
|
{ typ: exports.EnumToken.CommaTokenType },
|
|
20813
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
20485
|
+
{ typ: exports.EnumToken.NumberTokenType, val: round(sy) },
|
|
20814
20486
|
]
|
|
20815
20487
|
});
|
|
20816
20488
|
}
|
|
@@ -20819,25 +20491,15 @@ function minify$1(matrix) {
|
|
|
20819
20491
|
typ: exports.EnumToken.FunctionTokenType,
|
|
20820
20492
|
val: 'scale3d',
|
|
20821
20493
|
chi: [
|
|
20822
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
20494
|
+
{ typ: exports.EnumToken.NumberTokenType, val: round(sx) },
|
|
20823
20495
|
{ typ: exports.EnumToken.CommaTokenType },
|
|
20824
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
20496
|
+
{ typ: exports.EnumToken.NumberTokenType, val: round(sy) },
|
|
20825
20497
|
{ typ: exports.EnumToken.CommaTokenType },
|
|
20826
|
-
{ typ: exports.EnumToken.NumberTokenType, val:
|
|
20498
|
+
{ typ: exports.EnumToken.NumberTokenType, val: round(sz) }
|
|
20827
20499
|
]
|
|
20828
20500
|
});
|
|
20829
20501
|
}
|
|
20830
20502
|
}
|
|
20831
|
-
// if (transforms.has('perspective')) {
|
|
20832
|
-
//
|
|
20833
|
-
// result.push({
|
|
20834
|
-
// typ: EnumToken.FunctionTokenType,
|
|
20835
|
-
// val: 'perspective',
|
|
20836
|
-
// chi: [
|
|
20837
|
-
// {typ: EnumToken.Length, val: '' + round(1 / decomposed.perspective[2]), unit: 'px'},
|
|
20838
|
-
// ]
|
|
20839
|
-
// });
|
|
20840
|
-
// }
|
|
20841
20503
|
// identity
|
|
20842
20504
|
return result.length == 0 || (result.length == 1 && eqMatrix(identity(), result)) ? [
|
|
20843
20505
|
{
|
|
@@ -20847,10 +20509,13 @@ function minify$1(matrix) {
|
|
|
20847
20509
|
] : result;
|
|
20848
20510
|
}
|
|
20849
20511
|
function eqMatrix(a, b) {
|
|
20512
|
+
// console.error(JSON.stringify({a, b}, null, 1));
|
|
20850
20513
|
let mat = identity();
|
|
20851
20514
|
let tmp = identity();
|
|
20852
20515
|
// @ts-ignore
|
|
20853
|
-
const data = Array.isArray(a) ? a : parseMatrix(a);
|
|
20516
|
+
const data = (Array.isArray(a) ? a : parseMatrix(a));
|
|
20517
|
+
// toZero(data);
|
|
20518
|
+
// console.error({data});
|
|
20854
20519
|
for (const transform of b) {
|
|
20855
20520
|
tmp = computeMatrix([transform], identity());
|
|
20856
20521
|
if (tmp == null) {
|
|
@@ -20858,12 +20523,14 @@ function eqMatrix(a, b) {
|
|
|
20858
20523
|
}
|
|
20859
20524
|
mat = multiply(mat, tmp);
|
|
20860
20525
|
}
|
|
20526
|
+
// toZero(mat);
|
|
20527
|
+
// console.error({mat});
|
|
20861
20528
|
if (mat == null) {
|
|
20862
20529
|
return false;
|
|
20863
20530
|
}
|
|
20864
20531
|
for (let i = 0; i < 4; i++) {
|
|
20865
20532
|
for (let j = 0; j < 4; j++) {
|
|
20866
|
-
if (Math.abs(mat[i
|
|
20533
|
+
if (Math.abs(mat[i * 4 + j] - data[i * 4 + j]) > epsilon) {
|
|
20867
20534
|
return false;
|
|
20868
20535
|
}
|
|
20869
20536
|
}
|
|
@@ -20873,20 +20540,20 @@ function eqMatrix(a, b) {
|
|
|
20873
20540
|
|
|
20874
20541
|
function skewX(x, from) {
|
|
20875
20542
|
const matrix = identity();
|
|
20876
|
-
matrix[1
|
|
20543
|
+
matrix[1 * 4 + 0] = Math.tan(x);
|
|
20877
20544
|
return multiply(from, matrix);
|
|
20878
20545
|
}
|
|
20879
20546
|
function skewY(y, from) {
|
|
20880
20547
|
const matrix = identity();
|
|
20881
|
-
matrix[0
|
|
20548
|
+
matrix[0 * 4 + 1] = Math.tan(y);
|
|
20882
20549
|
return multiply(from, matrix);
|
|
20883
20550
|
}
|
|
20884
20551
|
// convert angle to radian
|
|
20885
20552
|
function skew(values, from) {
|
|
20886
20553
|
const matrix = identity();
|
|
20887
|
-
matrix[1
|
|
20554
|
+
matrix[1 * 4 + 0] = Math.tan(values[0]);
|
|
20888
20555
|
if (values.length > 1) {
|
|
20889
|
-
matrix[0
|
|
20556
|
+
matrix[0 * 4 + 1] = Math.tan(values[1]);
|
|
20890
20557
|
}
|
|
20891
20558
|
return multiply(from, matrix);
|
|
20892
20559
|
}
|
|
@@ -20894,17 +20561,13 @@ function skew(values, from) {
|
|
|
20894
20561
|
function perspective(x, from) {
|
|
20895
20562
|
const matrix = identity();
|
|
20896
20563
|
// @ts-ignore
|
|
20897
|
-
matrix[2
|
|
20564
|
+
matrix[2 * 4 + 3] = typeof x == 'object' && x.val == 'none' ? 0 : x == 0 ? Number.NEGATIVE_INFINITY : -1 / x;
|
|
20898
20565
|
return multiply(from, matrix);
|
|
20899
20566
|
}
|
|
20900
20567
|
|
|
20901
20568
|
function compute(transformLists) {
|
|
20902
20569
|
transformLists = transformLists.slice();
|
|
20903
20570
|
stripCommaToken(transformLists);
|
|
20904
|
-
// if (transformLists.length == 0) {
|
|
20905
|
-
//
|
|
20906
|
-
// return null;
|
|
20907
|
-
// }
|
|
20908
20571
|
let matrix = identity();
|
|
20909
20572
|
let mat;
|
|
20910
20573
|
const cumulative = [];
|
|
@@ -20929,8 +20592,10 @@ function compute(transformLists) {
|
|
|
20929
20592
|
});
|
|
20930
20593
|
}
|
|
20931
20594
|
}
|
|
20595
|
+
// console.error({matrix});
|
|
20596
|
+
// matrix = toZero(matrix) as Matrix;
|
|
20932
20597
|
return {
|
|
20933
|
-
matrix: serialize(matrix),
|
|
20598
|
+
matrix: serialize(toZero(matrix)),
|
|
20934
20599
|
cumulative,
|
|
20935
20600
|
minified: minify$1(matrix) ?? [serialized]
|
|
20936
20601
|
};
|
|
@@ -20940,10 +20605,6 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
20940
20605
|
let val;
|
|
20941
20606
|
let i = 0;
|
|
20942
20607
|
for (; i < transformList.length; i++) {
|
|
20943
|
-
// if (transformList[i].typ == EnumToken.WhitespaceTokenType) {
|
|
20944
|
-
//
|
|
20945
|
-
// continue;
|
|
20946
|
-
// }
|
|
20947
20608
|
if (transformList[i].typ != exports.EnumToken.FunctionTokenType || !transformFunctions.includes(transformList[i].val)) {
|
|
20948
20609
|
return null;
|
|
20949
20610
|
}
|
|
@@ -20956,16 +20617,7 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
20956
20617
|
{
|
|
20957
20618
|
values.length = 0;
|
|
20958
20619
|
const children = stripCommaToken(transformList[i].chi.slice());
|
|
20959
|
-
// if (children == null || children.length == 0) {
|
|
20960
|
-
//
|
|
20961
|
-
// return null;
|
|
20962
|
-
// }
|
|
20963
20620
|
const valCount = transformList[i].val == 'translate3d' || transformList[i].val == 'translate' ? 3 : 1;
|
|
20964
|
-
// if (children.length == 1 && children[0].typ == EnumToken.IdenTokenType && (children[0] as IdentToken).val == 'none') {
|
|
20965
|
-
//
|
|
20966
|
-
// values.fill(0, 0, valCount);
|
|
20967
|
-
//
|
|
20968
|
-
// } else {
|
|
20969
20621
|
for (let j = 0; j < children.length; j++) {
|
|
20970
20622
|
if (children[j].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
20971
20623
|
continue;
|
|
@@ -20976,7 +20628,6 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
20976
20628
|
}
|
|
20977
20629
|
values.push(val);
|
|
20978
20630
|
}
|
|
20979
|
-
// }
|
|
20980
20631
|
if (values.length == 0 || values.length > valCount) {
|
|
20981
20632
|
return null;
|
|
20982
20633
|
}
|
|
@@ -21011,10 +20662,6 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
21011
20662
|
let values = [];
|
|
21012
20663
|
let valuesCount = transformList[i].val == 'rotate3d' ? 4 : 1;
|
|
21013
20664
|
for (const child of stripCommaToken(transformList[i].chi.slice())) {
|
|
21014
|
-
// if (child.typ == EnumToken.WhitespaceTokenType) {
|
|
21015
|
-
//
|
|
21016
|
-
// continue;
|
|
21017
|
-
// }
|
|
21018
20665
|
values.push(child);
|
|
21019
20666
|
if (transformList[i].val == 'rotateX') {
|
|
21020
20667
|
x = 1;
|
|
@@ -21057,19 +20704,11 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
21057
20704
|
const children = stripCommaToken(transformList[i].chi.slice());
|
|
21058
20705
|
for (let k = 0; k < children.length; k++) {
|
|
21059
20706
|
child = children[k];
|
|
21060
|
-
// if (child.typ == EnumToken.CommentTokenType || child.typ == EnumToken.WhitespaceTokenType) {
|
|
21061
|
-
//
|
|
21062
|
-
// continue;
|
|
21063
|
-
// }
|
|
21064
20707
|
if (child.typ != exports.EnumToken.NumberTokenType) {
|
|
21065
20708
|
return null;
|
|
21066
20709
|
}
|
|
21067
20710
|
values.push(getNumber(child));
|
|
21068
20711
|
}
|
|
21069
|
-
// if (values.length == 0) {
|
|
21070
|
-
//
|
|
21071
|
-
// return null;
|
|
21072
|
-
// }
|
|
21073
20712
|
if (transformList[i].val == 'scale3d') {
|
|
21074
20713
|
if (values.length != 3) {
|
|
21075
20714
|
return null;
|
|
@@ -21113,10 +20752,6 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
21113
20752
|
continue;
|
|
21114
20753
|
}
|
|
21115
20754
|
value = getAngle(child);
|
|
21116
|
-
// if (value == null) {
|
|
21117
|
-
//
|
|
21118
|
-
// return null;
|
|
21119
|
-
// }
|
|
21120
20755
|
values.push(value * 2 * Math.PI);
|
|
21121
20756
|
}
|
|
21122
20757
|
if (values.length == 0 || (values.length > (transformList[i].val == 'skew' ? 2 : 1))) {
|
|
@@ -21157,7 +20792,6 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
21157
20792
|
}
|
|
21158
20793
|
break;
|
|
21159
20794
|
case 'matrix3d':
|
|
21160
|
-
// return null;
|
|
21161
20795
|
case 'matrix':
|
|
21162
20796
|
{
|
|
21163
20797
|
const values = [];
|
|
@@ -21256,11 +20890,11 @@ class TransformCssFeature {
|
|
|
21256
20890
|
const children = node.val.reduce((acc, curr) => {
|
|
21257
20891
|
if (curr.typ == exports.EnumToken.FunctionTokenType && 'skew' == curr.val.toLowerCase()) {
|
|
21258
20892
|
if (curr.chi.length == 3) {
|
|
21259
|
-
if (curr.chi[2].val ==
|
|
20893
|
+
if (curr.chi[2].val == 0) {
|
|
21260
20894
|
curr.chi.length = 1;
|
|
21261
20895
|
curr.val = 'skew';
|
|
21262
20896
|
}
|
|
21263
|
-
else if (curr.chi[0].val ==
|
|
20897
|
+
else if (curr.chi[0].val == 0) {
|
|
21264
20898
|
curr.chi = [curr.chi[2]];
|
|
21265
20899
|
curr.val = 'skewY';
|
|
21266
20900
|
}
|