@tbela99/css-parser 1.4.3 → 1.4.4
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 +192 -2
- package/README.md +69 -1120
- package/dist/config.json.js +43 -2
- package/dist/index-umd-web.js +17226 -15037
- package/dist/index.cjs +16889 -14705
- package/dist/index.d.ts +1804 -1684
- package/dist/lib/ast/clone.js +4 -3
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/calc.js +59 -54
- package/dist/lib/ast/features/if.js +22 -16
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +343 -6
- package/dist/lib/ast/features/transform.js +7 -4
- package/dist/lib/ast/find.js +5 -5
- package/dist/lib/ast/math/expression.js +12 -8
- package/dist/lib/ast/minify.js +28 -33
- package/dist/lib/ast/transform/minify.js +135 -131
- package/dist/lib/ast/transform/utils.js +3 -2
- package/dist/lib/ast/types.js +69 -8
- package/dist/lib/ast/walk.js +4 -5
- package/dist/lib/fs/resolve.js +71 -57
- package/dist/lib/parser/declaration/list.js +92 -3
- package/dist/lib/parser/declaration/map.js +5 -5
- package/dist/lib/parser/parse.js +528 -466
- package/dist/lib/parser/tokenize.js +110 -4
- package/dist/lib/parser/utils/angle.js +29 -0
- package/dist/lib/parser/utils/at-rule-container.js +2 -2
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +2 -2
- package/dist/lib/parser/utils/at-rule-generic.js +1 -1
- package/dist/lib/parser/utils/at-rule-media.js +2 -2
- package/dist/lib/parser/utils/at-rule-support.js +73 -8
- package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
- package/dist/lib/parser/utils/at-rule.js +2 -8
- package/dist/lib/parser/utils/declaration.js +179 -76
- package/dist/lib/parser/utils/selector.js +53 -11
- package/dist/lib/parser/utils/token.js +13 -11
- package/dist/lib/renderer/render.js +501 -59
- package/dist/lib/syntax/color/alpha.js +64 -0
- package/dist/lib/syntax/color/cmyk.js +2 -2
- package/dist/lib/syntax/color/color-mix.js +283 -220
- package/dist/lib/syntax/color/color.js +37 -28
- package/dist/lib/syntax/color/hex.js +2 -2
- package/dist/lib/syntax/color/hsl.js +3 -3
- package/dist/lib/syntax/color/hwb.js +7 -7
- package/dist/lib/syntax/color/lab.js +5 -5
- package/dist/lib/syntax/color/lch.js +4 -4
- package/dist/lib/syntax/color/oklab.js +3 -3
- package/dist/lib/syntax/color/oklch.js +3 -3
- package/dist/lib/syntax/color/relativecolor.js +97 -12
- package/dist/lib/syntax/color/srgb.js +5 -5
- package/dist/lib/syntax/color/utils/color-type.js +18 -0
- package/dist/lib/syntax/color/utils/colorspace.js +46 -0
- package/dist/lib/syntax/color/utils/components.js +7 -3
- package/dist/lib/syntax/color/utils/distance.js +21 -4
- package/dist/lib/syntax/color/utils/make-color.js +56 -0
- package/dist/lib/syntax/color/xyz.js +2 -2
- package/dist/lib/syntax/constants.js +29 -1
- package/dist/lib/syntax/syntax.js +307 -39
- package/dist/lib/validation/config.js +2 -2
- package/dist/lib/validation/config.json.js +32 -17
- package/dist/lib/validation/match.js +239 -104
- package/dist/lib/validation/parser/parse.js +0 -1
- package/dist/lib/validation/parser/typedef.js +6 -0
- package/dist/node.js +64 -22
- package/dist/web.js +65 -18
- package/package.json +26 -15
- package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.repl_history +0 -4
- package/badges/coverage.svg +0 -20
- package/deno.lock +0 -2861
- package/dist/lib/ast/clone.d.ts +0 -10
- package/dist/lib/ast/expand.d.ts +0 -14
- package/dist/lib/ast/features/calc.d.ts +0 -10
- package/dist/lib/ast/features/if.d.ts +0 -10
- package/dist/lib/ast/features/index.d.ts +0 -6
- package/dist/lib/ast/features/inlinecssvariables.d.ts +0 -15
- package/dist/lib/ast/features/prefix.d.ts +0 -8
- package/dist/lib/ast/features/shorthand.d.ts +0 -12
- package/dist/lib/ast/features/transform.d.ts +0 -10
- package/dist/lib/ast/features/type.d.ts +0 -15
- package/dist/lib/ast/find.d.ts +0 -165
- package/dist/lib/ast/math/expression.d.ts +0 -18
- package/dist/lib/ast/math/math.d.ts +0 -6
- package/dist/lib/ast/minify.d.ts +0 -19
- package/dist/lib/ast/transform/compute.d.ts +0 -8
- package/dist/lib/ast/transform/matrix.d.ts +0 -22
- package/dist/lib/ast/transform/minify.d.ts +0 -5
- package/dist/lib/ast/transform/perspective.d.ts +0 -3
- package/dist/lib/ast/transform/rotate.d.ts +0 -12
- package/dist/lib/ast/transform/scale.d.ts +0 -6
- package/dist/lib/ast/transform/skew.d.ts +0 -4
- package/dist/lib/ast/transform/translate.d.ts +0 -6
- package/dist/lib/ast/transform/utils.d.ts +0 -9
- package/dist/lib/ast/types.d.ts +0 -903
- package/dist/lib/ast/walk.d.ts +0 -162
- package/dist/lib/fs/resolve.d.ts +0 -20
- package/dist/lib/parser/declaration/list.d.ts +0 -16
- package/dist/lib/parser/declaration/map.d.ts +0 -15
- package/dist/lib/parser/declaration/set.d.ts +0 -9
- package/dist/lib/parser/node.d.ts +0 -7
- package/dist/lib/parser/parse.d.ts +0 -107
- package/dist/lib/parser/tokenize.d.ts +0 -57
- package/dist/lib/parser/utils/at-rule-container.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-generic.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-import.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-media.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.js +0 -28
- package/dist/lib/parser/utils/at-rule-support.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-token.d.ts +0 -1
- package/dist/lib/parser/utils/at-rule-when-else.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule.d.ts +0 -13
- package/dist/lib/parser/utils/cache.d.ts +0 -6
- package/dist/lib/parser/utils/config.d.ts +0 -2
- package/dist/lib/parser/utils/declaration-list.d.ts +0 -5
- package/dist/lib/parser/utils/declaration.d.ts +0 -18
- package/dist/lib/parser/utils/eq.d.ts +0 -1
- package/dist/lib/parser/utils/hash.d.ts +0 -21
- package/dist/lib/parser/utils/selector.d.ts +0 -5
- package/dist/lib/parser/utils/text.d.ts +0 -3
- package/dist/lib/parser/utils/token.d.ts +0 -14
- package/dist/lib/parser/utils/type.d.ts +0 -2
- package/dist/lib/renderer/render.d.ts +0 -28
- package/dist/lib/renderer/sourcemap/lib/encode.d.ts +0 -1
- package/dist/lib/renderer/sourcemap/sourcemap.d.ts +0 -26
- package/dist/lib/syntax/color/a98rgb.d.ts +0 -2
- package/dist/lib/syntax/color/cmyk.d.ts +0 -10
- package/dist/lib/syntax/color/color-mix.d.ts +0 -2
- package/dist/lib/syntax/color/color.d.ts +0 -42
- package/dist/lib/syntax/color/hex.d.ts +0 -16
- package/dist/lib/syntax/color/hsl.d.ts +0 -20
- package/dist/lib/syntax/color/hsv.d.ts +0 -2
- package/dist/lib/syntax/color/hwb.d.ts +0 -21
- package/dist/lib/syntax/color/lab.d.ts +0 -25
- package/dist/lib/syntax/color/lch.d.ts +0 -23
- package/dist/lib/syntax/color/oklab.d.ts +0 -22
- package/dist/lib/syntax/color/oklch.d.ts +0 -20
- package/dist/lib/syntax/color/p3.d.ts +0 -6
- package/dist/lib/syntax/color/prophotorgb.d.ts +0 -2
- package/dist/lib/syntax/color/rec2020.d.ts +0 -2
- package/dist/lib/syntax/color/relativecolor.d.ts +0 -13
- package/dist/lib/syntax/color/rgb.d.ts +0 -20
- package/dist/lib/syntax/color/srgb.d.ts +0 -23
- package/dist/lib/syntax/color/utils/components.d.ts +0 -2
- package/dist/lib/syntax/color/utils/distance.d.ts +0 -18
- package/dist/lib/syntax/color/utils/matrix.d.ts +0 -6
- package/dist/lib/syntax/color/xyz.d.ts +0 -5
- package/dist/lib/syntax/color/xyzd50.d.ts +0 -4
- package/dist/lib/syntax/constants.d.ts +0 -67
- package/dist/lib/syntax/syntax.d.ts +0 -38
- package/dist/lib/validation/config.d.ts +0 -14
- package/dist/lib/validation/json.d.ts +0 -2
- package/dist/lib/validation/match.d.ts +0 -38
- package/dist/lib/validation/parser/parse.d.ts +0 -8
- package/dist/lib/validation/parser/typedef.d.ts +0 -95
- package/dist/lib/validation/utils/list.d.ts +0 -4
- package/dist/lib/validation/utils/whitespace.d.ts +0 -2
- package/dist/node.d.ts +0 -207
- package/dist/web.d.ts +0 -169
- package/playground/index.html +0 -1328
- package/playground/sw.js +0 -55
- package/playground/tree.js +0 -176
package/dist/lib/ast/minify.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { eq } from '../parser/utils/eq.js';
|
|
2
|
-
import {
|
|
2
|
+
import { renderValue, doRender } from '../renderer/render.js';
|
|
3
3
|
import * as index from './features/index.js';
|
|
4
4
|
import { walkValues } from './walk.js';
|
|
5
5
|
import { EnumToken } from './types.js';
|
|
@@ -7,7 +7,7 @@ import { isWhiteSpace, isIdent, isFunction, isIdentStart } from '../syntax/synta
|
|
|
7
7
|
import { FeatureWalkMode } from './features/type.js';
|
|
8
8
|
import { trimArray } from '../validation/match.js';
|
|
9
9
|
import { definedPropertySettings, combinators } from '../syntax/constants.js';
|
|
10
|
-
import {
|
|
10
|
+
import { replaceNodeOrValue } from '../parser/utils/token.js';
|
|
11
11
|
import { parseString } from '../parser/parse.js';
|
|
12
12
|
import { tokenize } from '../parser/tokenize.js';
|
|
13
13
|
import { replaceCompound } from './expand.js';
|
|
@@ -22,7 +22,7 @@ const rules = [
|
|
|
22
22
|
// @ts-ignore
|
|
23
23
|
const features = Object.values(index).sort((a, b) => a.ordering - b.ordering);
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* Apply minification rules to the ast tree
|
|
26
26
|
* @param ast
|
|
27
27
|
* @param options
|
|
28
28
|
* @param recursive
|
|
@@ -87,7 +87,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
|
|
|
87
87
|
}
|
|
88
88
|
if (replacement != parent && parent.parent != null) {
|
|
89
89
|
// @ts-ignore
|
|
90
|
-
|
|
90
|
+
replaceNodeOrValue(parent.parent, parent, replacement);
|
|
91
91
|
}
|
|
92
92
|
if ("chi" in replacement) {
|
|
93
93
|
// @ts-ignore
|
|
@@ -127,7 +127,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
|
|
|
127
127
|
}
|
|
128
128
|
if (replacement != null && replacement != parent && parent.parent != null) {
|
|
129
129
|
// @ts-ignore
|
|
130
|
-
|
|
130
|
+
replaceNodeOrValue(parent.parent, parent, replacement);
|
|
131
131
|
}
|
|
132
132
|
if ("chi" in replacement) {
|
|
133
133
|
for (const node of replacement.chi) {
|
|
@@ -162,7 +162,7 @@ function transformAtRuleMediaPrelude(values) {
|
|
|
162
162
|
values[values.indexOf(value)] = value.l;
|
|
163
163
|
}
|
|
164
164
|
else {
|
|
165
|
-
|
|
165
|
+
replaceNodeOrValue(parent, value, value.l);
|
|
166
166
|
// @ts-ignore
|
|
167
167
|
value = value.l;
|
|
168
168
|
}
|
|
@@ -218,7 +218,7 @@ function transformAtRuleMediaPrelude(values) {
|
|
|
218
218
|
// @ts-expect-error
|
|
219
219
|
const p = parents?.[parents?.indexOf?.(parent) + 1];
|
|
220
220
|
if (p != null) {
|
|
221
|
-
|
|
221
|
+
replaceNodeOrValue(p, parent, replacement);
|
|
222
222
|
}
|
|
223
223
|
else {
|
|
224
224
|
values.splice(values.indexOf(parent), 1, replacement);
|
|
@@ -232,7 +232,7 @@ function transformAtRuleMediaPrelude(values) {
|
|
|
232
232
|
return { hasUpdates, values: trimArray(values) };
|
|
233
233
|
}
|
|
234
234
|
/**
|
|
235
|
-
*
|
|
235
|
+
* Minify at-rule media
|
|
236
236
|
* - remove redundant tokens
|
|
237
237
|
* - generate range queries
|
|
238
238
|
* @param ast
|
|
@@ -262,7 +262,7 @@ function minifyAtRuleMedia(tokens) {
|
|
|
262
262
|
if (result.hasUpdates) {
|
|
263
263
|
hasUpdates = true;
|
|
264
264
|
}
|
|
265
|
-
acc.set(values.reduce((acc, t) => acc +
|
|
265
|
+
acc.set(values.reduce((acc, t) => acc + renderValue(t), ""), result.values);
|
|
266
266
|
return acc;
|
|
267
267
|
}, new Map());
|
|
268
268
|
if (sections.has("all")) {
|
|
@@ -284,7 +284,7 @@ function minifyAtRuleMedia(tokens) {
|
|
|
284
284
|
return tokens;
|
|
285
285
|
}
|
|
286
286
|
/**
|
|
287
|
-
*
|
|
287
|
+
* Reduce selectors
|
|
288
288
|
* @param acc
|
|
289
289
|
* @param curr
|
|
290
290
|
*
|
|
@@ -301,7 +301,7 @@ function reduce(acc, curr) {
|
|
|
301
301
|
return acc;
|
|
302
302
|
}
|
|
303
303
|
/**
|
|
304
|
-
*
|
|
304
|
+
* Apply minification rules to the ast tree
|
|
305
305
|
* @param ast
|
|
306
306
|
* @param options
|
|
307
307
|
* @param recursive
|
|
@@ -330,14 +330,10 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
330
330
|
let node = null;
|
|
331
331
|
let nodeIndex = -1;
|
|
332
332
|
for (; i < ast.chi.length; i++) {
|
|
333
|
-
if (ast.chi[i].typ === EnumToken.CommentNodeType
|
|
334
|
-
ast.chi[i].typ === EnumToken.InvalidRuleNodeType ||
|
|
335
|
-
ast.chi[i].typ === EnumToken.InvalidRuleNodeType) {
|
|
333
|
+
if (ast.chi[i].typ === EnumToken.CommentNodeType) {
|
|
336
334
|
continue;
|
|
337
335
|
}
|
|
338
|
-
while (previous?.typ === EnumToken.CommentNodeType
|
|
339
|
-
previous?.typ === EnumToken.InvalidRuleNodeType ||
|
|
340
|
-
previous?.typ === EnumToken.InvalidRuleNodeType) {
|
|
336
|
+
while (previous?.typ === EnumToken.CommentNodeType) {
|
|
341
337
|
previous = ast.chi[--nodeIndex];
|
|
342
338
|
continue;
|
|
343
339
|
}
|
|
@@ -399,12 +395,11 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
399
395
|
(index + 3 < arr.length ||
|
|
400
396
|
arr[index + 2]?.typ === EnumToken.WhitespaceTokenType))
|
|
401
397
|
? ""
|
|
402
|
-
:
|
|
398
|
+
: renderValue(curr)), "");
|
|
403
399
|
}
|
|
404
400
|
}
|
|
405
401
|
if (["all", "", null].includes(node.val)) {
|
|
406
|
-
ast.chi?.splice(i
|
|
407
|
-
i--;
|
|
402
|
+
ast.chi?.splice(i--, 1, ...node.chi);
|
|
408
403
|
continue;
|
|
409
404
|
}
|
|
410
405
|
}
|
|
@@ -428,7 +423,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
428
423
|
arr[index + 1]?.typ === EnumToken.CommentTokenType &&
|
|
429
424
|
(index + 3 < arr.length || arr[index + 2].typ === EnumToken.WhitespaceTokenType))
|
|
430
425
|
? ""
|
|
431
|
-
:
|
|
426
|
+
: renderValue(curr)), "");
|
|
432
427
|
}
|
|
433
428
|
}
|
|
434
429
|
if (previous?.typ == EnumToken.AtRuleNodeType &&
|
|
@@ -671,7 +666,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
671
666
|
}
|
|
672
667
|
}
|
|
673
668
|
}
|
|
674
|
-
if (recursive && previous != node) {
|
|
669
|
+
if (recursive && previous != null && previous != node) {
|
|
675
670
|
if (!hasDeclaration(previous)) {
|
|
676
671
|
doMinify(previous, options, recursive, errors, nestingContent, context);
|
|
677
672
|
}
|
|
@@ -705,7 +700,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
705
700
|
return ast;
|
|
706
701
|
}
|
|
707
702
|
/**
|
|
708
|
-
*
|
|
703
|
+
* Check if a rule has a declaration
|
|
709
704
|
* @param node
|
|
710
705
|
*
|
|
711
706
|
* @private
|
|
@@ -723,7 +718,7 @@ function hasDeclaration(node) {
|
|
|
723
718
|
return true;
|
|
724
719
|
}
|
|
725
720
|
/**
|
|
726
|
-
*
|
|
721
|
+
* Optimize selector
|
|
727
722
|
* @param selector
|
|
728
723
|
*
|
|
729
724
|
* @private
|
|
@@ -829,7 +824,7 @@ function optimizeSelector(selector) {
|
|
|
829
824
|
};
|
|
830
825
|
}
|
|
831
826
|
/**
|
|
832
|
-
*
|
|
827
|
+
* Split selector string
|
|
833
828
|
* @param buffer
|
|
834
829
|
*
|
|
835
830
|
* @internal
|
|
@@ -928,7 +923,7 @@ function splitRule(buffer) {
|
|
|
928
923
|
return result;
|
|
929
924
|
}
|
|
930
925
|
/**
|
|
931
|
-
*
|
|
926
|
+
* Reduce selector
|
|
932
927
|
* @param acc
|
|
933
928
|
* @param curr
|
|
934
929
|
*
|
|
@@ -986,7 +981,7 @@ function reduceSelector(acc, curr) {
|
|
|
986
981
|
return acc;
|
|
987
982
|
}
|
|
988
983
|
/**
|
|
989
|
-
*
|
|
984
|
+
* Match selectors
|
|
990
985
|
* @param selector1
|
|
991
986
|
* @param selector2
|
|
992
987
|
*
|
|
@@ -1092,7 +1087,7 @@ function matchSelectors(selector1, selector2) {
|
|
|
1092
1087
|
};
|
|
1093
1088
|
}
|
|
1094
1089
|
/**
|
|
1095
|
-
*
|
|
1090
|
+
* Fix selector
|
|
1096
1091
|
* @param node
|
|
1097
1092
|
*
|
|
1098
1093
|
* @private
|
|
@@ -1111,11 +1106,11 @@ function fixSelector(node) {
|
|
|
1111
1106
|
}
|
|
1112
1107
|
}
|
|
1113
1108
|
}
|
|
1114
|
-
node.sel = attributes.reduce((acc, curr) => acc +
|
|
1109
|
+
node.sel = attributes.reduce((acc, curr) => acc + renderValue(curr), "");
|
|
1115
1110
|
}
|
|
1116
1111
|
}
|
|
1117
1112
|
/**
|
|
1118
|
-
*
|
|
1113
|
+
* Wrap nodes
|
|
1119
1114
|
* @param previous
|
|
1120
1115
|
* @param node
|
|
1121
1116
|
* @param match
|
|
@@ -1159,7 +1154,7 @@ function wrapNodes(previous, node, match, ast, reducer, i, nodeIndex) {
|
|
|
1159
1154
|
return wrapper;
|
|
1160
1155
|
}
|
|
1161
1156
|
/**
|
|
1162
|
-
*
|
|
1157
|
+
* Diff nodes
|
|
1163
1158
|
* @param n1
|
|
1164
1159
|
* @param n2
|
|
1165
1160
|
* @param reducer
|
|
@@ -1323,7 +1318,7 @@ function diff(n1, n2, reducer, options = {}) {
|
|
|
1323
1318
|
return { result, node1: exchanged ? node2 : node1, node2: exchanged ? node1 : node2 };
|
|
1324
1319
|
}
|
|
1325
1320
|
/**
|
|
1326
|
-
*
|
|
1321
|
+
* Reduce rule selector
|
|
1327
1322
|
* @param node
|
|
1328
1323
|
*
|
|
1329
1324
|
* @private
|
|
@@ -1370,4 +1365,4 @@ function reduceRuleSelector(node) {
|
|
|
1370
1365
|
}
|
|
1371
1366
|
}
|
|
1372
1367
|
|
|
1373
|
-
export { minify, splitRule };
|
|
1368
|
+
export { minify, optimizeSelector, splitRule };
|