@tbela99/css-parser 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -12
- package/dist/config.json.js +9 -9
- package/dist/index-umd-web.js +382 -340
- package/dist/index.cjs +379 -339
- 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 +200 -175
- 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++) {
|
|
@@ -6338,6 +6385,7 @@ async function parseNode(results, context, stats, options, errors, src, map) {
|
|
|
6338
6385
|
const root = await options.load(url, options.src).then((src) => {
|
|
6339
6386
|
return doParse(src, Object.assign({}, options, {
|
|
6340
6387
|
minify: false,
|
|
6388
|
+
setParent: false,
|
|
6341
6389
|
// @ts-ignore
|
|
6342
6390
|
src: options.resolve(url, options.src).absolute
|
|
6343
6391
|
}));
|
|
@@ -6371,7 +6419,7 @@ async function parseNode(results, context, stats, options, errors, src, map) {
|
|
|
6371
6419
|
nam: renderToken(atRule, { removeComments: true }),
|
|
6372
6420
|
val: raw.join('')
|
|
6373
6421
|
};
|
|
6374
|
-
Object.defineProperty(node, 'raw', {
|
|
6422
|
+
Object.defineProperty(node, 'raw', { ...definedPropertySettings, value: raw });
|
|
6375
6423
|
if (delim.typ == exports.EnumToken.BlockStartTokenType) {
|
|
6376
6424
|
node.chi = [];
|
|
6377
6425
|
}
|
|
@@ -6497,11 +6545,6 @@ async function parseNode(results, context, stats, options, errors, src, map) {
|
|
|
6497
6545
|
}
|
|
6498
6546
|
}
|
|
6499
6547
|
}
|
|
6500
|
-
function mapToken(token, map) {
|
|
6501
|
-
const node = getTokenType(token.token, token.hint);
|
|
6502
|
-
map.set(node, token.position);
|
|
6503
|
-
return node;
|
|
6504
|
-
}
|
|
6505
6548
|
function parseString(src, options = { location: false }) {
|
|
6506
6549
|
return parseTokens([...tokenize(src)].map(t => {
|
|
6507
6550
|
const token = getTokenType(t.token, t.hint);
|
|
@@ -6516,13 +6559,7 @@ function getTokenType(val, hint) {
|
|
|
6516
6559
|
throw new Error('empty string?');
|
|
6517
6560
|
}
|
|
6518
6561
|
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 });
|
|
6562
|
+
return enumTokenHints.has(hint) ? { typ: hint } : { typ: hint, val };
|
|
6526
6563
|
}
|
|
6527
6564
|
if (val == ' ') {
|
|
6528
6565
|
return { typ: exports.EnumToken.WhitespaceTokenType };
|
|
@@ -6641,10 +6678,10 @@ function getTokenType(val, hint) {
|
|
|
6641
6678
|
return parseDimension(val);
|
|
6642
6679
|
}
|
|
6643
6680
|
const v = val.toLowerCase();
|
|
6644
|
-
if (v == 'currentcolor' ||
|
|
6681
|
+
if (v == 'currentcolor' || v == 'transparent' || v in COLORS_NAMES) {
|
|
6645
6682
|
return {
|
|
6646
6683
|
typ: exports.EnumToken.ColorTokenType,
|
|
6647
|
-
val,
|
|
6684
|
+
val: v,
|
|
6648
6685
|
kin: 'lit'
|
|
6649
6686
|
};
|
|
6650
6687
|
}
|
|
@@ -6994,12 +7031,47 @@ function parseTokens(tokens, options = {}) {
|
|
|
6994
7031
|
return tokens;
|
|
6995
7032
|
}
|
|
6996
7033
|
|
|
7034
|
+
function eq(a, b) {
|
|
7035
|
+
if (a == null || b == null) {
|
|
7036
|
+
return a == b;
|
|
7037
|
+
}
|
|
7038
|
+
if (typeof a != 'object' || typeof b != 'object') {
|
|
7039
|
+
return a === b;
|
|
7040
|
+
}
|
|
7041
|
+
if (a.constructor != b.constructor) {
|
|
7042
|
+
return false;
|
|
7043
|
+
}
|
|
7044
|
+
if (Array.isArray(a)) {
|
|
7045
|
+
if (a.length != b.length) {
|
|
7046
|
+
return false;
|
|
7047
|
+
}
|
|
7048
|
+
let i = 0;
|
|
7049
|
+
for (; i < a.length; i++) {
|
|
7050
|
+
if (!eq(a[i], b[i])) {
|
|
7051
|
+
return false;
|
|
7052
|
+
}
|
|
7053
|
+
}
|
|
7054
|
+
return true;
|
|
7055
|
+
}
|
|
7056
|
+
const k1 = Object.keys(a);
|
|
7057
|
+
const k2 = Object.keys(b);
|
|
7058
|
+
if (k1.length != k2.length) {
|
|
7059
|
+
return false;
|
|
7060
|
+
}
|
|
7061
|
+
let key;
|
|
7062
|
+
for (key of k1) {
|
|
7063
|
+
if (!(key in b) || !eq(a[key], b[key])) {
|
|
7064
|
+
return false;
|
|
7065
|
+
}
|
|
7066
|
+
}
|
|
7067
|
+
return true;
|
|
7068
|
+
}
|
|
7069
|
+
|
|
6997
7070
|
function* walk(node, filter) {
|
|
6998
7071
|
const parents = [node];
|
|
6999
7072
|
const root = node;
|
|
7000
|
-
const
|
|
7001
|
-
while (parents.
|
|
7002
|
-
node = parents.shift();
|
|
7073
|
+
const map = new Map;
|
|
7074
|
+
while ((node = parents.shift())) {
|
|
7003
7075
|
let option = null;
|
|
7004
7076
|
if (filter != null) {
|
|
7005
7077
|
option = filter(node);
|
|
@@ -7013,22 +7085,21 @@ function* walk(node, filter) {
|
|
|
7013
7085
|
// @ts-ignore
|
|
7014
7086
|
if (option !== 'children') {
|
|
7015
7087
|
// @ts-ignore
|
|
7016
|
-
yield { node, parent:
|
|
7088
|
+
yield { node, parent: map.get(node), root };
|
|
7017
7089
|
}
|
|
7018
7090
|
if (option !== 'ignore-children' && 'chi' in node) {
|
|
7019
7091
|
parents.unshift(...node.chi);
|
|
7020
7092
|
for (const child of node.chi.slice()) {
|
|
7021
|
-
|
|
7093
|
+
map.set(child, node);
|
|
7022
7094
|
}
|
|
7023
7095
|
}
|
|
7024
7096
|
}
|
|
7025
7097
|
}
|
|
7026
7098
|
function* walkValues(values, root = null, filter) {
|
|
7027
7099
|
const stack = values.slice();
|
|
7028
|
-
const
|
|
7100
|
+
const map = new Map;
|
|
7029
7101
|
let value;
|
|
7030
|
-
while (stack.
|
|
7031
|
-
value = stack.shift();
|
|
7102
|
+
while ((value = stack.shift())) {
|
|
7032
7103
|
let option = null;
|
|
7033
7104
|
if (filter != null) {
|
|
7034
7105
|
option = filter(value);
|
|
@@ -7042,17 +7113,17 @@ function* walkValues(values, root = null, filter) {
|
|
|
7042
7113
|
// @ts-ignore
|
|
7043
7114
|
if (option !== 'children') {
|
|
7044
7115
|
// @ts-ignore
|
|
7045
|
-
yield { value, parent:
|
|
7116
|
+
yield { value, parent: map.get(value), root };
|
|
7046
7117
|
}
|
|
7047
7118
|
if (option !== 'ignore-children' && 'chi' in value) {
|
|
7048
7119
|
for (const child of value.chi.slice()) {
|
|
7049
|
-
|
|
7120
|
+
map.set(child, value);
|
|
7050
7121
|
}
|
|
7051
7122
|
stack.unshift(...value.chi);
|
|
7052
7123
|
}
|
|
7053
7124
|
else if (value.typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
7054
|
-
|
|
7055
|
-
|
|
7125
|
+
map.set(value.l, value);
|
|
7126
|
+
map.set(value.r, value);
|
|
7056
7127
|
stack.unshift(value.l, value.r);
|
|
7057
7128
|
}
|
|
7058
7129
|
}
|
|
@@ -7203,61 +7274,6 @@ function replaceCompoundLiteral(selector, replace) {
|
|
|
7203
7274
|
}).reduce((acc, curr) => acc + (curr == '&' ? replace : curr), '');
|
|
7204
7275
|
}
|
|
7205
7276
|
|
|
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
7277
|
function replace(node, variableScope) {
|
|
7262
7278
|
for (const { value, parent: parentValue } of walkValues(node.val)) {
|
|
7263
7279
|
if (value?.typ == exports.EnumToken.FunctionTokenType && value.val == 'var') {
|
|
@@ -7281,7 +7297,7 @@ function replace(node, variableScope) {
|
|
|
7281
7297
|
}
|
|
7282
7298
|
}
|
|
7283
7299
|
}
|
|
7284
|
-
class InlineCssVariablesFeature
|
|
7300
|
+
class InlineCssVariablesFeature {
|
|
7285
7301
|
static get ordering() {
|
|
7286
7302
|
return 0;
|
|
7287
7303
|
}
|
|
@@ -7316,7 +7332,7 @@ class InlineCssVariablesFeature extends MinifyFeature {
|
|
|
7316
7332
|
const info = {
|
|
7317
7333
|
globalScope: isRoot,
|
|
7318
7334
|
// @ts-ignore
|
|
7319
|
-
parent: new
|
|
7335
|
+
parent: new Set(),
|
|
7320
7336
|
declarationCount: 1,
|
|
7321
7337
|
replaceable: isRoot,
|
|
7322
7338
|
node: node
|
|
@@ -7354,6 +7370,9 @@ class InlineCssVariablesFeature extends MinifyFeature {
|
|
|
7354
7370
|
}
|
|
7355
7371
|
cleanup(ast, options = {}, context) {
|
|
7356
7372
|
const variableScope = context.variableScope;
|
|
7373
|
+
if (variableScope == null) {
|
|
7374
|
+
return;
|
|
7375
|
+
}
|
|
7357
7376
|
for (const info of variableScope.values()) {
|
|
7358
7377
|
if (info.replaceable) {
|
|
7359
7378
|
let i;
|
|
@@ -7444,6 +7463,7 @@ class PropertySet {
|
|
|
7444
7463
|
}
|
|
7445
7464
|
tokens[current].push(token);
|
|
7446
7465
|
}
|
|
7466
|
+
// @ts-ignore
|
|
7447
7467
|
if (token.typ == exports.EnumToken.LiteralTokenType && token.val == this.config.separator) {
|
|
7448
7468
|
tokens.push([]);
|
|
7449
7469
|
current++;
|
|
@@ -7547,6 +7567,7 @@ class PropertySet {
|
|
|
7547
7567
|
}
|
|
7548
7568
|
}
|
|
7549
7569
|
if (acc.length > 0) {
|
|
7570
|
+
// @ts-ignore
|
|
7550
7571
|
acc.push({ typ: exports.EnumToken.LiteralTokenType, val: this.config.separator });
|
|
7551
7572
|
}
|
|
7552
7573
|
acc.push(...curr);
|
|
@@ -7592,6 +7613,7 @@ class PropertyMap {
|
|
|
7592
7613
|
else {
|
|
7593
7614
|
const separator = this.config.separator != null ? {
|
|
7594
7615
|
...this.config.separator,
|
|
7616
|
+
// @ts-ignore
|
|
7595
7617
|
typ: exports.EnumToken[this.config.separator.typ]
|
|
7596
7618
|
} : null;
|
|
7597
7619
|
// expand shorthand
|
|
@@ -7601,7 +7623,7 @@ class PropertyMap {
|
|
|
7601
7623
|
// @ts-ignore
|
|
7602
7624
|
this.declarations.get(this.config.shorthand).val.slice().reduce((acc, curr) => {
|
|
7603
7625
|
// @ts-ignore
|
|
7604
|
-
if (separator != null && separator.typ == curr.typ &&
|
|
7626
|
+
if (separator != null && separator.typ == curr.typ && separator.val == curr.val) {
|
|
7605
7627
|
acc.push([]);
|
|
7606
7628
|
return acc;
|
|
7607
7629
|
}
|
|
@@ -7640,11 +7662,8 @@ class PropertyMap {
|
|
|
7640
7662
|
i--;
|
|
7641
7663
|
// @ts-ignore
|
|
7642
7664
|
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
|
-
})) {
|
|
7665
|
+
// @ts-ignore
|
|
7666
|
+
if (acc[i].typ == exports.EnumToken[props.prefix.typ] && acc[i].val == this.config.properties[property].prefix.val) {
|
|
7648
7667
|
acc.splice(i, 1);
|
|
7649
7668
|
i--;
|
|
7650
7669
|
}
|
|
@@ -7811,6 +7830,7 @@ class PropertyMap {
|
|
|
7811
7830
|
let values = [];
|
|
7812
7831
|
// @ts-ignore
|
|
7813
7832
|
let typ = (exports.EnumToken[this.config.separator?.typ] ?? exports.EnumToken.CommaTokenType);
|
|
7833
|
+
// @ts-ignore
|
|
7814
7834
|
let separator = this.config.separator ? renderToken(this.config.separator) : ',';
|
|
7815
7835
|
this.matchTypes(declaration);
|
|
7816
7836
|
values.push(value);
|
|
@@ -7890,6 +7910,26 @@ class PropertyMap {
|
|
|
7890
7910
|
}
|
|
7891
7911
|
return (filtered.length > 0 ? filtered : values)[Symbol.iterator]();
|
|
7892
7912
|
}
|
|
7913
|
+
for (const declaration of this.declarations.values()) {
|
|
7914
|
+
if (declaration instanceof PropertySet) {
|
|
7915
|
+
continue;
|
|
7916
|
+
}
|
|
7917
|
+
const config = declaration.nam == this.config.shorthand ? this.config : this.config.properties[declaration.nam] ?? this.config;
|
|
7918
|
+
if (!('mapping' in config)) {
|
|
7919
|
+
continue;
|
|
7920
|
+
}
|
|
7921
|
+
// @ts-ignore
|
|
7922
|
+
for (const [key, val] of Object.entries(config.mapping)) {
|
|
7923
|
+
const keys = parseString(key);
|
|
7924
|
+
if (keys.length != declaration.val.length) {
|
|
7925
|
+
continue;
|
|
7926
|
+
}
|
|
7927
|
+
if (eq(declaration.val, keys)) {
|
|
7928
|
+
declaration.val = parseString(val);
|
|
7929
|
+
break;
|
|
7930
|
+
}
|
|
7931
|
+
}
|
|
7932
|
+
}
|
|
7893
7933
|
// @ts-ignore
|
|
7894
7934
|
iterable = this.declarations.values();
|
|
7895
7935
|
}
|
|
@@ -7898,6 +7938,7 @@ class PropertyMap {
|
|
|
7898
7938
|
let match;
|
|
7899
7939
|
const separator = this.config.separator != null ? {
|
|
7900
7940
|
...this.config.separator,
|
|
7941
|
+
// @ts-ignore
|
|
7901
7942
|
typ: exports.EnumToken[this.config.separator.typ]
|
|
7902
7943
|
} : null;
|
|
7903
7944
|
const tokens = {};
|
|
@@ -7915,7 +7956,8 @@ class PropertyMap {
|
|
|
7915
7956
|
for (const declaration of [(properties instanceof PropertySet ? [...properties][0] : properties)]) {
|
|
7916
7957
|
// @ts-ignore
|
|
7917
7958
|
for (const val of declaration.val) {
|
|
7918
|
-
|
|
7959
|
+
// @ts-ignore
|
|
7960
|
+
if (separator != null && separator.typ == val.typ && separator.val == val.val) {
|
|
7919
7961
|
current++;
|
|
7920
7962
|
if (tokens[curr[0]].length == current) {
|
|
7921
7963
|
tokens[curr[0]].push([]);
|
|
@@ -7926,10 +7968,11 @@ class PropertyMap {
|
|
|
7926
7968
|
continue;
|
|
7927
7969
|
}
|
|
7928
7970
|
// @ts-ignore
|
|
7929
|
-
if (props.multiple && props.separator != null &&
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7971
|
+
if (props.multiple && props.separator != null &&
|
|
7972
|
+
// @ts-ignore
|
|
7973
|
+
exports.EnumToken[props.separator.typ] == val.typ &&
|
|
7974
|
+
// @ts-ignore
|
|
7975
|
+
props.separator.val == val.val) {
|
|
7933
7976
|
continue;
|
|
7934
7977
|
}
|
|
7935
7978
|
// @ts-ignore
|
|
@@ -8034,6 +8077,7 @@ class PropertyMap {
|
|
|
8034
8077
|
acc.push({
|
|
8035
8078
|
...((props.separator && {
|
|
8036
8079
|
...props.separator,
|
|
8080
|
+
// @ts-ignore
|
|
8037
8081
|
typ: exports.EnumToken[props.separator.typ]
|
|
8038
8082
|
}) ?? { typ: exports.EnumToken.WhitespaceTokenType })
|
|
8039
8083
|
});
|
|
@@ -8134,6 +8178,7 @@ class PropertyMap {
|
|
|
8134
8178
|
if (value[index].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
8135
8179
|
continue;
|
|
8136
8180
|
}
|
|
8181
|
+
// @ts-ignore@
|
|
8137
8182
|
if (value[index].typ == exports.EnumToken[config.prefix.typ] &&
|
|
8138
8183
|
// @ts-ignore
|
|
8139
8184
|
value[index].val == config.prefix.val) {
|
|
@@ -8154,12 +8199,7 @@ class PropertyList {
|
|
|
8154
8199
|
options = { removeDuplicateDeclarations: true, computeShorthand: true };
|
|
8155
8200
|
declarations;
|
|
8156
8201
|
constructor(options = {}) {
|
|
8157
|
-
|
|
8158
|
-
if (key in options) {
|
|
8159
|
-
// @ts-ignore
|
|
8160
|
-
this.options[key] = options[key];
|
|
8161
|
-
}
|
|
8162
|
-
}
|
|
8202
|
+
this.options = options;
|
|
8163
8203
|
this.declarations = new Map;
|
|
8164
8204
|
}
|
|
8165
8205
|
set(nam, value) {
|
|
@@ -8253,7 +8293,7 @@ class PropertyList {
|
|
|
8253
8293
|
}
|
|
8254
8294
|
}
|
|
8255
8295
|
|
|
8256
|
-
class ComputeShorthandFeature
|
|
8296
|
+
class ComputeShorthandFeature {
|
|
8257
8297
|
static get ordering() {
|
|
8258
8298
|
return 2;
|
|
8259
8299
|
}
|
|
@@ -8265,7 +8305,7 @@ class ComputeShorthandFeature extends MinifyFeature {
|
|
|
8265
8305
|
}
|
|
8266
8306
|
}
|
|
8267
8307
|
// @ts-ignore
|
|
8268
|
-
options.features.push(new ComputeShorthandFeature());
|
|
8308
|
+
options.features.push(new ComputeShorthandFeature(options));
|
|
8269
8309
|
}
|
|
8270
8310
|
}
|
|
8271
8311
|
run(ast, options = {}, parent, context) {
|
|
@@ -8289,7 +8329,7 @@ class ComputeShorthandFeature extends MinifyFeature {
|
|
|
8289
8329
|
}
|
|
8290
8330
|
}
|
|
8291
8331
|
|
|
8292
|
-
class ComputeCalcExpressionFeature
|
|
8332
|
+
class ComputeCalcExpressionFeature {
|
|
8293
8333
|
static get ordering() {
|
|
8294
8334
|
return 1;
|
|
8295
8335
|
}
|
|
@@ -8313,7 +8353,7 @@ class ComputeCalcExpressionFeature extends MinifyFeature {
|
|
|
8313
8353
|
if (node.typ != exports.EnumToken.DeclarationNodeType) {
|
|
8314
8354
|
continue;
|
|
8315
8355
|
}
|
|
8316
|
-
const set = new
|
|
8356
|
+
const set = new Set;
|
|
8317
8357
|
for (const { value, parent } of walkValues(node.val)) {
|
|
8318
8358
|
if (value != null && value.typ == exports.EnumToken.FunctionTokenType && value.val == 'calc') {
|
|
8319
8359
|
if (!set.has(parent)) {
|
|
@@ -8354,8 +8394,8 @@ var allFeatures = /*#__PURE__*/Object.freeze({
|
|
|
8354
8394
|
});
|
|
8355
8395
|
|
|
8356
8396
|
const combinators = ['+', '>', '~', '||'];
|
|
8357
|
-
const notEndingWith = ['(', '['].concat(combinators);
|
|
8358
8397
|
const definedPropertySettings = { configurable: true, enumerable: false, writable: true };
|
|
8398
|
+
const notEndingWith = ['(', '['].concat(combinators);
|
|
8359
8399
|
// @ts-ignore
|
|
8360
8400
|
const features = Object.values(allFeatures).sort((a, b) => a.ordering - b.ordering);
|
|
8361
8401
|
function minify(ast, options = {}, recursive = false, errors, nestingContent, context = {}) {
|