@tbela99/css-parser 1.8.2 → 2.0.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/CHANGELOG.md +62 -0
- package/README.md +129 -31
- package/dist/index-umd-web.js +27383 -24083
- package/dist/index.d.ts +2737 -2200
- package/dist/package.json.js +2 -2
- package/dist/src/data/properties.json.js +1 -1
- package/dist/src/data/validation.json.js +1 -1
- package/dist/src/lib/ast/arena-node.js +548 -0
- package/dist/src/lib/ast/arena.js +3198 -0
- package/dist/src/lib/ast/features/calc.js +85 -76
- package/dist/src/lib/ast/features/if.js +155 -115
- package/dist/src/lib/ast/features/index.js +1 -1
- package/dist/src/lib/ast/features/inlinecssvariables.js +77 -84
- package/dist/src/lib/ast/features/prefix.js +184 -183
- package/dist/src/lib/ast/features/shorthand.js +40 -46
- package/dist/src/lib/ast/features/transform.js +24 -24
- package/dist/src/lib/ast/features/type.js +1 -1
- package/dist/src/lib/ast/fingerprint.js +333 -0
- package/dist/src/lib/ast/math/expression.js +458 -543
- package/dist/src/lib/ast/math/math.js +19 -41
- package/dist/src/lib/ast/minify.js +590 -647
- package/dist/src/lib/ast/transform/compute.js +82 -85
- package/dist/src/lib/ast/transform/matrix.js +21 -38
- package/dist/src/lib/ast/transform/minify.js +82 -193
- package/dist/src/lib/ast/transform/perspective.js +2 -3
- package/dist/src/lib/ast/transform/rotate.js +1 -1
- package/dist/src/lib/ast/transform/scale.js +1 -1
- package/dist/src/lib/ast/transform/skew.js +1 -1
- package/dist/src/lib/ast/transform/translate.js +1 -1
- package/dist/src/lib/ast/transform/utils.js +2 -2
- package/dist/src/lib/ast/types.js +263 -258
- package/dist/src/lib/ast/walk.js +246 -610
- package/dist/src/lib/fs/resolve.js +1 -1
- package/dist/src/lib/parser/declaration/list.js +223 -139
- package/dist/src/lib/parser/declaration/map.js +251 -238
- package/dist/src/lib/parser/declaration/set.js +74 -66
- package/dist/src/lib/parser/linesmap.js +1 -1
- package/dist/src/lib/parser/parse.js +1379 -1658
- package/dist/src/lib/parser/source.js +7 -4
- package/dist/src/lib/parser/tokenize.js +406 -199
- package/dist/src/lib/parser/utils/angle.js +11 -13
- package/dist/src/lib/parser/utils/at-rule-container.js +183 -168
- package/dist/src/lib/parser/utils/at-rule-font-feature-values.js +5 -5
- package/dist/src/lib/parser/utils/at-rule-generic.js +31 -24
- package/dist/src/lib/parser/utils/at-rule-import.js +44 -44
- package/dist/src/lib/parser/utils/at-rule-media.js +216 -205
- package/dist/src/lib/parser/utils/at-rule-support.js +83 -88
- package/dist/src/lib/parser/utils/at-rule-when-else.js +47 -47
- package/dist/src/lib/parser/utils/at-rule.js +5 -5
- package/dist/src/lib/parser/utils/base64.js +2 -2
- package/dist/src/lib/parser/utils/cache.js +1 -1
- package/dist/src/lib/parser/utils/config.js +1 -1
- package/dist/src/lib/parser/utils/declaration.js +233 -234
- package/dist/src/lib/parser/utils/eq.js +50 -3
- package/dist/src/lib/parser/utils/hash.js +2 -35
- package/dist/src/lib/parser/utils/selector.js +309 -387
- package/dist/src/lib/parser/utils/text.js +18 -4
- package/dist/src/lib/parser/utils/token.js +16 -69
- package/dist/src/lib/parser/utils/type.js +37 -24
- package/dist/src/lib/printer/render.js +965 -511
- package/dist/src/lib/printer/sourcemap/lib/codec.js +1 -1
- package/dist/src/lib/printer/sourcemap/sourcemap.js +1 -1
- package/dist/src/lib/syntax/color/a98rgb.js +1 -1
- package/dist/src/lib/syntax/color/alpha.js +36 -37
- package/dist/src/lib/syntax/color/cmyk.js +35 -52
- package/dist/src/lib/syntax/color/color-mix.js +96 -132
- package/dist/src/lib/syntax/color/color.js +222 -231
- package/dist/src/lib/syntax/color/hex.js +45 -55
- package/dist/src/lib/syntax/color/hsl.js +54 -62
- package/dist/src/lib/syntax/color/hwb.js +60 -68
- package/dist/src/lib/syntax/color/lab.js +59 -67
- package/dist/src/lib/syntax/color/lch.js +59 -67
- package/dist/src/lib/syntax/color/oklab.js +60 -68
- package/dist/src/lib/syntax/color/oklch.js +60 -67
- package/dist/src/lib/syntax/color/p3.js +1 -1
- package/dist/src/lib/syntax/color/prophotorgb.js +1 -1
- package/dist/src/lib/syntax/color/rec2020.js +1 -1
- package/dist/src/lib/syntax/color/relative-color.js +94 -144
- package/dist/src/lib/syntax/color/rgb.js +54 -57
- package/dist/src/lib/syntax/color/srgb.js +55 -53
- package/dist/src/lib/syntax/color/utils/color-type.js +13 -10
- package/dist/src/lib/syntax/color/utils/colorspace.js +11 -11
- package/dist/src/lib/syntax/color/utils/components.js +19 -20
- package/dist/src/lib/syntax/color/utils/distance.js +15 -13
- package/dist/src/lib/syntax/color/utils/make-color.js +15 -19
- package/dist/src/lib/syntax/color/utils/matrix.js +2 -2
- package/dist/src/lib/syntax/color/xyz.js +1 -1
- package/dist/src/lib/syntax/color/xyzd50.js +1 -1
- package/dist/src/lib/syntax/constants.js +2 -16
- package/dist/src/lib/syntax/syntax.js +301 -407
- package/dist/src/lib/validation/config.js +1 -1
- package/dist/src/lib/validation/match.js +959 -723
- package/dist/src/lib/validation/parser/parse.js +230 -112
- package/dist/src/lib/validation/parser/typedef.js +1 -1
- package/dist/src/lib/validation/utils/list.js +27 -12
- package/dist/src/node.js +12 -72
- package/dist/src/types.js +1 -1
- package/dist/src/utils/sync.js +9 -6
- package/dist/src/web.js +11 -73
- package/package.json +9 -10
- package/dist/index.cjs +0 -35870
- package/dist/src/lib/ast/clone.js +0 -51
- package/dist/src/lib/ast/expand.js +0 -311
- package/dist/src/lib/ast/find.js +0 -192
- package/dist/src/lib/ast/node.js +0 -59
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version:
|
|
5
|
+
Version: 2.0.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
@@ -15,7 +15,7 @@ function eq(a, b) {
|
|
|
15
15
|
if (a == null || b == null) {
|
|
16
16
|
return a == b;
|
|
17
17
|
}
|
|
18
|
-
if (typeof a !=
|
|
18
|
+
if (typeof a != "object" || typeof b != "object") {
|
|
19
19
|
return a === b;
|
|
20
20
|
}
|
|
21
21
|
if (a.constructor != b.constructor) {
|
|
@@ -46,5 +46,52 @@ function eq(a, b) {
|
|
|
46
46
|
}
|
|
47
47
|
return true;
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* structural equality of two tokens (source location is ignored): same type, name, values, tokens and children.
|
|
51
|
+
* same result as comparing their {@link nodeSignature}
|
|
52
|
+
* @param arena
|
|
53
|
+
* @param a
|
|
54
|
+
* @param b
|
|
55
|
+
*/
|
|
56
|
+
function eqToken(arena, a, b) {
|
|
57
|
+
if (a == b) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
if (arena.dataTypes[a] != arena.dataTypes[b] ||
|
|
61
|
+
arena.name[a] != arena.name[b] ||
|
|
62
|
+
arena.stringValue[a] != arena.stringValue[b] ||
|
|
63
|
+
arena.unit[a] != arena.unit[b] ||
|
|
64
|
+
arena.colorType[a] != arena.colorType[b]) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const x = arena.numericValue[a];
|
|
68
|
+
const y = arena.numericValue[b];
|
|
69
|
+
// NaN values are equal
|
|
70
|
+
if (x !== y && (x === x || y === y)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
let ta = arena.firstToken[a];
|
|
74
|
+
let tb = arena.firstToken[b];
|
|
75
|
+
while (ta != 0 && tb != 0) {
|
|
76
|
+
if (!eqToken(arena, ta, tb)) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
ta = arena.nextSibling[ta];
|
|
80
|
+
tb = arena.nextSibling[tb];
|
|
81
|
+
}
|
|
82
|
+
if (ta != tb) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
ta = arena.firstChild[a];
|
|
86
|
+
tb = arena.firstChild[b];
|
|
87
|
+
while (ta != 0 && tb != 0) {
|
|
88
|
+
if (!eqToken(arena, ta, tb)) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
ta = arena.nextSibling[ta];
|
|
92
|
+
tb = arena.nextSibling[tb];
|
|
93
|
+
}
|
|
94
|
+
return ta == tb;
|
|
95
|
+
}
|
|
49
96
|
|
|
50
|
-
export { eq };
|
|
97
|
+
export { eq, eqToken };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version:
|
|
5
|
+
Version: 2.0.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
// Alphabet: a-z, A-Z, 0-9, _, -
|
|
@@ -41,39 +41,6 @@ function hashId(input, length = 6) {
|
|
|
41
41
|
}
|
|
42
42
|
return chars.join("");
|
|
43
43
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Object to string
|
|
46
|
-
* @param input
|
|
47
|
-
* @returns
|
|
48
|
-
*/
|
|
49
|
-
function toSortedString(input) {
|
|
50
|
-
if (input == null) {
|
|
51
|
-
return "null";
|
|
52
|
-
}
|
|
53
|
-
if (typeof input !== "object") {
|
|
54
|
-
return String(input);
|
|
55
|
-
}
|
|
56
|
-
if (Array.isArray(input)) {
|
|
57
|
-
const result = new Array(input.length);
|
|
58
|
-
for (const value of input) {
|
|
59
|
-
result.push(toSortedString(value));
|
|
60
|
-
}
|
|
61
|
-
return JSON.stringify(result);
|
|
62
|
-
}
|
|
63
|
-
const keys = Object.keys(input).sort();
|
|
64
|
-
for (let i = 0; i < keys.length; i++) {
|
|
65
|
-
keys[i] = `${keys[i]}:${toSortedString(input[keys[i]])}`;
|
|
66
|
-
}
|
|
67
|
-
return `{${keys.join(",")}}`;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Object hash
|
|
71
|
-
* @param object
|
|
72
|
-
* @returns
|
|
73
|
-
*/
|
|
74
|
-
function objectHash(object) {
|
|
75
|
-
return hashCode(toSortedString(object)).toString(16);
|
|
76
|
-
}
|
|
77
44
|
/**
|
|
78
45
|
* convert input to hex
|
|
79
46
|
* @param input
|
|
@@ -149,4 +116,4 @@ function syncHash(input, length = 6, algo) {
|
|
|
149
116
|
return hashId(input, length);
|
|
150
117
|
}
|
|
151
118
|
|
|
152
|
-
export { DIGITS, FIRST_ALPHABET, FULL_ALPHABET, LOWER, hash, hashAlgorithms, hashId,
|
|
119
|
+
export { DIGITS, FIRST_ALPHABET, FULL_ALPHABET, LOWER, hash, hashAlgorithms, hashId, syncHash };
|