@tbela99/css-parser 1.4.7 → 1.4.9
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 +33 -2
- package/dist/index-umd-web.js +12953 -13248
- package/dist/index.cjs +10358 -10655
- package/dist/index.d.ts +820 -89
- package/dist/lib/ast/features/calc.js +3 -1
- package/dist/lib/ast/features/if.js +2 -96
- package/dist/lib/ast/features/prefix.js +7 -2
- package/dist/lib/ast/features/shorthand.js +1 -1
- package/dist/lib/ast/features/transform.js +1 -1
- package/dist/lib/ast/find.js +6 -6
- package/dist/lib/ast/math/expression.js +30 -12
- package/dist/lib/ast/minify.js +34 -5
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/utils.js +29 -21
- package/dist/lib/ast/types.js +12 -0
- package/dist/lib/fs/resolve.js +2 -17
- package/dist/lib/parser/declaration/list.js +6 -1
- package/dist/lib/parser/linesmap.js +78 -0
- package/dist/lib/parser/parse.js +1264 -151
- package/dist/lib/parser/source.js +103 -0
- package/dist/lib/parser/tokenize.js +112 -133
- package/dist/lib/parser/utils/at-rule-container.js +12 -44
- package/dist/lib/parser/utils/at-rule-generic.js +12 -24
- package/dist/lib/parser/utils/at-rule-import.js +4 -172
- package/dist/lib/parser/utils/at-rule-media.js +27 -263
- package/dist/lib/parser/utils/at-rule-support.js +8 -258
- package/dist/lib/parser/utils/at-rule-when-else.js +4 -214
- package/dist/lib/parser/utils/declaration.js +5 -95
- package/dist/lib/parser/utils/hash.js +54 -1
- package/dist/lib/parser/utils/selector.js +1 -1
- package/dist/lib/parser/utils/token.js +1 -0
- package/dist/lib/renderer/render.js +79 -45
- package/dist/lib/renderer/sourcemap/sourcemap.js +47 -43
- package/dist/lib/syntax/color/cmyk.js +3 -3
- package/dist/lib/syntax/color/color-mix.js +15 -8
- package/dist/lib/syntax/color/color.js +19 -11
- package/dist/lib/syntax/color/hex.js +1 -1
- package/dist/lib/syntax/color/hsl.js +6 -6
- package/dist/lib/syntax/color/hwb.js +6 -6
- package/dist/lib/syntax/color/lab.js +5 -5
- package/dist/lib/syntax/color/lch.js +6 -6
- package/dist/lib/syntax/color/oklab.js +5 -5
- package/dist/lib/syntax/color/oklch.js +5 -5
- package/dist/lib/syntax/color/p3.js +9 -1
- package/dist/lib/syntax/color/{relativecolor.js → relative-color.js} +8 -1
- package/dist/lib/syntax/color/utils/distance.js +7 -2
- package/dist/lib/syntax/constants.js +5 -1
- package/dist/lib/syntax/syntax.js +12 -21
- package/dist/lib/validation/config.json.js +27 -6
- package/dist/lib/validation/match.js +42 -845
- package/dist/node.js +136 -11
- package/dist/web.js +135 -8
- package/llms.txt +73 -0
- package/package.json +14 -17
|
@@ -31,13 +31,25 @@ function inverse(matrix) {
|
|
|
31
31
|
// Create augmented matrix [matrix | identity]
|
|
32
32
|
let augmented = [
|
|
33
33
|
...matrix.slice(0, 4),
|
|
34
|
-
1,
|
|
34
|
+
1,
|
|
35
|
+
0,
|
|
36
|
+
0,
|
|
37
|
+
0,
|
|
35
38
|
...matrix.slice(4, 8),
|
|
36
|
-
0,
|
|
39
|
+
0,
|
|
40
|
+
1,
|
|
41
|
+
0,
|
|
42
|
+
0,
|
|
37
43
|
...matrix.slice(8, 12),
|
|
38
|
-
0,
|
|
44
|
+
0,
|
|
45
|
+
0,
|
|
46
|
+
1,
|
|
47
|
+
0,
|
|
39
48
|
...matrix.slice(12, 16),
|
|
40
|
-
0,
|
|
49
|
+
0,
|
|
50
|
+
0,
|
|
51
|
+
0,
|
|
52
|
+
1,
|
|
41
53
|
];
|
|
42
54
|
// Gaussian elimination with partial pivoting
|
|
43
55
|
for (let col = 0; col < 4; col++) {
|
|
@@ -52,7 +64,7 @@ function inverse(matrix) {
|
|
|
52
64
|
}
|
|
53
65
|
}
|
|
54
66
|
// Check for singularity
|
|
55
|
-
if (maxVal <
|
|
67
|
+
if (maxVal < epsilon) {
|
|
56
68
|
return null;
|
|
57
69
|
}
|
|
58
70
|
// Swap rows if necessary
|
|
@@ -132,11 +144,7 @@ function decompose(original) {
|
|
|
132
144
|
const scaleX = Math.hypot(...row0);
|
|
133
145
|
const row0Norm = normalize(row0);
|
|
134
146
|
const skewXY = dot(row0Norm, row1);
|
|
135
|
-
const row1Proj = [
|
|
136
|
-
row1[0] - skewXY * row0Norm[0],
|
|
137
|
-
row1[1] - skewXY * row0Norm[1],
|
|
138
|
-
row1[2] - skewXY * row0Norm[2]
|
|
139
|
-
];
|
|
147
|
+
const row1Proj = [row1[0] - skewXY * row0Norm[0], row1[1] - skewXY * row0Norm[1], row1[2] - skewXY * row0Norm[2]];
|
|
140
148
|
const scaleY = Math.hypot(...row1Proj);
|
|
141
149
|
const row1Norm = normalize(row1Proj);
|
|
142
150
|
const skewXZ = dot(row0Norm, row2);
|
|
@@ -144,7 +152,7 @@ function decompose(original) {
|
|
|
144
152
|
const row2Proj = [
|
|
145
153
|
row2[0] - skewXZ * row0Norm[0] - skewYZ * row1Norm[0],
|
|
146
154
|
row2[1] - skewXZ * row0Norm[1] - skewYZ * row1Norm[1],
|
|
147
|
-
row2[2] - skewXZ * row0Norm[2] - skewYZ * row1Norm[2]
|
|
155
|
+
row2[2] - skewXZ * row0Norm[2] - skewYZ * row1Norm[2],
|
|
148
156
|
];
|
|
149
157
|
const row2Norm = normalize(row2Proj);
|
|
150
158
|
const determinant = row0[0] * cross[0] + row0[1] * cross[1] + row0[2] * cross[2];
|
|
@@ -196,7 +204,12 @@ function decompose(original) {
|
|
|
196
204
|
qy /= q;
|
|
197
205
|
qz /= q;
|
|
198
206
|
}
|
|
199
|
-
const rotate = [
|
|
207
|
+
const rotate = [
|
|
208
|
+
qx,
|
|
209
|
+
qy,
|
|
210
|
+
qz,
|
|
211
|
+
Object.is(qw, 0) ? 0 : (2 * Math.acos(qw) * 180) / Math.PI,
|
|
212
|
+
];
|
|
200
213
|
const scale = [scaleX, scaleY, scaleZ];
|
|
201
214
|
const skew = [skewXY, skewXZ, skewYZ];
|
|
202
215
|
return {
|
|
@@ -204,16 +217,11 @@ function decompose(original) {
|
|
|
204
217
|
scale,
|
|
205
218
|
rotate,
|
|
206
219
|
skew,
|
|
207
|
-
perspective
|
|
220
|
+
perspective,
|
|
208
221
|
};
|
|
209
222
|
}
|
|
210
223
|
function transposeMatrix4(m) {
|
|
211
|
-
return [
|
|
212
|
-
m[0], m[4], m[8], m[12],
|
|
213
|
-
m[1], m[5], m[9], m[13],
|
|
214
|
-
m[2], m[6], m[10], m[14],
|
|
215
|
-
m[3], m[7], m[11], m[15],
|
|
216
|
-
];
|
|
224
|
+
return [m[0], m[4], m[8], m[12], m[1], m[5], m[9], m[13], m[2], m[6], m[10], m[14], m[3], m[7], m[11], m[15]];
|
|
217
225
|
}
|
|
218
226
|
function toZero(v) {
|
|
219
227
|
for (let i = 0; i < v.length; i++) {
|
|
@@ -229,7 +237,7 @@ function toZero(v) {
|
|
|
229
237
|
// https://drafts.csswg.org/css-transforms-1/#2d-matrix
|
|
230
238
|
function is2DMatrix(matrix) {
|
|
231
239
|
// m13,m14, m23, m24, m31, m32, m34, m43 are all 0
|
|
232
|
-
return matrix[2] === 0 &&
|
|
240
|
+
return (matrix[2] === 0 &&
|
|
233
241
|
matrix[3] === 0 &&
|
|
234
242
|
matrix[6] === 0 &&
|
|
235
243
|
matrix[7] === 0 &&
|
|
@@ -238,7 +246,7 @@ function is2DMatrix(matrix) {
|
|
|
238
246
|
matrix[11] === 0 &&
|
|
239
247
|
matrix[14] === 0 &&
|
|
240
248
|
matrix[10] === 1 &&
|
|
241
|
-
matrix[15] === 1;
|
|
249
|
+
matrix[15] === 1);
|
|
242
250
|
}
|
|
243
251
|
|
|
244
252
|
export { decompose, identity, is2DMatrix, multiply, round, toZero };
|
package/dist/lib/ast/types.js
CHANGED
|
@@ -879,6 +879,18 @@ var ColorType;
|
|
|
879
879
|
* alpha() color function
|
|
880
880
|
*/
|
|
881
881
|
ColorType[ColorType["ALPHA"] = 25] = "ALPHA";
|
|
882
|
+
/**
|
|
883
|
+
* color using display-p3-linear
|
|
884
|
+
*/
|
|
885
|
+
ColorType[ColorType["DISPLAY_P3_LINEAR"] = 26] = "DISPLAY_P3_LINEAR";
|
|
886
|
+
/**
|
|
887
|
+
* Contrast color
|
|
888
|
+
*/
|
|
889
|
+
ColorType[ColorType["CONTRAST_COLOR"] = 27] = "CONTRAST_COLOR";
|
|
890
|
+
/**
|
|
891
|
+
* color layers
|
|
892
|
+
*/
|
|
893
|
+
ColorType[ColorType["COLOR_LAYERS"] = 28] = "COLOR_LAYERS";
|
|
882
894
|
/**
|
|
883
895
|
* alias for rgba
|
|
884
896
|
*/
|
package/dist/lib/fs/resolve.js
CHANGED
|
@@ -140,7 +140,7 @@ const resolve = memoize(function (url, currentDirectory, cwd) {
|
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
if (currentDirectory === "" && cwd !== "") {
|
|
143
|
+
if ((currentDirectory === "" || currentDirectory === ".") && cwd !== "") {
|
|
144
144
|
cwd = normalize(cwd);
|
|
145
145
|
if (url.startsWith(cwd == "/" ? cwd : cwd + "/")) {
|
|
146
146
|
const absolute = url;
|
|
@@ -151,24 +151,9 @@ const resolve = memoize(function (url, currentDirectory, cwd) {
|
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
// if (matchUrl.test(currentDirectory)) {
|
|
155
|
-
// const path: string = new URL(url, currentDirectory).href;
|
|
156
|
-
// return {
|
|
157
|
-
// absolute: path,
|
|
158
|
-
// relative: path,
|
|
159
|
-
// };
|
|
160
|
-
// }
|
|
161
|
-
// let result: string = "";
|
|
162
|
-
// if (url.charAt(0) == "/") {
|
|
163
|
-
// result = url;
|
|
164
|
-
// }
|
|
165
|
-
// else if (currentDirectory.charAt(0) == "/") {
|
|
166
|
-
// result = dirname(currentDirectory) + "/" + url;
|
|
167
|
-
// }
|
|
168
|
-
// const absolute = url; // normalize(result);
|
|
169
154
|
return {
|
|
170
155
|
absolute: url,
|
|
171
|
-
relative: url === "" ? "" : diff(url, cwd
|
|
156
|
+
relative: url === "" ? "" : diff(url, cwd || currentDirectory),
|
|
172
157
|
};
|
|
173
158
|
});
|
|
174
159
|
|
|
@@ -7,6 +7,7 @@ import { getParsedSyntax } from '../../validation/config.js';
|
|
|
7
7
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
8
8
|
import { matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
|
|
9
9
|
import { STATE } from '../../syntax/constants.js';
|
|
10
|
+
import { objectHash } from '../utils/hash.js';
|
|
10
11
|
|
|
11
12
|
const config = getConfig();
|
|
12
13
|
class PropertyList {
|
|
@@ -42,7 +43,11 @@ class PropertyList {
|
|
|
42
43
|
(Array.isArray(this.options.removeDuplicateDeclarations)
|
|
43
44
|
? this.options.removeDuplicateDeclarations.includes(declaration.nam)
|
|
44
45
|
: !this.options.removeDuplicateDeclarations)) {
|
|
45
|
-
|
|
46
|
+
const key = objectHash(declaration);
|
|
47
|
+
if (this.declarations.has(key)) {
|
|
48
|
+
this.declarations.delete(key);
|
|
49
|
+
}
|
|
50
|
+
this.declarations.set(key, declaration);
|
|
46
51
|
continue;
|
|
47
52
|
}
|
|
48
53
|
if (!this.options.computeShorthand) {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute line and column of the offset
|
|
3
|
+
*/
|
|
4
|
+
class LineMap {
|
|
5
|
+
/**
|
|
6
|
+
* line starts
|
|
7
|
+
*/
|
|
8
|
+
lineStarts;
|
|
9
|
+
/**
|
|
10
|
+
* Constructor
|
|
11
|
+
* @param lines
|
|
12
|
+
*/
|
|
13
|
+
constructor(lines) {
|
|
14
|
+
if (lines.length === 0) {
|
|
15
|
+
lines.push(0);
|
|
16
|
+
}
|
|
17
|
+
this.lineStarts = lines;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Compute line and column of the offset
|
|
21
|
+
* @param offset
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
getOffsets(offset) {
|
|
25
|
+
const line = this.search(offset);
|
|
26
|
+
if (offset < 0 || line < 0) {
|
|
27
|
+
return [1, 1];
|
|
28
|
+
}
|
|
29
|
+
const column = offset - this.lineStarts[line];
|
|
30
|
+
// [line, column]
|
|
31
|
+
return [line + 1, column === 0 ? 1 : column];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* search the greatest index of the value less than or equal to offset
|
|
35
|
+
* @param offset
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
search(offset) {
|
|
39
|
+
// search lineStarts using binary search
|
|
40
|
+
let start = 0;
|
|
41
|
+
let end = this.lineStarts.length - 1;
|
|
42
|
+
let mid = 0;
|
|
43
|
+
let result = -1;
|
|
44
|
+
while (start <= end) {
|
|
45
|
+
mid = start + ((end - start) >>> 1);
|
|
46
|
+
if (this.lineStarts[mid] <= offset) {
|
|
47
|
+
result = mid;
|
|
48
|
+
start = mid + 1;
|
|
49
|
+
}
|
|
50
|
+
else if (this.lineStarts[mid] > offset) {
|
|
51
|
+
end = mid - 1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* get line starts
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
getLineStarts() {
|
|
61
|
+
return this.lineStarts;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* add line start
|
|
65
|
+
*/
|
|
66
|
+
addLineStart(lineStart) {
|
|
67
|
+
this.lineStarts.push(lineStart);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* clone the linemap
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
clone() {
|
|
74
|
+
return new LineMap(this.lineStarts.slice());
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { LineMap };
|