@tbela99/css-parser 1.6.0 → 1.6.2
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 +118 -2
- package/README.md +4 -3
- package/dist/index-umd-web.js +1629 -467
- package/dist/index.cjs +1629 -467
- package/dist/index.d.ts +72 -7
- package/dist/lib/ast/features/prefix.js +9 -1
- package/dist/lib/ast/features/shorthand.js +1 -1
- package/dist/lib/ast/features/transform.js +1 -1
- package/dist/lib/ast/math/expression.js +175 -5
- package/dist/lib/ast/minify.js +84 -10
- package/dist/lib/ast/transform/compute.js +24 -55
- package/dist/lib/ast/transform/minify.js +1 -1
- package/dist/lib/ast/types.js +12 -0
- package/dist/{config.json.js → lib/data/properties.json.js} +106 -0
- package/dist/lib/{validation/config.json.js → data/validation.json.js} +11 -8
- package/dist/lib/parser/declaration/list.js +8 -10
- package/dist/lib/parser/parse.js +8 -14
- package/dist/lib/parser/tokenize.js +89 -58
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +1 -1
- package/dist/lib/parser/utils/at-rule-media.js +66 -0
- package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
- package/dist/lib/parser/utils/base64.js +14 -0
- package/dist/lib/parser/utils/config.js +1 -1
- package/dist/lib/parser/utils/declaration.js +18 -17
- package/dist/lib/parser/utils/eq.js +6 -0
- package/dist/lib/parser/utils/hash.js +1 -0
- package/dist/lib/parser/utils/selector.js +99 -89
- package/dist/lib/parser/utils/text.js +16 -0
- package/dist/lib/renderer/render.js +20 -6
- package/dist/lib/renderer/sourcemap/lib/codec.js +8 -3
- package/dist/lib/renderer/sourcemap/sourcemap.js +35 -5
- package/dist/lib/syntax/color/alpha.js +57 -22
- package/dist/lib/syntax/color/cmyk.js +4 -3
- package/dist/lib/syntax/color/color-mix.js +18 -18
- package/dist/lib/syntax/color/srgb.js +11 -5
- package/dist/lib/syntax/color/utils/components.js +1 -1
- package/dist/lib/syntax/color/utils/distance.js +2 -2
- package/dist/lib/syntax/color/utils/matrix.js +1 -0
- package/dist/lib/syntax/color/xyz.js +5 -0
- package/dist/lib/syntax/color/xyzd50.js +17 -0
- package/dist/lib/syntax/constants.js +1 -1
- package/dist/lib/syntax/syntax.js +549 -13
- package/dist/lib/validation/config.js +27 -1
- package/dist/lib/validation/match.js +16 -4
- package/dist/lib/validation/parser/parse.js +7 -3
- package/dist/node.js +8 -14
- package/dist/web.js +8 -14
- package/package.json +4 -4
package/dist/index-umd-web.js
CHANGED
|
@@ -666,6 +666,18 @@
|
|
|
666
666
|
* wrapped values token type like {Arial, sans-serif}
|
|
667
667
|
*/
|
|
668
668
|
EnumToken[EnumToken["WrappedValuesTokenType"] = 140] = "WrappedValuesTokenType";
|
|
669
|
+
/**
|
|
670
|
+
* infinity token
|
|
671
|
+
*/
|
|
672
|
+
EnumToken[EnumToken["NaNTokenType"] = 141] = "NaNTokenType";
|
|
673
|
+
/**
|
|
674
|
+
* infinity token
|
|
675
|
+
*/
|
|
676
|
+
EnumToken[EnumToken["InfinityTokenType"] = 142] = "InfinityTokenType";
|
|
677
|
+
/**
|
|
678
|
+
* negative infinity token
|
|
679
|
+
*/
|
|
680
|
+
EnumToken[EnumToken["NegativeInfinityTokenType"] = 143] = "NegativeInfinityTokenType";
|
|
669
681
|
/* aliases */
|
|
670
682
|
/**
|
|
671
683
|
* alias for time token type
|
|
@@ -2569,7 +2581,7 @@
|
|
|
2569
2581
|
syntax: "none | nearest"
|
|
2570
2582
|
},
|
|
2571
2583
|
"scroll-margin": {
|
|
2572
|
-
syntax: "<length>{1,4}"
|
|
2584
|
+
syntax: " <length>{1,4}"
|
|
2573
2585
|
},
|
|
2574
2586
|
"scroll-margin-block": {
|
|
2575
2587
|
syntax: "<length>{1,2}"
|
|
@@ -2581,7 +2593,7 @@
|
|
|
2581
2593
|
syntax: "<length>"
|
|
2582
2594
|
},
|
|
2583
2595
|
"scroll-margin-bottom": {
|
|
2584
|
-
syntax: "<length>"
|
|
2596
|
+
syntax: " auto | <length-percentage [0,∞]>"
|
|
2585
2597
|
},
|
|
2586
2598
|
"scroll-margin-inline": {
|
|
2587
2599
|
syntax: "<length>{1,2}"
|
|
@@ -2593,13 +2605,13 @@
|
|
|
2593
2605
|
syntax: "<length>"
|
|
2594
2606
|
},
|
|
2595
2607
|
"scroll-margin-left": {
|
|
2596
|
-
syntax: "<length>"
|
|
2608
|
+
syntax: " auto | <length-percentage [0,∞]>"
|
|
2597
2609
|
},
|
|
2598
2610
|
"scroll-margin-right": {
|
|
2599
|
-
syntax: "<length>"
|
|
2611
|
+
syntax: " auto | <length-percentage [0,∞]>"
|
|
2600
2612
|
},
|
|
2601
2613
|
"scroll-margin-top": {
|
|
2602
|
-
syntax: "<length>"
|
|
2614
|
+
syntax: " auto | <length-percentage [0,∞]>"
|
|
2603
2615
|
},
|
|
2604
2616
|
"scroll-marker-group": {
|
|
2605
2617
|
syntax: "none | before | after"
|
|
@@ -2668,13 +2680,13 @@
|
|
|
2668
2680
|
syntax: "none | auto"
|
|
2669
2681
|
},
|
|
2670
2682
|
"scroll-timeline": {
|
|
2671
|
-
syntax: "[ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#"
|
|
2683
|
+
syntax: " [ <'scroll-timeline-name'> <'scroll-timeline-axis'>? ]#"
|
|
2672
2684
|
},
|
|
2673
2685
|
"scroll-timeline-axis": {
|
|
2674
|
-
syntax: "[ block | inline | x | y ]#"
|
|
2686
|
+
syntax: " [ block | inline | x | y ]#"
|
|
2675
2687
|
},
|
|
2676
2688
|
"scroll-timeline-name": {
|
|
2677
|
-
syntax: "[ none | <dashed-ident> ]#"
|
|
2689
|
+
syntax: " [ none | <dashed-ident> ]#"
|
|
2678
2690
|
},
|
|
2679
2691
|
"scrollbar-color": {
|
|
2680
2692
|
syntax: "auto | <color>{2}"
|
|
@@ -3167,6 +3179,9 @@
|
|
|
3167
3179
|
acos: {
|
|
3168
3180
|
syntax: "acos( <calc-sum> )"
|
|
3169
3181
|
},
|
|
3182
|
+
alpha: {
|
|
3183
|
+
syntax: "alpha( from <color> / [ <alpha-value> | none ] )"
|
|
3184
|
+
},
|
|
3170
3185
|
anchor: {
|
|
3171
3186
|
syntax: "anchor( <anchor-name>? && <anchor-side>, <length-percentage>? )"
|
|
3172
3187
|
},
|
|
@@ -6835,12 +6850,28 @@
|
|
|
6835
6850
|
]);
|
|
6836
6851
|
const combinators = ["+", ">", "~", "||", "|"];
|
|
6837
6852
|
|
|
6853
|
+
/**
|
|
6854
|
+
*
|
|
6855
|
+
* @param value
|
|
6856
|
+
* @returns
|
|
6857
|
+
*/
|
|
6838
6858
|
function dasherize(value) {
|
|
6839
6859
|
return value.replace(/([A-Z])/g, (all, one) => `-${one.toLowerCase()}`);
|
|
6840
6860
|
}
|
|
6861
|
+
/**
|
|
6862
|
+
*
|
|
6863
|
+
* @param value
|
|
6864
|
+
* @returns
|
|
6865
|
+
*/
|
|
6841
6866
|
function camelize(value) {
|
|
6842
6867
|
return value.replace(/-([a-z])/g, (all, one) => one.toUpperCase());
|
|
6843
6868
|
}
|
|
6869
|
+
/**
|
|
6870
|
+
*
|
|
6871
|
+
* @param a
|
|
6872
|
+
* @param b
|
|
6873
|
+
* @returns
|
|
6874
|
+
*/
|
|
6844
6875
|
function equalsIgnoreCase(a, b) {
|
|
6845
6876
|
if (a.length !== b.length)
|
|
6846
6877
|
return false;
|
|
@@ -6869,7 +6900,7 @@
|
|
|
6869
6900
|
// }
|
|
6870
6901
|
// }
|
|
6871
6902
|
if (token.kin == exports.ColorType.HEX || token.kin == exports.ColorType.LIT) {
|
|
6872
|
-
if (equalsIgnoreCase(
|
|
6903
|
+
if (equalsIgnoreCase("currentcolor", token.val)) {
|
|
6873
6904
|
return null;
|
|
6874
6905
|
}
|
|
6875
6906
|
const value = expandHexValue(token.kin == exports.ColorType.LIT ? COLORS_NAMES[token.val.toLowerCase()] : token.val);
|
|
@@ -6927,6 +6958,7 @@
|
|
|
6927
6958
|
*/
|
|
6928
6959
|
// A is m x n. B is n x p. product is m x p.
|
|
6929
6960
|
function multiplyMatrices(A, B) {
|
|
6961
|
+
// let m: number = A.length;
|
|
6930
6962
|
// if (!Array.isArray(A[0])) {
|
|
6931
6963
|
// // A is vector, convert to [[a, b, c, ...]]
|
|
6932
6964
|
// A = <number[][]>[A];
|
|
@@ -7142,6 +7174,23 @@
|
|
|
7142
7174
|
return alpha == null ? [l, c, h] : [l, c, h, alpha];
|
|
7143
7175
|
}
|
|
7144
7176
|
|
|
7177
|
+
// export function srgb2xyzd50values(r: number, g: number, b: number, alpha: number | null = null): number[] {
|
|
7178
|
+
// [r, g, b] = srgb2lsrgbvalues(r, g, b);
|
|
7179
|
+
//
|
|
7180
|
+
// const rgb: number[] = [
|
|
7181
|
+
// 0.436065742824811 * r + 0.3851514688337912 * g + 0.14307845442264197 * b,
|
|
7182
|
+
//
|
|
7183
|
+
// 0.22249319175623702 * r + 0.7168870538238823 * g + 0.06061979053616537 * b,
|
|
7184
|
+
//
|
|
7185
|
+
// 0.013923904500943465 * r + 0.09708128566574634 * g + 0.7140993584005155 * b,
|
|
7186
|
+
// ];
|
|
7187
|
+
//
|
|
7188
|
+
// if (alpha != null && alpha != 1) {
|
|
7189
|
+
// rgb.push(alpha);
|
|
7190
|
+
// }
|
|
7191
|
+
//
|
|
7192
|
+
// return rgb;
|
|
7193
|
+
// }
|
|
7145
7194
|
/*
|
|
7146
7195
|
*/
|
|
7147
7196
|
function xyzd502lch(x, y, z, alpha) {
|
|
@@ -7175,6 +7224,11 @@
|
|
|
7175
7224
|
x * 0.07195537988411677 - y * 0.2289768264158322 + 1.405386058324125 * z, alpha);
|
|
7176
7225
|
}
|
|
7177
7226
|
|
|
7227
|
+
// export function lab2xyz(l: number, a: number, b: number, alpha?: number): number[] {
|
|
7228
|
+
// const [x, y, z] = Lab_to_XYZ(l, a, b);
|
|
7229
|
+
//
|
|
7230
|
+
// return alpha == null || alpha == 1 ? [x, y, z] : [x, y, z, alpha];
|
|
7231
|
+
// }
|
|
7178
7232
|
function XYZ_to_lin_sRGB(x, y, z, alpha = null) {
|
|
7179
7233
|
// convert XYZ to linear-light sRGB
|
|
7180
7234
|
const M = [
|
|
@@ -7891,6 +7945,15 @@
|
|
|
7891
7945
|
? getNumber(t)
|
|
7892
7946
|
: getNumber(t) / 255) ?? null);
|
|
7893
7947
|
}
|
|
7948
|
+
// export function rgbvalues2srgbvalues(r: number, g: number, b: number, a: number | null = null): number[] | null {
|
|
7949
|
+
// const result = [r / 255, g / 255, b / 255];
|
|
7950
|
+
//
|
|
7951
|
+
// if (a != null && a != 1) {
|
|
7952
|
+
// result.push(a);
|
|
7953
|
+
// }
|
|
7954
|
+
//
|
|
7955
|
+
// return result;
|
|
7956
|
+
// }
|
|
7894
7957
|
function hex2srgbvalues(token) {
|
|
7895
7958
|
const value = expandHexValue(token.kin == exports.ColorType.LIT ? COLORS_NAMES[token.val.toLowerCase()] : token.val);
|
|
7896
7959
|
const rgb = [];
|
|
@@ -7951,11 +8014,8 @@
|
|
|
7951
8014
|
t = components[3];
|
|
7952
8015
|
// @ts-ignore
|
|
7953
8016
|
const k = getNumber(t);
|
|
7954
|
-
const
|
|
7955
|
-
|
|
7956
|
-
1 - Math.min(1, m * (1 - k) + k),
|
|
7957
|
-
1 - Math.min(1, y * (1 - k) + k),
|
|
7958
|
-
];
|
|
8017
|
+
const mul = 1 - k;
|
|
8018
|
+
const rgb = [1 - Math.min(1, c * mul + k), 1 - Math.min(1, m * mul + k), 1 - Math.min(1, y * mul + k)];
|
|
7959
8019
|
if (components.length == 5) {
|
|
7960
8020
|
rgb.push(getNumber(components[4]));
|
|
7961
8021
|
}
|
|
@@ -9127,7 +9187,7 @@
|
|
|
9127
9187
|
let colorSpace = "oklab";
|
|
9128
9188
|
let hueInterpolationMethod = "shorter";
|
|
9129
9189
|
let values = null;
|
|
9130
|
-
const colors = [];
|
|
9190
|
+
// const colors: ColorToken[] = [];
|
|
9131
9191
|
const percentages = [];
|
|
9132
9192
|
const srgbComponentValues = [];
|
|
9133
9193
|
const colorComponents = [];
|
|
@@ -9236,7 +9296,8 @@
|
|
|
9236
9296
|
return null;
|
|
9237
9297
|
}
|
|
9238
9298
|
srgbComponentValues.push(values);
|
|
9239
|
-
colors.push(args[i++]);
|
|
9299
|
+
// colors.push(args[i++] as ColorToken);
|
|
9300
|
+
i++;
|
|
9240
9301
|
if (i >= args.length) {
|
|
9241
9302
|
missingPercentageCount++;
|
|
9242
9303
|
percentages.push(null);
|
|
@@ -9278,9 +9339,16 @@
|
|
|
9278
9339
|
for (i = 0; i < percentages.length; i++) {
|
|
9279
9340
|
percentages[i] = percentages[i] / perc;
|
|
9280
9341
|
}
|
|
9281
|
-
totalPercentage = 1;
|
|
9282
9342
|
}
|
|
9283
|
-
|
|
9343
|
+
const stack = [];
|
|
9344
|
+
const lchSpaces = ["lch", "oklch"];
|
|
9345
|
+
i = srgbComponentValues.length;
|
|
9346
|
+
while (i--) {
|
|
9347
|
+
stack.push({
|
|
9348
|
+
color: srgbComponentValues[i],
|
|
9349
|
+
alpha: percentages[i],
|
|
9350
|
+
});
|
|
9351
|
+
}
|
|
9284
9352
|
let currentIndex = 0;
|
|
9285
9353
|
let r1;
|
|
9286
9354
|
let r2;
|
|
@@ -9291,18 +9359,11 @@
|
|
|
9291
9359
|
let premult1;
|
|
9292
9360
|
let premult2;
|
|
9293
9361
|
let mixedPremult;
|
|
9294
|
-
let colorSpace1
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
|
-
i = srgbComponentValues.length;
|
|
9298
|
-
while (i--) {
|
|
9299
|
-
stack.push({
|
|
9300
|
-
color: srgbComponentValues[i],
|
|
9301
|
-
alpha: percentages[i],
|
|
9302
|
-
});
|
|
9303
|
-
}
|
|
9362
|
+
let colorSpace1 = exports.ColorType[
|
|
9363
|
+
// @ts-expect-error
|
|
9364
|
+
colorComponents.at(-1).kin
|
|
9304
9365
|
// @ts-expect-error
|
|
9305
|
-
|
|
9366
|
+
]?.toLowerCase?.();
|
|
9306
9367
|
if (colorComponents[0][3] != null &&
|
|
9307
9368
|
colorComponents[0][3].typ == exports.EnumToken.IdenTokenType &&
|
|
9308
9369
|
colorComponents[0][3].val == "none" &&
|
|
@@ -9384,14 +9445,13 @@
|
|
|
9384
9445
|
else {
|
|
9385
9446
|
values = xyz2lchvalues(values[0], values[1], values[2], values[3]);
|
|
9386
9447
|
}
|
|
9387
|
-
// @ts-ignore
|
|
9388
9448
|
return {
|
|
9389
9449
|
typ: exports.EnumToken.ColorTokenType,
|
|
9390
9450
|
val: "lch",
|
|
9391
|
-
chi: values.map((
|
|
9451
|
+
chi: values.map((val) => {
|
|
9392
9452
|
return {
|
|
9393
9453
|
typ: exports.EnumToken.NumberTokenType,
|
|
9394
|
-
val
|
|
9454
|
+
val,
|
|
9395
9455
|
};
|
|
9396
9456
|
}),
|
|
9397
9457
|
kin: exports.ColorType.LCH,
|
|
@@ -10124,6 +10184,35 @@
|
|
|
10124
10184
|
if (!isScalarToken(l) || !isScalarToken(r) || (l.typ == r.typ && "unit" in l && "unit" in r && l.unit != r.unit)) {
|
|
10125
10185
|
return defaultReturn;
|
|
10126
10186
|
}
|
|
10187
|
+
if (l.typ == exports.EnumToken.IdenTokenType) {
|
|
10188
|
+
if (equalsIgnoreCase(l.val, "Infinity")) {
|
|
10189
|
+
Object.assign(l, { typ: exports.EnumToken.InfinityTokenType });
|
|
10190
|
+
}
|
|
10191
|
+
else if (equalsIgnoreCase(l.val, "-Infinity")) {
|
|
10192
|
+
Object.assign(l, { typ: exports.EnumToken.NegativeInfinityTokenType });
|
|
10193
|
+
}
|
|
10194
|
+
else if (equalsIgnoreCase(l.val, "NaN")) {
|
|
10195
|
+
Object.assign(l, { typ: exports.EnumToken.NaNTokenType });
|
|
10196
|
+
}
|
|
10197
|
+
}
|
|
10198
|
+
if (r.typ == exports.EnumToken.IdenTokenType) {
|
|
10199
|
+
if (equalsIgnoreCase(r.val, "Infinity")) {
|
|
10200
|
+
Object.assign(r, { typ: exports.EnumToken.InfinityTokenType });
|
|
10201
|
+
}
|
|
10202
|
+
else if (equalsIgnoreCase(r.val, "-Infinity")) {
|
|
10203
|
+
Object.assign(r, { typ: exports.EnumToken.NegativeInfinityTokenType });
|
|
10204
|
+
}
|
|
10205
|
+
}
|
|
10206
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/calc-keyword#notes
|
|
10207
|
+
if (l.typ == exports.EnumToken.NaNTokenType || r.typ == exports.EnumToken.NaNTokenType) {
|
|
10208
|
+
return computeNaN(l, r, defaultReturn);
|
|
10209
|
+
}
|
|
10210
|
+
if (l.typ == exports.EnumToken.InfinityTokenType ||
|
|
10211
|
+
l.typ == exports.EnumToken.NegativeInfinityTokenType ||
|
|
10212
|
+
r.typ == exports.EnumToken.InfinityTokenType ||
|
|
10213
|
+
r.typ == exports.EnumToken.NegativeInfinityTokenType) {
|
|
10214
|
+
return computeInfinity(l, r, op, defaultReturn);
|
|
10215
|
+
}
|
|
10127
10216
|
if (r.typ == exports.EnumToken.FunctionTokenType || r.typ == exports.EnumToken.MathFunctionTokenType) {
|
|
10128
10217
|
const val = evaluateFunc(r);
|
|
10129
10218
|
if (val == null) {
|
|
@@ -10194,6 +10283,18 @@
|
|
|
10194
10283
|
}
|
|
10195
10284
|
}
|
|
10196
10285
|
}
|
|
10286
|
+
if (op == exports.EnumToken.Div && v2 == 0) {
|
|
10287
|
+
if (v1 == 0) {
|
|
10288
|
+
return Object.assign(l, { typ: exports.EnumToken.IdenTokenType, val: "NaN" });
|
|
10289
|
+
}
|
|
10290
|
+
let sign = Math.sign(v1) * Math.sign(v2);
|
|
10291
|
+
sign = Object.is(sign, -0) ? -1 : 1;
|
|
10292
|
+
Object.assign(l, {
|
|
10293
|
+
typ: l.typ == exports.EnumToken.IdenTokenType ? exports.EnumToken.NumberTokenType : l.typ,
|
|
10294
|
+
val: Object.is(sign, -0) ? -1 : sign,
|
|
10295
|
+
});
|
|
10296
|
+
return defaultReturn;
|
|
10297
|
+
}
|
|
10197
10298
|
// @ts-ignore
|
|
10198
10299
|
const val = compute$1(v1, v2, op);
|
|
10199
10300
|
const token = {
|
|
@@ -10210,6 +10311,112 @@
|
|
|
10210
10311
|
}
|
|
10211
10312
|
return token;
|
|
10212
10313
|
}
|
|
10314
|
+
/**
|
|
10315
|
+
*
|
|
10316
|
+
* @param l
|
|
10317
|
+
* @param r
|
|
10318
|
+
* @param defaultReturn
|
|
10319
|
+
* @returns
|
|
10320
|
+
*/
|
|
10321
|
+
function computeNaN(l, r, defaultReturn) {
|
|
10322
|
+
if (l.typ == exports.EnumToken.NaNTokenType) {
|
|
10323
|
+
if (r.typ == exports.EnumToken.NumberTokenType ||
|
|
10324
|
+
// @ts-expect-error
|
|
10325
|
+
(r.typ == exports.EnumToken.IdenTokenType && typeof Math[r.val.toUpperCase()] == "string")) {
|
|
10326
|
+
return l;
|
|
10327
|
+
}
|
|
10328
|
+
// NaN Infinity e pi ...
|
|
10329
|
+
if (r.typ == exports.EnumToken.IdenTokenType ||
|
|
10330
|
+
r.typ == exports.EnumToken.InfinityTokenType ||
|
|
10331
|
+
r.typ == exports.EnumToken.NegativeInfinityTokenType) {
|
|
10332
|
+
return l;
|
|
10333
|
+
}
|
|
10334
|
+
if (typeof r.val == "number") {
|
|
10335
|
+
Object.assign(r, { val: 1 });
|
|
10336
|
+
}
|
|
10337
|
+
return r.typ == exports.EnumToken.NaNTokenType ? l : defaultReturn;
|
|
10338
|
+
}
|
|
10339
|
+
if (r.typ == exports.EnumToken.NaNTokenType) {
|
|
10340
|
+
// if ((r as IdentToken).val == "NaN") {
|
|
10341
|
+
if (l.typ == exports.EnumToken.NumberTokenType ||
|
|
10342
|
+
// @ts-expect-error
|
|
10343
|
+
(l.typ == exports.EnumToken.IdenTokenType && typeof Math[l.val.toUpperCase()] == "string")) {
|
|
10344
|
+
return r;
|
|
10345
|
+
}
|
|
10346
|
+
if (typeof l.val == "number") {
|
|
10347
|
+
Object.assign(l, { val: 1 });
|
|
10348
|
+
}
|
|
10349
|
+
// return defaultReturn;
|
|
10350
|
+
}
|
|
10351
|
+
// }
|
|
10352
|
+
return defaultReturn;
|
|
10353
|
+
}
|
|
10354
|
+
/**
|
|
10355
|
+
*
|
|
10356
|
+
* @param l
|
|
10357
|
+
* @param r
|
|
10358
|
+
* @param op
|
|
10359
|
+
* @param defaultReturn
|
|
10360
|
+
* @returns
|
|
10361
|
+
*/
|
|
10362
|
+
function computeInfinity(l, r, op, defaultReturn) {
|
|
10363
|
+
if (l.typ == exports.EnumToken.InfinityTokenType || l.typ == exports.EnumToken.NegativeInfinityTokenType) {
|
|
10364
|
+
if (r.typ == exports.EnumToken.InfinityTokenType || r.typ == exports.EnumToken.NegativeInfinityTokenType) {
|
|
10365
|
+
// Infinity / Infinity Infinity - Infinity
|
|
10366
|
+
if (op == exports.EnumToken.Div ||
|
|
10367
|
+
(op == exports.EnumToken.Add && l.typ != r.typ) ||
|
|
10368
|
+
(op == exports.EnumToken.Sub && l.typ == r.typ)) {
|
|
10369
|
+
return Object.assign(l, { typ: exports.EnumToken.NaNTokenType });
|
|
10370
|
+
}
|
|
10371
|
+
if (l.typ != r.typ) {
|
|
10372
|
+
l.typ = exports.EnumToken.NegativeInfinityTokenType;
|
|
10373
|
+
}
|
|
10374
|
+
return l;
|
|
10375
|
+
}
|
|
10376
|
+
const value = getValue$1(r);
|
|
10377
|
+
const sign = Math.sign(value);
|
|
10378
|
+
const isNumber = r.typ == exports.EnumToken.NumberTokenType || r.typ == exports.EnumToken.IdenTokenType;
|
|
10379
|
+
// Infinity * 0
|
|
10380
|
+
if (value == 0 && op == exports.EnumToken.Mul) {
|
|
10381
|
+
l.typ = exports.EnumToken.NaNTokenType;
|
|
10382
|
+
return isNumber ? l : defaultReturn;
|
|
10383
|
+
}
|
|
10384
|
+
if (isNumber) {
|
|
10385
|
+
// @ts-ignore
|
|
10386
|
+
r.val /= r.val * sign;
|
|
10387
|
+
}
|
|
10388
|
+
if (op == exports.EnumToken.Div) {
|
|
10389
|
+
return isNumber
|
|
10390
|
+
? Object.assign(r, { typ: exports.EnumToken.NumberTokenType, val: sign < 0 ? -0 : 0 })
|
|
10391
|
+
: defaultReturn;
|
|
10392
|
+
}
|
|
10393
|
+
if (sign == -1) {
|
|
10394
|
+
l.typ =
|
|
10395
|
+
l.typ == exports.EnumToken.InfinityTokenType
|
|
10396
|
+
? exports.EnumToken.NegativeInfinityTokenType
|
|
10397
|
+
: exports.EnumToken.InfinityTokenType;
|
|
10398
|
+
}
|
|
10399
|
+
return isNumber ? l : defaultReturn;
|
|
10400
|
+
}
|
|
10401
|
+
if (r.typ == exports.EnumToken.InfinityTokenType || r.typ == exports.EnumToken.NegativeInfinityTokenType) {
|
|
10402
|
+
const value = getValue$1(l);
|
|
10403
|
+
let sign = Math.sign(value);
|
|
10404
|
+
const isNumber = l.typ == exports.EnumToken.NumberTokenType || l.typ == exports.EnumToken.IdenTokenType;
|
|
10405
|
+
if (isNumber) {
|
|
10406
|
+
Object.assign(l, { typ: exports.EnumToken.NumberTokenType, val: sign });
|
|
10407
|
+
}
|
|
10408
|
+
if (value == 0 && op == exports.EnumToken.Mul) {
|
|
10409
|
+
return Object.assign(l, { typ: exports.EnumToken.NaNTokenType });
|
|
10410
|
+
}
|
|
10411
|
+
if (op == exports.EnumToken.Div) {
|
|
10412
|
+
return isNumber
|
|
10413
|
+
? Object.assign(l, { typ: exports.EnumToken.NumberTokenType, val: sign < 0 ? -0 : 0 })
|
|
10414
|
+
: defaultReturn;
|
|
10415
|
+
}
|
|
10416
|
+
return l.typ == isNumber || value == 0 ? r : defaultReturn;
|
|
10417
|
+
}
|
|
10418
|
+
return defaultReturn;
|
|
10419
|
+
}
|
|
10213
10420
|
function getValue$1(t) {
|
|
10214
10421
|
if (t.typ == exports.EnumToken.IdenTokenType) {
|
|
10215
10422
|
// @ts-ignore
|
|
@@ -10262,7 +10469,9 @@
|
|
|
10262
10469
|
}
|
|
10263
10470
|
const value = evaluate(values);
|
|
10264
10471
|
// @ts-ignore
|
|
10265
|
-
let val = value[0].typ == exports.EnumToken.NumberTokenType ||
|
|
10472
|
+
let val = value[0].typ == exports.EnumToken.NumberTokenType ||
|
|
10473
|
+
value[0].typ == exports.EnumToken.AngleTokenType ||
|
|
10474
|
+
value[0].typ == exports.EnumToken.PercentageTokenType
|
|
10266
10475
|
? +value[0].val
|
|
10267
10476
|
: // @ts-expect-error
|
|
10268
10477
|
value[0].l.val / value[0].r.val;
|
|
@@ -10277,7 +10486,7 @@
|
|
|
10277
10486
|
[LOCEND]: value[0][LOCEND],
|
|
10278
10487
|
}
|
|
10279
10488
|
: {
|
|
10280
|
-
typ: exports.EnumToken.NumberTokenType,
|
|
10489
|
+
typ: token.val == "sign" ? exports.EnumToken.NumberTokenType : value[0].typ,
|
|
10281
10490
|
val: Math[token.val](val),
|
|
10282
10491
|
[LOCSRCID]: value[0][LOCSRCID],
|
|
10283
10492
|
[LOCSTA]: value[0][LOCSTA],
|
|
@@ -10307,10 +10516,23 @@
|
|
|
10307
10516
|
},
|
|
10308
10517
|
];
|
|
10309
10518
|
}
|
|
10519
|
+
case "mod":
|
|
10310
10520
|
case "atan2":
|
|
10311
10521
|
case "pow":
|
|
10312
|
-
case "rem":
|
|
10313
|
-
|
|
10522
|
+
case "rem": {
|
|
10523
|
+
{
|
|
10524
|
+
let typ = token.chi[0]?.typ;
|
|
10525
|
+
for (let i = 1; i < token.chi.length; i++) {
|
|
10526
|
+
if (token.chi[i].typ == exports.EnumToken.WhitespaceTokenType ||
|
|
10527
|
+
token.chi[i].typ == exports.EnumToken.CommaTokenType ||
|
|
10528
|
+
token.chi[i].typ == exports.EnumToken.CommentTokenType) {
|
|
10529
|
+
continue;
|
|
10530
|
+
}
|
|
10531
|
+
if (token.chi[i].typ != typ) {
|
|
10532
|
+
return null;
|
|
10533
|
+
}
|
|
10534
|
+
}
|
|
10535
|
+
}
|
|
10314
10536
|
const chi = values.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ));
|
|
10315
10537
|
if (token.val == "atan2") {
|
|
10316
10538
|
for (let i = 0; i < chi.length; i++) {
|
|
@@ -10529,7 +10751,14 @@
|
|
|
10529
10751
|
(token.typ == exports.EnumToken.FunctionTokenType && mathFuncs.includes(token.val)) ||
|
|
10530
10752
|
// @ts-ignore
|
|
10531
10753
|
(token.typ == exports.EnumToken.IdenTokenType && typeof Math[token.val.toUpperCase()] == "number") ||
|
|
10532
|
-
|
|
10754
|
+
(token.typ == exports.EnumToken.IdenTokenType && token.val == "NaN") ||
|
|
10755
|
+
(token.typ == exports.EnumToken.IdenTokenType &&
|
|
10756
|
+
(equalsIgnoreCase(token.val, "Infinity") ||
|
|
10757
|
+
equalsIgnoreCase(token.val, "-Infinity"))) ||
|
|
10758
|
+
[exports.EnumToken.NumberTokenType, exports.EnumToken.FractionTokenType, exports.EnumToken.PercentageTokenType].includes(token.typ) ||
|
|
10759
|
+
token.typ == exports.EnumToken.NaNTokenType ||
|
|
10760
|
+
token.typ == exports.EnumToken.InfinityTokenType ||
|
|
10761
|
+
token.typ == exports.EnumToken.NegativeInfinityTokenType);
|
|
10533
10762
|
}
|
|
10534
10763
|
/**
|
|
10535
10764
|
*
|
|
@@ -10931,9 +11160,10 @@
|
|
|
10931
11160
|
}
|
|
10932
11161
|
function srgb2cmykvalues(r, g, b, a = null) {
|
|
10933
11162
|
const k = 1 - Math.max(r, g, b);
|
|
10934
|
-
const
|
|
10935
|
-
const
|
|
10936
|
-
const
|
|
11163
|
+
const div = 1 - k;
|
|
11164
|
+
const c = k == 1 ? 0 : (1 - r - k) / div;
|
|
11165
|
+
const m = k == 1 ? 0 : (1 - g - k) / div;
|
|
11166
|
+
const y = k == 1 ? 0 : (1 - b - k) / div;
|
|
10937
11167
|
const result = [c, m, y, k];
|
|
10938
11168
|
if (a != null && a < 1) {
|
|
10939
11169
|
result.push(a);
|
|
@@ -11747,9 +11977,13 @@
|
|
|
11747
11977
|
stack.pop();
|
|
11748
11978
|
}
|
|
11749
11979
|
}
|
|
11750
|
-
if (stack.length > 0) {
|
|
11751
|
-
|
|
11752
|
-
}
|
|
11980
|
+
// if (stack.length > 0) {
|
|
11981
|
+
// throw new SyntaxError(
|
|
11982
|
+
// `Unexpected token ${ValidationTokenEnum[stack.at(-1)?.typ as ValidationTokenEnum]} at ${
|
|
11983
|
+
// stack.at(-1)?.[LOC]?.lin
|
|
11984
|
+
// }:${stack.at(-1)?.[LOC]?.col}`,
|
|
11985
|
+
// );
|
|
11986
|
+
// }
|
|
11753
11987
|
return trimSyntaxArray(tokens);
|
|
11754
11988
|
}
|
|
11755
11989
|
|
|
@@ -11805,6 +12039,32 @@
|
|
|
11805
12039
|
// @ts-expect-error
|
|
11806
12040
|
return config$4;
|
|
11807
12041
|
}
|
|
12042
|
+
// export const getSyntax = memoize((group: ValidationSyntaxGroupEnum, key: string | string[]): null | string => {
|
|
12043
|
+
// // @ts-expect-error
|
|
12044
|
+
// let obj = config[group] as Record<ValidationSyntaxGroupEnum, ValidationSyntaxNode>;
|
|
12045
|
+
//
|
|
12046
|
+
// const keys: string[] = Array.isArray(key) ? key : [key];
|
|
12047
|
+
//
|
|
12048
|
+
// for (let i = 0; i < keys.length; i++) {
|
|
12049
|
+
// key = keys[i];
|
|
12050
|
+
//
|
|
12051
|
+
// if (!(key in obj)) {
|
|
12052
|
+
// if ((i == 0 && key.charAt(0) == "@") || key.charAt(0) == "-") {
|
|
12053
|
+
// const matches: RegExpMatchArray = key.match(/^(@?)(-[a-zA-Z]+)-(.*?)$/) as RegExpMatchArray;
|
|
12054
|
+
//
|
|
12055
|
+
// if (matches != null) {
|
|
12056
|
+
// key = matches[1] + matches[3];
|
|
12057
|
+
// }
|
|
12058
|
+
// }
|
|
12059
|
+
// }
|
|
12060
|
+
//
|
|
12061
|
+
// // @ts-expect-error
|
|
12062
|
+
// obj = obj[key];
|
|
12063
|
+
// }
|
|
12064
|
+
//
|
|
12065
|
+
// // @ts-expect-error
|
|
12066
|
+
// return obj?.syntax ?? null;
|
|
12067
|
+
// }) as (group: ValidationSyntaxGroupEnum, key: string | string[]) => null | string;
|
|
11808
12068
|
function findNode(group, key) {
|
|
11809
12069
|
// @ts-expect-error
|
|
11810
12070
|
let obj = config$4[group];
|
|
@@ -11954,6 +12214,15 @@
|
|
|
11954
12214
|
}
|
|
11955
12215
|
return tokens;
|
|
11956
12216
|
}
|
|
12217
|
+
/**
|
|
12218
|
+
* is a media feature
|
|
12219
|
+
* @param featureName
|
|
12220
|
+
* @returns
|
|
12221
|
+
*/
|
|
12222
|
+
// export function isMFName(featureName: string): boolean {
|
|
12223
|
+
// // @ts-expect-error
|
|
12224
|
+
// return featureName.startsWith("--") || config.mediaFeatures[featureName.toLowerCase()] != null;
|
|
12225
|
+
// }
|
|
11957
12226
|
/**
|
|
11958
12227
|
*
|
|
11959
12228
|
* @param featureName
|
|
@@ -11967,6 +12236,7 @@
|
|
|
11967
12236
|
*
|
|
11968
12237
|
* @param featureName
|
|
11969
12238
|
* @param tokens
|
|
12239
|
+
* @param isMFRange
|
|
11970
12240
|
* @returns object with:
|
|
11971
12241
|
* - valid: boolean. true the media feaure is known or is a custom property. false otherwise
|
|
11972
12242
|
* - success: boolean. validation result
|
|
@@ -12084,9 +12354,10 @@
|
|
|
12084
12354
|
},
|
|
12085
12355
|
/**
|
|
12086
12356
|
*
|
|
12087
|
-
* @param stopCondition
|
|
12088
|
-
* @param matchCount
|
|
12089
12357
|
* @returns
|
|
12358
|
+
* @param open
|
|
12359
|
+
* @param close
|
|
12360
|
+
* @param counter
|
|
12090
12361
|
*/
|
|
12091
12362
|
peekRange(open = exports.EnumToken.StartParensTokenType, close = exports.EnumToken.EndParensTokenType, counter = 0) {
|
|
12092
12363
|
let index = this.index;
|
|
@@ -12309,7 +12580,7 @@
|
|
|
12309
12580
|
case exports.EnumToken.CDOCOMMTokenType:
|
|
12310
12581
|
break;
|
|
12311
12582
|
case exports.EnumToken.NestingSelectorTokenType:
|
|
12312
|
-
if (nested
|
|
12583
|
+
if (!nested && !options.nestedRule) {
|
|
12313
12584
|
return {
|
|
12314
12585
|
success: false,
|
|
12315
12586
|
errors: [
|
|
@@ -13350,7 +13621,8 @@
|
|
|
13350
13621
|
errors: [],
|
|
13351
13622
|
};
|
|
13352
13623
|
case ValidationTokenEnum.FunctionDefinition:
|
|
13353
|
-
if (
|
|
13624
|
+
if (token.val &&
|
|
13625
|
+
equalsIgnoreCase(token.val, syntaxes[i].val)) {
|
|
13354
13626
|
if (tokensfuncDefMap.has(token.typ)) {
|
|
13355
13627
|
const children = trimArray(context.peekRange());
|
|
13356
13628
|
result = matchSyntax((getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()")?.[0]).chi ?? [], createValidationContext(children.slice(1, -1)), options);
|
|
@@ -14375,104 +14647,6 @@
|
|
|
14375
14647
|
return color.kin;
|
|
14376
14648
|
}
|
|
14377
14649
|
|
|
14378
|
-
const trimTokenSpace = new Set([
|
|
14379
|
-
exports.EnumToken.CommaTokenType,
|
|
14380
|
-
exports.EnumToken.DelimTokenType,
|
|
14381
|
-
exports.EnumToken.GtTokenType,
|
|
14382
|
-
exports.EnumToken.GteTokenType,
|
|
14383
|
-
exports.EnumToken.LtTokenType,
|
|
14384
|
-
exports.EnumToken.LteTokenType,
|
|
14385
|
-
exports.EnumToken.ChildCombinatorTokenType,
|
|
14386
|
-
]);
|
|
14387
|
-
const trimSpaceAfter = new Set([
|
|
14388
|
-
...tokensfuncSet.values(),
|
|
14389
|
-
exports.EnumToken.ChildCombinatorTokenType,
|
|
14390
|
-
exports.EnumToken.SupportsQueryConditionTokenType,
|
|
14391
|
-
exports.EnumToken.SupportsQueryUnaryConditionTokenType,
|
|
14392
|
-
]);
|
|
14393
|
-
/**
|
|
14394
|
-
* Replace token in its parent node
|
|
14395
|
-
* @param parent
|
|
14396
|
-
* @param node
|
|
14397
|
-
* @param replacement
|
|
14398
|
-
* @throws TypeError replacement is null
|
|
14399
|
-
* @throws ReferenceError node not found in parent
|
|
14400
|
-
*/
|
|
14401
|
-
function replaceNodeOrValue(parent, node, replacement) {
|
|
14402
|
-
if (replacement == null || (Array.isArray(replacement) && replacement.length === 0)) {
|
|
14403
|
-
throw new TypeError(`replacement is null`);
|
|
14404
|
-
}
|
|
14405
|
-
for (const newNode of Array.isArray(replacement) ? replacement : [replacement]) {
|
|
14406
|
-
if (newNode[PARENT] != node[PARENT]) {
|
|
14407
|
-
newNode[PARENT] = node[PARENT];
|
|
14408
|
-
}
|
|
14409
|
-
}
|
|
14410
|
-
if (parent.typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
14411
|
-
if (parent.l == node) {
|
|
14412
|
-
parent.l = replacement;
|
|
14413
|
-
}
|
|
14414
|
-
else if (parent.r == node) {
|
|
14415
|
-
parent.r = replacement;
|
|
14416
|
-
}
|
|
14417
|
-
else {
|
|
14418
|
-
throw new ReferenceError("Node not found");
|
|
14419
|
-
}
|
|
14420
|
-
}
|
|
14421
|
-
else {
|
|
14422
|
-
const target = "val" in parent && Array.isArray(parent.val)
|
|
14423
|
-
? parent.val
|
|
14424
|
-
: (parent.chi ?? parent);
|
|
14425
|
-
if (Array.isArray(target)) {
|
|
14426
|
-
// @ts-ignore
|
|
14427
|
-
const index = target.indexOf(node);
|
|
14428
|
-
if (index == -1) {
|
|
14429
|
-
throw new ReferenceError("Node not found");
|
|
14430
|
-
}
|
|
14431
|
-
target.splice(index, 1, ...(Array.isArray(replacement) ? replacement : [replacement]));
|
|
14432
|
-
}
|
|
14433
|
-
else if ("l" in target && target.l == node) {
|
|
14434
|
-
target.l = replacement;
|
|
14435
|
-
}
|
|
14436
|
-
else if ("r" in target && target.r == node) {
|
|
14437
|
-
target.r = replacement;
|
|
14438
|
-
}
|
|
14439
|
-
else {
|
|
14440
|
-
throw new ReferenceError("Node not found");
|
|
14441
|
-
}
|
|
14442
|
-
}
|
|
14443
|
-
node[PARENT] = null;
|
|
14444
|
-
return true;
|
|
14445
|
-
}
|
|
14446
|
-
function trimWhiteSpaceTokens(tokens) {
|
|
14447
|
-
let i = 0;
|
|
14448
|
-
if (tokens[0]?.typ === exports.EnumToken.WhitespaceTokenType) {
|
|
14449
|
-
tokens.shift();
|
|
14450
|
-
}
|
|
14451
|
-
if (tokens[tokens.length - 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
|
|
14452
|
-
tokens.pop();
|
|
14453
|
-
}
|
|
14454
|
-
if (tokens.length === 1) {
|
|
14455
|
-
if (tokens[0].typ === exports.EnumToken.WhitespaceTokenType) {
|
|
14456
|
-
tokens.length = 0;
|
|
14457
|
-
}
|
|
14458
|
-
return tokens;
|
|
14459
|
-
}
|
|
14460
|
-
for (; i < tokens.length; i++) {
|
|
14461
|
-
if (trimSpaceAfter.has(tokens[i].typ) && tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
|
|
14462
|
-
tokens.splice(i + 1, 1);
|
|
14463
|
-
}
|
|
14464
|
-
else if (trimTokenSpace.has(tokens[i].typ)) {
|
|
14465
|
-
if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
|
|
14466
|
-
tokens.splice(i + 1, 1);
|
|
14467
|
-
}
|
|
14468
|
-
if (i > 0 && tokens[i - 1].typ === exports.EnumToken.Whitespace) {
|
|
14469
|
-
tokens.splice(--i, 1);
|
|
14470
|
-
}
|
|
14471
|
-
}
|
|
14472
|
-
}
|
|
14473
|
-
return tokens;
|
|
14474
|
-
}
|
|
14475
|
-
|
|
14476
14650
|
/**
|
|
14477
14651
|
* Compute alpha color
|
|
14478
14652
|
* @param color
|
|
@@ -14483,40 +14657,76 @@
|
|
|
14483
14657
|
if (alpha == null) {
|
|
14484
14658
|
return color;
|
|
14485
14659
|
}
|
|
14660
|
+
// https://www.w3.org/TR/css-color-5/#:~:text=There%20is%20no%20relative%20device%2Dcmyk%28%29%20syntax
|
|
14486
14661
|
if (color.kin === exports.ColorType.DEVICE_CMYK) {
|
|
14487
14662
|
return null;
|
|
14488
14663
|
}
|
|
14664
|
+
let components = getColorComponents(color);
|
|
14665
|
+
if (alpha.typ === exports.EnumToken.MathFunctionTokenType) {
|
|
14666
|
+
const originalAlpha = cloneNode(alpha, true);
|
|
14667
|
+
for (const { value } of walkValues(alpha.chi, alpha)) {
|
|
14668
|
+
if (value.typ === exports.EnumToken.IdenTokenType) {
|
|
14669
|
+
if (equalsIgnoreCase(value.val, "alpha")) {
|
|
14670
|
+
Object.assign(value, components?.[3]
|
|
14671
|
+
? cloneNode(components[3], true)
|
|
14672
|
+
: {
|
|
14673
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
14674
|
+
val: 1,
|
|
14675
|
+
});
|
|
14676
|
+
// continue;
|
|
14677
|
+
}
|
|
14678
|
+
else if (equalsIgnoreCase(value.val, "none")) {
|
|
14679
|
+
Object.assign(value, {
|
|
14680
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
14681
|
+
val: 0,
|
|
14682
|
+
});
|
|
14683
|
+
}
|
|
14684
|
+
}
|
|
14685
|
+
}
|
|
14686
|
+
const result = evaluate([alpha]);
|
|
14687
|
+
if (result.length == 1) {
|
|
14688
|
+
alpha = result[0];
|
|
14689
|
+
}
|
|
14690
|
+
else {
|
|
14691
|
+
// @ts-expect-error
|
|
14692
|
+
alpha = originalAlpha;
|
|
14693
|
+
}
|
|
14694
|
+
}
|
|
14695
|
+
// console.error({ alpha });
|
|
14696
|
+
if (alpha.typ !== exports.EnumToken.IdenTokenType &&
|
|
14697
|
+
alpha.typ !== exports.EnumToken.NumberTokenType &&
|
|
14698
|
+
alpha.typ !== exports.EnumToken.PercentageTokenType) {
|
|
14699
|
+
return null;
|
|
14700
|
+
}
|
|
14701
|
+
if (alpha.typ === exports.EnumToken.IdenTokenType) {
|
|
14702
|
+
if (equalsIgnoreCase(alpha.val, "NaN") ||
|
|
14703
|
+
equalsIgnoreCase(alpha.val, "Infinity") ||
|
|
14704
|
+
equalsIgnoreCase(alpha.val, "-Infinity")) {
|
|
14705
|
+
return null;
|
|
14706
|
+
}
|
|
14707
|
+
}
|
|
14489
14708
|
if (color.kin === exports.ColorType.COLOR_MIX || color.cal === "rel") {
|
|
14490
14709
|
color = convertColor(color, getColorType(color));
|
|
14491
14710
|
if (color == null) {
|
|
14492
14711
|
return null;
|
|
14493
14712
|
}
|
|
14713
|
+
components = getColorComponents(color);
|
|
14494
14714
|
}
|
|
14495
|
-
const components = getColorComponents(color);
|
|
14496
14715
|
if (components == null) {
|
|
14497
14716
|
return null;
|
|
14498
14717
|
}
|
|
14499
|
-
if (alpha?.typ === exports.EnumToken.IdenTokenType
|
|
14500
|
-
alpha
|
|
14501
|
-
|
|
14502
|
-
|
|
14503
|
-
|
|
14504
|
-
|
|
14505
|
-
else if (alpha.typ === exports.EnumToken.MathFunctionTokenType &&
|
|
14506
|
-
equalsIgnoreCase(alpha.val, "calc")) {
|
|
14507
|
-
alpha = cloneNode(alpha, true);
|
|
14508
|
-
const alphaValue = components[3] ?? {
|
|
14509
|
-
typ: exports.EnumToken.NumberTokenType,
|
|
14510
|
-
val: 1,
|
|
14511
|
-
};
|
|
14512
|
-
for (const { value, parent } of walkValues(alpha.chi, alpha)) {
|
|
14513
|
-
if (value.typ === exports.EnumToken.IdenTokenType && equalsIgnoreCase(value.val, "alpha")) {
|
|
14514
|
-
replaceNodeOrValue(parent, value, alphaValue);
|
|
14515
|
-
}
|
|
14718
|
+
if (alpha?.typ === exports.EnumToken.IdenTokenType) {
|
|
14719
|
+
if (equalsIgnoreCase(alpha.val, "alpha")) {
|
|
14720
|
+
alpha = components[3] ?? {
|
|
14721
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
14722
|
+
val: 1,
|
|
14723
|
+
};
|
|
14516
14724
|
}
|
|
14517
|
-
|
|
14518
|
-
|
|
14519
|
-
|
|
14725
|
+
else if (equalsIgnoreCase(alpha.val, "node")) {
|
|
14726
|
+
alpha = {
|
|
14727
|
+
typ: exports.EnumToken.NumberTokenType,
|
|
14728
|
+
val: 0,
|
|
14729
|
+
};
|
|
14520
14730
|
}
|
|
14521
14731
|
}
|
|
14522
14732
|
return makeColor(color.kin, components, alpha);
|
|
@@ -15086,11 +15296,11 @@
|
|
|
15086
15296
|
|
|
15087
15297
|
/**
|
|
15088
15298
|
* Calculate the distance between two okLab colors.
|
|
15089
|
-
* @param okLab1
|
|
15090
|
-
* @param okLab2
|
|
15091
15299
|
*
|
|
15092
15300
|
* @private
|
|
15093
15301
|
* {@link https://drafts.csswg.org/css-color-4/#comparing-color-values}
|
|
15302
|
+
* @param color1
|
|
15303
|
+
* @param color2
|
|
15094
15304
|
*/
|
|
15095
15305
|
function okLabDistance(color1, color2) {
|
|
15096
15306
|
color1 = convertColor(color1, exports.ColorType.OKLAB);
|
|
@@ -15419,6 +15629,300 @@
|
|
|
15419
15629
|
":-moz-ui-valid": ":user-valid",
|
|
15420
15630
|
"::-moz-selection": "::selection",
|
|
15421
15631
|
};
|
|
15632
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions
|
|
15633
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-scrollbar
|
|
15634
|
+
// export const webkitExtensions = new Set([
|
|
15635
|
+
// "-webkit-app-region",
|
|
15636
|
+
// "-webkit-border-horizontal-spacing",
|
|
15637
|
+
// "-webkit-border-vertical-spacing",
|
|
15638
|
+
// "-webkit-box-reflect",
|
|
15639
|
+
// "-webkit-column-axis",
|
|
15640
|
+
// "-webkit-column-progression",
|
|
15641
|
+
// "-webkit-cursor-visibility",
|
|
15642
|
+
// "-webkit-font-smoothing",
|
|
15643
|
+
// "-webkit-hyphenate-limit-after",
|
|
15644
|
+
// "-webkit-hyphenate-limit-before",
|
|
15645
|
+
// "-webkit-hyphenate-limit-lines",
|
|
15646
|
+
// "-webkit-line-align",
|
|
15647
|
+
// "-webkit-line-box-contain",
|
|
15648
|
+
// "-webkit-line-clamp",
|
|
15649
|
+
// "-webkit-line-grid",
|
|
15650
|
+
// "-webkit-line-snap",
|
|
15651
|
+
// "-webkit-locale",
|
|
15652
|
+
// "-webkit-logical-height",
|
|
15653
|
+
// "-webkit-logical-width",
|
|
15654
|
+
// "-webkit-margin-after",
|
|
15655
|
+
// "-webkit-margin-before",
|
|
15656
|
+
// "-webkit-mask-box-image-outset",
|
|
15657
|
+
// "-webkit-mask-box-image-repeat",
|
|
15658
|
+
// "-webkit-mask-box-image-slice",
|
|
15659
|
+
// "-webkit-mask-box-image-source",
|
|
15660
|
+
// "-webkit-mask-box-image-width",
|
|
15661
|
+
// "-webkit-mask-box-image",
|
|
15662
|
+
// "-webkit-mask-composite",
|
|
15663
|
+
// "-webkit-mask-position-x",
|
|
15664
|
+
// "-webkit-mask-position-y",
|
|
15665
|
+
// "-webkit-mask-repeat-x",
|
|
15666
|
+
// "-webkit-mask-repeat-y",
|
|
15667
|
+
// "-webkit-mask-source-type",
|
|
15668
|
+
// "-webkit-max-logical-height",
|
|
15669
|
+
// "-webkit-max-logical-width",
|
|
15670
|
+
// "-webkit-min-logical-height",
|
|
15671
|
+
// "-webkit-min-logical-width",
|
|
15672
|
+
// "-webkit-nbsp-mode",
|
|
15673
|
+
// "-webkit-match-parent",
|
|
15674
|
+
// "-webkit-perspective-origin-x",
|
|
15675
|
+
// "-webkit-perspective-origin-y",
|
|
15676
|
+
// "-webkit-rtl-ordering",
|
|
15677
|
+
// "-webkit-tap-highlight-color",
|
|
15678
|
+
// "-webkit-text-decoration-skip",
|
|
15679
|
+
// "-webkit-text-decorations-in-effect",
|
|
15680
|
+
// "-webkit-text-fill-color",
|
|
15681
|
+
// "-webkit-text-security",
|
|
15682
|
+
// "-webkit-text-stroke-color",
|
|
15683
|
+
// "-webkit-text-stroke-width",
|
|
15684
|
+
// "-webkit-text-stroke",
|
|
15685
|
+
// "-webkit-text-zoom",
|
|
15686
|
+
// "-webkit-touch-callout",
|
|
15687
|
+
// "-webkit-transform-origin-x",
|
|
15688
|
+
// "-webkit-transform-origin-y",
|
|
15689
|
+
// "-webkit-transform-origin-z",
|
|
15690
|
+
// "-webkit-user-drag",
|
|
15691
|
+
// "-webkit-user-modify",
|
|
15692
|
+
// "-webkit-border-after",
|
|
15693
|
+
// "-webkit-border-after-color",
|
|
15694
|
+
// "-webkit-border-after-style",
|
|
15695
|
+
// "-webkit-border-after-width",
|
|
15696
|
+
// "-webkit-border-before",
|
|
15697
|
+
// "-webkit-border-before-color",
|
|
15698
|
+
// "-webkit-border-before-style",
|
|
15699
|
+
// "-webkit-border-before-width",
|
|
15700
|
+
// "-webkit-border-end",
|
|
15701
|
+
// "-webkit-border-end-color",
|
|
15702
|
+
// "-webkit-border-end-style",
|
|
15703
|
+
// "-webkit-border-end-width",
|
|
15704
|
+
// "-webkit-border-start",
|
|
15705
|
+
// "-webkit-border-start-color",
|
|
15706
|
+
// "-webkit-border-start-style",
|
|
15707
|
+
// "-webkit-border-start-width",
|
|
15708
|
+
// "-webkit-box-align",
|
|
15709
|
+
// "-webkit-box-direction",
|
|
15710
|
+
// "-webkit-box-flex-group",
|
|
15711
|
+
// "-webkit-box-flex",
|
|
15712
|
+
// "-webkit-box-lines",
|
|
15713
|
+
// "-webkit-box-ordinal-group",
|
|
15714
|
+
// "-webkit-box-orient",
|
|
15715
|
+
// "-webkit-box-pack",
|
|
15716
|
+
// "-webkit-column-break-after",
|
|
15717
|
+
// "-webkit-column-break-before",
|
|
15718
|
+
// "-webkit-column-break-inside",
|
|
15719
|
+
// "-webkit-font-feature-settings",
|
|
15720
|
+
// "-webkit-hyphenate-character",
|
|
15721
|
+
// "-webkit-initial-letter",
|
|
15722
|
+
// "-webkit-margin-end",
|
|
15723
|
+
// "-webkit-margin-start",
|
|
15724
|
+
// "-webkit-padding-after",
|
|
15725
|
+
// "-webkit-padding-before",
|
|
15726
|
+
// "-webkit-padding-end",
|
|
15727
|
+
// "-webkit-padding-start",
|
|
15728
|
+
// "-webkit-fill-available",
|
|
15729
|
+
// ":-webkit-animating-full-screen-transition",
|
|
15730
|
+
// ":-webkit-any",
|
|
15731
|
+
// ":-webkit-any-link",
|
|
15732
|
+
// ":-webkit-autofill",
|
|
15733
|
+
// ":-webkit-autofill-strong-password",
|
|
15734
|
+
// ":-webkit-drag",
|
|
15735
|
+
// ":-webkit-full-page-media",
|
|
15736
|
+
// ":-webkit-full-screen*",
|
|
15737
|
+
// ":-webkit-full-screen-ancestor",
|
|
15738
|
+
// ":-webkit-full-screen-document",
|
|
15739
|
+
// ":-webkit-full-screen-controls-hidden",
|
|
15740
|
+
// "::-webkit-file-upload-button*",
|
|
15741
|
+
// "::-webkit-inner-spin-button",
|
|
15742
|
+
// "::-webkit-input-placeholder",
|
|
15743
|
+
// "::-webkit-meter-bar",
|
|
15744
|
+
// "::-webkit-meter-even-less-good-value",
|
|
15745
|
+
// "::-webkit-meter-inner-element",
|
|
15746
|
+
// "::-webkit-meter-optimum-value",
|
|
15747
|
+
// "::-webkit-meter-suboptimum-value",
|
|
15748
|
+
// "::-webkit-progress-bar",
|
|
15749
|
+
// "::-webkit-progress-inner-element",
|
|
15750
|
+
// "::-webkit-progress-value",
|
|
15751
|
+
// "::-webkit-search-cancel-button",
|
|
15752
|
+
// "::-webkit-search-results-button",
|
|
15753
|
+
// "::-webkit-slider-runnable-track",
|
|
15754
|
+
// "::-webkit-slider-thumb",
|
|
15755
|
+
// "-webkit-animation",
|
|
15756
|
+
// "-webkit-device-pixel-ratio",
|
|
15757
|
+
// "-webkit-transform-2d",
|
|
15758
|
+
// "-webkit-transform-3d",
|
|
15759
|
+
// "-webkit-transition",
|
|
15760
|
+
// "::-webkit-scrollbar",
|
|
15761
|
+
// "::-webkit-scrollbar-button",
|
|
15762
|
+
// "::-webkit-scrollbar",
|
|
15763
|
+
// "::-webkit-scrollbar-thumb",
|
|
15764
|
+
// "::-webkit-scrollbar-track",
|
|
15765
|
+
// "::-webkit-scrollbar-track-piece",
|
|
15766
|
+
// "::-webkit-scrollbar:vertical",
|
|
15767
|
+
// "::-webkit-scrollbar-corner ",
|
|
15768
|
+
// "::-webkit-resizer",
|
|
15769
|
+
// ":vertical",
|
|
15770
|
+
// ":horizontal",
|
|
15771
|
+
// ]);
|
|
15772
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions
|
|
15773
|
+
// export const mozExtensions = new Set([
|
|
15774
|
+
// "-moz-box-align",
|
|
15775
|
+
// "-moz-box-direction",
|
|
15776
|
+
// "-moz-box-flex",
|
|
15777
|
+
// "-moz-box-ordinal-group",
|
|
15778
|
+
// "-moz-box-orient",
|
|
15779
|
+
// "-moz-box-pack",
|
|
15780
|
+
// "-moz-float-edge",
|
|
15781
|
+
// "-moz-force-broken-image-icon",
|
|
15782
|
+
// "-moz-image-region",
|
|
15783
|
+
// "-moz-orient",
|
|
15784
|
+
// "-moz-osx-font-smoothing",
|
|
15785
|
+
// "-moz-user-focus",
|
|
15786
|
+
// "-moz-user-input",
|
|
15787
|
+
// "-moz-user-modify",
|
|
15788
|
+
// "-moz-animation",
|
|
15789
|
+
// "-moz-animation-delay",
|
|
15790
|
+
// "-moz-animation-direction",
|
|
15791
|
+
// "-moz-animation-duration",
|
|
15792
|
+
// "-moz-animation-fill-mode",
|
|
15793
|
+
// "-moz-animation-iteration-count",
|
|
15794
|
+
// "-moz-animation-name",
|
|
15795
|
+
// "-moz-animation-play-state",
|
|
15796
|
+
// "-moz-animation-timing-function",
|
|
15797
|
+
// "-moz-appearance",
|
|
15798
|
+
// "-moz-backface-visibility",
|
|
15799
|
+
// "-moz-background-clip",
|
|
15800
|
+
// "-moz-background-origin",
|
|
15801
|
+
// "-moz-background-inline-policy",
|
|
15802
|
+
// "-moz-background-size",
|
|
15803
|
+
// "-moz-border-end",
|
|
15804
|
+
// "-moz-border-end-color",
|
|
15805
|
+
// "-moz-border-end-style",
|
|
15806
|
+
// "-moz-border-end-width",
|
|
15807
|
+
// "-moz-border-image",
|
|
15808
|
+
// "-moz-border-start",
|
|
15809
|
+
// "-moz-border-start-color",
|
|
15810
|
+
// "-moz-border-start-style",
|
|
15811
|
+
// "-moz-border-start-width",
|
|
15812
|
+
// "-moz-box-sizing",
|
|
15813
|
+
// "clip-path",
|
|
15814
|
+
// "-moz-column-count",
|
|
15815
|
+
// "-moz-column-fill",
|
|
15816
|
+
// "-moz-column-gap",
|
|
15817
|
+
// "-moz-column-width",
|
|
15818
|
+
// "-moz-column-rule",
|
|
15819
|
+
// "-moz-column-rule-width",
|
|
15820
|
+
// "-moz-column-rule-style",
|
|
15821
|
+
// "-moz-column-rule-color",
|
|
15822
|
+
// "filter",
|
|
15823
|
+
// "-moz-font-feature-settings",
|
|
15824
|
+
// "-moz-font-language-override",
|
|
15825
|
+
// "-moz-hyphens",
|
|
15826
|
+
// "-moz-margin-end",
|
|
15827
|
+
// "-moz-margin-start",
|
|
15828
|
+
// "mask",
|
|
15829
|
+
// "-moz-opacity",
|
|
15830
|
+
// "-moz-outline",
|
|
15831
|
+
// "-moz-outline-color",
|
|
15832
|
+
// "-moz-outline-offset",
|
|
15833
|
+
// "-moz-outline-style",
|
|
15834
|
+
// "-moz-outline-width",
|
|
15835
|
+
// "-moz-padding-end",
|
|
15836
|
+
// "-moz-padding-start",
|
|
15837
|
+
// "-moz-perspective",
|
|
15838
|
+
// "-moz-perspective-origin",
|
|
15839
|
+
// "pointer-events",
|
|
15840
|
+
// "-moz-tab-size",
|
|
15841
|
+
// "-moz-text-align-last",
|
|
15842
|
+
// "-moz-text-decoration-color",
|
|
15843
|
+
// "-moz-text-decoration-line",
|
|
15844
|
+
// "-moz-text-decoration-style",
|
|
15845
|
+
// "-moz-text-size-adjust",
|
|
15846
|
+
// "-moz-transform",
|
|
15847
|
+
// "-moz-transform-origin",
|
|
15848
|
+
// "-moz-transform-style",
|
|
15849
|
+
// "-moz-transition",
|
|
15850
|
+
// "-moz-transition-delay",
|
|
15851
|
+
// "-moz-transition-duration",
|
|
15852
|
+
// "-moz-transition-property",
|
|
15853
|
+
// "-moz-transition-timing-function",
|
|
15854
|
+
// "-moz-user-select",
|
|
15855
|
+
// "-moz-initial",
|
|
15856
|
+
// "-moz-appearance",
|
|
15857
|
+
// "-moz-linear-gradient",
|
|
15858
|
+
// "-moz-radial-gradient",
|
|
15859
|
+
// "-moz-element",
|
|
15860
|
+
// "-moz-image-rect",
|
|
15861
|
+
// "::-moz-anonymous-block",
|
|
15862
|
+
// "::-moz-anonymous-positioned-block",
|
|
15863
|
+
// ":-moz-any",
|
|
15864
|
+
// ":-moz-any-link",
|
|
15865
|
+
// ":-moz-broken",
|
|
15866
|
+
// "::-moz-canvas",
|
|
15867
|
+
// "::-moz-color-swatch",
|
|
15868
|
+
// "::-moz-cell-content",
|
|
15869
|
+
// ":-moz-drag-over",
|
|
15870
|
+
// ":-moz-first-node",
|
|
15871
|
+
// "::-moz-focus-inner",
|
|
15872
|
+
// "::-moz-focus-outer",
|
|
15873
|
+
// ":-moz-full-screen",
|
|
15874
|
+
// ":-moz-full-screen-ancestor",
|
|
15875
|
+
// ":-moz-handler-blocked",
|
|
15876
|
+
// ":-moz-handler-crashed",
|
|
15877
|
+
// ":-moz-handler-disabled",
|
|
15878
|
+
// "::-moz-inline-table",
|
|
15879
|
+
// ":-moz-last-node",
|
|
15880
|
+
// "::-moz-list-bullet",
|
|
15881
|
+
// "::-moz-list-number",
|
|
15882
|
+
// ":-moz-loading",
|
|
15883
|
+
// ":-moz-locale-dir",
|
|
15884
|
+
// ":-moz-locale-dir",
|
|
15885
|
+
// ":-moz-lwtheme",
|
|
15886
|
+
// ":-moz-lwtheme-brighttext",
|
|
15887
|
+
// ":-moz-lwtheme-darktext",
|
|
15888
|
+
// "::-moz-meter-bar",
|
|
15889
|
+
// ":-moz-native-anonymous",
|
|
15890
|
+
// ":-moz-only-whitespace",
|
|
15891
|
+
// "::-moz-pagebreak",
|
|
15892
|
+
// "::-moz-pagecontent",
|
|
15893
|
+
// ":-moz-placeholder",
|
|
15894
|
+
// "::-moz-placeholder",
|
|
15895
|
+
// "::-moz-progress-bar",
|
|
15896
|
+
// "::-moz-range-progress",
|
|
15897
|
+
// "::-moz-range-thumb",
|
|
15898
|
+
// "::-moz-range-track",
|
|
15899
|
+
// ":-moz-read-only",
|
|
15900
|
+
// ":-moz-read-write",
|
|
15901
|
+
// "::-moz-scrolled-canvas",
|
|
15902
|
+
// "::-moz-scrolled-content",
|
|
15903
|
+
// "::-moz-selection",
|
|
15904
|
+
// ":-moz-submit-invalid",
|
|
15905
|
+
// ":-moz-suppressed",
|
|
15906
|
+
// "::-moz-svg-foreign-content",
|
|
15907
|
+
// "::-moz-table",
|
|
15908
|
+
// "::-moz-table-cell",
|
|
15909
|
+
// "::-moz-table-column",
|
|
15910
|
+
// "::-moz-table-column-group",
|
|
15911
|
+
// "::-moz-table-outer",
|
|
15912
|
+
// "::-moz-table-row",
|
|
15913
|
+
// "::-moz-table-row-group",
|
|
15914
|
+
// ":-moz-ui-invalid",
|
|
15915
|
+
// ":-moz-ui-valid",
|
|
15916
|
+
// ":-moz-user-disabled",
|
|
15917
|
+
// "::-moz-viewport",
|
|
15918
|
+
// "::-moz-viewport-scroll",
|
|
15919
|
+
// ":-moz-window-inactive",
|
|
15920
|
+
// "-moz-device-pixel-ratio",
|
|
15921
|
+
// "-moz-os-version",
|
|
15922
|
+
// "-moz-touch-enabled",
|
|
15923
|
+
// "-moz-windows-glass",
|
|
15924
|
+
// "-moz-alt-content",
|
|
15925
|
+
// ]);
|
|
15422
15926
|
// renamed standard properties
|
|
15423
15927
|
const renamedStandardProperties = new Map([["color-adjust", "print-color-adjust"]]);
|
|
15424
15928
|
function isLength(dimension) {
|
|
@@ -15437,8 +15941,36 @@
|
|
|
15437
15941
|
return "unit" in dimension && frequencyUnits.includes(dimension.unit.toLowerCase());
|
|
15438
15942
|
}
|
|
15439
15943
|
/**
|
|
15440
|
-
*
|
|
15441
|
-
* @param
|
|
15944
|
+
* Is color space
|
|
15945
|
+
* @param token
|
|
15946
|
+
* @returns
|
|
15947
|
+
*/
|
|
15948
|
+
// export function isColorspace(token: Token): boolean {
|
|
15949
|
+
// return (
|
|
15950
|
+
// token.typ === EnumToken.IdenTokenType &&
|
|
15951
|
+
// [
|
|
15952
|
+
// "srgb",
|
|
15953
|
+
// "srgb-linear",
|
|
15954
|
+
// "lab",
|
|
15955
|
+
// "oklab",
|
|
15956
|
+
// "lch",
|
|
15957
|
+
// "oklch",
|
|
15958
|
+
// "xyz",
|
|
15959
|
+
// "xyz-d50",
|
|
15960
|
+
// "xyz-d65",
|
|
15961
|
+
// "display-p3",
|
|
15962
|
+
// "a98-rgb",
|
|
15963
|
+
// "prophoto-rgb",
|
|
15964
|
+
// "rec2020",
|
|
15965
|
+
// "rgb",
|
|
15966
|
+
// "hsl",
|
|
15967
|
+
// "hwb",
|
|
15968
|
+
// ].includes((token as IdentToken).val.toLowerCase())
|
|
15969
|
+
// );
|
|
15970
|
+
// }
|
|
15971
|
+
/**
|
|
15972
|
+
* Reduce color stops
|
|
15973
|
+
* @param stops
|
|
15442
15974
|
* @returns
|
|
15443
15975
|
*/
|
|
15444
15976
|
function reduceColorStops(stops) {
|
|
@@ -15633,6 +16165,26 @@
|
|
|
15633
16165
|
return (token.typ === exports.EnumToken.IdenTokenType &&
|
|
15634
16166
|
["hsl", "hwb", "lch", "oklch"].some((t) => equalsIgnoreCase(t, token.val)));
|
|
15635
16167
|
}
|
|
16168
|
+
/**
|
|
16169
|
+
* Is hue interpolation method
|
|
16170
|
+
* @param token
|
|
16171
|
+
* @returns
|
|
16172
|
+
*/
|
|
16173
|
+
// export function isHueInterpolationMethod(token: Token | Token[]): boolean {
|
|
16174
|
+
// if (!Array.isArray(token)) {
|
|
16175
|
+
// return token.typ == EnumToken.IdenTokenType && "hue" === (token as IdentToken).val?.toLowerCase?.();
|
|
16176
|
+
// }
|
|
16177
|
+
//
|
|
16178
|
+
// if (token.length != 2 || token[0].typ != EnumToken.IdenTokenType || token[1].typ != EnumToken.IdenTokenType) {
|
|
16179
|
+
// return false;
|
|
16180
|
+
// }
|
|
16181
|
+
//
|
|
16182
|
+
// return (
|
|
16183
|
+
// ["shorter", "longer", "increasing", "decreasing"].some((t) =>
|
|
16184
|
+
// equalsIgnoreCase(t, (token[0] as IdentToken).val ?? ""),
|
|
16185
|
+
// ) && "hue" === (token[1] as IdentToken).val?.toLowerCase?.()
|
|
16186
|
+
// );
|
|
16187
|
+
// }
|
|
15636
16188
|
/**
|
|
15637
16189
|
* Is ident color
|
|
15638
16190
|
* @param token
|
|
@@ -15643,6 +16195,12 @@
|
|
|
15643
16195
|
[exports.ColorType.SYS, exports.ColorType.DPSYS, exports.ColorType.LIT].includes(token.kin) &&
|
|
15644
16196
|
isIdent(token.val));
|
|
15645
16197
|
}
|
|
16198
|
+
// export function isPercentageToken(token: Token): boolean {
|
|
16199
|
+
// return (
|
|
16200
|
+
// token.typ == EnumToken.PercentageTokenType ||
|
|
16201
|
+
// (token.typ == EnumToken.NumberTokenType && (token as NumberToken).val == 0)
|
|
16202
|
+
// );
|
|
16203
|
+
// }
|
|
15646
16204
|
function isColor(token, errors) {
|
|
15647
16205
|
if (token.typ == exports.EnumToken.WildCardFunctionTokenType) {
|
|
15648
16206
|
return true;
|
|
@@ -15906,21 +16464,33 @@
|
|
|
15906
16464
|
return true;
|
|
15907
16465
|
}
|
|
15908
16466
|
else {
|
|
15909
|
-
//
|
|
15910
|
-
|
|
15911
|
-
|
|
15912
|
-
|
|
15913
|
-
|
|
16467
|
+
// const keywords: string[] = ["from", "none"];
|
|
16468
|
+
//
|
|
16469
|
+
// // @ts-ignore
|
|
16470
|
+
// if (
|
|
16471
|
+
// ["rgb", "hsl", "hwb", "lab", "lch", "oklab", "oklch"].some((t) =>
|
|
16472
|
+
// equalsIgnoreCase(t, (token as ColorToken).val),
|
|
16473
|
+
// )
|
|
16474
|
+
// ) {
|
|
16475
|
+
// // @ts-ignore
|
|
16476
|
+
// keywords.push("alpha");
|
|
16477
|
+
//
|
|
16478
|
+
// for (const keyword of (token as ColorToken).val.slice(-3).split("")) {
|
|
16479
|
+
// keywords.push(keyword);
|
|
16480
|
+
// }
|
|
16481
|
+
// }
|
|
15914
16482
|
// @ts-ignore
|
|
15915
16483
|
for (const v of token.chi) {
|
|
15916
|
-
if (v.typ ==
|
|
15917
|
-
|
|
15918
|
-
}
|
|
15919
|
-
if (
|
|
15920
|
-
|
|
15921
|
-
|
|
15922
|
-
|
|
15923
|
-
|
|
16484
|
+
// if (v.typ == EnumToken.IdenTokenType) {
|
|
16485
|
+
// continue;
|
|
16486
|
+
// }
|
|
16487
|
+
// if (
|
|
16488
|
+
// v.typ === EnumToken.MathFunctionTokenType ||
|
|
16489
|
+
// v.typ === EnumToken.WildCardFunctionTokenType ||
|
|
16490
|
+
// colorsFunc.includes(v.val)
|
|
16491
|
+
// ) {
|
|
16492
|
+
// continue;
|
|
16493
|
+
// }
|
|
15924
16494
|
}
|
|
15925
16495
|
}
|
|
15926
16496
|
return true;
|
|
@@ -16066,6 +16636,44 @@
|
|
|
16066
16636
|
codepoint == 0x7f ||
|
|
16067
16637
|
(codepoint >= 0xe && codepoint <= 0x1f));
|
|
16068
16638
|
}
|
|
16639
|
+
// export function isURLToken(str: string): boolean {
|
|
16640
|
+
// let i: number = -1;
|
|
16641
|
+
// let c: number;
|
|
16642
|
+
//
|
|
16643
|
+
// while (++i < str.length) {
|
|
16644
|
+
// c = str.charCodeAt(i) as number;
|
|
16645
|
+
//
|
|
16646
|
+
// // single quote or double quote or start parenthesis or close parenthesis
|
|
16647
|
+
// if (isNonPrintable(c) || c == 0x27 || c == 0x22 || c == 0x28 || c == 0x29) {
|
|
16648
|
+
// return false;
|
|
16649
|
+
// }
|
|
16650
|
+
//
|
|
16651
|
+
// // valid escape
|
|
16652
|
+
// if (c == REVERSE_SOLIDUS) {
|
|
16653
|
+
// i++;
|
|
16654
|
+
//
|
|
16655
|
+
// if (i >= str.length) {
|
|
16656
|
+
// return false;
|
|
16657
|
+
// }
|
|
16658
|
+
//
|
|
16659
|
+
// c = str.charCodeAt(i) as number;
|
|
16660
|
+
//
|
|
16661
|
+
// // c is not '\n' or '\r' or '\f'
|
|
16662
|
+
// if (c == 0x6e || c == 0x72 || c == 0x66) {
|
|
16663
|
+
// return false;
|
|
16664
|
+
// }
|
|
16665
|
+
//
|
|
16666
|
+
// continue;
|
|
16667
|
+
// }
|
|
16668
|
+
//
|
|
16669
|
+
// // is white space
|
|
16670
|
+
// if (c == 0x20 || c == 0x09) {
|
|
16671
|
+
// break;
|
|
16672
|
+
// }
|
|
16673
|
+
// }
|
|
16674
|
+
//
|
|
16675
|
+
// return i == str.length;
|
|
16676
|
+
// }
|
|
16069
16677
|
function isPseudo(name) {
|
|
16070
16678
|
return (name.charAt(0) == ":" &&
|
|
16071
16679
|
((name.endsWith("(") && isIdent(name.charAt(1) == ":" ? name.slice(2, -1) : name.slice(1, -1))) ||
|
|
@@ -16074,6 +16682,94 @@
|
|
|
16074
16682
|
function isHash(name) {
|
|
16075
16683
|
return name.charAt(0) == "#" && isIdentStart(name.charCodeAt(1));
|
|
16076
16684
|
}
|
|
16685
|
+
// export const isNumber = memoize(function (name: string): boolean {
|
|
16686
|
+
// let codepoint: number = name.charCodeAt(0) as number;
|
|
16687
|
+
// let i: number = 0;
|
|
16688
|
+
// const j: number = name.length;
|
|
16689
|
+
//
|
|
16690
|
+
// if (j == 1 && !isDigit(codepoint)) {
|
|
16691
|
+
// return false;
|
|
16692
|
+
// }
|
|
16693
|
+
//
|
|
16694
|
+
// // '+' '-'
|
|
16695
|
+
// if ([0x2b, 0x2d].includes(codepoint)) {
|
|
16696
|
+
// i++;
|
|
16697
|
+
// }
|
|
16698
|
+
//
|
|
16699
|
+
// // consume digits
|
|
16700
|
+
// while (i < j) {
|
|
16701
|
+
// codepoint = name.charCodeAt(i) as number;
|
|
16702
|
+
//
|
|
16703
|
+
// if (isDigit(codepoint)) {
|
|
16704
|
+
// i++;
|
|
16705
|
+
// continue;
|
|
16706
|
+
// }
|
|
16707
|
+
//
|
|
16708
|
+
// // '.' 'E' 'e'
|
|
16709
|
+
// if (codepoint == 0x2e || codepoint == 0x45 || codepoint == 0x65) {
|
|
16710
|
+
// break;
|
|
16711
|
+
// }
|
|
16712
|
+
//
|
|
16713
|
+
// return false;
|
|
16714
|
+
// }
|
|
16715
|
+
//
|
|
16716
|
+
// // '.'
|
|
16717
|
+
// if (codepoint == 0x2e) {
|
|
16718
|
+
// if (!isDigit(name.charCodeAt(++i) as number)) {
|
|
16719
|
+
// return false;
|
|
16720
|
+
// }
|
|
16721
|
+
// }
|
|
16722
|
+
//
|
|
16723
|
+
// while (i < j) {
|
|
16724
|
+
// codepoint = name.charCodeAt(i) as number;
|
|
16725
|
+
//
|
|
16726
|
+
// if (isDigit(codepoint)) {
|
|
16727
|
+
// i++;
|
|
16728
|
+
// continue;
|
|
16729
|
+
// }
|
|
16730
|
+
//
|
|
16731
|
+
// // 'E' 'e'
|
|
16732
|
+
// if (codepoint == 0x45 || codepoint == 0x65) {
|
|
16733
|
+
// i++;
|
|
16734
|
+
// break;
|
|
16735
|
+
// }
|
|
16736
|
+
//
|
|
16737
|
+
// return false;
|
|
16738
|
+
// }
|
|
16739
|
+
//
|
|
16740
|
+
// // 'E' 'e'
|
|
16741
|
+
// if (codepoint == 0x45 || codepoint == 0x65) {
|
|
16742
|
+
// // if (i == j) {
|
|
16743
|
+
// // return false;
|
|
16744
|
+
// // }
|
|
16745
|
+
//
|
|
16746
|
+
// codepoint = name.charCodeAt(i + 1) as number;
|
|
16747
|
+
//
|
|
16748
|
+
// // '+' '-'
|
|
16749
|
+
// // if ([0x2b, 0x2d].includes(codepoint)) {
|
|
16750
|
+
// // i++;
|
|
16751
|
+
// // }
|
|
16752
|
+
//
|
|
16753
|
+
// codepoint = name.charCodeAt(i + 1) as number;
|
|
16754
|
+
//
|
|
16755
|
+
// if (!isDigit(codepoint)) {
|
|
16756
|
+
// return false;
|
|
16757
|
+
// }
|
|
16758
|
+
// }
|
|
16759
|
+
//
|
|
16760
|
+
// // while (++i < j) {
|
|
16761
|
+
// // codepoint = name.charCodeAt(i) as number;
|
|
16762
|
+
//
|
|
16763
|
+
// // if (!isDigit(codepoint)) {
|
|
16764
|
+
// // return false;
|
|
16765
|
+
// // }
|
|
16766
|
+
// // }
|
|
16767
|
+
//
|
|
16768
|
+
// return true;
|
|
16769
|
+
// }) as (name: string) => boolean;
|
|
16770
|
+
// export function isPercentage(name: string) {
|
|
16771
|
+
// return name.endsWith("%") && isNumber(name.slice(0, -1));
|
|
16772
|
+
// }
|
|
16077
16773
|
function isFlex(dimension) {
|
|
16078
16774
|
return "unit" in dimension && "fr" == dimension.unit.toLowerCase();
|
|
16079
16775
|
}
|
|
@@ -16128,9 +16824,33 @@
|
|
|
16128
16824
|
}
|
|
16129
16825
|
return dimension;
|
|
16130
16826
|
}
|
|
16827
|
+
// export function isHexColor(name: string): boolean {
|
|
16828
|
+
// if (name.charAt(0) != "#" || ![4, 5, 7, 9].includes(name.length)) {
|
|
16829
|
+
// return false;
|
|
16830
|
+
// }
|
|
16831
|
+
//
|
|
16832
|
+
// for (let chr of name.slice(1)) {
|
|
16833
|
+
// let codepoint: number = chr.charCodeAt(0) as number;
|
|
16834
|
+
//
|
|
16835
|
+
// if (
|
|
16836
|
+
// !isDigit(codepoint) &&
|
|
16837
|
+
// // A-F
|
|
16838
|
+
// !(codepoint >= 0x41 && codepoint <= 0x46) &&
|
|
16839
|
+
// // a-f
|
|
16840
|
+
// !(codepoint >= 0x61 && codepoint <= 0x66)
|
|
16841
|
+
// ) {
|
|
16842
|
+
// return false;
|
|
16843
|
+
// }
|
|
16844
|
+
// }
|
|
16845
|
+
//
|
|
16846
|
+
// return true;
|
|
16847
|
+
// }
|
|
16131
16848
|
function isFunction(name) {
|
|
16132
16849
|
return name.endsWith("(") && isIdent(name.slice(0, -1));
|
|
16133
16850
|
}
|
|
16851
|
+
// export function isAtKeyword(name: string): boolean {
|
|
16852
|
+
// return name.charCodeAt(0) == 0x40 && isIdent(name.slice(1));
|
|
16853
|
+
// }
|
|
16134
16854
|
function isNewLine(codepoint) {
|
|
16135
16855
|
// \n \r \f \v
|
|
16136
16856
|
return (codepoint == 0xa ||
|
|
@@ -16151,6 +16871,32 @@
|
|
|
16151
16871
|
codepoint == 0x2028 ||
|
|
16152
16872
|
codepoint == 0x2029);
|
|
16153
16873
|
}
|
|
16874
|
+
// export function isValue(token: Token) {
|
|
16875
|
+
// if (token == null) {
|
|
16876
|
+
// return false;
|
|
16877
|
+
// }
|
|
16878
|
+
//
|
|
16879
|
+
// return (
|
|
16880
|
+
// token.typ === EnumToken.IdenTokenType ||
|
|
16881
|
+
// token.typ === EnumToken.DimensionTokenType ||
|
|
16882
|
+
// token.typ === EnumToken.LengthTokenType ||
|
|
16883
|
+
// token.typ === EnumToken.AngleTokenType ||
|
|
16884
|
+
// token.typ === EnumToken.FlexTokenType ||
|
|
16885
|
+
// token.typ === EnumToken.TimeTokenType ||
|
|
16886
|
+
// token.typ === EnumToken.ResolutionTokenType ||
|
|
16887
|
+
// token.typ === EnumToken.FrequencyTokenType ||
|
|
16888
|
+
// token.typ === EnumToken.NumberTokenType ||
|
|
16889
|
+
// token.typ === EnumToken.ColorTokenType ||
|
|
16890
|
+
// token.typ === EnumToken.FunctionTokenType ||
|
|
16891
|
+
// token.typ === EnumToken.UrlFunctionTokenType ||
|
|
16892
|
+
// token.typ === EnumToken.GridTemplateFuncTokenType ||
|
|
16893
|
+
// token.typ === EnumToken.ImageFunctionTokenType ||
|
|
16894
|
+
// token.typ === EnumToken.TimelineFunctionTokenType ||
|
|
16895
|
+
// token.typ === EnumToken.TimingFunctionTokenType ||
|
|
16896
|
+
// token.typ === EnumToken.MathFunctionTokenType ||
|
|
16897
|
+
// token.typ === EnumToken.TransformFunctionTokenType
|
|
16898
|
+
// );
|
|
16899
|
+
// }
|
|
16154
16900
|
// https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Values_and_units#absolute_length_units
|
|
16155
16901
|
/**
|
|
16156
16902
|
* Convert length to px
|
|
@@ -16233,6 +16979,12 @@
|
|
|
16233
16979
|
return angle;
|
|
16234
16980
|
}
|
|
16235
16981
|
|
|
16982
|
+
/**
|
|
16983
|
+
*
|
|
16984
|
+
* @param a
|
|
16985
|
+
* @param b
|
|
16986
|
+
* @returns
|
|
16987
|
+
*/
|
|
16236
16988
|
function eq(a, b) {
|
|
16237
16989
|
if (a == null || b == null) {
|
|
16238
16990
|
return a == b;
|
|
@@ -16312,7 +17064,6 @@
|
|
|
16312
17064
|
token.val = pseudoAliasMap[token.val];
|
|
16313
17065
|
if ((equalsIgnoreCase(token.val, "min-resolution") ||
|
|
16314
17066
|
equalsIgnoreCase(token.val, "max-resolution")) &&
|
|
16315
|
-
// ["min-resolution", "max-resolution"].includes((token as IdentToken).val) &&
|
|
16316
17067
|
value.r?.[0]?.typ == exports.EnumToken.NumberTokenType) {
|
|
16317
17068
|
Object.assign(value.r?.[0], {
|
|
16318
17069
|
typ: exports.EnumToken.ResolutionTokenType,
|
|
@@ -16320,6 +17071,14 @@
|
|
|
16320
17071
|
});
|
|
16321
17072
|
result = true;
|
|
16322
17073
|
}
|
|
17074
|
+
let isMin = token.val.startsWith("min-");
|
|
17075
|
+
let isMax = token.val.startsWith("max-");
|
|
17076
|
+
if (isMin || isMax) {
|
|
17077
|
+
token.val = token.val.slice(4);
|
|
17078
|
+
value.op.typ = isMax
|
|
17079
|
+
? exports.EnumToken.LteTokenType
|
|
17080
|
+
: exports.EnumToken.GteTokenType;
|
|
17081
|
+
}
|
|
16323
17082
|
}
|
|
16324
17083
|
}
|
|
16325
17084
|
}
|
|
@@ -16352,6 +17111,7 @@
|
|
|
16352
17111
|
}
|
|
16353
17112
|
}
|
|
16354
17113
|
}
|
|
17114
|
+
// remove duplicate tokens
|
|
16355
17115
|
if (tokens.find((t) => t.typ == exports.EnumToken.CommaTokenType) != null) {
|
|
16356
17116
|
const set = new Set();
|
|
16357
17117
|
const split = splitTokenList(tokens, [exports.EnumToken.CommaTokenType]);
|
|
@@ -17212,6 +17972,65 @@
|
|
|
17212
17972
|
"padding-left": {
|
|
17213
17973
|
shorthand: "padding"
|
|
17214
17974
|
},
|
|
17975
|
+
"scroll-margin": {
|
|
17976
|
+
shorthand: "scroll-margin",
|
|
17977
|
+
properties: [
|
|
17978
|
+
"scroll-margin-top",
|
|
17979
|
+
"scroll-margin-right",
|
|
17980
|
+
"scroll-margin-bottom",
|
|
17981
|
+
"scroll-margin-left"
|
|
17982
|
+
],
|
|
17983
|
+
types: [
|
|
17984
|
+
"Length",
|
|
17985
|
+
"Perc"
|
|
17986
|
+
],
|
|
17987
|
+
"default": [
|
|
17988
|
+
"0"
|
|
17989
|
+
],
|
|
17990
|
+
keywords: [
|
|
17991
|
+
"auto"
|
|
17992
|
+
]
|
|
17993
|
+
},
|
|
17994
|
+
"scroll-margin-top": {
|
|
17995
|
+
shorthand: "scroll-margin"
|
|
17996
|
+
},
|
|
17997
|
+
"scroll-margin-right": {
|
|
17998
|
+
shorthand: "scroll-margin"
|
|
17999
|
+
},
|
|
18000
|
+
"scroll-margin-bottom": {
|
|
18001
|
+
shorthand: "scroll-margin"
|
|
18002
|
+
},
|
|
18003
|
+
"scroll-margin-left": {
|
|
18004
|
+
shorthand: "scroll-margin"
|
|
18005
|
+
},
|
|
18006
|
+
"scroll-padding": {
|
|
18007
|
+
shorthand: "scroll-padding",
|
|
18008
|
+
properties: [
|
|
18009
|
+
"scroll-padding-top",
|
|
18010
|
+
"scroll-padding-right",
|
|
18011
|
+
"scroll-padding-bottom",
|
|
18012
|
+
"scroll-padding-left"
|
|
18013
|
+
],
|
|
18014
|
+
types: [
|
|
18015
|
+
"Length",
|
|
18016
|
+
"Perc"
|
|
18017
|
+
],
|
|
18018
|
+
keywords: [
|
|
18019
|
+
"auto"
|
|
18020
|
+
]
|
|
18021
|
+
},
|
|
18022
|
+
"scroll-padding-top": {
|
|
18023
|
+
shorthand: "scroll-padding"
|
|
18024
|
+
},
|
|
18025
|
+
"scroll-padding-right": {
|
|
18026
|
+
shorthand: "scroll-padding"
|
|
18027
|
+
},
|
|
18028
|
+
"scroll-padding-bottom": {
|
|
18029
|
+
shorthand: "scroll-padding"
|
|
18030
|
+
},
|
|
18031
|
+
"scroll-padding-left": {
|
|
18032
|
+
shorthand: "scroll-padding"
|
|
18033
|
+
},
|
|
17215
18034
|
"border-radius": {
|
|
17216
18035
|
shorthand: "border-radius",
|
|
17217
18036
|
properties: [
|
|
@@ -17433,6 +18252,53 @@
|
|
|
17433
18252
|
"flex-wrap": {
|
|
17434
18253
|
shorthand: "flex-flow"
|
|
17435
18254
|
},
|
|
18255
|
+
"scroll-timeline": {
|
|
18256
|
+
shorthand: "scroll-timeline",
|
|
18257
|
+
pattern: "scroll-timeline-name scroll-timeline-axis",
|
|
18258
|
+
keywords: [
|
|
18259
|
+
"none",
|
|
18260
|
+
"block",
|
|
18261
|
+
"inline",
|
|
18262
|
+
"x",
|
|
18263
|
+
"y"
|
|
18264
|
+
],
|
|
18265
|
+
"default": [
|
|
18266
|
+
"none",
|
|
18267
|
+
"block"
|
|
18268
|
+
],
|
|
18269
|
+
properties: {
|
|
18270
|
+
"scroll-timeline-name": {
|
|
18271
|
+
keywords: [
|
|
18272
|
+
"none"
|
|
18273
|
+
],
|
|
18274
|
+
"default": [
|
|
18275
|
+
"none"
|
|
18276
|
+
],
|
|
18277
|
+
types: [
|
|
18278
|
+
"DashedIden"
|
|
18279
|
+
]
|
|
18280
|
+
},
|
|
18281
|
+
"scroll-timeline-axis": {
|
|
18282
|
+
keywords: [
|
|
18283
|
+
"block",
|
|
18284
|
+
"inline",
|
|
18285
|
+
"x",
|
|
18286
|
+
"y"
|
|
18287
|
+
],
|
|
18288
|
+
"default": [
|
|
18289
|
+
"block"
|
|
18290
|
+
],
|
|
18291
|
+
types: [
|
|
18292
|
+
]
|
|
18293
|
+
}
|
|
18294
|
+
}
|
|
18295
|
+
},
|
|
18296
|
+
"scroll-timeline-name": {
|
|
18297
|
+
shorthand: "scroll-timeline"
|
|
18298
|
+
},
|
|
18299
|
+
"scroll-timeline-axis": {
|
|
18300
|
+
shorthand: "scroll-timeline"
|
|
18301
|
+
},
|
|
17436
18302
|
container: {
|
|
17437
18303
|
shorthand: "container",
|
|
17438
18304
|
pattern: "container-name container-type",
|
|
@@ -19451,6 +20317,7 @@
|
|
|
19451
20317
|
/**
|
|
19452
20318
|
* convert input to hex
|
|
19453
20319
|
* @param input
|
|
20320
|
+
* @param length
|
|
19454
20321
|
*/
|
|
19455
20322
|
function toHex(input, length) {
|
|
19456
20323
|
let result = "";
|
|
@@ -19526,18 +20393,17 @@
|
|
|
19526
20393
|
class PropertyList {
|
|
19527
20394
|
options = { removeDuplicateDeclarations: true, computeShorthand: true };
|
|
19528
20395
|
declarations;
|
|
19529
|
-
// ketsey = new Map;
|
|
19530
20396
|
constructor(options = {}) {
|
|
19531
20397
|
this.options = options;
|
|
19532
20398
|
this.declarations = new Map();
|
|
19533
20399
|
}
|
|
19534
|
-
set(nam, value) {
|
|
19535
|
-
|
|
19536
|
-
|
|
19537
|
-
|
|
19538
|
-
|
|
19539
|
-
|
|
19540
|
-
}
|
|
20400
|
+
// set(nam: string, value: string | Token[]) {
|
|
20401
|
+
// return this.add({
|
|
20402
|
+
// typ: EnumToken.DeclarationNodeType,
|
|
20403
|
+
// nam,
|
|
20404
|
+
// val: Array.isArray(value) ? value : parseString(String(value)),
|
|
20405
|
+
// });
|
|
20406
|
+
// }
|
|
19541
20407
|
add(...declarations) {
|
|
19542
20408
|
let name;
|
|
19543
20409
|
let syntaxRules = null;
|
|
@@ -19756,7 +20622,7 @@
|
|
|
19756
20622
|
}
|
|
19757
20623
|
}
|
|
19758
20624
|
run(ast, options) {
|
|
19759
|
-
if (!("chi" in ast)) {
|
|
20625
|
+
if (!("chi" in ast || ast.chi?.length == 0)) {
|
|
19760
20626
|
return null;
|
|
19761
20627
|
}
|
|
19762
20628
|
// @ts-ignore
|
|
@@ -19799,6 +20665,104 @@
|
|
|
19799
20665
|
}
|
|
19800
20666
|
}
|
|
19801
20667
|
|
|
20668
|
+
const trimTokenSpace = new Set([
|
|
20669
|
+
exports.EnumToken.CommaTokenType,
|
|
20670
|
+
exports.EnumToken.DelimTokenType,
|
|
20671
|
+
exports.EnumToken.GtTokenType,
|
|
20672
|
+
exports.EnumToken.GteTokenType,
|
|
20673
|
+
exports.EnumToken.LtTokenType,
|
|
20674
|
+
exports.EnumToken.LteTokenType,
|
|
20675
|
+
exports.EnumToken.ChildCombinatorTokenType,
|
|
20676
|
+
]);
|
|
20677
|
+
const trimSpaceAfter = new Set([
|
|
20678
|
+
...tokensfuncSet.values(),
|
|
20679
|
+
exports.EnumToken.ChildCombinatorTokenType,
|
|
20680
|
+
exports.EnumToken.SupportsQueryConditionTokenType,
|
|
20681
|
+
exports.EnumToken.SupportsQueryUnaryConditionTokenType,
|
|
20682
|
+
]);
|
|
20683
|
+
/**
|
|
20684
|
+
* Replace token in its parent node
|
|
20685
|
+
* @param parent
|
|
20686
|
+
* @param node
|
|
20687
|
+
* @param replacement
|
|
20688
|
+
* @throws TypeError replacement is null
|
|
20689
|
+
* @throws ReferenceError node not found in parent
|
|
20690
|
+
*/
|
|
20691
|
+
function replaceNodeOrValue(parent, node, replacement) {
|
|
20692
|
+
if (replacement == null || (Array.isArray(replacement) && replacement.length === 0)) {
|
|
20693
|
+
throw new TypeError(`replacement is null`);
|
|
20694
|
+
}
|
|
20695
|
+
for (const newNode of Array.isArray(replacement) ? replacement : [replacement]) {
|
|
20696
|
+
if (newNode[PARENT] != node[PARENT]) {
|
|
20697
|
+
newNode[PARENT] = node[PARENT];
|
|
20698
|
+
}
|
|
20699
|
+
}
|
|
20700
|
+
if (parent.typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
20701
|
+
if (parent.l == node) {
|
|
20702
|
+
parent.l = replacement;
|
|
20703
|
+
}
|
|
20704
|
+
else if (parent.r == node) {
|
|
20705
|
+
parent.r = replacement;
|
|
20706
|
+
}
|
|
20707
|
+
else {
|
|
20708
|
+
throw new ReferenceError("Node not found");
|
|
20709
|
+
}
|
|
20710
|
+
}
|
|
20711
|
+
else {
|
|
20712
|
+
const target = "val" in parent && Array.isArray(parent.val)
|
|
20713
|
+
? parent.val
|
|
20714
|
+
: (parent.chi ?? parent);
|
|
20715
|
+
if (Array.isArray(target)) {
|
|
20716
|
+
// @ts-ignore
|
|
20717
|
+
const index = target.indexOf(node);
|
|
20718
|
+
if (index == -1) {
|
|
20719
|
+
throw new ReferenceError("Node not found");
|
|
20720
|
+
}
|
|
20721
|
+
target.splice(index, 1, ...(Array.isArray(replacement) ? replacement : [replacement]));
|
|
20722
|
+
}
|
|
20723
|
+
else if ("l" in target && target.l == node) {
|
|
20724
|
+
target.l = replacement;
|
|
20725
|
+
}
|
|
20726
|
+
else if ("r" in target && target.r == node) {
|
|
20727
|
+
target.r = replacement;
|
|
20728
|
+
}
|
|
20729
|
+
else {
|
|
20730
|
+
throw new ReferenceError("Node not found");
|
|
20731
|
+
}
|
|
20732
|
+
}
|
|
20733
|
+
node[PARENT] = null;
|
|
20734
|
+
return true;
|
|
20735
|
+
}
|
|
20736
|
+
function trimWhiteSpaceTokens(tokens) {
|
|
20737
|
+
let i = 0;
|
|
20738
|
+
if (tokens[0]?.typ === exports.EnumToken.WhitespaceTokenType) {
|
|
20739
|
+
tokens.shift();
|
|
20740
|
+
}
|
|
20741
|
+
if (tokens[tokens.length - 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
|
|
20742
|
+
tokens.pop();
|
|
20743
|
+
}
|
|
20744
|
+
if (tokens.length === 1) {
|
|
20745
|
+
if (tokens[0].typ === exports.EnumToken.WhitespaceTokenType) {
|
|
20746
|
+
tokens.length = 0;
|
|
20747
|
+
}
|
|
20748
|
+
return tokens;
|
|
20749
|
+
}
|
|
20750
|
+
for (; i < tokens.length; i++) {
|
|
20751
|
+
if (trimSpaceAfter.has(tokens[i].typ) && tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
|
|
20752
|
+
tokens.splice(i + 1, 1);
|
|
20753
|
+
}
|
|
20754
|
+
else if (trimTokenSpace.has(tokens[i].typ)) {
|
|
20755
|
+
if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
|
|
20756
|
+
tokens.splice(i + 1, 1);
|
|
20757
|
+
}
|
|
20758
|
+
if (i > 0 && tokens[i - 1].typ === exports.EnumToken.Whitespace) {
|
|
20759
|
+
tokens.splice(--i, 1);
|
|
20760
|
+
}
|
|
20761
|
+
}
|
|
20762
|
+
}
|
|
20763
|
+
return tokens;
|
|
20764
|
+
}
|
|
20765
|
+
|
|
19802
20766
|
class ComputeCalcExpressionFeature {
|
|
19803
20767
|
accept = new Set([exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType]);
|
|
19804
20768
|
get ordering() {
|
|
@@ -20637,7 +21601,7 @@
|
|
|
20637
21601
|
return true;
|
|
20638
21602
|
}
|
|
20639
21603
|
function minifyTransformFunctions(transform) {
|
|
20640
|
-
const name = transform.val
|
|
21604
|
+
const name = transform.val;
|
|
20641
21605
|
if ("skewX" == name) {
|
|
20642
21606
|
transform.val = "skew";
|
|
20643
21607
|
return transform;
|
|
@@ -20773,6 +21737,29 @@
|
|
|
20773
21737
|
let mat;
|
|
20774
21738
|
let transforms;
|
|
20775
21739
|
const cumulative = [];
|
|
21740
|
+
// all transform function arguments must be 0 or scale(1)
|
|
21741
|
+
for (const transform of transformLists) {
|
|
21742
|
+
switch (transform.val) {
|
|
21743
|
+
case "rotate":
|
|
21744
|
+
case "rotateX":
|
|
21745
|
+
case "rotateY":
|
|
21746
|
+
case "rotateZ":
|
|
21747
|
+
case "rotate3d":
|
|
21748
|
+
for (const child of transform.chi) {
|
|
21749
|
+
if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) {
|
|
21750
|
+
continue;
|
|
21751
|
+
}
|
|
21752
|
+
if ((child.typ != exports.EnumToken.AngleTokenType &&
|
|
21753
|
+
child.typ != exports.EnumToken.NumberTokenType &&
|
|
21754
|
+
child.typ != exports.EnumToken.PercentageTokenType) ||
|
|
21755
|
+
// angle >= 360deg, do not transform
|
|
21756
|
+
Math.abs(getAngle(child)) >= 1) {
|
|
21757
|
+
return null;
|
|
21758
|
+
}
|
|
21759
|
+
}
|
|
21760
|
+
// break;
|
|
21761
|
+
}
|
|
21762
|
+
}
|
|
20776
21763
|
for (const transformList of splitTransformList(transformLists)) {
|
|
20777
21764
|
mat = computeMatrix(transformList, identity());
|
|
20778
21765
|
if (mat == null) {
|
|
@@ -20803,60 +21790,6 @@
|
|
|
20803
21790
|
cumulative,
|
|
20804
21791
|
minified: minify$1(matrix) ?? [serialized],
|
|
20805
21792
|
};
|
|
20806
|
-
// valid identity matrix
|
|
20807
|
-
if ((result.minified.length == 1 &&
|
|
20808
|
-
result.minified[0].typ == exports.EnumToken.IdenTokenType &&
|
|
20809
|
-
result.minified[0].val == "none") ||
|
|
20810
|
-
(result.cumulative.length == 1 &&
|
|
20811
|
-
result.cumulative[0].typ == exports.EnumToken.IdenTokenType &&
|
|
20812
|
-
result.cumulative[0].val == "none") ||
|
|
20813
|
-
(result.matrix?.typ == exports.EnumToken.IdenTokenType && result.matrix.val == "none")) {
|
|
20814
|
-
// all transform function arguments must be 0 or scale(1)
|
|
20815
|
-
for (const transform of transformLists) {
|
|
20816
|
-
switch (transform.val) {
|
|
20817
|
-
case "translate":
|
|
20818
|
-
case "translateX":
|
|
20819
|
-
case "translateY":
|
|
20820
|
-
case "translateZ":
|
|
20821
|
-
case "translate3d":
|
|
20822
|
-
case "rotate":
|
|
20823
|
-
case "rotateX":
|
|
20824
|
-
case "rotateY":
|
|
20825
|
-
case "rotateZ":
|
|
20826
|
-
case "rotate3d":
|
|
20827
|
-
case "skew":
|
|
20828
|
-
case "skewX":
|
|
20829
|
-
case "skewY":
|
|
20830
|
-
for (const child of transform.chi) {
|
|
20831
|
-
if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) {
|
|
20832
|
-
continue;
|
|
20833
|
-
}
|
|
20834
|
-
if ((child.typ != exports.EnumToken.AngleTokenType &&
|
|
20835
|
-
child.typ != exports.EnumToken.NumberTokenType &&
|
|
20836
|
-
child.typ != exports.EnumToken.PercentageTokenType) ||
|
|
20837
|
-
getNumber(child) != 0) {
|
|
20838
|
-
return null;
|
|
20839
|
-
}
|
|
20840
|
-
}
|
|
20841
|
-
break;
|
|
20842
|
-
case "scale":
|
|
20843
|
-
case "scaleX":
|
|
20844
|
-
case "scaleY":
|
|
20845
|
-
case "scaleZ":
|
|
20846
|
-
case "scale3d":
|
|
20847
|
-
for (const child of transform.chi) {
|
|
20848
|
-
if (child.typ == exports.EnumToken.WhitespaceTokenType || child.typ == exports.EnumToken.CommaTokenType) {
|
|
20849
|
-
continue;
|
|
20850
|
-
}
|
|
20851
|
-
if ((child.typ != exports.EnumToken.NumberTokenType && child.typ != exports.EnumToken.PercentageTokenType) ||
|
|
20852
|
-
getNumber(child) != 1) {
|
|
20853
|
-
return null;
|
|
20854
|
-
}
|
|
20855
|
-
}
|
|
20856
|
-
break;
|
|
20857
|
-
}
|
|
20858
|
-
}
|
|
20859
|
-
}
|
|
20860
21793
|
return result;
|
|
20861
21794
|
}
|
|
20862
21795
|
function computeMatrix(transformList, matrixVar) {
|
|
@@ -21184,7 +22117,7 @@
|
|
|
21184
22117
|
minified: null,
|
|
21185
22118
|
};
|
|
21186
22119
|
if (matrix == null || cumulative == null || minified == null) {
|
|
21187
|
-
node.val = children;
|
|
22120
|
+
node.val = children.map((t) => t.typ == exports.EnumToken.TransformFunctionTokenType ? minifyTransformFunctions(t) : t);
|
|
21188
22121
|
continue;
|
|
21189
22122
|
}
|
|
21190
22123
|
let r = [filterValues(children)];
|
|
@@ -21868,7 +22801,15 @@
|
|
|
21868
22801
|
// trim :is()
|
|
21869
22802
|
if (curr[0] == "&") {
|
|
21870
22803
|
if (curr[1] == " " && !isIdent(curr[2]) && !isFunction(curr[2])) {
|
|
21871
|
-
curr.
|
|
22804
|
+
const all = new Array(Math.max(curr.length - 2, 0));
|
|
22805
|
+
let write = 0;
|
|
22806
|
+
for (let read = 2; read < curr.length; read++) {
|
|
22807
|
+
all[write++] = curr[read];
|
|
22808
|
+
}
|
|
22809
|
+
curr.length = 0;
|
|
22810
|
+
for (let index = 0; index < write; index++) {
|
|
22811
|
+
curr[index] = all[index];
|
|
22812
|
+
}
|
|
21872
22813
|
}
|
|
21873
22814
|
}
|
|
21874
22815
|
acc.push(curr.join(""));
|
|
@@ -22146,19 +23087,40 @@
|
|
|
22146
23087
|
if (optimized.length > 1) {
|
|
22147
23088
|
const check = optimized.at(-2);
|
|
22148
23089
|
if (!combinators.includes(check)) {
|
|
22149
|
-
|
|
23090
|
+
const last = optimized[optimized.length - 1];
|
|
23091
|
+
const all = new Array(Math.max(optimized.length - 1, 0));
|
|
23092
|
+
let write = 0;
|
|
23093
|
+
for (let read = 0; read < optimized.length - 1; read++) {
|
|
23094
|
+
all[write++] = optimized[read];
|
|
23095
|
+
}
|
|
23096
|
+
optimized.length = 0;
|
|
23097
|
+
for (let index = 0; index < write; index++) {
|
|
23098
|
+
optimized[index] = all[index];
|
|
23099
|
+
}
|
|
22150
23100
|
wrap = false;
|
|
22151
23101
|
rule =
|
|
22152
23102
|
optimized.join("") +
|
|
22153
23103
|
`:is(${selector
|
|
22154
23104
|
.map((s) => {
|
|
23105
|
+
const next = s[0] == "&" ? new Array(s.length) : new Array(s.length + 1);
|
|
23106
|
+
let write = 0;
|
|
22155
23107
|
if (s[0] == "&") {
|
|
22156
|
-
|
|
23108
|
+
next[write++] = last;
|
|
23109
|
+
for (let read = 1; read < s.length; read++) {
|
|
23110
|
+
next[write++] = s[read];
|
|
23111
|
+
}
|
|
22157
23112
|
}
|
|
22158
23113
|
else {
|
|
22159
|
-
|
|
23114
|
+
next[write++] = last;
|
|
23115
|
+
for (let read = 0; read < s.length; read++) {
|
|
23116
|
+
next[write++] = s[read];
|
|
23117
|
+
}
|
|
23118
|
+
}
|
|
23119
|
+
const rebuilt = new Array(write);
|
|
23120
|
+
for (let index = 0; index < write; index++) {
|
|
23121
|
+
rebuilt[index] = next[index];
|
|
22160
23122
|
}
|
|
22161
|
-
return
|
|
23123
|
+
return rebuilt.join("");
|
|
22162
23124
|
})
|
|
22163
23125
|
.join(",")})`;
|
|
22164
23126
|
}
|
|
@@ -22167,7 +23129,20 @@
|
|
|
22167
23129
|
rule = selector
|
|
22168
23130
|
.map((s) => {
|
|
22169
23131
|
if (s[0] == "&") {
|
|
22170
|
-
|
|
23132
|
+
const replacement = node[OPTIMIZED].optimized;
|
|
23133
|
+
const all = new Array(Math.max(s.length - 1 + replacement.length, 0));
|
|
23134
|
+
let write = 0;
|
|
23135
|
+
for (let read = 0; read < replacement.length; read++) {
|
|
23136
|
+
all[write++] = replacement[read];
|
|
23137
|
+
}
|
|
23138
|
+
for (let read = 1; read < s.length; read++) {
|
|
23139
|
+
all[write++] = s[read];
|
|
23140
|
+
}
|
|
23141
|
+
const rebuilt = new Array(write);
|
|
23142
|
+
for (let index = 0; index < write; index++) {
|
|
23143
|
+
rebuilt[index] = all[index];
|
|
23144
|
+
}
|
|
23145
|
+
return rebuilt.join("");
|
|
22171
23146
|
}
|
|
22172
23147
|
return s.join("");
|
|
22173
23148
|
})
|
|
@@ -22399,18 +23374,42 @@
|
|
|
22399
23374
|
while (optimized.length > 0) {
|
|
22400
23375
|
const last = optimized.at(-1);
|
|
22401
23376
|
if (last == " " || combinators.includes(last)) {
|
|
22402
|
-
optimized.
|
|
23377
|
+
const all = new Array(Math.max(optimized.length - 1, 0));
|
|
23378
|
+
let write = 0;
|
|
23379
|
+
for (let read = 0; read < optimized.length - 1; read++) {
|
|
23380
|
+
all[write++] = optimized[read];
|
|
23381
|
+
}
|
|
23382
|
+
optimized.length = 0;
|
|
23383
|
+
for (let index = 0; index < write; index++) {
|
|
23384
|
+
optimized[index] = all[index];
|
|
23385
|
+
}
|
|
22403
23386
|
continue;
|
|
22404
23387
|
}
|
|
22405
23388
|
break;
|
|
22406
23389
|
}
|
|
22407
23390
|
for (let i1 = 0; i1 < selector.length; i1++) {
|
|
22408
|
-
selector[i1].
|
|
23391
|
+
const all = new Array(Math.max(selector[i1].length - optimized.length, 0));
|
|
23392
|
+
let write = 0;
|
|
23393
|
+
for (let read = optimized.length; read < selector[i1].length; read++) {
|
|
23394
|
+
all[write++] = selector[i1][read];
|
|
23395
|
+
}
|
|
23396
|
+
selector[i1].length = 0;
|
|
23397
|
+
for (let index = 0; index < write; index++) {
|
|
23398
|
+
selector[i1][index] = all[index];
|
|
23399
|
+
}
|
|
22409
23400
|
}
|
|
22410
23401
|
let reducible = optimized.length == 1;
|
|
22411
23402
|
if (optimized[0] == "&") {
|
|
22412
23403
|
if (optimized[1] == " ") {
|
|
22413
|
-
optimized.
|
|
23404
|
+
const all = new Array(Math.max(optimized.length - 2, 0));
|
|
23405
|
+
let write = 0;
|
|
23406
|
+
for (let read = 2; read < optimized.length; read++) {
|
|
23407
|
+
all[write++] = optimized[read];
|
|
23408
|
+
}
|
|
23409
|
+
optimized.length = 0;
|
|
23410
|
+
for (let index = 0; index < write; index++) {
|
|
23411
|
+
optimized[index] = all[index];
|
|
23412
|
+
}
|
|
22414
23413
|
}
|
|
22415
23414
|
}
|
|
22416
23415
|
if (optimized.length == 0 || optimized[0].charAt(0) == "&" || selector.length == 1) {
|
|
@@ -22997,7 +23996,15 @@
|
|
|
22997
23996
|
if (selector.length > 1 &&
|
|
22998
23997
|
selector[0] == "&" &&
|
|
22999
23998
|
(combinators.includes(selector[1]) || !/^[a-zA-Z:]/.test(selector[1]))) {
|
|
23000
|
-
selector.
|
|
23999
|
+
const all = new Array(Math.max(selector.length - 1, 0));
|
|
24000
|
+
let write = 0;
|
|
24001
|
+
for (let read = 1; read < selector.length; read++) {
|
|
24002
|
+
all[write++] = selector[read];
|
|
24003
|
+
}
|
|
24004
|
+
selector.length = 0;
|
|
24005
|
+
for (let index = 0; index < write; index++) {
|
|
24006
|
+
selector[index] = all[index];
|
|
24007
|
+
}
|
|
23001
24008
|
}
|
|
23002
24009
|
}
|
|
23003
24010
|
const unique = new Set();
|
|
@@ -23319,6 +24326,19 @@
|
|
|
23319
24326
|
.reduce((acc, curr) => acc + (curr == "&" ? replace : curr), "");
|
|
23320
24327
|
}
|
|
23321
24328
|
|
|
24329
|
+
/**
|
|
24330
|
+
*
|
|
24331
|
+
* @param value
|
|
24332
|
+
* @returns
|
|
24333
|
+
*/
|
|
24334
|
+
function toBase64(value) {
|
|
24335
|
+
let result = '';
|
|
24336
|
+
for (const c of new TextEncoder().encode(value)) {
|
|
24337
|
+
result += String.fromCharCode(c);
|
|
24338
|
+
}
|
|
24339
|
+
return btoa(result);
|
|
24340
|
+
}
|
|
24341
|
+
|
|
23322
24342
|
// from https://github.com/Rich-Harris/vlq/tree/master
|
|
23323
24343
|
// credit: Rich Harris
|
|
23324
24344
|
const integer_to_char = {};
|
|
@@ -23368,15 +24388,20 @@
|
|
|
23368
24388
|
* @returns
|
|
23369
24389
|
*/
|
|
23370
24390
|
function encode(value) {
|
|
23371
|
-
if (typeof value === 'number') {
|
|
23372
|
-
|
|
23373
|
-
}
|
|
24391
|
+
// if (typeof value === 'number') {
|
|
24392
|
+
// return encode_integer(value);
|
|
24393
|
+
// }
|
|
23374
24394
|
let result = '';
|
|
23375
24395
|
for (let i = 0; i < value.length; i += 1) {
|
|
23376
24396
|
result += encode_integer(value[i]);
|
|
23377
24397
|
}
|
|
23378
24398
|
return result;
|
|
23379
24399
|
}
|
|
24400
|
+
/**
|
|
24401
|
+
*
|
|
24402
|
+
* @param num
|
|
24403
|
+
* @returns
|
|
24404
|
+
*/
|
|
23380
24405
|
function encode_integer(num) {
|
|
23381
24406
|
let result = '';
|
|
23382
24407
|
if (num < 0) {
|
|
@@ -23398,6 +24423,35 @@
|
|
|
23398
24423
|
|
|
23399
24424
|
/**
|
|
23400
24425
|
* Generate and parse source map
|
|
24426
|
+
*
|
|
24427
|
+
* ```ts
|
|
24428
|
+
* const sourcemap = new SourceMap();
|
|
24429
|
+
*
|
|
24430
|
+
* // you can also pass an input sourcemap
|
|
24431
|
+
* // const sourcemap = new SourceMap(sourcemapObjectOrJSONString);
|
|
24432
|
+
*
|
|
24433
|
+
* sourcemap.addSourceContent(0, '/css/styles.css', null);
|
|
24434
|
+
* sourcemap.addSourceContent(1, '/css/typography.css', null);
|
|
24435
|
+
*
|
|
24436
|
+
* const maps = [];
|
|
24437
|
+
*
|
|
24438
|
+
* maps.add([
|
|
24439
|
+
1, 1, 0, 1, 1]);
|
|
24440
|
+
* maps.add([
|
|
24441
|
+
2, 1, 1, 1, 1
|
|
24442
|
+
]);
|
|
24443
|
+
|
|
24444
|
+
sourcemap.add(maps);
|
|
24445
|
+
|
|
24446
|
+
// convert to inline sourcemap
|
|
24447
|
+
sourcemap.toUrl();
|
|
24448
|
+
|
|
24449
|
+
// convert to JSON
|
|
24450
|
+
sourcemap.toJSON();
|
|
24451
|
+
|
|
24452
|
+
// find the original file, line and column
|
|
24453
|
+
sourcemap.find(2, 1);
|
|
24454
|
+
```
|
|
23401
24455
|
*/
|
|
23402
24456
|
class SourceMap {
|
|
23403
24457
|
/**
|
|
@@ -23448,7 +24502,7 @@
|
|
|
23448
24502
|
line = -1;
|
|
23449
24503
|
/**
|
|
23450
24504
|
*
|
|
23451
|
-
* @param sourcemaps
|
|
24505
|
+
* @param sourcemaps input sourcemap
|
|
23452
24506
|
*/
|
|
23453
24507
|
constructor(sourcemaps) {
|
|
23454
24508
|
if (typeof sourcemaps === "string") {
|
|
@@ -23489,9 +24543,9 @@
|
|
|
23489
24543
|
}
|
|
23490
24544
|
/**
|
|
23491
24545
|
* add source
|
|
23492
|
-
* @param id
|
|
23493
|
-
* @param fileName
|
|
23494
|
-
* @param content
|
|
24546
|
+
* @param id source id
|
|
24547
|
+
* @param fileName source file
|
|
24548
|
+
* @param content source content
|
|
23495
24549
|
* @returns
|
|
23496
24550
|
*/
|
|
23497
24551
|
addSourceContent(id, fileName, content) {
|
|
@@ -23627,7 +24681,7 @@
|
|
|
23627
24681
|
*/
|
|
23628
24682
|
toUrl() {
|
|
23629
24683
|
// /*# sourceMappingURL = ${url} */
|
|
23630
|
-
return `data:application/json;charset=utf-8;base64,${
|
|
24684
|
+
return `data:application/json;charset=utf-8;base64,${toBase64(JSON.stringify(this.toJSON()))}`;
|
|
23631
24685
|
}
|
|
23632
24686
|
/**
|
|
23633
24687
|
* Convert to JSON object
|
|
@@ -24067,11 +25121,13 @@
|
|
|
24067
25121
|
...options,
|
|
24068
25122
|
};
|
|
24069
25123
|
if (options.withParents) {
|
|
24070
|
-
|
|
24071
|
-
let parent = data[PARENT];
|
|
25124
|
+
let parent;
|
|
24072
25125
|
while (data[PARENT] != null) {
|
|
24073
25126
|
// @ts-ignore
|
|
24074
|
-
parent = { ...data[PARENT], chi: [
|
|
25127
|
+
// parent = { ...data[PARENT], chi: [data] };
|
|
25128
|
+
parent = cloneNode(data[PARENT]);
|
|
25129
|
+
// @ts-ignore
|
|
25130
|
+
parent.chi = [data];
|
|
24075
25131
|
// @ts-ignore
|
|
24076
25132
|
parent[PARENT] = data[PARENT][PARENT];
|
|
24077
25133
|
// @ts-ignore
|
|
@@ -24241,6 +25297,8 @@
|
|
|
24241
25297
|
* @param sourceLocation
|
|
24242
25298
|
* @param linesMap
|
|
24243
25299
|
* @param str
|
|
25300
|
+
* @param start
|
|
25301
|
+
* @param end
|
|
24244
25302
|
*/
|
|
24245
25303
|
function move(sourceLocation, linesMap, str, start, end) {
|
|
24246
25304
|
let i = start ?? 0;
|
|
@@ -24433,8 +25491,8 @@
|
|
|
24433
25491
|
};
|
|
24434
25492
|
}
|
|
24435
25493
|
switch (token.typ) {
|
|
24436
|
-
case exports.EnumToken.FunctionTokenDefType:
|
|
24437
25494
|
case exports.EnumToken.UrlFunctionTokenDefType:
|
|
25495
|
+
case exports.EnumToken.FunctionTokenDefType:
|
|
24438
25496
|
case exports.EnumToken.MathFunctionTokenDefType:
|
|
24439
25497
|
case exports.EnumToken.ImageFunctionTokenDefType:
|
|
24440
25498
|
case exports.EnumToken.ColorFunctionTokenDefType:
|
|
@@ -24534,8 +25592,8 @@
|
|
|
24534
25592
|
return token.val;
|
|
24535
25593
|
}
|
|
24536
25594
|
if (Array.isArray(token.chi)) {
|
|
24537
|
-
const fnName = token.val
|
|
24538
|
-
const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val
|
|
25595
|
+
const fnName = token.val;
|
|
25596
|
+
const isLegacy = ["rgb", "rgba", "hsl", "hsla"].includes(token.val);
|
|
24539
25597
|
const hasAlpha = [
|
|
24540
25598
|
"rgb",
|
|
24541
25599
|
"rgba",
|
|
@@ -24578,6 +25636,9 @@
|
|
|
24578
25636
|
}
|
|
24579
25637
|
case exports.EnumToken.UrlFunctionTokenType:
|
|
24580
25638
|
if (options.minify && token.typ === exports.EnumToken.UrlFunctionTokenType) {
|
|
25639
|
+
if (token.chi[0]?.typ === exports.EnumToken.BadUrlTokenType) {
|
|
25640
|
+
return "url()";
|
|
25641
|
+
}
|
|
24581
25642
|
for (const child of token.chi) {
|
|
24582
25643
|
if (child.typ === exports.EnumToken.StringTokenType) {
|
|
24583
25644
|
if (child.val.slice(1, 5) !== "data:" &&
|
|
@@ -25265,6 +26326,12 @@
|
|
|
25265
26326
|
return token.val.typ == exports.EnumToken.FractionTokenType
|
|
25266
26327
|
? renderValue(token.val, options, cache)
|
|
25267
26328
|
: minifyNumber(token.val);
|
|
26329
|
+
case exports.EnumToken.InfinityTokenType:
|
|
26330
|
+
return "0/0";
|
|
26331
|
+
case exports.EnumToken.NegativeInfinityTokenType:
|
|
26332
|
+
return "-0/0";
|
|
26333
|
+
case exports.EnumToken.NaNTokenType:
|
|
26334
|
+
return "NaN";
|
|
25268
26335
|
case exports.EnumToken.AtRuleTokenType:
|
|
25269
26336
|
return "@" + token.nam;
|
|
25270
26337
|
case exports.EnumToken.CommentTokenType:
|
|
@@ -25394,9 +26461,19 @@
|
|
|
25394
26461
|
|
|
25395
26462
|
const SymbolsMapTokens = Object.create(null);
|
|
25396
26463
|
// Regex for escape sequence decoding - compile once, reuse many times
|
|
25397
|
-
const ESCAPE_SEQUENCE_REGEX = /\\([0-9a-fA-F]{1,6})
|
|
26464
|
+
const ESCAPE_SEQUENCE_REGEX = /\\((\n|\r|\f|\v|\u2028|\u2029|([0-9a-fA-F]{1,6})) ?)/gms;
|
|
25398
26465
|
function decodeEscapeSequences(value) {
|
|
25399
26466
|
return value.replace(ESCAPE_SEQUENCE_REGEX, (_, sequence) => {
|
|
26467
|
+
// \n \r \f \v
|
|
26468
|
+
switch (sequence.charCodeAt(0)) {
|
|
26469
|
+
case 0xa:
|
|
26470
|
+
case 0xb:
|
|
26471
|
+
case 0xc:
|
|
26472
|
+
case 0xd:
|
|
26473
|
+
case 0x2028:
|
|
26474
|
+
case 0x2029:
|
|
26475
|
+
return "";
|
|
26476
|
+
}
|
|
25400
26477
|
const codepoint = parseInt(sequence, 16);
|
|
25401
26478
|
if (codepoint == 0 ||
|
|
25402
26479
|
// leading surrogate
|
|
@@ -25634,18 +26711,17 @@
|
|
|
25634
26711
|
constructor(parseInfo, input = null) {
|
|
25635
26712
|
this.parseInfo = parseInfo;
|
|
25636
26713
|
this.input = input;
|
|
25637
|
-
|
|
25638
|
-
|
|
25639
|
-
|
|
26714
|
+
this.parseInfo =
|
|
26715
|
+
typeof parseInfo == "string"
|
|
26716
|
+
? {
|
|
25640
26717
|
stream: parseInfo,
|
|
25641
26718
|
source: new SourceFile(parseInfo, [], ""),
|
|
25642
26719
|
offset: 0,
|
|
25643
26720
|
time: 0,
|
|
25644
26721
|
position: 0,
|
|
25645
26722
|
currentPosition: 0,
|
|
25646
|
-
}
|
|
25647
|
-
|
|
25648
|
-
}
|
|
26723
|
+
}
|
|
26724
|
+
: parseInfo;
|
|
25649
26725
|
}
|
|
25650
26726
|
/**
|
|
25651
26727
|
*
|
|
@@ -25662,6 +26738,18 @@
|
|
|
25662
26738
|
this.advance(parseInfo, 2);
|
|
25663
26739
|
continue;
|
|
25664
26740
|
}
|
|
26741
|
+
charCode = parseInfo.stream.charCodeAt(parseInfo.currentPosition - parseInfo.offset + 1);
|
|
26742
|
+
// \n \r \f \v
|
|
26743
|
+
if (charCode == 0xa ||
|
|
26744
|
+
charCode == 0xb ||
|
|
26745
|
+
charCode == 0xc ||
|
|
26746
|
+
charCode == 0xd ||
|
|
26747
|
+
charCode == 0x2028 ||
|
|
26748
|
+
charCode == 0x2029) {
|
|
26749
|
+
this.advance(parseInfo, 2);
|
|
26750
|
+
decodeSegments = true;
|
|
26751
|
+
continue;
|
|
26752
|
+
}
|
|
25665
26753
|
const sequence = this.peek(parseInfo, 7);
|
|
25666
26754
|
let escapeSequence = "";
|
|
25667
26755
|
let codepoint;
|
|
@@ -25705,7 +26793,7 @@
|
|
|
25705
26793
|
this.advance(parseInfo);
|
|
25706
26794
|
}
|
|
25707
26795
|
// EOF - 'Unclosed-string' fixed
|
|
25708
|
-
return this.makeToken(parseInfo, exports.EnumToken.StringTokenType);
|
|
26796
|
+
return this.makeToken(parseInfo, exports.EnumToken.StringTokenType, decodeSegments ? { decodeSegments } : null);
|
|
25709
26797
|
// return result;
|
|
25710
26798
|
}
|
|
25711
26799
|
/**
|
|
@@ -25713,7 +26801,7 @@
|
|
|
25713
26801
|
* @param parseInfo
|
|
25714
26802
|
* @returns
|
|
25715
26803
|
*/
|
|
25716
|
-
|
|
26804
|
+
consumeStringAsURLToken(parseInfo) {
|
|
25717
26805
|
const quote = this.advance(parseInfo).charCodeAt(0);
|
|
25718
26806
|
let charCode;
|
|
25719
26807
|
let decodeSegments = false;
|
|
@@ -25767,7 +26855,7 @@
|
|
|
25767
26855
|
return this.makeToken(parseInfo, exports.EnumToken.BadUrlTokenType);
|
|
25768
26856
|
}
|
|
25769
26857
|
if (isWhiteSpace(charCode)) {
|
|
25770
|
-
this.advance(parseInfo, k);
|
|
26858
|
+
// this.advance(parseInfo, k);
|
|
25771
26859
|
k++;
|
|
25772
26860
|
continue;
|
|
25773
26861
|
}
|
|
@@ -26155,7 +27243,7 @@
|
|
|
26155
27243
|
}
|
|
26156
27244
|
return 0;
|
|
26157
27245
|
}
|
|
26158
|
-
|
|
27246
|
+
consumeURLToken(parseInfo, endPosition) {
|
|
26159
27247
|
let charCode;
|
|
26160
27248
|
// consume an <url>
|
|
26161
27249
|
while (isWhiteSpace(this.peekCharCode(parseInfo))) {
|
|
@@ -26163,7 +27251,7 @@
|
|
|
26163
27251
|
}
|
|
26164
27252
|
charCode = this.peekCharCode(parseInfo);
|
|
26165
27253
|
if (charCode == 34 /* TokenMap.DOUBLE_QUOTE */ || charCode == 39 /* TokenMap.SINGLE_QUOTE */) {
|
|
26166
|
-
return this.
|
|
27254
|
+
return this.consumeStringAsURLToken(parseInfo);
|
|
26167
27255
|
}
|
|
26168
27256
|
do {
|
|
26169
27257
|
this.advance(parseInfo);
|
|
@@ -26171,14 +27259,28 @@
|
|
|
26171
27259
|
} while (
|
|
26172
27260
|
// !(value === "/" && this.match(parseInfo, "/*") &&
|
|
26173
27261
|
charCode !== 41 /* TokenMap.RIGHT_PARENTHESIS */ &&
|
|
27262
|
+
!isWhiteSpace(charCode) &&
|
|
26174
27263
|
parseInfo.currentPosition < endPosition);
|
|
26175
|
-
|
|
27264
|
+
if (charCode !== 41 /* TokenMap.RIGHT_PARENTHESIS */) {
|
|
27265
|
+
let k = 1;
|
|
27266
|
+
while (k < endPosition) {
|
|
27267
|
+
charCode = parseInfo.stream.charCodeAt(parseInfo.currentPosition - parseInfo.offset + k);
|
|
27268
|
+
if (isWhiteSpace(charCode)) {
|
|
27269
|
+
k++;
|
|
27270
|
+
continue;
|
|
27271
|
+
}
|
|
27272
|
+
break;
|
|
27273
|
+
}
|
|
27274
|
+
if (charCode != charCode || (charCode != 41 /* TokenMap.RIGHT_PARENTHESIS */ && !isIdentStart(charCode))) {
|
|
27275
|
+
this.advance(parseInfo, k);
|
|
27276
|
+
return this.makeToken(parseInfo, exports.EnumToken.BadUrlTokenType);
|
|
27277
|
+
}
|
|
27278
|
+
}
|
|
26176
27279
|
return this.makeToken(parseInfo,
|
|
26177
27280
|
// parseInfo.position < parseInfo.currentPosition
|
|
26178
27281
|
(charCode = this.peekCharCode(parseInfo)) != charCode || !this.isURLToken(parseInfo)
|
|
26179
27282
|
? exports.EnumToken.BadUrlTokenType
|
|
26180
27283
|
: exports.EnumToken.UrlTokenTokenType);
|
|
26181
|
-
// }
|
|
26182
27284
|
}
|
|
26183
27285
|
/**
|
|
26184
27286
|
*
|
|
@@ -26423,31 +27525,26 @@
|
|
|
26423
27525
|
/**
|
|
26424
27526
|
*
|
|
26425
27527
|
* @param parseInfo
|
|
26426
|
-
* @param start
|
|
26427
|
-
* @param end
|
|
26428
27528
|
* @returns
|
|
26429
27529
|
*/
|
|
26430
|
-
isIdentToken(parseInfo, start, end) {
|
|
27530
|
+
isIdentToken(parseInfo /* , start?: number, end?: number */) {
|
|
26431
27531
|
let j = parseInfo.currentPosition - parseInfo.offset;
|
|
26432
27532
|
let i = parseInfo.position - parseInfo.offset;
|
|
26433
|
-
if (start != null) {
|
|
26434
|
-
|
|
26435
|
-
|
|
26436
|
-
|
|
26437
|
-
|
|
26438
|
-
|
|
26439
|
-
|
|
26440
|
-
|
|
26441
|
-
|
|
26442
|
-
|
|
26443
|
-
|
|
26444
|
-
|
|
26445
|
-
|
|
26446
|
-
|
|
26447
|
-
|
|
26448
|
-
}
|
|
26449
|
-
}
|
|
26450
|
-
}
|
|
27533
|
+
// if (start != null) {
|
|
27534
|
+
// if (end == null) {
|
|
27535
|
+
// if (start < 0) {
|
|
27536
|
+
// j += start;
|
|
27537
|
+
// } else {
|
|
27538
|
+
// i += start;
|
|
27539
|
+
// }
|
|
27540
|
+
// } else {
|
|
27541
|
+
// if (end < 0) {
|
|
27542
|
+
// j += end;
|
|
27543
|
+
// } else {
|
|
27544
|
+
// j = parseInfo.position + end;
|
|
27545
|
+
// }
|
|
27546
|
+
// }
|
|
27547
|
+
// }
|
|
26451
27548
|
j--;
|
|
26452
27549
|
let codepoint = parseInfo.stream.charCodeAt(i);
|
|
26453
27550
|
// -
|
|
@@ -26490,18 +27587,18 @@
|
|
|
26490
27587
|
* @param parseInfo
|
|
26491
27588
|
* @returns
|
|
26492
27589
|
*/
|
|
26493
|
-
isPseudo(parseInfo) {
|
|
26494
|
-
|
|
26495
|
-
|
|
26496
|
-
|
|
26497
|
-
|
|
26498
|
-
|
|
26499
|
-
|
|
26500
|
-
|
|
26501
|
-
|
|
26502
|
-
|
|
26503
|
-
|
|
26504
|
-
}
|
|
27590
|
+
// isPseudo(parseInfo: ParseInfo): boolean {
|
|
27591
|
+
// let position: number = parseInfo.currentPosition - parseInfo.offset;
|
|
27592
|
+
// let endPosition: number = parseInfo.currentPosition - parseInfo.offset;
|
|
27593
|
+
// return (parseInfo.stream.charAt(position) == ":" &&
|
|
27594
|
+
// parseInfo.stream.charAt(endPosition - 1) == "(" &&
|
|
27595
|
+
// (parseInfo.stream.charAt(position + 1) == ":"
|
|
27596
|
+
// ? this.isIdentToken(parseInfo, 2, -1)
|
|
27597
|
+
// : this.isIdentToken(parseInfo, 1, -1))) ||
|
|
27598
|
+
// parseInfo.stream.charAt(position + 1) == ":"
|
|
27599
|
+
// ? this.isIdentToken(parseInfo, 2)
|
|
27600
|
+
// : this.isIdentToken(parseInfo, 1);
|
|
27601
|
+
// }
|
|
26505
27602
|
/**
|
|
26506
27603
|
*
|
|
26507
27604
|
* @param parseInfo
|
|
@@ -26558,8 +27655,6 @@
|
|
|
26558
27655
|
}
|
|
26559
27656
|
/**
|
|
26560
27657
|
* Tokenize CSS string
|
|
26561
|
-
* @param parseInfo
|
|
26562
|
-
* @param yieldEOFToken
|
|
26563
27658
|
*/
|
|
26564
27659
|
next( /* parseInfo: ParseInfo | string, yieldEOFToken: boolean = true */) {
|
|
26565
27660
|
const parseInfo = this.parseInfo;
|
|
@@ -26574,7 +27669,7 @@
|
|
|
26574
27669
|
while ((charCode = this.peekCharCode(parseInfo)) == charCode) {
|
|
26575
27670
|
if (this.state === exports.EnumToken.UrlFunctionTokenDefType) {
|
|
26576
27671
|
this.state = null;
|
|
26577
|
-
return this.
|
|
27672
|
+
return this.consumeURLToken(parseInfo, endPosition);
|
|
26578
27673
|
}
|
|
26579
27674
|
if (parseInfo.position == parseInfo.currentPosition) {
|
|
26580
27675
|
if (charCode == 45 /* TokenMap.MINUS */ ||
|
|
@@ -26694,12 +27789,14 @@
|
|
|
26694
27789
|
// '('
|
|
26695
27790
|
case 40 /* TokenMap.LEFT_PARENTHESIS */:
|
|
26696
27791
|
if (parseInfo.position < parseInfo.currentPosition) {
|
|
26697
|
-
if (
|
|
26698
|
-
|
|
26699
|
-
|
|
26700
|
-
|
|
26701
|
-
|
|
26702
|
-
|
|
27792
|
+
// if (
|
|
27793
|
+
// parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" &&
|
|
27794
|
+
// this.isPseudo(parseInfo)
|
|
27795
|
+
// ) {
|
|
27796
|
+
// this.advance(parseInfo);
|
|
27797
|
+
// return this.makeToken(parseInfo, EnumToken.PseudoClassFunctionTokenDefType);
|
|
27798
|
+
// } else
|
|
27799
|
+
if (this.isIdentToken(parseInfo)) {
|
|
26703
27800
|
const hint = this.startsWith(parseInfo, "--")
|
|
26704
27801
|
? exports.EnumToken.CustomFunctionTokenDefType
|
|
26705
27802
|
: (getSymbolHint(parseInfo, parseInfo.position - parseInfo.offset, parseInfo.currentPosition - parseInfo.offset + 1) ?? exports.EnumToken.FunctionTokenDefType);
|
|
@@ -26943,6 +28040,9 @@
|
|
|
26943
28040
|
case 46 /* TokenMap.DOT */:
|
|
26944
28041
|
const codepoint = parseInfo.stream.charCodeAt(parseInfo.currentPosition - parseInfo.offset + 1);
|
|
26945
28042
|
if (isIdentStart(codepoint) || codepoint == 45 /* TokenMap.MINUS */) {
|
|
28043
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
28044
|
+
return this.makeToken(parseInfo);
|
|
28045
|
+
}
|
|
26946
28046
|
this.advance(parseInfo);
|
|
26947
28047
|
let tokensCount = this.consumeIdentToken(parseInfo);
|
|
26948
28048
|
if (tokensCount > 0) {
|
|
@@ -26974,8 +28074,6 @@
|
|
|
26974
28074
|
}
|
|
26975
28075
|
/**
|
|
26976
28076
|
* tokenize readable stream
|
|
26977
|
-
* @param input
|
|
26978
|
-
* @param parseInfo
|
|
26979
28077
|
*/
|
|
26980
28078
|
async tokenizeStream() {
|
|
26981
28079
|
const decoder = new TextDecoder("utf-8");
|
|
@@ -27062,7 +28160,6 @@
|
|
|
27062
28160
|
const stack = [];
|
|
27063
28161
|
const uniq = new Map();
|
|
27064
28162
|
let allowed = true;
|
|
27065
|
-
let i = 0;
|
|
27066
28163
|
let index;
|
|
27067
28164
|
let parent = context;
|
|
27068
28165
|
let nested = false;
|
|
@@ -27096,121 +28193,132 @@
|
|
|
27096
28193
|
nested = parent?.typ == exports.EnumToken.RuleNodeType;
|
|
27097
28194
|
parent = parent?.[PARENT];
|
|
27098
28195
|
} while (!nested && parent != null);
|
|
27099
|
-
|
|
27100
|
-
|
|
27101
|
-
|
|
27102
|
-
|
|
28196
|
+
const all = new Array(tokens.length);
|
|
28197
|
+
let write = 0;
|
|
28198
|
+
for (let read = 0; read < tokens.length; read++) {
|
|
28199
|
+
let token = tokens[read];
|
|
28200
|
+
if (token.typ == exports.EnumToken.ColonTokenType) {
|
|
28201
|
+
const next = tokens[read + 1];
|
|
28202
|
+
if (next?.typ == exports.EnumToken.IdenTokenType) {
|
|
28203
|
+
all[write++] = {
|
|
28204
|
+
...token,
|
|
27103
28205
|
typ: exports.EnumToken.PseudoElementTokenType,
|
|
27104
|
-
val: ":" +
|
|
27105
|
-
|
|
27106
|
-
|
|
27107
|
-
|
|
28206
|
+
val: ":" + next.val,
|
|
28207
|
+
[LOCEND]: next[LOCEND],
|
|
28208
|
+
};
|
|
28209
|
+
read++;
|
|
27108
28210
|
continue;
|
|
27109
28211
|
}
|
|
27110
|
-
if (
|
|
27111
|
-
val = ":" +
|
|
27112
|
-
|
|
28212
|
+
if (next?.typ == exports.EnumToken.FunctionTokenDefType) {
|
|
28213
|
+
val = ":" + next.val;
|
|
28214
|
+
all[write++] = {
|
|
28215
|
+
...token,
|
|
27113
28216
|
typ: val + "()" in getSyntaxConfig().selectors
|
|
27114
28217
|
? exports.EnumToken.PseudoClassFunctionTokenDefType
|
|
27115
|
-
:
|
|
28218
|
+
: next.typ,
|
|
27116
28219
|
val,
|
|
27117
|
-
|
|
27118
|
-
|
|
27119
|
-
|
|
28220
|
+
[LOCEND]: next[LOCEND],
|
|
28221
|
+
};
|
|
28222
|
+
read++;
|
|
27120
28223
|
continue;
|
|
27121
28224
|
}
|
|
27122
28225
|
}
|
|
27123
|
-
if (
|
|
27124
|
-
|
|
27125
|
-
|
|
27126
|
-
|
|
28226
|
+
if (token.typ == exports.EnumToken.DoubleColonTokenType) {
|
|
28227
|
+
const next = tokens[read + 1];
|
|
28228
|
+
val = ":" + next.val;
|
|
28229
|
+
if (next?.typ == exports.EnumToken.IdenTokenType) {
|
|
28230
|
+
all[write++] = {
|
|
28231
|
+
...token,
|
|
27127
28232
|
typ: exports.EnumToken.PseudoClassTokenType,
|
|
27128
28233
|
val: (pseudoElements.includes(val) ? "" : ":") + val,
|
|
27129
|
-
|
|
27130
|
-
|
|
27131
|
-
|
|
28234
|
+
[LOCEND]: next[LOCEND],
|
|
28235
|
+
};
|
|
28236
|
+
read++;
|
|
27132
28237
|
continue;
|
|
27133
28238
|
}
|
|
27134
|
-
if (
|
|
27135
|
-
val = "::" +
|
|
27136
|
-
|
|
28239
|
+
if (next?.typ == exports.EnumToken.FunctionTokenDefType) {
|
|
28240
|
+
val = "::" + next.val;
|
|
28241
|
+
all[write++] = {
|
|
28242
|
+
...token,
|
|
27137
28243
|
typ: val + "()" in getSyntaxConfig().selectors
|
|
27138
28244
|
? exports.EnumToken.PseudoClassFunctionTokenDefType
|
|
27139
28245
|
: exports.EnumToken.FunctionTokenDefType,
|
|
27140
28246
|
val,
|
|
27141
|
-
|
|
27142
|
-
|
|
27143
|
-
|
|
28247
|
+
[LOCEND]: next[LOCEND],
|
|
28248
|
+
};
|
|
28249
|
+
read++;
|
|
27144
28250
|
continue;
|
|
27145
28251
|
}
|
|
27146
28252
|
}
|
|
27147
|
-
if (
|
|
27148
|
-
if (isHash(
|
|
27149
|
-
|
|
27150
|
-
|
|
27151
|
-
|
|
28253
|
+
if (token.typ == exports.EnumToken.ColorTokenType) {
|
|
28254
|
+
if (isHash(token.val)) {
|
|
28255
|
+
token.typ = exports.EnumToken.HashTokenType;
|
|
28256
|
+
all[write++] = token;
|
|
28257
|
+
continue;
|
|
27152
28258
|
}
|
|
27153
|
-
|
|
27154
|
-
|
|
27155
|
-
|
|
27156
|
-
|
|
27157
|
-
|
|
27158
|
-
|
|
27159
|
-
|
|
27160
|
-
|
|
27161
|
-
|
|
27162
|
-
|
|
27163
|
-
|
|
27164
|
-
trimWhiteSpace.includes(array[index + 1]?.typ) ||
|
|
27165
|
-
combinators.includes(array[index - 1]?.val) ||
|
|
27166
|
-
combinators.includes(array[index + 1]?.val)) {
|
|
27167
|
-
return acc;
|
|
27168
|
-
}
|
|
27169
|
-
}
|
|
27170
|
-
let t = renderValue(curr, { minify: false });
|
|
27171
|
-
if (t == ",") {
|
|
27172
|
-
acc.push([]);
|
|
27173
|
-
}
|
|
27174
|
-
else {
|
|
27175
|
-
acc[acc.length - 1].push(t);
|
|
28259
|
+
return {
|
|
28260
|
+
typ: exports.EnumToken.RuleNodeType,
|
|
28261
|
+
sel: [
|
|
28262
|
+
...tokens
|
|
28263
|
+
.reduce((acc, curr, index, array) => {
|
|
28264
|
+
if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
28265
|
+
if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
|
|
28266
|
+
trimWhiteSpace.includes(array[index + 1]?.typ) ||
|
|
28267
|
+
combinators.includes(array[index - 1]?.val) ||
|
|
28268
|
+
combinators.includes(array[index + 1]?.val)) {
|
|
28269
|
+
return acc;
|
|
27176
28270
|
}
|
|
27177
|
-
|
|
27178
|
-
|
|
27179
|
-
|
|
27180
|
-
|
|
27181
|
-
|
|
27182
|
-
|
|
27183
|
-
|
|
27184
|
-
|
|
27185
|
-
|
|
27186
|
-
|
|
27187
|
-
|
|
28271
|
+
}
|
|
28272
|
+
let t = renderValue(curr, { minify: false });
|
|
28273
|
+
if (t == ",") {
|
|
28274
|
+
acc.push([]);
|
|
28275
|
+
}
|
|
28276
|
+
else {
|
|
28277
|
+
acc[acc.length - 1].push(t);
|
|
28278
|
+
}
|
|
28279
|
+
return acc;
|
|
28280
|
+
}, [[]])
|
|
28281
|
+
.reduce((acc, curr) => {
|
|
28282
|
+
let i = 0;
|
|
28283
|
+
for (; i < curr.length; i++) {
|
|
28284
|
+
if (i + 1 < curr.length && curr[i] == "*") {
|
|
28285
|
+
if (curr[i] == "*") {
|
|
28286
|
+
let index = curr[i + 1] == " " ? 2 : 1;
|
|
28287
|
+
if (![">", "~", "+"].includes(curr[index])) {
|
|
28288
|
+
curr.splice(i, index);
|
|
27188
28289
|
}
|
|
27189
28290
|
}
|
|
27190
28291
|
}
|
|
27191
|
-
|
|
27192
|
-
|
|
27193
|
-
|
|
27194
|
-
|
|
27195
|
-
|
|
27196
|
-
|
|
27197
|
-
|
|
27198
|
-
|
|
27199
|
-
|
|
27200
|
-
|
|
27201
|
-
|
|
27202
|
-
|
|
27203
|
-
|
|
27204
|
-
|
|
27205
|
-
|
|
27206
|
-
|
|
27207
|
-
|
|
27208
|
-
|
|
27209
|
-
|
|
27210
|
-
}
|
|
28292
|
+
}
|
|
28293
|
+
acc.set(curr.join(""), curr);
|
|
28294
|
+
return acc;
|
|
28295
|
+
}, uniq)
|
|
28296
|
+
.keys(),
|
|
28297
|
+
].join(","),
|
|
28298
|
+
chi: [],
|
|
28299
|
+
[LOCSRCID]: tokens[0][LOCSRCID],
|
|
28300
|
+
[LOCSTA]: tokens[0][LOCSTA],
|
|
28301
|
+
[LOCEND]: tokens[tokens.length - 1][LOCEND],
|
|
28302
|
+
[TOKENS]: tokens,
|
|
28303
|
+
[STATE]: exports.EnumAstNodeStatus.Invalid,
|
|
28304
|
+
[ERRORS]: [
|
|
28305
|
+
{
|
|
28306
|
+
action: "drop",
|
|
28307
|
+
node: token,
|
|
28308
|
+
message: "invalid hash id",
|
|
28309
|
+
},
|
|
28310
|
+
],
|
|
28311
|
+
};
|
|
27211
28312
|
}
|
|
28313
|
+
all[write++] = token;
|
|
27212
28314
|
}
|
|
27213
|
-
|
|
28315
|
+
if (write !== tokens.length) {
|
|
28316
|
+
for (let index = 0; index < write; index++) {
|
|
28317
|
+
tokens[index] = all[index];
|
|
28318
|
+
}
|
|
28319
|
+
tokens.length = write;
|
|
28320
|
+
}
|
|
28321
|
+
const result = matchSelectorSyntax(tokens, errors, options, nested);
|
|
27214
28322
|
trimArray(tokens);
|
|
27215
28323
|
if (result.success) {
|
|
27216
28324
|
for (let i = 0; i < tokens.length; i++) {
|
|
@@ -27527,7 +28635,6 @@
|
|
|
27527
28635
|
* @param errors
|
|
27528
28636
|
*/
|
|
27529
28637
|
function parseDeclaration(tokens, parent, options, errors) {
|
|
27530
|
-
// console.error(tokens);
|
|
27531
28638
|
const name = tokens.shift();
|
|
27532
28639
|
let i;
|
|
27533
28640
|
let rules = null;
|
|
@@ -27642,7 +28749,7 @@
|
|
|
27642
28749
|
let token;
|
|
27643
28750
|
let index;
|
|
27644
28751
|
if (syntaxRules != null) {
|
|
27645
|
-
const doNotValidate = options.validation === false
|
|
28752
|
+
const doNotValidate = options.validation === false;
|
|
27646
28753
|
result = doNotValidate ? null : matchAllSyntaxes(syntaxRules, createValidationContext(tokens), options);
|
|
27647
28754
|
if (doNotValidate || result != null) {
|
|
27648
28755
|
success = doNotValidate || result?.success;
|
|
@@ -27673,17 +28780,11 @@
|
|
|
27673
28780
|
stack.push(token);
|
|
27674
28781
|
continue;
|
|
27675
28782
|
}
|
|
28783
|
+
if (token.typ === exports.EnumToken.ColonTokenType && stack.length == 0) {
|
|
28784
|
+
stack.push(token);
|
|
28785
|
+
continue;
|
|
28786
|
+
}
|
|
27676
28787
|
switch (token.typ) {
|
|
27677
|
-
// case EnumToken.IdenTokenType:
|
|
27678
|
-
// if (tokens[i + 1]?.typ == EnumToken.StartParensTokenType) {
|
|
27679
|
-
// Object.assign(token, {
|
|
27680
|
-
// typ: EnumToken.FunctionTokenDefType,
|
|
27681
|
-
// });
|
|
27682
|
-
// token[LOCEND] = tokens[i + 1][LOCEND];
|
|
27683
|
-
// tokens.splice(i + 1, 1);
|
|
27684
|
-
// stack.push(token);
|
|
27685
|
-
// }
|
|
27686
|
-
// break;
|
|
27687
28788
|
case exports.EnumToken.Literal:
|
|
27688
28789
|
if (token.val === "/" && stack.at(-1)?.typ == exports.EnumToken.MathFunctionTokenDefType) {
|
|
27689
28790
|
Object.assign(token, {
|
|
@@ -27861,10 +28962,19 @@
|
|
|
27861
28962
|
}
|
|
27862
28963
|
if (trimTokenSpace$1.has(token.typ)) {
|
|
27863
28964
|
if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
|
|
27864
|
-
|
|
28965
|
+
for (let index = i + 1; index < tokens.length - 1; index++) {
|
|
28966
|
+
tokens[index] = tokens[index + 1];
|
|
28967
|
+
}
|
|
28968
|
+
tokens.length--;
|
|
28969
|
+
i--;
|
|
28970
|
+
continue;
|
|
27865
28971
|
}
|
|
27866
28972
|
if (tokens[i - 1]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
27867
|
-
|
|
28973
|
+
for (let index = i - 1; index < tokens.length - 1; index++) {
|
|
28974
|
+
tokens[index] = tokens[index + 1];
|
|
28975
|
+
}
|
|
28976
|
+
tokens.length--;
|
|
28977
|
+
i--;
|
|
27868
28978
|
}
|
|
27869
28979
|
}
|
|
27870
28980
|
}
|
|
@@ -27916,12 +29026,11 @@
|
|
|
27916
29026
|
name[STATE] = exports.EnumAstNodeStatus.Unknown;
|
|
27917
29027
|
name[ERRORS] = result?.errors ?? [];
|
|
27918
29028
|
// @ts-expect-error
|
|
27919
|
-
|
|
29029
|
+
return Object.assign(name, {
|
|
27920
29030
|
typ: exports.EnumToken.DeclarationNodeType,
|
|
27921
29031
|
nam: name.val,
|
|
27922
29032
|
val: tokens,
|
|
27923
29033
|
});
|
|
27924
|
-
return node;
|
|
27925
29034
|
}
|
|
27926
29035
|
if (equalsIgnoreCase("composes", name.val)) {
|
|
27927
29036
|
let index = -1;
|
|
@@ -28240,6 +29349,16 @@
|
|
|
28240
29349
|
val.splice(0, val.length, ...filteredValues);
|
|
28241
29350
|
}
|
|
28242
29351
|
}
|
|
29352
|
+
if (stack.at(-1)?.typ === exports.EnumToken.ColonTokenType) {
|
|
29353
|
+
if (name.startsWith("min-")) {
|
|
29354
|
+
filteredNames[0].val = name.substring(4);
|
|
29355
|
+
stack.at(-1).typ = exports.EnumToken.GteTokenType;
|
|
29356
|
+
}
|
|
29357
|
+
else if (name.startsWith("max-")) {
|
|
29358
|
+
filteredNames[0].val = name.substring(4);
|
|
29359
|
+
stack.at(-1).typ = exports.EnumToken.LteTokenType;
|
|
29360
|
+
}
|
|
29361
|
+
}
|
|
28243
29362
|
// @ts-expect-error
|
|
28244
29363
|
tokens.splice(index3 + 1, tokens.length - index3 - 2, {
|
|
28245
29364
|
typ: exports.EnumToken.MediaQueryConditionTokenType,
|
|
@@ -28295,6 +29414,61 @@
|
|
|
28295
29414
|
[LOCEND]: right.at(-1)[LOCEND],
|
|
28296
29415
|
};
|
|
28297
29416
|
tokens.length = l + 1;
|
|
29417
|
+
// media range query
|
|
29418
|
+
if (options.minify &&
|
|
29419
|
+
tokens[l].op.typ === exports.EnumToken.AndTokenType) {
|
|
29420
|
+
if (left.length === 1 &&
|
|
29421
|
+
left[0].typ == exports.EnumToken.ParensTokenType &&
|
|
29422
|
+
left[0].chi.length == 1 &&
|
|
29423
|
+
left[0].chi[0].typ == exports.EnumToken.MediaQueryConditionTokenType &&
|
|
29424
|
+
left[0].chi[0].l.length == 1 &&
|
|
29425
|
+
left[0].chi[0].l[0].typ ==
|
|
29426
|
+
exports.EnumToken.IdenTokenType &&
|
|
29427
|
+
(left[0].chi[0].op.typ ==
|
|
29428
|
+
exports.EnumToken.GtTokenType ||
|
|
29429
|
+
left[0].chi[0].op.typ ==
|
|
29430
|
+
exports.EnumToken.GteTokenType) &&
|
|
29431
|
+
right.length === 1 &&
|
|
29432
|
+
left[0].typ == exports.EnumToken.ParensTokenType &&
|
|
29433
|
+
right[0].chi.length == 1 &&
|
|
29434
|
+
right[0].chi[0].typ ==
|
|
29435
|
+
exports.EnumToken.MediaQueryConditionTokenType &&
|
|
29436
|
+
right[0].chi[0].l.length == 1 &&
|
|
29437
|
+
right[0].chi[0].l[0].typ ==
|
|
29438
|
+
exports.EnumToken.IdenTokenType &&
|
|
29439
|
+
(right[0].chi[0].op.typ ==
|
|
29440
|
+
exports.EnumToken.LtTokenType ||
|
|
29441
|
+
right[0].chi[0].op.typ ==
|
|
29442
|
+
exports.EnumToken.LteTokenType) &&
|
|
29443
|
+
equalsIgnoreCase(left[0].chi[0]
|
|
29444
|
+
.l[0].val, right[0].chi[0]
|
|
29445
|
+
.l[0].val)) {
|
|
29446
|
+
tokens[l] = {
|
|
29447
|
+
typ: exports.EnumToken.ParensTokenType,
|
|
29448
|
+
chi: [
|
|
29449
|
+
{
|
|
29450
|
+
typ: exports.EnumToken.MediaRangeQueryTokenType,
|
|
29451
|
+
op1: Object.assign(left[0].chi[0]
|
|
29452
|
+
.op, {
|
|
29453
|
+
typ: left[0]
|
|
29454
|
+
.chi[0].op.typ == exports.EnumToken.GteTokenType
|
|
29455
|
+
? exports.EnumToken.LteTokenType
|
|
29456
|
+
: exports.EnumToken.LtTokenType,
|
|
29457
|
+
}),
|
|
29458
|
+
op2: right[0].chi[0]
|
|
29459
|
+
.op,
|
|
29460
|
+
l: left[0].chi[0].r,
|
|
29461
|
+
val: left[0].chi[0]
|
|
29462
|
+
.l,
|
|
29463
|
+
r: right[0].chi[0].r,
|
|
29464
|
+
[LOCSRCID]: left[0][LOCSRCID],
|
|
29465
|
+
[LOCSTA]: left[0][LOCSTA],
|
|
29466
|
+
[LOCEND]: right.at(-1)[LOCEND],
|
|
29467
|
+
},
|
|
29468
|
+
],
|
|
29469
|
+
};
|
|
29470
|
+
}
|
|
29471
|
+
}
|
|
28298
29472
|
expectAndOrComma = true;
|
|
28299
29473
|
}
|
|
28300
29474
|
}
|
|
@@ -28733,7 +29907,7 @@
|
|
|
28733
29907
|
let i = 0;
|
|
28734
29908
|
let success = true;
|
|
28735
29909
|
let expectAndOr = false;
|
|
28736
|
-
let scope = new Set();
|
|
29910
|
+
// let scope: Set<EnumToken> = new Set();
|
|
28737
29911
|
const errors = [];
|
|
28738
29912
|
// const scopes: Array<Set<EnumToken>> = [scope];
|
|
28739
29913
|
for (; i < stream.length; i++) {
|
|
@@ -28755,7 +29929,7 @@
|
|
|
28755
29929
|
Object.assign(stream[i], {
|
|
28756
29930
|
typ: "or" === val ? exports.EnumToken.OrTokenType : exports.EnumToken.AndTokenType,
|
|
28757
29931
|
});
|
|
28758
|
-
scope.add(stream[i].typ);
|
|
29932
|
+
// scope.add(stream[i].typ);
|
|
28759
29933
|
stack.push(stream[i]);
|
|
28760
29934
|
// break;
|
|
28761
29935
|
}
|
|
@@ -29135,7 +30309,7 @@
|
|
|
29135
30309
|
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + context.nam);
|
|
29136
30310
|
const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
|
|
29137
30311
|
trimArray(stream);
|
|
29138
|
-
const { success, errors} = matchAllSyntaxes(syntax, createValidationContext(stream), options);
|
|
30312
|
+
const { success, errors /* , ...all */ } = matchAllSyntaxes(syntax, createValidationContext(stream), options);
|
|
29139
30313
|
return { success, errors };
|
|
29140
30314
|
}
|
|
29141
30315
|
|
|
@@ -29647,7 +30821,7 @@
|
|
|
29647
30821
|
}
|
|
29648
30822
|
/**
|
|
29649
30823
|
* Parse css string
|
|
29650
|
-
* @param
|
|
30824
|
+
* @param tokenizer
|
|
29651
30825
|
* @param options
|
|
29652
30826
|
*
|
|
29653
30827
|
* @throws Error
|
|
@@ -30644,6 +31818,7 @@
|
|
|
30644
31818
|
const imports = [];
|
|
30645
31819
|
let item;
|
|
30646
31820
|
let node;
|
|
31821
|
+
// @ts-ignore ignore error
|
|
30647
31822
|
let parensMatch = 0;
|
|
30648
31823
|
let curlyBracketMatch = 0;
|
|
30649
31824
|
let tokenizer = iter instanceof Promise ? await iter : iter;
|
|
@@ -32606,17 +33781,18 @@
|
|
|
32606
33781
|
* console.log(declarations);
|
|
32607
33782
|
* ```
|
|
32608
33783
|
*/
|
|
32609
|
-
|
|
33784
|
+
function parseDeclarations(declaration) {
|
|
32610
33785
|
const stream = `.x{${declaration}}`;
|
|
32611
|
-
|
|
33786
|
+
const result = doParseSync(new Tokenizer({
|
|
32612
33787
|
stream,
|
|
32613
33788
|
offset: 0,
|
|
32614
33789
|
position: 0,
|
|
32615
33790
|
source: new SourceFile(stream, [], ""),
|
|
32616
33791
|
currentPosition: 0,
|
|
32617
|
-
}), { setParent: false, minify: false, validation: false })
|
|
32618
|
-
|
|
32619
|
-
|
|
33792
|
+
}), { setParent: false, minify: false, validation: false });
|
|
33793
|
+
// .then((result) => {
|
|
33794
|
+
return result.ast.chi[0].chi.filter((t) => t.typ == exports.EnumToken.DeclarationNodeType || t.typ == exports.EnumToken.CommentNodeType);
|
|
33795
|
+
// });
|
|
32620
33796
|
}
|
|
32621
33797
|
/**
|
|
32622
33798
|
* Parse css string and return an array of tokens
|
|
@@ -32641,14 +33817,6 @@
|
|
|
32641
33817
|
* ```
|
|
32642
33818
|
*/
|
|
32643
33819
|
function parseString(src, options = { parseColor: true }, errors) {
|
|
32644
|
-
// const parseInfo: ParseInfo = {
|
|
32645
|
-
// stream: src,
|
|
32646
|
-
// offset: 0,
|
|
32647
|
-
// time: 0,
|
|
32648
|
-
// source: new SourceFile(src, [], ""),
|
|
32649
|
-
// position: 0,
|
|
32650
|
-
// currentPosition: 0,
|
|
32651
|
-
// };
|
|
32652
33820
|
const tokenizer = new Tokenizer({
|
|
32653
33821
|
stream: src,
|
|
32654
33822
|
buffer: "",
|
|
@@ -33256,13 +34424,10 @@
|
|
|
33256
34424
|
const parseResult = parseSync(stream, options);
|
|
33257
34425
|
let mapping = null;
|
|
33258
34426
|
let importMapping = null;
|
|
33259
|
-
if (typeof options.module == "number" && options.module & exports.ModuleScopeEnumOptions.ICSS)
|
|
33260
|
-
|
|
33261
|
-
|
|
33262
|
-
|
|
33263
|
-
else if (typeof options.module == "object" &&
|
|
33264
|
-
typeof options.module.scoped == "number" &&
|
|
33265
|
-
options.module.scoped & exports.ModuleScopeEnumOptions.ICSS) {
|
|
34427
|
+
if ((typeof options.module == "number" && options.module & exports.ModuleScopeEnumOptions.ICSS) ||
|
|
34428
|
+
(typeof options.module == "object" &&
|
|
34429
|
+
typeof options.module.scoped == "number" &&
|
|
34430
|
+
options.module.scoped & exports.ModuleScopeEnumOptions.ICSS)) {
|
|
33266
34431
|
mapping = parseResult.mapping;
|
|
33267
34432
|
importMapping = parseResult.importMapping;
|
|
33268
34433
|
}
|
|
@@ -33434,13 +34599,10 @@
|
|
|
33434
34599
|
return parse(stream, options).then((parseResult) => {
|
|
33435
34600
|
let mapping = null;
|
|
33436
34601
|
let importMapping = null;
|
|
33437
|
-
if (typeof options.module == "number" && options.module & exports.ModuleScopeEnumOptions.ICSS)
|
|
33438
|
-
|
|
33439
|
-
|
|
33440
|
-
|
|
33441
|
-
else if (typeof options.module == "object" &&
|
|
33442
|
-
typeof options.module.scoped == "number" &&
|
|
33443
|
-
options.module.scoped & exports.ModuleScopeEnumOptions.ICSS) {
|
|
34602
|
+
if ((typeof options.module == "number" && options.module & exports.ModuleScopeEnumOptions.ICSS) ||
|
|
34603
|
+
(typeof options.module == "object" &&
|
|
34604
|
+
typeof options.module.scoped == "number" &&
|
|
34605
|
+
options.module.scoped & exports.ModuleScopeEnumOptions.ICSS)) {
|
|
33444
34606
|
mapping = parseResult.mapping;
|
|
33445
34607
|
importMapping = parseResult.importMapping;
|
|
33446
34608
|
}
|