@tbela99/css-parser 2.3.0 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/README.md +66 -21
- package/architecture.png +0 -0
- package/dist/ast/arena-node.js +32 -3
- package/dist/ast/arena.js +88 -10
- package/dist/ast/cache.js +1 -1
- package/dist/ast/features/calc.js +1 -1
- package/dist/ast/features/if.js +1 -1
- package/dist/ast/features/index.js +1 -1
- package/dist/ast/features/inlinecssvariables.js +1 -1
- package/dist/ast/features/mixin.js +1 -1
- package/dist/ast/features/prefix.js +1 -1
- package/dist/ast/features/shorthand.js +1 -1
- package/dist/ast/features/transform.js +1 -1
- package/dist/ast/features/type.js +1 -1
- package/dist/ast/math/expression.js +1 -1
- package/dist/ast/math/math.js +1 -1
- package/dist/ast/minify.js +131 -36
- package/dist/ast/mixins/custom-function.js +1 -1
- package/dist/ast/mixins/utils.js +1 -1
- package/dist/ast/mixins/variables.js +1 -1
- package/dist/ast/strings.js +26 -1
- package/dist/ast/transform/compute.js +6 -2
- package/dist/ast/transform/matrix.js +1 -1
- package/dist/ast/transform/minify.js +1 -1
- package/dist/ast/transform/perspective.js +1 -1
- package/dist/ast/transform/rotate.js +1 -1
- package/dist/ast/transform/scale.js +1 -1
- package/dist/ast/transform/skew.js +1 -1
- package/dist/ast/transform/translate.js +1 -1
- package/dist/ast/transform/utils.js +1 -1
- package/dist/ast/types.js +22 -2
- package/dist/ast/walk.js +1 -1
- package/dist/data/properties.json.js +1 -1
- package/dist/data/validation.json.js +1 -1
- package/dist/fs/resolve.js +1 -1
- package/dist/index-umd-web.js +1099 -295
- package/dist/index.d.ts +612 -688
- package/dist/node.js +14 -8
- package/dist/parser/declaration/list.js +8 -5
- package/dist/parser/declaration/map.js +1 -1
- package/dist/parser/declaration/set.js +1 -1
- package/dist/parser/input.js +62 -4
- package/dist/parser/linesmap.js +1 -1
- package/dist/parser/parse.js +121 -13
- package/dist/parser/source.js +1 -1
- package/dist/parser/tokenize.js +161 -19
- package/dist/parser/utils/angle.js +1 -1
- package/dist/parser/utils/at-rule-container.js +1 -1
- package/dist/parser/utils/at-rule-font-feature-values.js +1 -1
- package/dist/parser/utils/at-rule-generic.js +1 -1
- package/dist/parser/utils/at-rule-import.js +1 -1
- package/dist/parser/utils/at-rule-media.js +42 -2
- package/dist/parser/utils/at-rule-support.js +1 -1
- package/dist/parser/utils/at-rule-when-else.js +1 -1
- package/dist/parser/utils/at-rule.js +1 -1
- package/dist/parser/utils/base64.js +1 -1
- package/dist/parser/utils/cache.js +1 -1
- package/dist/parser/utils/canonical.js +1 -1
- package/dist/parser/utils/codes.js +1 -1
- package/dist/parser/utils/config.js +1 -1
- package/dist/parser/utils/declaration.js +1 -1
- package/dist/parser/utils/eq.js +1 -1
- package/dist/parser/utils/hash.js +1 -1
- package/dist/parser/utils/selector.js +98 -6
- package/dist/parser/utils/text.js +1 -1
- package/dist/parser/utils/token.js +1 -1
- package/dist/parser/utils/type.js +1 -1
- package/dist/printer/lib/codec.js +1 -1
- package/dist/printer/render.js +5 -7
- package/dist/printer/result.js +18 -3
- package/dist/printer/sourcemap.js +1 -1
- package/dist/printer/writer.js +1 -1
- package/dist/syntax/color/a98rgb.js +1 -1
- package/dist/syntax/color/alpha.js +1 -1
- package/dist/syntax/color/cmyk.js +1 -1
- package/dist/syntax/color/color-mix.js +1 -1
- package/dist/syntax/color/color.js +1 -1
- package/dist/syntax/color/hex.js +1 -1
- package/dist/syntax/color/hsl.js +12 -4
- package/dist/syntax/color/hwb.js +9 -3
- package/dist/syntax/color/lab.js +1 -1
- package/dist/syntax/color/lch.js +1 -1
- package/dist/syntax/color/oklab.js +1 -1
- package/dist/syntax/color/oklch.js +2 -2
- package/dist/syntax/color/p3.js +1 -1
- package/dist/syntax/color/prophotorgb.js +1 -1
- package/dist/syntax/color/rec2020.js +1 -1
- package/dist/syntax/color/relative-color.js +1 -1
- package/dist/syntax/color/rgb.js +1 -1
- package/dist/syntax/color/srgb.js +3 -2
- package/dist/syntax/color/utils/color-type.js +1 -1
- package/dist/syntax/color/utils/colorspace.js +1 -1
- package/dist/syntax/color/utils/components.js +1 -1
- package/dist/syntax/color/utils/distance.js +1 -1
- package/dist/syntax/color/utils/make-color.js +1 -1
- package/dist/syntax/color/utils/matrix.js +1 -1
- package/dist/syntax/color/xyz.js +1 -1
- package/dist/syntax/color/xyzd50.js +1 -1
- package/dist/syntax/constants.js +2 -2
- package/dist/syntax/syntax.js +1 -1
- package/dist/types.js +1 -1
- package/dist/utils/sync.js +1 -1
- package/dist/validation/compiled/builtins.js +1 -1
- package/dist/validation/compiled/runtime.js +1 -1
- package/dist/validation/compiled/syntaxes.js +1 -1
- package/dist/validation/config.js +1 -1
- package/dist/validation/first.js +1 -1
- package/dist/validation/match.js +77 -4
- package/dist/validation/parser/parse.js +1 -1
- package/dist/validation/parser/typedef.js +4 -1
- package/dist/validation/utils/list.js +1 -1
- package/dist/version.js +2 -2
- package/dist/web.js +13 -6
- package/package.json +15 -6
package/dist/ast/minify.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { eq, eqToken } from '../parser/utils/eq.js';
|
|
9
9
|
import { renderValue, NodeRenderer } from '../printer/render.js';
|
|
10
10
|
import * as index from './features/index.js';
|
|
11
|
-
import { EnumToken, EnumAstNodeStatus } from './types.js';
|
|
11
|
+
import { EnumToken, EnumAstNodeStatus, MergeRulesEnum } from './types.js';
|
|
12
12
|
import { StringBuilder } from './strings.js';
|
|
13
13
|
import { isWhiteSpace, isIdent, isFunction, isIdentStart } from '../syntax/syntax.js';
|
|
14
14
|
import { FeatureWalkMode } from './features/type.js';
|
|
@@ -286,6 +286,22 @@ function factorSelector(optimized) {
|
|
|
286
286
|
*
|
|
287
287
|
* @private
|
|
288
288
|
*/
|
|
289
|
+
/**
|
|
290
|
+
* Merge the adjacent rules without minifying the ast: `minify: false` with {@link ParserOptions.mergeRules}. The style
|
|
291
|
+
* rules that have the same selector, the keyframes rules that have the same selector, the at-rules that have the same
|
|
292
|
+
* name and prelude (not `@font-face`) and, depending on `mergeRules`, the rules that share declarations are merged. Of
|
|
293
|
+
* the `@keyframes` that have the same name, the last one is kept. The other minifications are not applied
|
|
294
|
+
* @param arena
|
|
295
|
+
* @param ast
|
|
296
|
+
* @param options
|
|
297
|
+
*
|
|
298
|
+
* @private
|
|
299
|
+
*/
|
|
300
|
+
function mergeRules(arena, ast, options) {
|
|
301
|
+
return doMinify(arena, ast, { ...options, nestingRules: false, optimizeSelectors: false }, true, undefined, false, {
|
|
302
|
+
mergeOnly: true,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
289
305
|
function doMinify(arena, ast, options = {}, recursive = false, errors, nestingContent, context = {}) {
|
|
290
306
|
if (!("nodes" in context)) {
|
|
291
307
|
context.nodes = new Set();
|
|
@@ -336,7 +352,7 @@ function doMinify(arena, ast, options = {}, recursive = false, errors, nestingCo
|
|
|
336
352
|
}
|
|
337
353
|
// there is no early return: the result that precedes the conditional rules is moved after them.
|
|
338
354
|
// the conditional rules are never removed
|
|
339
|
-
if (equalsIgnoreCase(nam, "function")) {
|
|
355
|
+
if (!context.mergeOnly && equalsIgnoreCase(nam, "function")) {
|
|
340
356
|
moveResult(arena, node);
|
|
341
357
|
}
|
|
342
358
|
}
|
|
@@ -363,7 +379,8 @@ function doMinify(arena, ast, options = {}, recursive = false, errors, nestingCo
|
|
|
363
379
|
cursor = arena.nextSibling[previous];
|
|
364
380
|
continue;
|
|
365
381
|
}
|
|
366
|
-
|
|
382
|
+
// merge only (see mergeRules()): the declarations are not removed
|
|
383
|
+
let k = context.mergeOnly ? 0 : arena.firstChild[node];
|
|
367
384
|
while (k !== 0) {
|
|
368
385
|
const next = arena.nextSibling[k];
|
|
369
386
|
if (arena.dataTypes[k] === EnumToken.DeclarationNodeType) {
|
|
@@ -396,7 +413,8 @@ function doMinify(arena, ast, options = {}, recursive = false, errors, nestingCo
|
|
|
396
413
|
(index + 3 < arr.length || arena.dataTypes[arr[index + 2]] === EnumToken.WhitespaceTokenType))
|
|
397
414
|
? ""
|
|
398
415
|
: renderValue(arena, curr));
|
|
399
|
-
if (
|
|
416
|
+
if (context.mergeOnly) ;
|
|
417
|
+
else if (nam === "apply") {
|
|
400
418
|
// `@apply --mixin()` is equivalent to `@apply --mixin`
|
|
401
419
|
minifyApplyPrelude(arena, node);
|
|
402
420
|
}
|
|
@@ -438,9 +456,11 @@ function doMinify(arena, ast, options = {}, recursive = false, errors, nestingCo
|
|
|
438
456
|
arena.stringValue[node] = arena.internString(trimArray(arena, tokens).reduce(renderPrelude, ""));
|
|
439
457
|
}
|
|
440
458
|
}
|
|
441
|
-
|
|
459
|
+
if (arena.dataTypes[ast] === nodeType &&
|
|
442
460
|
arena.name[ast] === arena.name[node] &&
|
|
443
|
-
arena.stringValue[ast] === arena.stringValue[node]
|
|
461
|
+
arena.stringValue[ast] === arena.stringValue[node] &&
|
|
462
|
+
// the at-rules handled above are not replaced when the ast is minified
|
|
463
|
+
(context.mergeOnly || (nam !== "apply" && nam !== "media" && !(nam === "import" && tokens != null)))) {
|
|
444
464
|
// the node is replaced by its children
|
|
445
465
|
cursor = arena.firstChild[node] || arena.nextSibling[node];
|
|
446
466
|
arena.moveChildren(node, ast, node);
|
|
@@ -472,8 +492,9 @@ function doMinify(arena, ast, options = {}, recursive = false, errors, nestingCo
|
|
|
472
492
|
}
|
|
473
493
|
else if (nodeType === EnumToken.RuleNodeType) {
|
|
474
494
|
// a single selector that does not end with a combinator is not reduced (see isSimpleSelector()): the
|
|
475
|
-
// selector is not read
|
|
476
|
-
if (
|
|
495
|
+
// selector is not read. the nesting reads the reduced selectors: optimizeSelectors only applies without it
|
|
496
|
+
if ((options.optimizeSelectors !== false || options.nestingRules) &&
|
|
497
|
+
!isSimpleSelector(arena, arena.name[node])) {
|
|
477
498
|
reduceRuleSelector(arena, node);
|
|
478
499
|
}
|
|
479
500
|
let wrapper = null;
|
|
@@ -639,7 +660,9 @@ function doMinify(arena, ast, options = {}, recursive = false, errors, nestingCo
|
|
|
639
660
|
cursor = arena.nextSibling[node];
|
|
640
661
|
continue;
|
|
641
662
|
}
|
|
642
|
-
else if (
|
|
663
|
+
else if (options.mergeRules !== false &&
|
|
664
|
+
options.mergeRules !== MergeRulesEnum.None &&
|
|
665
|
+
nodeType === previousType &&
|
|
643
666
|
[EnumToken.KeyframesRuleNodeType, EnumToken.RuleNodeType].includes(nodeType)) {
|
|
644
667
|
const intersect = diff(arena, previous, node, options, context);
|
|
645
668
|
if (intersect != null) {
|
|
@@ -682,6 +705,7 @@ function doMinify(arena, ast, options = {}, recursive = false, errors, nestingCo
|
|
|
682
705
|
}
|
|
683
706
|
}
|
|
684
707
|
if (!nestingContent &&
|
|
708
|
+
!context.mergeOnly &&
|
|
685
709
|
previous != null &&
|
|
686
710
|
arena.dataTypes[previous] === EnumToken.RuleNodeType &&
|
|
687
711
|
arena.stringIndexOf(arena.name[previous], 0x26) !== -1) {
|
|
@@ -699,6 +723,7 @@ function doMinify(arena, ast, options = {}, recursive = false, errors, nestingCo
|
|
|
699
723
|
}
|
|
700
724
|
}
|
|
701
725
|
if (!nestingContent &&
|
|
726
|
+
!context.mergeOnly &&
|
|
702
727
|
node != null &&
|
|
703
728
|
arena.dataTypes[node] === EnumToken.RuleNodeType &&
|
|
704
729
|
arena.stringIndexOf(arena.name[node], 0x26) !== -1) {
|
|
@@ -1292,24 +1317,38 @@ function hasAtRuleStatement(arena, node) {
|
|
|
1292
1317
|
*
|
|
1293
1318
|
* @private
|
|
1294
1319
|
*/
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1320
|
+
/**
|
|
1321
|
+
* the number of declarations of a rule: its children that are not comments
|
|
1322
|
+
* @param arena
|
|
1323
|
+
* @param node
|
|
1324
|
+
*/
|
|
1325
|
+
function declarationCount(arena, node) {
|
|
1326
|
+
let count = 0;
|
|
1327
|
+
for (let child = arena.firstChild[node]; child !== 0; child = arena.nextSibling[child]) {
|
|
1328
|
+
if (arena.dataTypes[child] !== EnumToken.CommentNodeType) {
|
|
1329
|
+
count++;
|
|
1330
|
+
}
|
|
1303
1331
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1332
|
+
return count;
|
|
1333
|
+
}
|
|
1334
|
+
/**
|
|
1335
|
+
* clear the matched flag of the children of a rule
|
|
1336
|
+
* @param arena
|
|
1337
|
+
* @param node
|
|
1338
|
+
*/
|
|
1339
|
+
function clearMatched(arena, node) {
|
|
1340
|
+
for (let child = arena.firstChild[node]; child !== 0; child = arena.nextSibling[child]) {
|
|
1341
|
+
arena.flags[child] &= ~EnumAstNodeStatus.Matched;
|
|
1312
1342
|
}
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* the selectors of both rules have the same vendor prefixes: the rules that do not are not merged (a browser drops a
|
|
1346
|
+
* selector list that contains a pseudo class with an unknown prefix)
|
|
1347
|
+
* @param arena
|
|
1348
|
+
* @param node1
|
|
1349
|
+
* @param node2
|
|
1350
|
+
*/
|
|
1351
|
+
function samePrefixes(arena, node1, node2) {
|
|
1313
1352
|
const raw1 = arena.raw.get(node1);
|
|
1314
1353
|
const raw2 = arena.raw.get(node2);
|
|
1315
1354
|
if (raw1 == null || raw2 == null) {
|
|
@@ -1318,11 +1357,11 @@ function diff(arena, n1, n2, options, context) {
|
|
|
1318
1357
|
const prefixes1 = raw1 == null ? selectorPrefixes(arena, arena.name[node1]) : rawSelectorPrefixes(raw1);
|
|
1319
1358
|
const prefixes2 = raw2 == null ? selectorPrefixes(arena, arena.name[node2]) : rawSelectorPrefixes(raw2);
|
|
1320
1359
|
if (prefixes1.size !== prefixes2.size) {
|
|
1321
|
-
return
|
|
1360
|
+
return false;
|
|
1322
1361
|
}
|
|
1323
1362
|
for (const prefix of prefixes1) {
|
|
1324
1363
|
if (!prefixes2.has(prefix)) {
|
|
1325
|
-
return
|
|
1364
|
+
return false;
|
|
1326
1365
|
}
|
|
1327
1366
|
}
|
|
1328
1367
|
}
|
|
@@ -1364,14 +1403,39 @@ function diff(arena, n1, n2, options, context) {
|
|
|
1364
1403
|
}
|
|
1365
1404
|
}
|
|
1366
1405
|
if (prefixes1.size !== prefixes2.size) {
|
|
1367
|
-
return
|
|
1406
|
+
return false;
|
|
1368
1407
|
}
|
|
1369
1408
|
for (const prefix of prefixes1) {
|
|
1370
1409
|
if (!prefixes2.has(prefix)) {
|
|
1371
|
-
return
|
|
1410
|
+
return false;
|
|
1372
1411
|
}
|
|
1373
1412
|
}
|
|
1374
1413
|
}
|
|
1414
|
+
return true;
|
|
1415
|
+
}
|
|
1416
|
+
function diff(arena, n1, n2, options, context) {
|
|
1417
|
+
// the declarations of a rule that applies a mixin are not moved: `@apply` inserts declarations at its position,
|
|
1418
|
+
// the declarations that follow it override them
|
|
1419
|
+
if (hasAtRuleStatement(arena, n1) || hasAtRuleStatement(arena, n2)) {
|
|
1420
|
+
return null;
|
|
1421
|
+
}
|
|
1422
|
+
// only the rules that have the same declarations are merged: the rules that have a different number of
|
|
1423
|
+
// declarations are not compared
|
|
1424
|
+
if (options.mergeRules === MergeRulesEnum.Identical && declarationCount(arena, n1) !== declarationCount(arena, n2)) {
|
|
1425
|
+
return null;
|
|
1426
|
+
}
|
|
1427
|
+
if (!("cache" in options)) {
|
|
1428
|
+
options.cache = new Map();
|
|
1429
|
+
}
|
|
1430
|
+
let node1 = n1;
|
|
1431
|
+
let node2 = n2;
|
|
1432
|
+
let exchanged = false;
|
|
1433
|
+
if (arena.childCount(node1) > arena.childCount(node2)) {
|
|
1434
|
+
const t = node1;
|
|
1435
|
+
node1 = node2;
|
|
1436
|
+
node2 = t;
|
|
1437
|
+
exchanged = true;
|
|
1438
|
+
}
|
|
1375
1439
|
// match the declarations of both rules, from the last to the first
|
|
1376
1440
|
let matches = 0;
|
|
1377
1441
|
for (let child1 = arena.lastChild[node1]; child1 !== 0; child1 = arena.previousSibling[child1]) {
|
|
@@ -1390,10 +1454,31 @@ function diff(arena, n1, n2, options, context) {
|
|
|
1390
1454
|
break;
|
|
1391
1455
|
}
|
|
1392
1456
|
}
|
|
1457
|
+
// a declaration without a match: the rules are not identical
|
|
1458
|
+
if (options.mergeRules === MergeRulesEnum.Identical && !(arena.flags[child1] & EnumAstNodeStatus.Matched)) {
|
|
1459
|
+
clearMatched(arena, node1);
|
|
1460
|
+
clearMatched(arena, node2);
|
|
1461
|
+
return null;
|
|
1462
|
+
}
|
|
1393
1463
|
}
|
|
1394
1464
|
if (matches === 0 && (arena.firstChild[node1] !== 0 || arena.firstChild[node2] !== 0)) {
|
|
1395
1465
|
return null;
|
|
1396
1466
|
}
|
|
1467
|
+
// every declaration of both rules is matched: the merged rule replaces both rules, it is always smaller, the sizes
|
|
1468
|
+
// are not computed
|
|
1469
|
+
const identical = matches === declarationCount(arena, node1) && matches === declarationCount(arena, node2);
|
|
1470
|
+
if (!identical && options.mergeRules === MergeRulesEnum.Identical) {
|
|
1471
|
+
// the rules are not merged: the matched declarations are released
|
|
1472
|
+
clearMatched(arena, node1);
|
|
1473
|
+
clearMatched(arena, node2);
|
|
1474
|
+
return null;
|
|
1475
|
+
}
|
|
1476
|
+
// the vendor prefixes are compared once the rules share declarations
|
|
1477
|
+
if (!samePrefixes(arena, node1, node2)) {
|
|
1478
|
+
clearMatched(arena, node1);
|
|
1479
|
+
clearMatched(arena, node2);
|
|
1480
|
+
return null;
|
|
1481
|
+
}
|
|
1397
1482
|
// the rules are rendered with the same options during the minification: the options are resolved once and
|
|
1398
1483
|
// identical values are rendered once
|
|
1399
1484
|
const renderer = (context.renderer ??= new NodeRenderer(options));
|
|
@@ -1408,7 +1493,7 @@ function diff(arena, n1, n2, options, context) {
|
|
|
1408
1493
|
return arena.firstChild[node] === 0 ? 0 : size;
|
|
1409
1494
|
};
|
|
1410
1495
|
// size of the original nodes
|
|
1411
|
-
const size = renderedSize(n1, true) + renderedSize(n2, true);
|
|
1496
|
+
const size = identical ? 0 : renderedSize(n1, true) + renderedSize(n2, true);
|
|
1412
1497
|
// the shared declarations are moved into the result node
|
|
1413
1498
|
const result = arena.cloneNode(node1);
|
|
1414
1499
|
// the distinct selectors of both rules: built from the code units of the selectors when they are normalized
|
|
@@ -1450,7 +1535,9 @@ function diff(arena, n1, n2, options, context) {
|
|
|
1450
1535
|
// the merge is kept when the output is smaller, or when it has the same size and removes a rule (an emptied rule is
|
|
1451
1536
|
// removed, its size is 0). the other rule keeps its selector, which is repeated in the merged selector: the merge of
|
|
1452
1537
|
// `html{margin:0}` and `body,div,...{margin:0;font:inherit}` is larger than the rules
|
|
1453
|
-
const mergedSize =
|
|
1538
|
+
const mergedSize = identical
|
|
1539
|
+
? 0
|
|
1540
|
+
: renderedSize(node1, false) + renderedSize(node2, false) + renderedSize(result, false);
|
|
1454
1541
|
if (size < mergedSize ||
|
|
1455
1542
|
(size === mergedSize && arena.firstChild[node1] !== 0 && arena.firstChild[node2] !== 0)) {
|
|
1456
1543
|
// restore the nodes: undo the moves in reverse order
|
|
@@ -1474,7 +1561,7 @@ function diff(arena, n1, n2, options, context) {
|
|
|
1474
1561
|
if (arena.optimized.get(result) != null) {
|
|
1475
1562
|
arena.optimized.set(result, null);
|
|
1476
1563
|
}
|
|
1477
|
-
const optimized = optimizeSelector(splitRule(arena.resolveString(arena.name[result])));
|
|
1564
|
+
const optimized = options.optimizeSelectors === false ? null : optimizeSelector(splitRule(arena.resolveString(arena.name[result])));
|
|
1478
1565
|
if (optimized?.match) {
|
|
1479
1566
|
const sel = factorSelector(optimized);
|
|
1480
1567
|
if (sel != null && sel.length < arena.resolveString(arena.name[result]).length) {
|
|
@@ -1825,8 +1912,12 @@ function readSelector(arena, id) {
|
|
|
1825
1912
|
* @param id selector string id
|
|
1826
1913
|
*/
|
|
1827
1914
|
function isSimpleSelector(arena, id) {
|
|
1915
|
+
const previousSelectorArena = selectorArena;
|
|
1828
1916
|
selectorArena = arena;
|
|
1829
|
-
|
|
1917
|
+
const simple = arena.stringFlagId(id, 1 /* StringFlag.SimpleSelector */, computeSimpleSelector);
|
|
1918
|
+
// the arena is not kept after the minification: the previous arena is restored (a nested call)
|
|
1919
|
+
selectorArena = previousSelectorArena;
|
|
1920
|
+
return simple;
|
|
1830
1921
|
}
|
|
1831
1922
|
/**
|
|
1832
1923
|
* the arena of the selector read by {@link computeSimpleSelector} and {@link hasVendorPrefix}: the functions passed to
|
|
@@ -1921,8 +2012,12 @@ function hasVendorPrefix(id) {
|
|
|
1921
2012
|
*/
|
|
1922
2013
|
function selectorPrefixes(arena, id) {
|
|
1923
2014
|
// the selectors without `:-` are skipped: computed once per string id
|
|
2015
|
+
const previousSelectorArena = selectorArena;
|
|
1924
2016
|
selectorArena = arena;
|
|
1925
|
-
|
|
2017
|
+
const prefixed = arena.stringFlagId(id, 2 /* StringFlag.VendorPrefix */, hasVendorPrefix);
|
|
2018
|
+
// the arena is not kept after the minification: the previous arena is restored (a nested call)
|
|
2019
|
+
selectorArena = previousSelectorArena;
|
|
2020
|
+
if (!prefixed) {
|
|
1926
2021
|
return emptyPrefixes;
|
|
1927
2022
|
}
|
|
1928
2023
|
const prefixes = new Set();
|
|
@@ -2096,4 +2191,4 @@ function reduceRuleSelector(arena, node) {
|
|
|
2096
2191
|
}
|
|
2097
2192
|
}
|
|
2098
2193
|
|
|
2099
|
-
export { minify, optimizeSelector, splitRule };
|
|
2194
|
+
export { mergeRules, minify, optimizeSelector, splitRule };
|
package/dist/ast/mixins/utils.js
CHANGED
package/dist/ast/strings.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { hashString, hashRange } from '../parser/utils/codes.js';
|
|
@@ -88,6 +88,10 @@ var StringDerived;
|
|
|
88
88
|
*/
|
|
89
89
|
StringDerived[StringDerived["AtRuleAcceptsRules"] = 3] = "AtRuleAcceptsRules";
|
|
90
90
|
})(StringDerived || (StringDerived = {}));
|
|
91
|
+
/**
|
|
92
|
+
* code units of a short string, see {@link fromCodes}
|
|
93
|
+
*/
|
|
94
|
+
const shortCodes = [];
|
|
91
95
|
/**
|
|
92
96
|
* string of a range of code units
|
|
93
97
|
* @param codes
|
|
@@ -95,6 +99,15 @@ var StringDerived;
|
|
|
95
99
|
* @param end
|
|
96
100
|
*/
|
|
97
101
|
function fromCodes(codes, start, end) {
|
|
102
|
+
const length = end - start;
|
|
103
|
+
// a short string: the code units are copied to an array, a subarray is slower to create
|
|
104
|
+
if (length <= 256) {
|
|
105
|
+
shortCodes.length = length;
|
|
106
|
+
for (let i = 0; i < length; i++) {
|
|
107
|
+
shortCodes[i] = codes[start + i];
|
|
108
|
+
}
|
|
109
|
+
return String.fromCharCode.apply(null, shortCodes);
|
|
110
|
+
}
|
|
98
111
|
let result = "";
|
|
99
112
|
// String.fromCharCode() with a limited number of arguments
|
|
100
113
|
while (start < end) {
|
|
@@ -266,6 +279,18 @@ class StringTable {
|
|
|
266
279
|
this.texts[source] = text;
|
|
267
280
|
this.codes[source] = codes ?? undefined;
|
|
268
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* code unit of the text of a source, NaN after its end
|
|
284
|
+
* @param source source index
|
|
285
|
+
* @param offset
|
|
286
|
+
*/
|
|
287
|
+
sourceCodeAt(source, offset) {
|
|
288
|
+
const text = this.texts[source];
|
|
289
|
+
if (text !== undefined && offset < text.length) {
|
|
290
|
+
return text.charCodeAt(offset);
|
|
291
|
+
}
|
|
292
|
+
return this.codes[source]?.[offset] ?? NaN;
|
|
293
|
+
}
|
|
269
294
|
/**
|
|
270
295
|
* drop the code units of a source: the source is no longer tokenized, see {@link setText}
|
|
271
296
|
* @param source
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { setIdentity, multiplyInto, toZero } from './utils.js';
|
|
@@ -132,8 +132,12 @@ function computeTransformKind(id) {
|
|
|
132
132
|
* @param id interned string id
|
|
133
133
|
*/
|
|
134
134
|
function transformKind(arena, id) {
|
|
135
|
+
const previousKindArena = kindArena;
|
|
135
136
|
kindArena = arena;
|
|
136
|
-
|
|
137
|
+
const kind = arena.stringDerived(id, 2 /* StringDerived.TransformKind */, computeTransformKind);
|
|
138
|
+
// the arena is not kept after the transformation: the previous arena is restored (a nested call)
|
|
139
|
+
kindArena = previousKindArena;
|
|
140
|
+
return kind;
|
|
137
141
|
}
|
|
138
142
|
/**
|
|
139
143
|
* numeric arguments of a transform function (the first 16 arguments), reused
|
package/dist/ast/types.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
@@ -1008,5 +1008,25 @@ var WalkerEvent;
|
|
|
1008
1008
|
*/
|
|
1009
1009
|
WalkerEvent[WalkerEvent["Leave"] = 2] = "Leave";
|
|
1010
1010
|
})(WalkerEvent || (WalkerEvent = {}));
|
|
1011
|
+
/**
|
|
1012
|
+
* Merge of the adjacent rules, see {@link ParserOptions.mergeRules}. `true` is a shortcut for
|
|
1013
|
+
* {@link MergeRulesEnum.All}, `false` for {@link MergeRulesEnum.None}
|
|
1014
|
+
*/
|
|
1015
|
+
var MergeRulesEnum;
|
|
1016
|
+
(function (MergeRulesEnum) {
|
|
1017
|
+
/**
|
|
1018
|
+
* the rules are not merged
|
|
1019
|
+
*/
|
|
1020
|
+
MergeRulesEnum[MergeRulesEnum["None"] = 0] = "None";
|
|
1021
|
+
/**
|
|
1022
|
+
* only the rules that have the same declarations are merged, the size of the output is not computed:
|
|
1023
|
+
* `.a{color:red}.b{color:red}` is merged into `.a,.b{color:red}`
|
|
1024
|
+
*/
|
|
1025
|
+
MergeRulesEnum[MergeRulesEnum["Identical"] = 1] = "Identical";
|
|
1026
|
+
/**
|
|
1027
|
+
* the rules that share declarations are merged when the output is smaller
|
|
1028
|
+
*/
|
|
1029
|
+
MergeRulesEnum[MergeRulesEnum["All"] = 2] = "All";
|
|
1030
|
+
})(MergeRulesEnum || (MergeRulesEnum = {}));
|
|
1011
1031
|
|
|
1012
|
-
export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, ModuleScopeEnumOptions, WalkerEvent, WalkerOptionEnum };
|
|
1032
|
+
export { ColorType, EnumAstNodeStatus, EnumToken, MergeRulesEnum, ModuleCaseTransformEnum, ModuleScopeEnumOptions, WalkerEvent, WalkerOptionEnum };
|
package/dist/ast/walk.js
CHANGED