@tbela99/css-parser 0.4.1 → 0.5.1
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/README.md +69 -12
- package/dist/config.json.js +9 -9
- package/dist/index-umd-web.js +392 -346
- package/dist/index.cjs +389 -345
- package/dist/index.d.ts +33 -20
- package/dist/lib/ast/features/calc.js +2 -4
- package/dist/lib/ast/features/inlinecssvariables.js +5 -4
- package/dist/lib/ast/features/shorthand.js +2 -3
- package/dist/lib/ast/minify.js +2 -2
- package/dist/lib/ast/walk.js +10 -12
- package/dist/lib/iterable/weakset.js +31 -21
- package/dist/lib/parser/declaration/list.js +1 -6
- package/dist/lib/parser/declaration/map.js +35 -11
- package/dist/lib/parser/declaration/set.js +2 -0
- package/dist/lib/parser/parse.js +210 -181
- package/dist/lib/parser/utils/eq.js +1 -1
- package/dist/lib/parser/utils/syntax.js +9 -5
- package/dist/lib/renderer/color/color.js +38 -1
- package/dist/lib/renderer/color/colormix.js +5 -6
- package/dist/lib/renderer/color/hsl.js +1 -2
- package/dist/lib/renderer/color/hwb.js +2 -3
- package/dist/lib/renderer/color/oklab.js +2 -3
- package/dist/lib/renderer/color/oklch.js +2 -3
- package/dist/lib/renderer/color/relativecolor.js +2 -6
- package/dist/lib/renderer/color/srgb.js +1 -5
- package/dist/lib/renderer/color/utils/constants.js +2 -2
- package/dist/lib/renderer/render.js +16 -3
- package/dist/web/load.js +3 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -177,7 +177,7 @@ const colorRange = {
|
|
|
177
177
|
}
|
|
178
178
|
};
|
|
179
179
|
const colorFuncColorSpace = ['srgb', 'srgb-linear', 'display-p3', 'prophoto-rgb', 'a98-rgb', 'rec2020', 'xyz', 'xyz-d65', 'xyz-d50'];
|
|
180
|
-
|
|
180
|
+
({ typ: exports.EnumToken.IdenTokenType, val: 'none' });
|
|
181
181
|
const D50 = [0.3457 / 0.3585, 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585];
|
|
182
182
|
const k = Math.pow(29, 3) / Math.pow(3, 3);
|
|
183
183
|
const e = Math.pow(6, 3) / Math.pow(29, 3);
|
|
@@ -557,42 +557,6 @@ function getLCHComponents(token) {
|
|
|
557
557
|
return alpha == null ? [l, c, h] : [l, c, h, alpha];
|
|
558
558
|
}
|
|
559
559
|
|
|
560
|
-
function eq(a, b) {
|
|
561
|
-
if (a == null || b == null) {
|
|
562
|
-
return a == b;
|
|
563
|
-
}
|
|
564
|
-
if (typeof a != 'object' || typeof b != 'object') {
|
|
565
|
-
return a === b;
|
|
566
|
-
}
|
|
567
|
-
if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) {
|
|
568
|
-
return false;
|
|
569
|
-
}
|
|
570
|
-
if (Array.isArray(a)) {
|
|
571
|
-
if (a.length != b.length) {
|
|
572
|
-
return false;
|
|
573
|
-
}
|
|
574
|
-
let i = 0;
|
|
575
|
-
for (; i < a.length; i++) {
|
|
576
|
-
if (!eq(a[i], b[i])) {
|
|
577
|
-
return false;
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
return true;
|
|
581
|
-
}
|
|
582
|
-
const k1 = Object.keys(a);
|
|
583
|
-
const k2 = Object.keys(b);
|
|
584
|
-
if (k1.length != k2.length) {
|
|
585
|
-
return false;
|
|
586
|
-
}
|
|
587
|
-
let key;
|
|
588
|
-
for (key of k1) {
|
|
589
|
-
if (!(key in b) || !eq(a[key], b[key])) {
|
|
590
|
-
return false;
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
return true;
|
|
594
|
-
}
|
|
595
|
-
|
|
596
560
|
function hex2oklch(token) {
|
|
597
561
|
// @ts-ignore
|
|
598
562
|
return lab2lchvalues(...hex2oklab(token));
|
|
@@ -642,7 +606,7 @@ function getOKLCHComponents(token) {
|
|
|
642
606
|
// @ts-ignore
|
|
643
607
|
t = components[3];
|
|
644
608
|
// @ts-ignore
|
|
645
|
-
const alpha = t == null ||
|
|
609
|
+
const alpha = t == null || (t.typ == exports.EnumToken.IdenTokenType && t.val == 'none') ? 1 : getNumber(t);
|
|
646
610
|
return [l, c, h, alpha];
|
|
647
611
|
}
|
|
648
612
|
|
|
@@ -701,7 +665,7 @@ function getOKLABComponents(token) {
|
|
|
701
665
|
// @ts-ignore
|
|
702
666
|
t = components[3];
|
|
703
667
|
// @ts-ignore
|
|
704
|
-
const alpha = t == null ||
|
|
668
|
+
const alpha = t == null || (t.typ == exports.EnumToken.IdenTokenType && t.val == 'none') ? 1 : getNumber(t);
|
|
705
669
|
const rgb = [l, a, b];
|
|
706
670
|
if (alpha != 1 && alpha != null) {
|
|
707
671
|
rgb.push(alpha);
|
|
@@ -906,10 +870,7 @@ function srgbvalues(token) {
|
|
|
906
870
|
return null;
|
|
907
871
|
}
|
|
908
872
|
function rgb2srgb(token) {
|
|
909
|
-
return getComponents(token).map((t, index) => index == 3 ? (
|
|
910
|
-
typ: exports.EnumToken.IdenTokenType,
|
|
911
|
-
val: 'none'
|
|
912
|
-
}) ? 1 : getNumber(t)) : (t.typ == exports.EnumToken.PercentageTokenType ? 255 : 1) * getNumber(t) / 255);
|
|
873
|
+
return getComponents(token).map((t, index) => index == 3 ? ((t.typ == exports.EnumToken.IdenTokenType && t.val == 'none') ? 1 : getNumber(t)) : (t.typ == exports.EnumToken.PercentageTokenType ? 255 : 1) * getNumber(t) / 255);
|
|
913
874
|
}
|
|
914
875
|
function hex2srgb(token) {
|
|
915
876
|
const value = expandHexValue(token.kin == 'lit' ? COLORS_NAMES[token.val.toLowerCase()] : token.val);
|
|
@@ -1196,7 +1157,7 @@ function rgb2hsl(token) {
|
|
|
1196
1157
|
t = chi[3];
|
|
1197
1158
|
// @ts-ignore
|
|
1198
1159
|
let a = null;
|
|
1199
|
-
if (t != null && !
|
|
1160
|
+
if (t != null && !(t.typ == exports.EnumToken.IdenTokenType && t.val == 'none')) {
|
|
1200
1161
|
// @ts-ignore
|
|
1201
1162
|
a = getNumber(t) / 255;
|
|
1202
1163
|
}
|
|
@@ -1282,7 +1243,7 @@ function srgb2hsl(r, g, b, a = null) {
|
|
|
1282
1243
|
function rgb2hwb(token) {
|
|
1283
1244
|
// @ts-ignore
|
|
1284
1245
|
return srgb2hwb(...getComponents(token).map((t, index) => {
|
|
1285
|
-
if (index == 3 &&
|
|
1246
|
+
if (index == 3 && t.typ == exports.EnumToken.IdenTokenType && t.val == 'none') {
|
|
1286
1247
|
return 1;
|
|
1287
1248
|
}
|
|
1288
1249
|
return getNumber(t) / 255;
|
|
@@ -1291,7 +1252,7 @@ function rgb2hwb(token) {
|
|
|
1291
1252
|
function hsl2hwb(token) {
|
|
1292
1253
|
// @ts-ignore
|
|
1293
1254
|
return hsl2hwbvalues(...getComponents(token).map((t, index) => {
|
|
1294
|
-
if (index == 3 &&
|
|
1255
|
+
if (index == 3 && (t.typ == exports.EnumToken.IdenTokenType && t.val == 'none')) {
|
|
1295
1256
|
return 1;
|
|
1296
1257
|
}
|
|
1297
1258
|
if (index == 0) {
|
|
@@ -1912,10 +1873,47 @@ function convert(token, to) {
|
|
|
1912
1873
|
case 'lch':
|
|
1913
1874
|
values.push(...lch2srgb(token));
|
|
1914
1875
|
break;
|
|
1915
|
-
case '
|
|
1876
|
+
case 'oklch':
|
|
1916
1877
|
// @ts-ignore
|
|
1917
1878
|
values.push(...srgb2oklch(...color2srgbvalues(token)));
|
|
1918
1879
|
break;
|
|
1880
|
+
case 'color':
|
|
1881
|
+
const val = color2srgbvalues(token);
|
|
1882
|
+
switch (to) {
|
|
1883
|
+
case 'srgb':
|
|
1884
|
+
values.push(...val);
|
|
1885
|
+
break;
|
|
1886
|
+
case 'srgb-linear':
|
|
1887
|
+
// @ts-ignore
|
|
1888
|
+
values.push(...srgb2lsrgbvalues(...val));
|
|
1889
|
+
break;
|
|
1890
|
+
case 'display-p3':
|
|
1891
|
+
// @ts-ignore
|
|
1892
|
+
values.push(...srgb2p3values(...val));
|
|
1893
|
+
break;
|
|
1894
|
+
case 'prophoto-rgb':
|
|
1895
|
+
// @ts-ignore
|
|
1896
|
+
values.push(...srgb2prophotorgbvalues(...val));
|
|
1897
|
+
break;
|
|
1898
|
+
case 'a98-rgb':
|
|
1899
|
+
// @ts-ignore
|
|
1900
|
+
values.push(...srgb2a98values(...val));
|
|
1901
|
+
break;
|
|
1902
|
+
case 'rec2020':
|
|
1903
|
+
// @ts-ignore
|
|
1904
|
+
values.push(...srgb2rec2020values(...val));
|
|
1905
|
+
break;
|
|
1906
|
+
case 'xyz':
|
|
1907
|
+
case 'xyz-d65':
|
|
1908
|
+
// @ts-ignore
|
|
1909
|
+
values.push(...srgb2xyz(...val));
|
|
1910
|
+
break;
|
|
1911
|
+
case 'xyz-d50':
|
|
1912
|
+
// @ts-ignore
|
|
1913
|
+
values.push(...(XYZ_D65_to_D50(...srgb2xyz(...val))));
|
|
1914
|
+
break;
|
|
1915
|
+
}
|
|
1916
|
+
break;
|
|
1919
1917
|
}
|
|
1920
1918
|
if (values.length > 0) {
|
|
1921
1919
|
return values2colortoken(values, to);
|
|
@@ -2189,10 +2187,10 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
|
|
|
2189
2187
|
}
|
|
2190
2188
|
const components1 = getComponents(color1);
|
|
2191
2189
|
const components2 = getComponents(color2);
|
|
2192
|
-
if (
|
|
2190
|
+
if ((components1[3] != null && components1[3].typ == exports.EnumToken.IdenTokenType && components1[3].val == 'none') && values2.length == 4) {
|
|
2193
2191
|
values1[3] = values2[3];
|
|
2194
2192
|
}
|
|
2195
|
-
if (
|
|
2193
|
+
if ((components2[3] != null && components2[3].typ == exports.EnumToken.IdenTokenType && components2[3].val == 'none') && values1.length == 4) {
|
|
2196
2194
|
values2[3] = values1[3];
|
|
2197
2195
|
}
|
|
2198
2196
|
const p1 = getNumber(percentage1);
|
|
@@ -2304,13 +2302,13 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
|
|
|
2304
2302
|
const lchSpaces = ['lch', 'oklch'];
|
|
2305
2303
|
// powerless
|
|
2306
2304
|
if (lchSpaces.includes(color1.kin) || lchSpaces.includes(colorSpace.val)) {
|
|
2307
|
-
if (
|
|
2305
|
+
if ((components1[2].typ == exports.EnumToken.IdenTokenType && components1[2].val == 'none') || values1[2] == 0) {
|
|
2308
2306
|
values1[2] = values2[2];
|
|
2309
2307
|
}
|
|
2310
2308
|
}
|
|
2311
2309
|
// powerless
|
|
2312
2310
|
if (lchSpaces.includes(color1.kin) || lchSpaces.includes(colorSpace.val)) {
|
|
2313
|
-
if (
|
|
2311
|
+
if ((components2[2].typ == exports.EnumToken.IdenTokenType && components2[2].val == 'none') || values2[2] == 0) {
|
|
2314
2312
|
values2[2] = values1[2];
|
|
2315
2313
|
}
|
|
2316
2314
|
}
|
|
@@ -2741,10 +2739,7 @@ function parseRelativeColor(relativeKeys, original, rExp, gExp, bExp, aExp) {
|
|
|
2741
2739
|
[names[1]]: getValue(g, converted, names[1]), // string,
|
|
2742
2740
|
[names[2]]: getValue(b, converted, names[2]),
|
|
2743
2741
|
// @ts-ignore
|
|
2744
|
-
alpha: alpha == null ||
|
|
2745
|
-
typ: exports.EnumToken.IdenTokenType,
|
|
2746
|
-
val: 'none'
|
|
2747
|
-
}) ? {
|
|
2742
|
+
alpha: alpha == null || (alpha.typ == exports.EnumToken.IdenTokenType && alpha.val == 'none') ? {
|
|
2748
2743
|
typ: exports.EnumToken.NumberTokenType,
|
|
2749
2744
|
val: '1'
|
|
2750
2745
|
} : (alpha.typ == exports.EnumToken.PercentageTokenType ? {
|
|
@@ -2757,7 +2752,7 @@ function parseRelativeColor(relativeKeys, original, rExp, gExp, bExp, aExp) {
|
|
|
2757
2752
|
[names[1]]: getValue(gExp, converted, names[1]),
|
|
2758
2753
|
[names[2]]: getValue(bExp, converted, names[2]),
|
|
2759
2754
|
// @ts-ignore
|
|
2760
|
-
alpha: getValue(aExp == null ||
|
|
2755
|
+
alpha: getValue(aExp == null || (aExp.typ == exports.EnumToken.IdenTokenType && aExp.val == 'none') ? {
|
|
2761
2756
|
typ: exports.EnumToken.NumberTokenType,
|
|
2762
2757
|
val: '1'
|
|
2763
2758
|
} : aExp)
|
|
@@ -2995,6 +2990,19 @@ function doRender(data, options = {}) {
|
|
|
2995
2990
|
removeComments: false,
|
|
2996
2991
|
}), sourcemap: false, convertColor: true, expandNestingRules: false, preserveLicense: false, ...options
|
|
2997
2992
|
};
|
|
2993
|
+
if (options.withParents) {
|
|
2994
|
+
// @ts-ignore
|
|
2995
|
+
let parent = data.parent;
|
|
2996
|
+
// @ts-ignore
|
|
2997
|
+
while (data.parent != null) {
|
|
2998
|
+
// @ts-ignore
|
|
2999
|
+
parent = { ...data.parent, chi: [{ ...data }] };
|
|
3000
|
+
// @ts-ignore
|
|
3001
|
+
parent.parent = data.parent.parent;
|
|
3002
|
+
// @ts-ignore
|
|
3003
|
+
data = parent;
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
2998
3006
|
const startTime = performance.now();
|
|
2999
3007
|
const errors = [];
|
|
3000
3008
|
const sourcemap = options.sourcemap ? new SourceMap : null;
|
|
@@ -3061,7 +3069,7 @@ function renderAstNode(data, options, sourcemap, position, errors, reducer, cach
|
|
|
3061
3069
|
return `${data.nam}:${options.indent}${data.val.reduce(reducer, '')}`;
|
|
3062
3070
|
case exports.EnumToken.CommentNodeType:
|
|
3063
3071
|
case exports.EnumToken.CDOCOMMNodeType:
|
|
3064
|
-
if (data.val.startsWith('
|
|
3072
|
+
if (data.val.startsWith('/*# sourceMappingURL=')) {
|
|
3065
3073
|
// ignore sourcemap
|
|
3066
3074
|
return '';
|
|
3067
3075
|
}
|
|
@@ -3073,12 +3081,12 @@ function renderAstNode(data, options, sourcemap, position, errors, reducer, cach
|
|
|
3073
3081
|
return css;
|
|
3074
3082
|
}
|
|
3075
3083
|
if (css === '') {
|
|
3076
|
-
if (sourcemap != null) {
|
|
3084
|
+
if (sourcemap != null && node.loc != null) {
|
|
3077
3085
|
updateSourceMap(node, options, cache, sourcemap, position, str);
|
|
3078
3086
|
}
|
|
3079
3087
|
return str;
|
|
3080
3088
|
}
|
|
3081
|
-
if (sourcemap != null) {
|
|
3089
|
+
if (sourcemap != null && node.loc != null) {
|
|
3082
3090
|
update(position, options.newLine);
|
|
3083
3091
|
updateSourceMap(node, options, cache, sourcemap, position, str);
|
|
3084
3092
|
}
|
|
@@ -3510,14 +3518,14 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
3510
3518
|
// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token
|
|
3511
3519
|
// '\\'
|
|
3512
3520
|
const REVERSE_SOLIDUS = 0x5c;
|
|
3513
|
-
const dimensionUnits = [
|
|
3521
|
+
const dimensionUnits = new Set([
|
|
3514
3522
|
'q', 'cap', 'ch', 'cm', 'cqb', 'cqh', 'cqi', 'cqmax', 'cqmin', 'cqw', 'dvb',
|
|
3515
3523
|
'dvh', 'dvi', 'dvmax', 'dvmin', 'dvw', 'em', 'ex', 'ic', 'in', 'lh', 'lvb',
|
|
3516
3524
|
'lvh', 'lvi', 'lvmax', 'lvw', 'mm', 'pc', 'pt', 'px', 'rem', 'rlh', 'svb',
|
|
3517
3525
|
'svh', 'svi', 'svmin', 'svw', 'vb', 'vh', 'vi', 'vmax', 'vmin', 'vw'
|
|
3518
|
-
];
|
|
3526
|
+
]);
|
|
3519
3527
|
function isLength(dimension) {
|
|
3520
|
-
return 'unit' in dimension && dimensionUnits.
|
|
3528
|
+
return 'unit' in dimension && dimensionUnits.has(dimension.unit.toLowerCase());
|
|
3521
3529
|
}
|
|
3522
3530
|
function isResolution(dimension) {
|
|
3523
3531
|
return 'unit' in dimension && ['dpi', 'dpcm', 'dppx', 'x'].includes(dimension.unit.toLowerCase());
|
|
@@ -3577,7 +3585,7 @@ function isColor(token) {
|
|
|
3577
3585
|
for (let i = 1; i < children.length - 2; i++) {
|
|
3578
3586
|
if (children[i].typ == exports.EnumToken.IdenTokenType) {
|
|
3579
3587
|
if (children[i].val != 'none' &&
|
|
3580
|
-
!(isRelative && ['alpha', 'r', 'g', 'b'].includes(children[i].val) || isColorspace(children[i]))) {
|
|
3588
|
+
!(isRelative && ['alpha', 'r', 'g', 'b', 'x', 'y', 'z'].includes(children[i].val) || isColorspace(children[i]))) {
|
|
3581
3589
|
return false;
|
|
3582
3590
|
}
|
|
3583
3591
|
}
|
|
@@ -3585,10 +3593,14 @@ function isColor(token) {
|
|
|
3585
3593
|
return false;
|
|
3586
3594
|
}
|
|
3587
3595
|
}
|
|
3596
|
+
if (children.length == 4 || (isRelative && children.length == 6)) {
|
|
3597
|
+
return true;
|
|
3598
|
+
}
|
|
3588
3599
|
if (children.length == 8 || children.length == 6) {
|
|
3589
3600
|
const sep = children.at(-2);
|
|
3590
3601
|
const alpha = children.at(-1);
|
|
3591
|
-
|
|
3602
|
+
// @ts-ignore
|
|
3603
|
+
if ((children.length > 6 || !isRelative) && sep.typ != exports.EnumToken.LiteralTokenType || sep.val != '/') {
|
|
3592
3604
|
return false;
|
|
3593
3605
|
}
|
|
3594
3606
|
if (alpha.typ == exports.EnumToken.IdenTokenType && alpha.val != 'none') {
|
|
@@ -4290,18 +4302,18 @@ var map = {
|
|
|
4290
4302
|
"initial"
|
|
4291
4303
|
],
|
|
4292
4304
|
"default": [
|
|
4293
|
-
"0",
|
|
4294
|
-
"0 1",
|
|
4295
|
-
"0 auto",
|
|
4296
|
-
"0 1 auto"
|
|
4297
4305
|
],
|
|
4306
|
+
mapping: {
|
|
4307
|
+
"0 1 auto": "initial",
|
|
4308
|
+
"0 0 auto": "none",
|
|
4309
|
+
"1 1 auto": "auto"
|
|
4310
|
+
},
|
|
4298
4311
|
properties: {
|
|
4299
4312
|
"flex-grow": {
|
|
4300
4313
|
required: true,
|
|
4301
4314
|
keywords: [
|
|
4302
4315
|
],
|
|
4303
4316
|
"default": [
|
|
4304
|
-
"0"
|
|
4305
4317
|
],
|
|
4306
4318
|
types: [
|
|
4307
4319
|
"Number"
|
|
@@ -4311,7 +4323,6 @@ var map = {
|
|
|
4311
4323
|
keywords: [
|
|
4312
4324
|
],
|
|
4313
4325
|
"default": [
|
|
4314
|
-
"1"
|
|
4315
4326
|
],
|
|
4316
4327
|
types: [
|
|
4317
4328
|
"Number"
|
|
@@ -4327,7 +4338,6 @@ var map = {
|
|
|
4327
4338
|
"auto"
|
|
4328
4339
|
],
|
|
4329
4340
|
"default": [
|
|
4330
|
-
"auto"
|
|
4331
4341
|
],
|
|
4332
4342
|
types: [
|
|
4333
4343
|
"Length",
|
|
@@ -4987,8 +4997,8 @@ var map = {
|
|
|
4987
4997
|
"Number"
|
|
4988
4998
|
],
|
|
4989
4999
|
"default": [
|
|
4990
|
-
"
|
|
4991
|
-
"
|
|
5000
|
+
"400",
|
|
5001
|
+
"normal"
|
|
4992
5002
|
],
|
|
4993
5003
|
keywords: [
|
|
4994
5004
|
"normal",
|
|
@@ -5343,6 +5353,8 @@ var map = {
|
|
|
5343
5353
|
left: "0",
|
|
5344
5354
|
top: "0",
|
|
5345
5355
|
center: "50%",
|
|
5356
|
+
"center center": "50%",
|
|
5357
|
+
"50% 50%": "50%",
|
|
5346
5358
|
bottom: "100%",
|
|
5347
5359
|
right: "100%"
|
|
5348
5360
|
},
|
|
@@ -6027,194 +6039,229 @@ const BadTokensTypes = [
|
|
|
6027
6039
|
exports.EnumToken.BadUrlTokenType,
|
|
6028
6040
|
exports.EnumToken.BadStringTokenType
|
|
6029
6041
|
];
|
|
6042
|
+
const enumTokenHints = new Set([
|
|
6043
|
+
exports.EnumToken.WhitespaceTokenType, exports.EnumToken.SemiColonTokenType, exports.EnumToken.ColonTokenType, exports.EnumToken.BlockStartTokenType,
|
|
6044
|
+
exports.EnumToken.BlockStartTokenType, exports.EnumToken.AttrStartTokenType, exports.EnumToken.AttrEndTokenType, exports.EnumToken.StartParensTokenType, exports.EnumToken.EndParensTokenType,
|
|
6045
|
+
exports.EnumToken.CommaTokenType, exports.EnumToken.GtTokenType, exports.EnumToken.LtTokenType, exports.EnumToken.GteTokenType, exports.EnumToken.LteTokenType, exports.EnumToken.CommaTokenType,
|
|
6046
|
+
exports.EnumToken.StartMatchTokenType, exports.EnumToken.EndMatchTokenType, exports.EnumToken.IncludeMatchTokenType, exports.EnumToken.DashMatchTokenType, exports.EnumToken.ContainMatchTokenType,
|
|
6047
|
+
exports.EnumToken.EOFTokenType
|
|
6048
|
+
]);
|
|
6030
6049
|
const webkitPseudoAliasMap = {
|
|
6031
6050
|
'-webkit-autofill': 'autofill'
|
|
6032
6051
|
};
|
|
6052
|
+
function reject(reason) {
|
|
6053
|
+
throw new Error(reason ?? 'Parsing aborted');
|
|
6054
|
+
}
|
|
6033
6055
|
async function doParse(iterator, options = {}) {
|
|
6034
|
-
return new Promise(async (resolve, reject) => {
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6056
|
+
// return new Promise(async (resolve, reject) => {
|
|
6057
|
+
if (options.signal != null) {
|
|
6058
|
+
options.signal.addEventListener('abort', reject);
|
|
6059
|
+
}
|
|
6060
|
+
options = {
|
|
6061
|
+
src: '',
|
|
6062
|
+
sourcemap: false,
|
|
6063
|
+
minify: true,
|
|
6064
|
+
parseColor: true,
|
|
6065
|
+
nestingRules: false,
|
|
6066
|
+
resolveImport: false,
|
|
6067
|
+
resolveUrls: false,
|
|
6068
|
+
removeCharset: true,
|
|
6069
|
+
removeEmpty: true,
|
|
6070
|
+
removeDuplicateDeclarations: true,
|
|
6071
|
+
computeShorthand: true,
|
|
6072
|
+
computeCalcExpression: true,
|
|
6073
|
+
inlineCssVariables: false,
|
|
6074
|
+
setParent: true,
|
|
6075
|
+
...options
|
|
6076
|
+
};
|
|
6077
|
+
if (options.expandNestingRules) {
|
|
6078
|
+
options.nestingRules = false;
|
|
6079
|
+
}
|
|
6080
|
+
if (options.resolveImport) {
|
|
6081
|
+
options.resolveUrls = true;
|
|
6082
|
+
}
|
|
6083
|
+
const startTime = performance.now();
|
|
6084
|
+
const errors = [];
|
|
6085
|
+
const src = options.src;
|
|
6086
|
+
const stack = [];
|
|
6087
|
+
const stats = {
|
|
6088
|
+
bytesIn: 0,
|
|
6089
|
+
importedBytesIn: 0,
|
|
6090
|
+
parse: `0ms`,
|
|
6091
|
+
minify: `0ms`,
|
|
6092
|
+
total: `0ms`
|
|
6093
|
+
};
|
|
6094
|
+
let ast = {
|
|
6095
|
+
typ: exports.EnumToken.StyleSheetNodeType,
|
|
6096
|
+
chi: []
|
|
6097
|
+
};
|
|
6098
|
+
let tokens = [];
|
|
6099
|
+
let map = new Map;
|
|
6100
|
+
let context = ast;
|
|
6101
|
+
if (options.sourcemap) {
|
|
6102
|
+
ast.loc = {
|
|
6103
|
+
sta: {
|
|
6104
|
+
ind: 0,
|
|
6105
|
+
lin: 1,
|
|
6106
|
+
col: 1
|
|
6107
|
+
},
|
|
6108
|
+
src: ''
|
|
6074
6109
|
};
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
src: ''
|
|
6086
|
-
};
|
|
6110
|
+
}
|
|
6111
|
+
const iter = tokenize(iterator);
|
|
6112
|
+
let item;
|
|
6113
|
+
while (item = iter.next().value) {
|
|
6114
|
+
stats.bytesIn = item.bytesIn;
|
|
6115
|
+
//
|
|
6116
|
+
// doParse error
|
|
6117
|
+
if (item.hint != null && BadTokensTypes.includes(item.hint)) {
|
|
6118
|
+
// bad token
|
|
6119
|
+
continue;
|
|
6087
6120
|
}
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
// bad token
|
|
6096
|
-
continue;
|
|
6097
|
-
}
|
|
6098
|
-
if (item.hint != exports.EnumToken.EOFTokenType) {
|
|
6099
|
-
tokens.push(item);
|
|
6100
|
-
}
|
|
6101
|
-
if (item.token == ';' || item.token == '{') {
|
|
6102
|
-
let node = await parseNode(tokens, context, stats, options, errors, src, map);
|
|
6103
|
-
if (node != null) {
|
|
6104
|
-
stack.push(node);
|
|
6105
|
-
// @ts-ignore
|
|
6106
|
-
context = node;
|
|
6107
|
-
}
|
|
6108
|
-
else if (item.token == '{') {
|
|
6109
|
-
// node == null
|
|
6110
|
-
// consume and throw away until the closing '}' or EOF
|
|
6111
|
-
let inBlock = 1;
|
|
6112
|
-
do {
|
|
6113
|
-
item = iter.next().value;
|
|
6114
|
-
if (item == null) {
|
|
6115
|
-
break;
|
|
6116
|
-
}
|
|
6117
|
-
if (item.token == '{') {
|
|
6118
|
-
inBlock++;
|
|
6119
|
-
}
|
|
6120
|
-
else if (item.token == '}') {
|
|
6121
|
-
inBlock--;
|
|
6122
|
-
}
|
|
6123
|
-
} while (inBlock != 0);
|
|
6124
|
-
}
|
|
6125
|
-
tokens = [];
|
|
6126
|
-
map = new Map;
|
|
6127
|
-
}
|
|
6128
|
-
else if (item.token == '}') {
|
|
6129
|
-
await parseNode(tokens, context, stats, options, errors, src, map);
|
|
6130
|
-
const previousNode = stack.pop();
|
|
6131
|
-
// @ts-ignore
|
|
6132
|
-
context = stack[stack.length - 1] || ast;
|
|
6121
|
+
if (item.hint != exports.EnumToken.EOFTokenType) {
|
|
6122
|
+
tokens.push(item);
|
|
6123
|
+
}
|
|
6124
|
+
if (item.token == ';' || item.token == '{') {
|
|
6125
|
+
let node = await parseNode(tokens, context, stats, options, errors, src, map);
|
|
6126
|
+
if (node != null) {
|
|
6127
|
+
stack.push(node);
|
|
6133
6128
|
// @ts-ignore
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6129
|
+
context = node;
|
|
6130
|
+
}
|
|
6131
|
+
else if (item.token == '{') {
|
|
6132
|
+
// node == null
|
|
6133
|
+
// consume and throw away until the closing '}' or EOF
|
|
6134
|
+
let inBlock = 1;
|
|
6135
|
+
do {
|
|
6136
|
+
item = iter.next().value;
|
|
6137
|
+
if (item == null) {
|
|
6138
|
+
break;
|
|
6139
|
+
}
|
|
6140
|
+
if (item.token == '{') {
|
|
6141
|
+
inBlock++;
|
|
6142
|
+
}
|
|
6143
|
+
else if (item.token == '}') {
|
|
6144
|
+
inBlock--;
|
|
6145
|
+
}
|
|
6146
|
+
} while (inBlock != 0);
|
|
6139
6147
|
}
|
|
6148
|
+
tokens = [];
|
|
6149
|
+
map = new Map;
|
|
6140
6150
|
}
|
|
6141
|
-
if (
|
|
6151
|
+
else if (item.token == '}') {
|
|
6142
6152
|
await parseNode(tokens, context, stats, options, errors, src, map);
|
|
6143
|
-
}
|
|
6144
|
-
while (stack.length > 0 && context != ast) {
|
|
6145
6153
|
const previousNode = stack.pop();
|
|
6146
6154
|
// @ts-ignore
|
|
6147
|
-
context = stack[stack.length - 1]
|
|
6155
|
+
context = stack[stack.length - 1] || ast;
|
|
6148
6156
|
// @ts-ignore
|
|
6149
6157
|
if (options.removeEmpty && previousNode != null && previousNode.chi.length == 0 && context.chi[context.chi.length - 1] == previousNode) {
|
|
6150
6158
|
context.chi.pop();
|
|
6151
|
-
continue;
|
|
6152
6159
|
}
|
|
6153
|
-
|
|
6160
|
+
tokens = [];
|
|
6161
|
+
map = new Map;
|
|
6154
6162
|
}
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6163
|
+
}
|
|
6164
|
+
if (tokens.length > 0) {
|
|
6165
|
+
await parseNode(tokens, context, stats, options, errors, src, map);
|
|
6166
|
+
}
|
|
6167
|
+
while (stack.length > 0 && context != ast) {
|
|
6168
|
+
const previousNode = stack.pop();
|
|
6169
|
+
// @ts-ignore
|
|
6170
|
+
context = stack[stack.length - 1] ?? ast;
|
|
6171
|
+
// @ts-ignore
|
|
6172
|
+
if (options.removeEmpty && previousNode != null && previousNode.chi.length == 0 && context.chi[context.chi.length - 1] == previousNode) {
|
|
6173
|
+
context.chi.pop();
|
|
6174
|
+
continue;
|
|
6158
6175
|
}
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6176
|
+
break;
|
|
6177
|
+
}
|
|
6178
|
+
const endParseTime = performance.now();
|
|
6179
|
+
if (options.expandNestingRules) {
|
|
6180
|
+
ast = expand(ast);
|
|
6181
|
+
}
|
|
6182
|
+
if (options.visitor != null) {
|
|
6183
|
+
for (const result of walk(ast)) {
|
|
6184
|
+
if (result.node.typ == exports.EnumToken.DeclarationNodeType &&
|
|
6185
|
+
// @ts-ignore
|
|
6186
|
+
(typeof options.visitor.Declaration == 'function' || options.visitor.Declaration?.[result.node.nam] != null)) {
|
|
6187
|
+
const callable = typeof options.visitor.Declaration == 'function' ? options.visitor.Declaration : options.visitor.Declaration[result.node.nam];
|
|
6188
|
+
const results = await callable(result.node);
|
|
6189
|
+
if (results == null || (Array.isArray(results) && results.length == 0)) {
|
|
6190
|
+
continue;
|
|
6171
6191
|
}
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6192
|
+
// @ts-ignore
|
|
6193
|
+
result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
|
|
6194
|
+
}
|
|
6195
|
+
else if (options.visitor.Rule != null && result.node.typ == exports.EnumToken.RuleNodeType) {
|
|
6196
|
+
const results = await options.visitor.Rule(result.node);
|
|
6197
|
+
if (results == null || (Array.isArray(results) && results.length == 0)) {
|
|
6198
|
+
continue;
|
|
6179
6199
|
}
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6200
|
+
// @ts-ignore
|
|
6201
|
+
result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
|
|
6202
|
+
}
|
|
6203
|
+
else if (options.visitor.AtRule != null &&
|
|
6204
|
+
result.node.typ == exports.EnumToken.AtRuleNodeType &&
|
|
6205
|
+
// @ts-ignore
|
|
6206
|
+
(typeof options.visitor.AtRule == 'function' || options.visitor.AtRule?.[result.node.nam] != null)) {
|
|
6207
|
+
const callable = typeof options.visitor.AtRule == 'function' ? options.visitor.AtRule : options.visitor.AtRule[result.node.nam];
|
|
6208
|
+
const results = await callable(result.node);
|
|
6209
|
+
if (results == null || (Array.isArray(results) && results.length == 0)) {
|
|
6210
|
+
continue;
|
|
6191
6211
|
}
|
|
6212
|
+
// @ts-ignore
|
|
6213
|
+
result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
|
|
6192
6214
|
}
|
|
6193
6215
|
}
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6216
|
+
}
|
|
6217
|
+
if (options.minify) {
|
|
6218
|
+
if (ast.chi.length > 0) {
|
|
6219
|
+
minify(ast, options, true, errors, false);
|
|
6220
|
+
}
|
|
6221
|
+
}
|
|
6222
|
+
if (options.setParent) {
|
|
6223
|
+
const nodes = [ast];
|
|
6224
|
+
let node;
|
|
6225
|
+
while ((node = nodes.shift())) {
|
|
6226
|
+
// @ts-ignore
|
|
6227
|
+
if (node.chi.length > 0) {
|
|
6228
|
+
// @ts-ignore
|
|
6229
|
+
for (const child of node.chi) {
|
|
6230
|
+
if (child.parent != node) {
|
|
6231
|
+
Object.defineProperty(child, 'parent', { ...definedPropertySettings, value: node });
|
|
6232
|
+
}
|
|
6233
|
+
if ('chi' in child && child.chi.length > 0) {
|
|
6234
|
+
// @ts-ignore
|
|
6235
|
+
nodes.push(child);
|
|
6236
|
+
}
|
|
6237
|
+
}
|
|
6197
6238
|
}
|
|
6198
6239
|
}
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6240
|
+
}
|
|
6241
|
+
const endTime = performance.now();
|
|
6242
|
+
if (options.signal != null) {
|
|
6243
|
+
options.signal.removeEventListener('abort', reject);
|
|
6244
|
+
}
|
|
6245
|
+
stats.bytesIn += stats.importedBytesIn;
|
|
6246
|
+
return {
|
|
6247
|
+
ast,
|
|
6248
|
+
errors,
|
|
6249
|
+
stats: {
|
|
6250
|
+
...stats,
|
|
6251
|
+
parse: `${(endParseTime - startTime).toFixed(2)}ms`,
|
|
6252
|
+
minify: `${(endTime - endParseTime).toFixed(2)}ms`,
|
|
6253
|
+
total: `${(endTime - startTime).toFixed(2)}ms`
|
|
6202
6254
|
}
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
ast,
|
|
6206
|
-
errors,
|
|
6207
|
-
stats: {
|
|
6208
|
-
...stats,
|
|
6209
|
-
parse: `${(endParseTime - startTime).toFixed(2)}ms`,
|
|
6210
|
-
minify: `${(endTime - endParseTime).toFixed(2)}ms`,
|
|
6211
|
-
total: `${(endTime - startTime).toFixed(2)}ms`
|
|
6212
|
-
}
|
|
6213
|
-
});
|
|
6214
|
-
});
|
|
6255
|
+
};
|
|
6256
|
+
// });
|
|
6215
6257
|
}
|
|
6216
6258
|
async function parseNode(results, context, stats, options, errors, src, map) {
|
|
6217
|
-
let tokens =
|
|
6259
|
+
let tokens = [];
|
|
6260
|
+
for (const t of results) {
|
|
6261
|
+
const node = getTokenType(t.token, t.hint);
|
|
6262
|
+
map.set(node, t.position);
|
|
6263
|
+
tokens.push(node);
|
|
6264
|
+
}
|
|
6218
6265
|
let i;
|
|
6219
6266
|
let loc;
|
|
6220
6267
|
for (i = 0; i < tokens.length; i++) {
|
|
@@ -6322,12 +6369,16 @@ async function parseNode(results, context, stats, options, errors, src, map) {
|
|
|
6322
6369
|
}
|
|
6323
6370
|
if (atRule.val == 'import') {
|
|
6324
6371
|
// @ts-ignore
|
|
6325
|
-
if (tokens[0].typ == exports.EnumToken.UrlFunctionTokenType
|
|
6326
|
-
tokens.
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6372
|
+
if (tokens[0].typ == exports.EnumToken.UrlFunctionTokenType) {
|
|
6373
|
+
if (tokens[1].typ == exports.EnumToken.UrlTokenTokenType || tokens[1].typ == exports.EnumToken.StringTokenType) {
|
|
6374
|
+
tokens.shift();
|
|
6375
|
+
if (tokens[1].typ == exports.EnumToken.UrlTokenTokenType) {
|
|
6376
|
+
// @ts-ignore
|
|
6377
|
+
tokens[0].typ = exports.EnumToken.StringTokenType;
|
|
6378
|
+
// @ts-ignore
|
|
6379
|
+
tokens[0].val = `"${tokens[0].val}"`;
|
|
6380
|
+
}
|
|
6381
|
+
}
|
|
6331
6382
|
}
|
|
6332
6383
|
// @ts-ignore
|
|
6333
6384
|
if (tokens[0].typ == exports.EnumToken.StringTokenType) {
|
|
@@ -6338,6 +6389,7 @@ async function parseNode(results, context, stats, options, errors, src, map) {
|
|
|
6338
6389
|
const root = await options.load(url, options.src).then((src) => {
|
|
6339
6390
|
return doParse(src, Object.assign({}, options, {
|
|
6340
6391
|
minify: false,
|
|
6392
|
+
setParent: false,
|
|
6341
6393
|
// @ts-ignore
|
|
6342
6394
|
src: options.resolve(url, options.src).absolute
|
|
6343
6395
|
}));
|
|
@@ -6371,7 +6423,7 @@ async function parseNode(results, context, stats, options, errors, src, map) {
|
|
|
6371
6423
|
nam: renderToken(atRule, { removeComments: true }),
|
|
6372
6424
|
val: raw.join('')
|
|
6373
6425
|
};
|
|
6374
|
-
Object.defineProperty(node, 'raw', {
|
|
6426
|
+
Object.defineProperty(node, 'raw', { ...definedPropertySettings, value: raw });
|
|
6375
6427
|
if (delim.typ == exports.EnumToken.BlockStartTokenType) {
|
|
6376
6428
|
node.chi = [];
|
|
6377
6429
|
}
|
|
@@ -6497,11 +6549,6 @@ async function parseNode(results, context, stats, options, errors, src, map) {
|
|
|
6497
6549
|
}
|
|
6498
6550
|
}
|
|
6499
6551
|
}
|
|
6500
|
-
function mapToken(token, map) {
|
|
6501
|
-
const node = getTokenType(token.token, token.hint);
|
|
6502
|
-
map.set(node, token.position);
|
|
6503
|
-
return node;
|
|
6504
|
-
}
|
|
6505
6552
|
function parseString(src, options = { location: false }) {
|
|
6506
6553
|
return parseTokens([...tokenize(src)].map(t => {
|
|
6507
6554
|
const token = getTokenType(t.token, t.hint);
|
|
@@ -6516,13 +6563,7 @@ function getTokenType(val, hint) {
|
|
|
6516
6563
|
throw new Error('empty string?');
|
|
6517
6564
|
}
|
|
6518
6565
|
if (hint != null) {
|
|
6519
|
-
return (
|
|
6520
|
-
exports.EnumToken.WhitespaceTokenType, exports.EnumToken.SemiColonTokenType, exports.EnumToken.ColonTokenType, exports.EnumToken.BlockStartTokenType,
|
|
6521
|
-
exports.EnumToken.BlockStartTokenType, exports.EnumToken.AttrStartTokenType, exports.EnumToken.AttrEndTokenType, exports.EnumToken.StartParensTokenType, exports.EnumToken.EndParensTokenType,
|
|
6522
|
-
exports.EnumToken.CommaTokenType, exports.EnumToken.GtTokenType, exports.EnumToken.LtTokenType, exports.EnumToken.GteTokenType, exports.EnumToken.LteTokenType, exports.EnumToken.CommaTokenType,
|
|
6523
|
-
exports.EnumToken.StartMatchTokenType, exports.EnumToken.EndMatchTokenType, exports.EnumToken.IncludeMatchTokenType, exports.EnumToken.DashMatchTokenType, exports.EnumToken.ContainMatchTokenType,
|
|
6524
|
-
exports.EnumToken.EOFTokenType
|
|
6525
|
-
].includes(hint) ? { typ: hint } : { typ: hint, val });
|
|
6566
|
+
return enumTokenHints.has(hint) ? { typ: hint } : { typ: hint, val };
|
|
6526
6567
|
}
|
|
6527
6568
|
if (val == ' ') {
|
|
6528
6569
|
return { typ: exports.EnumToken.WhitespaceTokenType };
|
|
@@ -6641,10 +6682,10 @@ function getTokenType(val, hint) {
|
|
|
6641
6682
|
return parseDimension(val);
|
|
6642
6683
|
}
|
|
6643
6684
|
const v = val.toLowerCase();
|
|
6644
|
-
if (v == 'currentcolor' ||
|
|
6685
|
+
if (v == 'currentcolor' || v == 'transparent' || v in COLORS_NAMES) {
|
|
6645
6686
|
return {
|
|
6646
6687
|
typ: exports.EnumToken.ColorTokenType,
|
|
6647
|
-
val,
|
|
6688
|
+
val: v,
|
|
6648
6689
|
kin: 'lit'
|
|
6649
6690
|
};
|
|
6650
6691
|
}
|
|
@@ -6994,12 +7035,47 @@ function parseTokens(tokens, options = {}) {
|
|
|
6994
7035
|
return tokens;
|
|
6995
7036
|
}
|
|
6996
7037
|
|
|
7038
|
+
function eq(a, b) {
|
|
7039
|
+
if (a == null || b == null) {
|
|
7040
|
+
return a == b;
|
|
7041
|
+
}
|
|
7042
|
+
if (typeof a != 'object' || typeof b != 'object') {
|
|
7043
|
+
return a === b;
|
|
7044
|
+
}
|
|
7045
|
+
if (a.constructor != b.constructor) {
|
|
7046
|
+
return false;
|
|
7047
|
+
}
|
|
7048
|
+
if (Array.isArray(a)) {
|
|
7049
|
+
if (a.length != b.length) {
|
|
7050
|
+
return false;
|
|
7051
|
+
}
|
|
7052
|
+
let i = 0;
|
|
7053
|
+
for (; i < a.length; i++) {
|
|
7054
|
+
if (!eq(a[i], b[i])) {
|
|
7055
|
+
return false;
|
|
7056
|
+
}
|
|
7057
|
+
}
|
|
7058
|
+
return true;
|
|
7059
|
+
}
|
|
7060
|
+
const k1 = Object.keys(a);
|
|
7061
|
+
const k2 = Object.keys(b);
|
|
7062
|
+
if (k1.length != k2.length) {
|
|
7063
|
+
return false;
|
|
7064
|
+
}
|
|
7065
|
+
let key;
|
|
7066
|
+
for (key of k1) {
|
|
7067
|
+
if (!(key in b) || !eq(a[key], b[key])) {
|
|
7068
|
+
return false;
|
|
7069
|
+
}
|
|
7070
|
+
}
|
|
7071
|
+
return true;
|
|
7072
|
+
}
|
|
7073
|
+
|
|
6997
7074
|
function* walk(node, filter) {
|
|
6998
7075
|
const parents = [node];
|
|
6999
7076
|
const root = node;
|
|
7000
|
-
const
|
|
7001
|
-
while (parents.
|
|
7002
|
-
node = parents.shift();
|
|
7077
|
+
const map = new Map;
|
|
7078
|
+
while ((node = parents.shift())) {
|
|
7003
7079
|
let option = null;
|
|
7004
7080
|
if (filter != null) {
|
|
7005
7081
|
option = filter(node);
|
|
@@ -7013,22 +7089,21 @@ function* walk(node, filter) {
|
|
|
7013
7089
|
// @ts-ignore
|
|
7014
7090
|
if (option !== 'children') {
|
|
7015
7091
|
// @ts-ignore
|
|
7016
|
-
yield { node, parent:
|
|
7092
|
+
yield { node, parent: map.get(node), root };
|
|
7017
7093
|
}
|
|
7018
7094
|
if (option !== 'ignore-children' && 'chi' in node) {
|
|
7019
7095
|
parents.unshift(...node.chi);
|
|
7020
7096
|
for (const child of node.chi.slice()) {
|
|
7021
|
-
|
|
7097
|
+
map.set(child, node);
|
|
7022
7098
|
}
|
|
7023
7099
|
}
|
|
7024
7100
|
}
|
|
7025
7101
|
}
|
|
7026
7102
|
function* walkValues(values, root = null, filter) {
|
|
7027
7103
|
const stack = values.slice();
|
|
7028
|
-
const
|
|
7104
|
+
const map = new Map;
|
|
7029
7105
|
let value;
|
|
7030
|
-
while (stack.
|
|
7031
|
-
value = stack.shift();
|
|
7106
|
+
while ((value = stack.shift())) {
|
|
7032
7107
|
let option = null;
|
|
7033
7108
|
if (filter != null) {
|
|
7034
7109
|
option = filter(value);
|
|
@@ -7042,17 +7117,17 @@ function* walkValues(values, root = null, filter) {
|
|
|
7042
7117
|
// @ts-ignore
|
|
7043
7118
|
if (option !== 'children') {
|
|
7044
7119
|
// @ts-ignore
|
|
7045
|
-
yield { value, parent:
|
|
7120
|
+
yield { value, parent: map.get(value), root };
|
|
7046
7121
|
}
|
|
7047
7122
|
if (option !== 'ignore-children' && 'chi' in value) {
|
|
7048
7123
|
for (const child of value.chi.slice()) {
|
|
7049
|
-
|
|
7124
|
+
map.set(child, value);
|
|
7050
7125
|
}
|
|
7051
7126
|
stack.unshift(...value.chi);
|
|
7052
7127
|
}
|
|
7053
7128
|
else if (value.typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
7054
|
-
|
|
7055
|
-
|
|
7129
|
+
map.set(value.l, value);
|
|
7130
|
+
map.set(value.r, value);
|
|
7056
7131
|
stack.unshift(value.l, value.r);
|
|
7057
7132
|
}
|
|
7058
7133
|
}
|
|
@@ -7203,61 +7278,6 @@ function replaceCompoundLiteral(selector, replace) {
|
|
|
7203
7278
|
}).reduce((acc, curr) => acc + (curr == '&' ? replace : curr), '');
|
|
7204
7279
|
}
|
|
7205
7280
|
|
|
7206
|
-
class MinifyFeature {
|
|
7207
|
-
static get ordering() {
|
|
7208
|
-
return 10000;
|
|
7209
|
-
}
|
|
7210
|
-
register(options) {
|
|
7211
|
-
}
|
|
7212
|
-
}
|
|
7213
|
-
|
|
7214
|
-
class IterableWeakSet {
|
|
7215
|
-
#weakset = new WeakSet;
|
|
7216
|
-
#set = new Set;
|
|
7217
|
-
constructor(iterable) {
|
|
7218
|
-
if (iterable) {
|
|
7219
|
-
for (const value of iterable) {
|
|
7220
|
-
const ref = new WeakRef(value);
|
|
7221
|
-
this.#weakset.add(value);
|
|
7222
|
-
this.#set.add(ref);
|
|
7223
|
-
}
|
|
7224
|
-
}
|
|
7225
|
-
}
|
|
7226
|
-
has(value) {
|
|
7227
|
-
return this.#weakset.has(value);
|
|
7228
|
-
}
|
|
7229
|
-
delete(value) {
|
|
7230
|
-
if (this.#weakset.has(value)) {
|
|
7231
|
-
for (const ref of this.#set) {
|
|
7232
|
-
if (ref.deref() === value) {
|
|
7233
|
-
this.#set.delete(ref);
|
|
7234
|
-
break;
|
|
7235
|
-
}
|
|
7236
|
-
}
|
|
7237
|
-
return this.#weakset.delete(value);
|
|
7238
|
-
}
|
|
7239
|
-
return false;
|
|
7240
|
-
}
|
|
7241
|
-
add(value) {
|
|
7242
|
-
if (!this.#weakset.has(value)) {
|
|
7243
|
-
this.#weakset.add(value);
|
|
7244
|
-
this.#set.add(new WeakRef(value));
|
|
7245
|
-
}
|
|
7246
|
-
return this;
|
|
7247
|
-
}
|
|
7248
|
-
*[Symbol.iterator]() {
|
|
7249
|
-
for (const ref of new Set(this.#set)) {
|
|
7250
|
-
const key = ref.deref();
|
|
7251
|
-
if (key != null) {
|
|
7252
|
-
yield key;
|
|
7253
|
-
}
|
|
7254
|
-
else {
|
|
7255
|
-
this.#set.delete(ref);
|
|
7256
|
-
}
|
|
7257
|
-
}
|
|
7258
|
-
}
|
|
7259
|
-
}
|
|
7260
|
-
|
|
7261
7281
|
function replace(node, variableScope) {
|
|
7262
7282
|
for (const { value, parent: parentValue } of walkValues(node.val)) {
|
|
7263
7283
|
if (value?.typ == exports.EnumToken.FunctionTokenType && value.val == 'var') {
|
|
@@ -7281,7 +7301,7 @@ function replace(node, variableScope) {
|
|
|
7281
7301
|
}
|
|
7282
7302
|
}
|
|
7283
7303
|
}
|
|
7284
|
-
class InlineCssVariablesFeature
|
|
7304
|
+
class InlineCssVariablesFeature {
|
|
7285
7305
|
static get ordering() {
|
|
7286
7306
|
return 0;
|
|
7287
7307
|
}
|
|
@@ -7316,7 +7336,7 @@ class InlineCssVariablesFeature extends MinifyFeature {
|
|
|
7316
7336
|
const info = {
|
|
7317
7337
|
globalScope: isRoot,
|
|
7318
7338
|
// @ts-ignore
|
|
7319
|
-
parent: new
|
|
7339
|
+
parent: new Set(),
|
|
7320
7340
|
declarationCount: 1,
|
|
7321
7341
|
replaceable: isRoot,
|
|
7322
7342
|
node: node
|
|
@@ -7354,6 +7374,9 @@ class InlineCssVariablesFeature extends MinifyFeature {
|
|
|
7354
7374
|
}
|
|
7355
7375
|
cleanup(ast, options = {}, context) {
|
|
7356
7376
|
const variableScope = context.variableScope;
|
|
7377
|
+
if (variableScope == null) {
|
|
7378
|
+
return;
|
|
7379
|
+
}
|
|
7357
7380
|
for (const info of variableScope.values()) {
|
|
7358
7381
|
if (info.replaceable) {
|
|
7359
7382
|
let i;
|
|
@@ -7444,6 +7467,7 @@ class PropertySet {
|
|
|
7444
7467
|
}
|
|
7445
7468
|
tokens[current].push(token);
|
|
7446
7469
|
}
|
|
7470
|
+
// @ts-ignore
|
|
7447
7471
|
if (token.typ == exports.EnumToken.LiteralTokenType && token.val == this.config.separator) {
|
|
7448
7472
|
tokens.push([]);
|
|
7449
7473
|
current++;
|
|
@@ -7547,6 +7571,7 @@ class PropertySet {
|
|
|
7547
7571
|
}
|
|
7548
7572
|
}
|
|
7549
7573
|
if (acc.length > 0) {
|
|
7574
|
+
// @ts-ignore
|
|
7550
7575
|
acc.push({ typ: exports.EnumToken.LiteralTokenType, val: this.config.separator });
|
|
7551
7576
|
}
|
|
7552
7577
|
acc.push(...curr);
|
|
@@ -7592,6 +7617,7 @@ class PropertyMap {
|
|
|
7592
7617
|
else {
|
|
7593
7618
|
const separator = this.config.separator != null ? {
|
|
7594
7619
|
...this.config.separator,
|
|
7620
|
+
// @ts-ignore
|
|
7595
7621
|
typ: exports.EnumToken[this.config.separator.typ]
|
|
7596
7622
|
} : null;
|
|
7597
7623
|
// expand shorthand
|
|
@@ -7601,7 +7627,7 @@ class PropertyMap {
|
|
|
7601
7627
|
// @ts-ignore
|
|
7602
7628
|
this.declarations.get(this.config.shorthand).val.slice().reduce((acc, curr) => {
|
|
7603
7629
|
// @ts-ignore
|
|
7604
|
-
if (separator != null && separator.typ == curr.typ &&
|
|
7630
|
+
if (separator != null && separator.typ == curr.typ && separator.val == curr.val) {
|
|
7605
7631
|
acc.push([]);
|
|
7606
7632
|
return acc;
|
|
7607
7633
|
}
|
|
@@ -7640,11 +7666,8 @@ class PropertyMap {
|
|
|
7640
7666
|
i--;
|
|
7641
7667
|
// @ts-ignore
|
|
7642
7668
|
if ('prefix' in props && acc[i]?.typ == exports.EnumToken[props.prefix.typ]) {
|
|
7643
|
-
|
|
7644
|
-
|
|
7645
|
-
// @ts-ignore
|
|
7646
|
-
typ: exports.EnumToken[props.prefix.typ]
|
|
7647
|
-
})) {
|
|
7669
|
+
// @ts-ignore
|
|
7670
|
+
if (acc[i].typ == exports.EnumToken[props.prefix.typ] && acc[i].val == this.config.properties[property].prefix.val) {
|
|
7648
7671
|
acc.splice(i, 1);
|
|
7649
7672
|
i--;
|
|
7650
7673
|
}
|
|
@@ -7811,6 +7834,7 @@ class PropertyMap {
|
|
|
7811
7834
|
let values = [];
|
|
7812
7835
|
// @ts-ignore
|
|
7813
7836
|
let typ = (exports.EnumToken[this.config.separator?.typ] ?? exports.EnumToken.CommaTokenType);
|
|
7837
|
+
// @ts-ignore
|
|
7814
7838
|
let separator = this.config.separator ? renderToken(this.config.separator) : ',';
|
|
7815
7839
|
this.matchTypes(declaration);
|
|
7816
7840
|
values.push(value);
|
|
@@ -7890,6 +7914,26 @@ class PropertyMap {
|
|
|
7890
7914
|
}
|
|
7891
7915
|
return (filtered.length > 0 ? filtered : values)[Symbol.iterator]();
|
|
7892
7916
|
}
|
|
7917
|
+
for (const declaration of this.declarations.values()) {
|
|
7918
|
+
if (declaration instanceof PropertySet) {
|
|
7919
|
+
continue;
|
|
7920
|
+
}
|
|
7921
|
+
const config = declaration.nam == this.config.shorthand ? this.config : this.config.properties[declaration.nam] ?? this.config;
|
|
7922
|
+
if (!('mapping' in config)) {
|
|
7923
|
+
continue;
|
|
7924
|
+
}
|
|
7925
|
+
// @ts-ignore
|
|
7926
|
+
for (const [key, val] of Object.entries(config.mapping)) {
|
|
7927
|
+
const keys = parseString(key);
|
|
7928
|
+
if (keys.length != declaration.val.length) {
|
|
7929
|
+
continue;
|
|
7930
|
+
}
|
|
7931
|
+
if (eq(declaration.val, keys)) {
|
|
7932
|
+
declaration.val = parseString(val);
|
|
7933
|
+
break;
|
|
7934
|
+
}
|
|
7935
|
+
}
|
|
7936
|
+
}
|
|
7893
7937
|
// @ts-ignore
|
|
7894
7938
|
iterable = this.declarations.values();
|
|
7895
7939
|
}
|
|
@@ -7898,6 +7942,7 @@ class PropertyMap {
|
|
|
7898
7942
|
let match;
|
|
7899
7943
|
const separator = this.config.separator != null ? {
|
|
7900
7944
|
...this.config.separator,
|
|
7945
|
+
// @ts-ignore
|
|
7901
7946
|
typ: exports.EnumToken[this.config.separator.typ]
|
|
7902
7947
|
} : null;
|
|
7903
7948
|
const tokens = {};
|
|
@@ -7915,7 +7960,8 @@ class PropertyMap {
|
|
|
7915
7960
|
for (const declaration of [(properties instanceof PropertySet ? [...properties][0] : properties)]) {
|
|
7916
7961
|
// @ts-ignore
|
|
7917
7962
|
for (const val of declaration.val) {
|
|
7918
|
-
|
|
7963
|
+
// @ts-ignore
|
|
7964
|
+
if (separator != null && separator.typ == val.typ && separator.val == val.val) {
|
|
7919
7965
|
current++;
|
|
7920
7966
|
if (tokens[curr[0]].length == current) {
|
|
7921
7967
|
tokens[curr[0]].push([]);
|
|
@@ -7926,10 +7972,11 @@ class PropertyMap {
|
|
|
7926
7972
|
continue;
|
|
7927
7973
|
}
|
|
7928
7974
|
// @ts-ignore
|
|
7929
|
-
if (props.multiple && props.separator != null &&
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7975
|
+
if (props.multiple && props.separator != null &&
|
|
7976
|
+
// @ts-ignore
|
|
7977
|
+
exports.EnumToken[props.separator.typ] == val.typ &&
|
|
7978
|
+
// @ts-ignore
|
|
7979
|
+
props.separator.val == val.val) {
|
|
7933
7980
|
continue;
|
|
7934
7981
|
}
|
|
7935
7982
|
// @ts-ignore
|
|
@@ -8034,6 +8081,7 @@ class PropertyMap {
|
|
|
8034
8081
|
acc.push({
|
|
8035
8082
|
...((props.separator && {
|
|
8036
8083
|
...props.separator,
|
|
8084
|
+
// @ts-ignore
|
|
8037
8085
|
typ: exports.EnumToken[props.separator.typ]
|
|
8038
8086
|
}) ?? { typ: exports.EnumToken.WhitespaceTokenType })
|
|
8039
8087
|
});
|
|
@@ -8134,6 +8182,7 @@ class PropertyMap {
|
|
|
8134
8182
|
if (value[index].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
8135
8183
|
continue;
|
|
8136
8184
|
}
|
|
8185
|
+
// @ts-ignore@
|
|
8137
8186
|
if (value[index].typ == exports.EnumToken[config.prefix.typ] &&
|
|
8138
8187
|
// @ts-ignore
|
|
8139
8188
|
value[index].val == config.prefix.val) {
|
|
@@ -8154,12 +8203,7 @@ class PropertyList {
|
|
|
8154
8203
|
options = { removeDuplicateDeclarations: true, computeShorthand: true };
|
|
8155
8204
|
declarations;
|
|
8156
8205
|
constructor(options = {}) {
|
|
8157
|
-
|
|
8158
|
-
if (key in options) {
|
|
8159
|
-
// @ts-ignore
|
|
8160
|
-
this.options[key] = options[key];
|
|
8161
|
-
}
|
|
8162
|
-
}
|
|
8206
|
+
this.options = options;
|
|
8163
8207
|
this.declarations = new Map;
|
|
8164
8208
|
}
|
|
8165
8209
|
set(nam, value) {
|
|
@@ -8253,7 +8297,7 @@ class PropertyList {
|
|
|
8253
8297
|
}
|
|
8254
8298
|
}
|
|
8255
8299
|
|
|
8256
|
-
class ComputeShorthandFeature
|
|
8300
|
+
class ComputeShorthandFeature {
|
|
8257
8301
|
static get ordering() {
|
|
8258
8302
|
return 2;
|
|
8259
8303
|
}
|
|
@@ -8265,7 +8309,7 @@ class ComputeShorthandFeature extends MinifyFeature {
|
|
|
8265
8309
|
}
|
|
8266
8310
|
}
|
|
8267
8311
|
// @ts-ignore
|
|
8268
|
-
options.features.push(new ComputeShorthandFeature());
|
|
8312
|
+
options.features.push(new ComputeShorthandFeature(options));
|
|
8269
8313
|
}
|
|
8270
8314
|
}
|
|
8271
8315
|
run(ast, options = {}, parent, context) {
|
|
@@ -8289,7 +8333,7 @@ class ComputeShorthandFeature extends MinifyFeature {
|
|
|
8289
8333
|
}
|
|
8290
8334
|
}
|
|
8291
8335
|
|
|
8292
|
-
class ComputeCalcExpressionFeature
|
|
8336
|
+
class ComputeCalcExpressionFeature {
|
|
8293
8337
|
static get ordering() {
|
|
8294
8338
|
return 1;
|
|
8295
8339
|
}
|
|
@@ -8313,7 +8357,7 @@ class ComputeCalcExpressionFeature extends MinifyFeature {
|
|
|
8313
8357
|
if (node.typ != exports.EnumToken.DeclarationNodeType) {
|
|
8314
8358
|
continue;
|
|
8315
8359
|
}
|
|
8316
|
-
const set = new
|
|
8360
|
+
const set = new Set;
|
|
8317
8361
|
for (const { value, parent } of walkValues(node.val)) {
|
|
8318
8362
|
if (value != null && value.typ == exports.EnumToken.FunctionTokenType && value.val == 'calc') {
|
|
8319
8363
|
if (!set.has(parent)) {
|
|
@@ -8354,8 +8398,8 @@ var allFeatures = /*#__PURE__*/Object.freeze({
|
|
|
8354
8398
|
});
|
|
8355
8399
|
|
|
8356
8400
|
const combinators = ['+', '>', '~', '||'];
|
|
8357
|
-
const notEndingWith = ['(', '['].concat(combinators);
|
|
8358
8401
|
const definedPropertySettings = { configurable: true, enumerable: false, writable: true };
|
|
8402
|
+
const notEndingWith = ['(', '['].concat(combinators);
|
|
8359
8403
|
// @ts-ignore
|
|
8360
8404
|
const features = Object.values(allFeatures).sort((a, b) => a.ordering - b.ordering);
|
|
8361
8405
|
function minify(ast, options = {}, recursive = false, errors, nestingContent, context = {}) {
|