@tbela99/css-parser 1.3.3 → 1.4.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 +44 -0
- package/README.md +64 -48
- package/dist/config.json.js +3 -0
- package/dist/index-umd-web.js +2266 -631
- package/dist/index.cjs +2271 -620
- package/dist/index.d.ts +522 -181
- package/dist/lib/ast/expand.js +5 -10
- package/dist/lib/ast/features/calc.js +3 -2
- package/dist/lib/ast/features/inlinecssvariables.js +5 -3
- package/dist/lib/ast/features/prefix.js +1 -1
- package/dist/lib/ast/features/shorthand.js +1 -0
- package/dist/lib/ast/features/transform.js +13 -19
- package/dist/lib/ast/features/type.js +1 -1
- package/dist/lib/ast/minify.js +6 -3
- package/dist/lib/ast/transform/compute.js +2 -4
- package/dist/lib/ast/transform/matrix.js +20 -20
- package/dist/lib/ast/transform/minify.js +105 -12
- package/dist/lib/ast/transform/rotate.js +11 -11
- package/dist/lib/ast/transform/scale.js +6 -6
- package/dist/lib/ast/transform/skew.js +4 -4
- package/dist/lib/ast/transform/translate.js +3 -3
- package/dist/lib/ast/transform/utils.js +30 -37
- package/dist/lib/ast/types.js +76 -5
- package/dist/lib/ast/walk.js +77 -58
- package/dist/lib/fs/resolve.js +69 -10
- package/dist/lib/parser/declaration/list.js +6 -1
- package/dist/lib/parser/parse.js +1169 -312
- package/dist/lib/parser/tokenize.js +33 -20
- package/dist/lib/parser/utils/declaration.js +54 -0
- package/dist/lib/parser/utils/hash.js +86 -0
- package/dist/lib/parser/utils/text.js +8 -0
- package/dist/lib/renderer/render.js +26 -7
- package/dist/lib/syntax/color/relativecolor.js +0 -3
- package/dist/lib/syntax/syntax.js +36 -18
- package/dist/lib/validation/at-rules/container.js +11 -0
- package/dist/lib/validation/at-rules/counter-style.js +11 -0
- package/dist/lib/validation/at-rules/font-feature-values.js +11 -0
- package/dist/lib/validation/at-rules/keyframes.js +11 -0
- package/dist/lib/validation/at-rules/layer.js +11 -0
- package/dist/lib/validation/at-rules/media.js +11 -0
- package/dist/lib/validation/at-rules/page-margin-box.js +11 -0
- package/dist/lib/validation/at-rules/page.js +11 -0
- package/dist/lib/validation/at-rules/supports.js +11 -0
- package/dist/lib/validation/at-rules/when.js +11 -0
- package/dist/lib/validation/config.js +0 -2
- package/dist/lib/validation/config.json.js +36 -4
- package/dist/lib/validation/parser/parse.js +53 -2
- package/dist/lib/validation/syntax.js +204 -36
- package/dist/lib/validation/syntaxes/compound-selector.js +1 -2
- package/dist/lib/validation/syntaxes/relative-selector-list.js +2 -5
- package/dist/node.js +60 -18
- package/dist/types.d.ts +17 -0
- package/dist/types.js +20 -0
- package/dist/web.js +43 -17
- package/package.json +20 -17
- package/dist/lib/validation/parser/types.js +0 -54
package/dist/index.cjs
CHANGED
|
@@ -26,14 +26,26 @@ exports.ValidationLevel = void 0;
|
|
|
26
26
|
* disable validation
|
|
27
27
|
*/
|
|
28
28
|
ValidationLevel[ValidationLevel["None"] = 0] = "None";
|
|
29
|
+
/**
|
|
30
|
+
* validate selectors
|
|
31
|
+
*/
|
|
32
|
+
ValidationLevel[ValidationLevel["Selector"] = 1] = "Selector";
|
|
33
|
+
/**
|
|
34
|
+
* validate at-rules
|
|
35
|
+
*/
|
|
36
|
+
ValidationLevel[ValidationLevel["AtRule"] = 2] = "AtRule";
|
|
37
|
+
/**
|
|
38
|
+
* validate declarations
|
|
39
|
+
*/
|
|
40
|
+
ValidationLevel[ValidationLevel["Declaration"] = 4] = "Declaration";
|
|
29
41
|
/**
|
|
30
42
|
* validate selectors and at-rules
|
|
31
43
|
*/
|
|
32
|
-
ValidationLevel[ValidationLevel["Default"] =
|
|
44
|
+
ValidationLevel[ValidationLevel["Default"] = 3] = "Default";
|
|
33
45
|
/**
|
|
34
46
|
* validate selectors, at-rules and declarations
|
|
35
47
|
*/
|
|
36
|
-
ValidationLevel[ValidationLevel["All"] =
|
|
48
|
+
ValidationLevel[ValidationLevel["All"] = 7] = "All"; // selectors + at-rules + declarations
|
|
37
49
|
})(exports.ValidationLevel || (exports.ValidationLevel = {}));
|
|
38
50
|
/**
|
|
39
51
|
* enum of all token types
|
|
@@ -422,6 +434,23 @@ exports.EnumToken = void 0;
|
|
|
422
434
|
* invalid declaration node type
|
|
423
435
|
*/
|
|
424
436
|
EnumToken[EnumToken["InvalidDeclarationNodeType"] = 94] = "InvalidDeclarationNodeType";
|
|
437
|
+
/* css module nodes */
|
|
438
|
+
/**
|
|
439
|
+
* composes token node type
|
|
440
|
+
*/
|
|
441
|
+
EnumToken[EnumToken["ComposesSelectorNodeType"] = 95] = "ComposesSelectorNodeType";
|
|
442
|
+
/**
|
|
443
|
+
* css variable token type
|
|
444
|
+
*/
|
|
445
|
+
EnumToken[EnumToken["CssVariableTokenType"] = 96] = "CssVariableTokenType";
|
|
446
|
+
/**
|
|
447
|
+
* css variable import token type
|
|
448
|
+
*/
|
|
449
|
+
EnumToken[EnumToken["CssVariableImportTokenType"] = 97] = "CssVariableImportTokenType";
|
|
450
|
+
/**
|
|
451
|
+
* css variable declaration map token type
|
|
452
|
+
*/
|
|
453
|
+
EnumToken[EnumToken["CssVariableDeclarationMapTokenType"] = 98] = "CssVariableDeclarationMapTokenType";
|
|
425
454
|
/* aliases */
|
|
426
455
|
/**
|
|
427
456
|
* alias for time token type
|
|
@@ -538,7 +567,7 @@ exports.EnumToken = void 0;
|
|
|
538
567
|
exports.ColorType = void 0;
|
|
539
568
|
(function (ColorType) {
|
|
540
569
|
/**
|
|
541
|
-
* system colors
|
|
570
|
+
* deprecated system colors
|
|
542
571
|
*/
|
|
543
572
|
ColorType[ColorType["SYS"] = 0] = "SYS";
|
|
544
573
|
/**
|
|
@@ -546,7 +575,7 @@ exports.ColorType = void 0;
|
|
|
546
575
|
*/
|
|
547
576
|
ColorType[ColorType["DPSYS"] = 1] = "DPSYS";
|
|
548
577
|
/**
|
|
549
|
-
* colors
|
|
578
|
+
* named colors
|
|
550
579
|
*/
|
|
551
580
|
ColorType[ColorType["LIT"] = 2] = "LIT";
|
|
552
581
|
/**
|
|
@@ -646,6 +675,48 @@ exports.ColorType = void 0;
|
|
|
646
675
|
*/
|
|
647
676
|
ColorType[ColorType["DEVICE_CMYK"] = 7] = "DEVICE_CMYK";
|
|
648
677
|
})(exports.ColorType || (exports.ColorType = {}));
|
|
678
|
+
exports.ModuleCaseTransformEnum = void 0;
|
|
679
|
+
(function (ModuleCaseTransformEnum) {
|
|
680
|
+
/**
|
|
681
|
+
* export class names as-is
|
|
682
|
+
*/
|
|
683
|
+
ModuleCaseTransformEnum[ModuleCaseTransformEnum["IgnoreCase"] = 1] = "IgnoreCase";
|
|
684
|
+
/**
|
|
685
|
+
* transform mapping key name to camel case
|
|
686
|
+
*/
|
|
687
|
+
ModuleCaseTransformEnum[ModuleCaseTransformEnum["CamelCase"] = 2] = "CamelCase";
|
|
688
|
+
/**
|
|
689
|
+
* transform class names and mapping key name to camel case
|
|
690
|
+
*/
|
|
691
|
+
ModuleCaseTransformEnum[ModuleCaseTransformEnum["CamelCaseOnly"] = 4] = "CamelCaseOnly";
|
|
692
|
+
/**
|
|
693
|
+
* transform mapping key name to dash case
|
|
694
|
+
*/
|
|
695
|
+
ModuleCaseTransformEnum[ModuleCaseTransformEnum["DashCase"] = 8] = "DashCase";
|
|
696
|
+
/**
|
|
697
|
+
* transform class names and mapping key name to dash case
|
|
698
|
+
*/
|
|
699
|
+
ModuleCaseTransformEnum[ModuleCaseTransformEnum["DashCaseOnly"] = 16] = "DashCaseOnly";
|
|
700
|
+
})(exports.ModuleCaseTransformEnum || (exports.ModuleCaseTransformEnum = {}));
|
|
701
|
+
exports.ModuleScopeEnumOptions = void 0;
|
|
702
|
+
(function (ModuleScopeEnumOptions) {
|
|
703
|
+
/**
|
|
704
|
+
* use the global scope
|
|
705
|
+
*/
|
|
706
|
+
ModuleScopeEnumOptions[ModuleScopeEnumOptions["Global"] = 32] = "Global";
|
|
707
|
+
/**
|
|
708
|
+
* use the local scope
|
|
709
|
+
*/
|
|
710
|
+
ModuleScopeEnumOptions[ModuleScopeEnumOptions["Local"] = 64] = "Local";
|
|
711
|
+
/**
|
|
712
|
+
* do not allow selector without an id or class
|
|
713
|
+
*/
|
|
714
|
+
ModuleScopeEnumOptions[ModuleScopeEnumOptions["Pure"] = 128] = "Pure";
|
|
715
|
+
/**
|
|
716
|
+
* export using ICSS module format
|
|
717
|
+
*/
|
|
718
|
+
ModuleScopeEnumOptions[ModuleScopeEnumOptions["ICSS"] = 256] = "ICSS";
|
|
719
|
+
})(exports.ModuleScopeEnumOptions || (exports.ModuleScopeEnumOptions = {}));
|
|
649
720
|
|
|
650
721
|
// from https://www.w3.org/TR/css-color-4/multiply-matrices.js
|
|
651
722
|
/**
|
|
@@ -3904,10 +3975,7 @@ function computeComponentValue(expr, converted, values) {
|
|
|
3904
3975
|
// normalize hue
|
|
3905
3976
|
for (const k of walkValues([object.h])) {
|
|
3906
3977
|
if (k.value.typ == exports.EnumToken.AngleTokenType && k.value.unit == 'deg') {
|
|
3907
|
-
// @ts-ignore
|
|
3908
3978
|
k.value.typ = exports.EnumToken.NumberTokenType;
|
|
3909
|
-
// @ts-ignore
|
|
3910
|
-
delete k.value.unit;
|
|
3911
3979
|
}
|
|
3912
3980
|
}
|
|
3913
3981
|
}
|
|
@@ -4110,10 +4178,7 @@ const epsilon = 1e-5;
|
|
|
4110
4178
|
function identity() {
|
|
4111
4179
|
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
4112
4180
|
}
|
|
4113
|
-
function
|
|
4114
|
-
return Math.sqrt(point[0] * point[0] + point[1] * point[1] + point[2] * point[2]);
|
|
4115
|
-
}
|
|
4116
|
-
function normalize(point) {
|
|
4181
|
+
function normalize$1(point) {
|
|
4117
4182
|
const [x, y, z] = point;
|
|
4118
4183
|
const norm = Math.sqrt(point[0] * point[0] + point[1] * point[1] + point[2] * point[2]);
|
|
4119
4184
|
return norm === 0 ? [0, 0, 0] : [x / norm, y / norm, z / norm];
|
|
@@ -4140,8 +4205,14 @@ function multiply(matrixA, matrixB) {
|
|
|
4140
4205
|
function inverse(matrix) {
|
|
4141
4206
|
// Create augmented matrix [matrix | identity]
|
|
4142
4207
|
let augmented = [
|
|
4143
|
-
|
|
4144
|
-
1, 0, 0, 0,
|
|
4208
|
+
...matrix.slice(0, 4),
|
|
4209
|
+
1, 0, 0, 0,
|
|
4210
|
+
...matrix.slice(4, 8),
|
|
4211
|
+
0, 1, 0, 0,
|
|
4212
|
+
...matrix.slice(8, 12),
|
|
4213
|
+
0, 0, 1, 0,
|
|
4214
|
+
...matrix.slice(12, 16),
|
|
4215
|
+
0, 0, 0, 1
|
|
4145
4216
|
];
|
|
4146
4217
|
// Gaussian elimination with partial pivoting
|
|
4147
4218
|
for (let col = 0; col < 4; col++) {
|
|
@@ -4181,24 +4252,9 @@ function inverse(matrix) {
|
|
|
4181
4252
|
// Extract the inverse from the right side of the augmented matrix
|
|
4182
4253
|
return augmented.slice(0, 16);
|
|
4183
4254
|
}
|
|
4184
|
-
// function transpose(matrix: Matrix): Matrix {
|
|
4185
|
-
// // Crée une nouvelle matrice vide 4x4
|
|
4186
|
-
// // @ts-ignore
|
|
4187
|
-
// let transposed: Matrix = [[], [], [], []] as Matrix;
|
|
4188
|
-
//
|
|
4189
|
-
// // Parcourt chaque ligne et colonne pour transposer
|
|
4190
|
-
// for (let i = 0; i < 4; i++) {
|
|
4191
|
-
//
|
|
4192
|
-
// for (let j = 0; j < 4; j++) {
|
|
4193
|
-
//
|
|
4194
|
-
// transposed[j][i] = matrix[i][j];
|
|
4195
|
-
// }
|
|
4196
|
-
// }
|
|
4197
|
-
//
|
|
4198
|
-
// return transposed;
|
|
4199
|
-
// }
|
|
4200
4255
|
function round(number) {
|
|
4201
|
-
|
|
4256
|
+
const rounded = Math.round(number);
|
|
4257
|
+
return Math.abs(rounded - number) <= epsilon ? rounded : +number.toPrecision(6);
|
|
4202
4258
|
}
|
|
4203
4259
|
// translate3d(25.9808px, 0, 15px ) rotateY(60deg) skewX(49.9999deg) scale(1, 1.2)
|
|
4204
4260
|
// translate → rotate → skew → scale
|
|
@@ -4221,7 +4277,7 @@ function decompose(original) {
|
|
|
4221
4277
|
perspectiveMatrix[15] = 1;
|
|
4222
4278
|
// @ts-ignore
|
|
4223
4279
|
const inverted = inverse(original.slice());
|
|
4224
|
-
if (
|
|
4280
|
+
if (inverted === null) {
|
|
4225
4281
|
return null;
|
|
4226
4282
|
}
|
|
4227
4283
|
const transposedInverse = transposeMatrix4(inverted);
|
|
@@ -4242,17 +4298,22 @@ function decompose(original) {
|
|
|
4242
4298
|
const row0 = [matrix[0], matrix[1], matrix[2]];
|
|
4243
4299
|
const row1 = [matrix[4], matrix[5], matrix[6]];
|
|
4244
4300
|
const row2 = [matrix[8], matrix[9], matrix[10]];
|
|
4301
|
+
const cross = [
|
|
4302
|
+
row1[1] * row2[2] - row1[2] * row2[1],
|
|
4303
|
+
row1[2] * row2[0] - row1[0] * row2[2],
|
|
4304
|
+
row1[0] * row2[1] - row1[1] * row2[0],
|
|
4305
|
+
];
|
|
4245
4306
|
// Compute scale
|
|
4246
|
-
const scaleX =
|
|
4247
|
-
const row0Norm = normalize(row0);
|
|
4307
|
+
const scaleX = Math.hypot(...row0);
|
|
4308
|
+
const row0Norm = normalize$1(row0);
|
|
4248
4309
|
const skewXY = dot(row0Norm, row1);
|
|
4249
4310
|
const row1Proj = [
|
|
4250
4311
|
row1[0] - skewXY * row0Norm[0],
|
|
4251
4312
|
row1[1] - skewXY * row0Norm[1],
|
|
4252
4313
|
row1[2] - skewXY * row0Norm[2]
|
|
4253
4314
|
];
|
|
4254
|
-
const scaleY =
|
|
4255
|
-
const row1Norm = normalize(row1Proj);
|
|
4315
|
+
const scaleY = Math.hypot(...row1Proj);
|
|
4316
|
+
const row1Norm = normalize$1(row1Proj);
|
|
4256
4317
|
const skewXZ = dot(row0Norm, row2);
|
|
4257
4318
|
const skewYZ = dot(row1Norm, row2);
|
|
4258
4319
|
const row2Proj = [
|
|
@@ -4260,8 +4321,9 @@ function decompose(original) {
|
|
|
4260
4321
|
row2[1] - skewXZ * row0Norm[1] - skewYZ * row1Norm[1],
|
|
4261
4322
|
row2[2] - skewXZ * row0Norm[2] - skewYZ * row1Norm[2]
|
|
4262
4323
|
];
|
|
4263
|
-
const
|
|
4264
|
-
const
|
|
4324
|
+
const row2Norm = normalize$1(row2Proj);
|
|
4325
|
+
const determinant = row0[0] * cross[0] + row0[1] * cross[1] + row0[2] * cross[2];
|
|
4326
|
+
const scaleZ = Math.hypot(...row2Proj) * (determinant < 0 ? -1 : 1);
|
|
4265
4327
|
// Build rotation matrix from orthonormalized vectors
|
|
4266
4328
|
const r00 = row0Norm[0], r01 = row1Norm[0], r02 = row2Norm[0];
|
|
4267
4329
|
const r10 = row0Norm[1], r11 = row1Norm[1], r12 = row2Norm[1];
|
|
@@ -4298,7 +4360,6 @@ function decompose(original) {
|
|
|
4298
4360
|
qz = 0.25 * s;
|
|
4299
4361
|
}
|
|
4300
4362
|
[qx, qy, qz] = toZero([qx, qy, qz]);
|
|
4301
|
-
// const q = gcd(qx, gcd(qy, qz));
|
|
4302
4363
|
let q = [Math.abs(qx), Math.abs(qy), Math.abs(qz)].reduce((acc, curr) => {
|
|
4303
4364
|
if (acc == 0 || (curr > 0 && curr < acc)) {
|
|
4304
4365
|
acc = curr;
|
|
@@ -4343,16 +4404,16 @@ function toZero(v) {
|
|
|
4343
4404
|
// https://drafts.csswg.org/css-transforms-1/#2d-matrix
|
|
4344
4405
|
function is2DMatrix(matrix) {
|
|
4345
4406
|
// m13,m14, m23, m24, m31, m32, m34, m43 are all 0
|
|
4346
|
-
return matrix[
|
|
4347
|
-
matrix[
|
|
4348
|
-
matrix[
|
|
4349
|
-
matrix[
|
|
4350
|
-
matrix[
|
|
4351
|
-
matrix[
|
|
4352
|
-
matrix[
|
|
4353
|
-
matrix[
|
|
4354
|
-
matrix[
|
|
4355
|
-
matrix[
|
|
4407
|
+
return matrix[2] === 0 &&
|
|
4408
|
+
matrix[3] === 0 &&
|
|
4409
|
+
matrix[6] === 0 &&
|
|
4410
|
+
matrix[7] === 0 &&
|
|
4411
|
+
matrix[8] === 0 &&
|
|
4412
|
+
matrix[9] === 0 &&
|
|
4413
|
+
matrix[11] === 0 &&
|
|
4414
|
+
matrix[14] === 0 &&
|
|
4415
|
+
matrix[10] === 1 &&
|
|
4416
|
+
matrix[15] === 1;
|
|
4356
4417
|
}
|
|
4357
4418
|
|
|
4358
4419
|
/**
|
|
@@ -5454,7 +5515,7 @@ function isColor(token) {
|
|
|
5454
5515
|
}
|
|
5455
5516
|
if (token.typ == exports.EnumToken.IdenTokenType) {
|
|
5456
5517
|
// named color
|
|
5457
|
-
return token.val.toLowerCase() in COLORS_NAMES;
|
|
5518
|
+
return token.val.toLowerCase() in COLORS_NAMES || 'currentcolor' === token.val.toLowerCase() || 'transparent' === token.val.toLowerCase();
|
|
5458
5519
|
}
|
|
5459
5520
|
let isLegacySyntax = false;
|
|
5460
5521
|
if (token.typ == exports.EnumToken.FunctionTokenType) {
|
|
@@ -5507,8 +5568,13 @@ function isColor(token) {
|
|
|
5507
5568
|
return false;
|
|
5508
5569
|
}
|
|
5509
5570
|
}
|
|
5510
|
-
if (children[i].typ == exports.EnumToken.FunctionTokenType
|
|
5511
|
-
|
|
5571
|
+
if (children[i].typ == exports.EnumToken.FunctionTokenType) {
|
|
5572
|
+
if ('var' == children[i].val.toLowerCase()) {
|
|
5573
|
+
continue;
|
|
5574
|
+
}
|
|
5575
|
+
if (!mathFuncs.includes(children[i].val)) {
|
|
5576
|
+
return false;
|
|
5577
|
+
}
|
|
5512
5578
|
}
|
|
5513
5579
|
}
|
|
5514
5580
|
if (children.length == 4 || (isRelative && children.length == 6)) {
|
|
@@ -5795,23 +5861,29 @@ function isNumber(name) {
|
|
|
5795
5861
|
}
|
|
5796
5862
|
return true;
|
|
5797
5863
|
}
|
|
5798
|
-
function isDimension(name) {
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5864
|
+
// export function isDimension(name: string) {
|
|
5865
|
+
//
|
|
5866
|
+
// let index: number = name.length;
|
|
5867
|
+
//
|
|
5868
|
+
// while (index--) {
|
|
5869
|
+
//
|
|
5870
|
+
// if (isLetter(<number>name.charCodeAt(index))) {
|
|
5871
|
+
//
|
|
5872
|
+
// continue
|
|
5873
|
+
// }
|
|
5874
|
+
//
|
|
5875
|
+
// index++;
|
|
5876
|
+
// break;
|
|
5877
|
+
// }
|
|
5878
|
+
//
|
|
5879
|
+
// const number: string = name.slice(0, index);
|
|
5880
|
+
// return number.length > 0 && isIdentStart(name.charCodeAt(index)) && isNumber(number);
|
|
5881
|
+
// }
|
|
5810
5882
|
function isPercentage(name) {
|
|
5811
5883
|
return name.endsWith('%') && isNumber(name.slice(0, -1));
|
|
5812
5884
|
}
|
|
5813
|
-
function isFlex(
|
|
5814
|
-
return
|
|
5885
|
+
function isFlex(dimension) {
|
|
5886
|
+
return 'unit' in dimension && 'fr' == dimension.unit.toLowerCase();
|
|
5815
5887
|
}
|
|
5816
5888
|
function parseDimension(name) {
|
|
5817
5889
|
let index = name.length;
|
|
@@ -5827,6 +5899,9 @@ function parseDimension(name) {
|
|
|
5827
5899
|
val: +name.slice(0, index),
|
|
5828
5900
|
unit: name.slice(index)
|
|
5829
5901
|
};
|
|
5902
|
+
if (index < 0 || Number.isNaN(dimension.val)) {
|
|
5903
|
+
return null;
|
|
5904
|
+
}
|
|
5830
5905
|
if (isAngle(dimension)) {
|
|
5831
5906
|
// @ts-ignore
|
|
5832
5907
|
dimension.typ = exports.EnumToken.AngleTokenType;
|
|
@@ -5850,6 +5925,10 @@ function parseDimension(name) {
|
|
|
5850
5925
|
// @ts-ignore
|
|
5851
5926
|
dimension.typ = exports.EnumToken.FrequencyTokenType;
|
|
5852
5927
|
}
|
|
5928
|
+
else if (isFlex(dimension)) {
|
|
5929
|
+
// @ts-ignore
|
|
5930
|
+
dimension.typ = exports.EnumToken.FlexTokenType;
|
|
5931
|
+
}
|
|
5853
5932
|
return dimension;
|
|
5854
5933
|
}
|
|
5855
5934
|
function isHexColor(name) {
|
|
@@ -6508,6 +6587,9 @@ var map = {
|
|
|
6508
6587
|
},
|
|
6509
6588
|
animation: {
|
|
6510
6589
|
shorthand: "animation",
|
|
6590
|
+
separator: {
|
|
6591
|
+
typ: "Comma"
|
|
6592
|
+
},
|
|
6511
6593
|
pattern: "animation-name animation-duration animation-timing-function animation-delay animation-iteration-count animation-direction animation-fill-mode animation-play-state animation-timeline",
|
|
6512
6594
|
"default": [
|
|
6513
6595
|
"1",
|
|
@@ -7458,6 +7540,60 @@ function parseDeclarationNode(node, errors, location) {
|
|
|
7458
7540
|
});
|
|
7459
7541
|
return null;
|
|
7460
7542
|
}
|
|
7543
|
+
if ('composes' == node.nam.toLowerCase()) {
|
|
7544
|
+
let left = [];
|
|
7545
|
+
let right = [];
|
|
7546
|
+
let current = 0;
|
|
7547
|
+
let hasFrom = 0;
|
|
7548
|
+
for (; current < node.val.length; current++) {
|
|
7549
|
+
if (exports.EnumToken.WhitespaceTokenType == node.val[current].typ || exports.EnumToken.CommentTokenType == node.val[current].typ) {
|
|
7550
|
+
if (!hasFrom) {
|
|
7551
|
+
left.push(node.val[current]);
|
|
7552
|
+
}
|
|
7553
|
+
else {
|
|
7554
|
+
right.push(node.val[current]);
|
|
7555
|
+
}
|
|
7556
|
+
continue;
|
|
7557
|
+
}
|
|
7558
|
+
if (exports.EnumToken.IdenTokenType == node.val[current].typ || exports.EnumToken.DashedIdenTokenType == node.val[current].typ || exports.EnumToken.StringTokenType == node.val[current].typ) {
|
|
7559
|
+
if (exports.EnumToken.IdenTokenType == node.val[current].typ) {
|
|
7560
|
+
if ('from' == node.val[current].val) {
|
|
7561
|
+
if (hasFrom) {
|
|
7562
|
+
return null;
|
|
7563
|
+
}
|
|
7564
|
+
hasFrom++;
|
|
7565
|
+
continue;
|
|
7566
|
+
}
|
|
7567
|
+
}
|
|
7568
|
+
if (hasFrom) {
|
|
7569
|
+
right.push(node.val[current]);
|
|
7570
|
+
}
|
|
7571
|
+
else {
|
|
7572
|
+
left.push(node.val[current]);
|
|
7573
|
+
}
|
|
7574
|
+
continue;
|
|
7575
|
+
}
|
|
7576
|
+
break;
|
|
7577
|
+
}
|
|
7578
|
+
if (hasFrom <= 1 && current > 0) {
|
|
7579
|
+
if (hasFrom == 0) {
|
|
7580
|
+
node.val.splice(0, left.length, {
|
|
7581
|
+
typ: exports.EnumToken.ComposesSelectorNodeType,
|
|
7582
|
+
l: left,
|
|
7583
|
+
r: null
|
|
7584
|
+
});
|
|
7585
|
+
}
|
|
7586
|
+
else {
|
|
7587
|
+
node.val.splice(0, current, {
|
|
7588
|
+
typ: exports.EnumToken.ComposesSelectorNodeType,
|
|
7589
|
+
l: left,
|
|
7590
|
+
r: right.reduce((a, b) => {
|
|
7591
|
+
return a == null ? b : b.typ == exports.EnumToken.WhitespaceTokenType || b.typ == exports.EnumToken.CommentTokenType ? a : b;
|
|
7592
|
+
}, null)
|
|
7593
|
+
});
|
|
7594
|
+
}
|
|
7595
|
+
}
|
|
7596
|
+
}
|
|
7461
7597
|
for (const { value: val, parent } of walkValues(node.val, node)) {
|
|
7462
7598
|
if (val.typ == exports.EnumToken.AttrTokenType && val.chi.every((t) => [exports.EnumToken.IdenTokenType, exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ))) {
|
|
7463
7599
|
// @ts-ignore
|
|
@@ -7504,6 +7640,13 @@ function parseGridTemplate(template) {
|
|
|
7504
7640
|
return buffer.length > 0 ? result + buffer : result;
|
|
7505
7641
|
}
|
|
7506
7642
|
|
|
7643
|
+
function dasherize(value) {
|
|
7644
|
+
return value.replace(/([A-Z])/g, (all, one) => `-${one.toLowerCase()}`);
|
|
7645
|
+
}
|
|
7646
|
+
function camelize(value) {
|
|
7647
|
+
return value.replace(/-([a-z])/g, (all, one) => one.toUpperCase());
|
|
7648
|
+
}
|
|
7649
|
+
|
|
7507
7650
|
// from https://github.com/Rich-Harris/vlq/tree/master
|
|
7508
7651
|
// credit: Rich Harris
|
|
7509
7652
|
const integer_to_char = {};
|
|
@@ -7650,9 +7793,10 @@ function update(position, str) {
|
|
|
7650
7793
|
* render ast
|
|
7651
7794
|
* @param data
|
|
7652
7795
|
* @param options
|
|
7796
|
+
* @param mapping
|
|
7653
7797
|
* @private
|
|
7654
7798
|
*/
|
|
7655
|
-
function doRender(data, options = {}) {
|
|
7799
|
+
function doRender(data, options = {}, mapping) {
|
|
7656
7800
|
const minify = options.minify ?? true;
|
|
7657
7801
|
const beautify = options.beautify ?? !minify;
|
|
7658
7802
|
options = {
|
|
@@ -7689,12 +7833,23 @@ function doRender(data, options = {}) {
|
|
|
7689
7833
|
const errors = [];
|
|
7690
7834
|
const sourcemap = options.sourcemap ? new SourceMap : null;
|
|
7691
7835
|
const cache = Object.create(null);
|
|
7836
|
+
const position = {
|
|
7837
|
+
ind: 0,
|
|
7838
|
+
lin: 1,
|
|
7839
|
+
col: 1
|
|
7840
|
+
};
|
|
7841
|
+
let code = '';
|
|
7842
|
+
if (mapping != null) {
|
|
7843
|
+
if (mapping.importMapping != null) {
|
|
7844
|
+
for (const [key, value] of Object.entries(mapping.importMapping)) {
|
|
7845
|
+
code += `:import("${key}")${options.indent}{${options.newLine}${Object.entries(value).reduce((acc, [k, v]) => acc + (acc.length > 0 ? options.newLine : '') + `${options.indent}${v}:${options.indent}${k};`, '')}${options.newLine}}${options.newLine}`;
|
|
7846
|
+
}
|
|
7847
|
+
}
|
|
7848
|
+
code += `:export${options.indent}{${options.newLine}${Object.entries(mapping.mapping).reduce((acc, [k, v]) => acc + (acc.length > 0 ? options.newLine : '') + `${options.indent}${k}:${options.indent}${v};`, '')}${options.newLine}}${options.newLine}`;
|
|
7849
|
+
update(position, code);
|
|
7850
|
+
}
|
|
7692
7851
|
const result = {
|
|
7693
|
-
code: renderAstNode(options.expandNestingRules ? expand(data) : data, options, sourcemap, {
|
|
7694
|
-
ind: 0,
|
|
7695
|
-
lin: 1,
|
|
7696
|
-
col: 1
|
|
7697
|
-
}, errors, function reducer(acc, curr) {
|
|
7852
|
+
code: code + renderAstNode(options.expandNestingRules && [exports.EnumToken.StyleSheetNodeType, exports.EnumToken.AtRuleNodeType, exports.EnumToken.RuleNodeType].includes(data.typ) && 'chi' in data ? expand(data) : data, options, sourcemap, position, errors, function reducer(acc, curr) {
|
|
7698
7853
|
if (curr.typ == exports.EnumToken.CommentTokenType && options.removeComments) {
|
|
7699
7854
|
if (!options.preserveLicense || !curr.val.startsWith('/*!')) {
|
|
7700
7855
|
return acc;
|
|
@@ -7830,7 +7985,7 @@ function renderAstNode(data, options, sourcemap, position, errors, reducer, cach
|
|
|
7830
7985
|
str = `${node.nam}:${options.indent}${(options.minify ? filterValues(node.val) : node.val).reduce(reducer, '').trimEnd()};`;
|
|
7831
7986
|
}
|
|
7832
7987
|
else if (node.typ == exports.EnumToken.AtRuleNodeType && !('chi' in node)) {
|
|
7833
|
-
str = `${
|
|
7988
|
+
str = `${node.val === '' ? '' : options.indent || ' '}${node.val};`;
|
|
7834
7989
|
}
|
|
7835
7990
|
else {
|
|
7836
7991
|
str = renderAstNode(node, options, sourcemap, { ...position }, errors, reducer, cache, level + 1, indents);
|
|
@@ -7853,6 +8008,11 @@ function renderAstNode(data, options, sourcemap, position, errors, reducer, cach
|
|
|
7853
8008
|
return `@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val}${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
|
|
7854
8009
|
}
|
|
7855
8010
|
return data.sel + `${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
|
|
8011
|
+
case exports.EnumToken.CssVariableTokenType:
|
|
8012
|
+
case exports.EnumToken.CssVariableImportTokenType:
|
|
8013
|
+
return `@value ${data.nam}:${options.indent}${filterValues((options.minify ? data.val : data.val)).reduce(reducer, '').trim()};`;
|
|
8014
|
+
case exports.EnumToken.CssVariableDeclarationMapTokenType:
|
|
8015
|
+
return `@value ${filterValues(data.vars).reduce((acc, curr) => acc + renderToken(curr), '').trim()} from ${filterValues(data.from).reduce((acc, curr) => acc + renderToken(curr), '').trim()};`;
|
|
7856
8016
|
case exports.EnumToken.InvalidDeclarationNodeType:
|
|
7857
8017
|
case exports.EnumToken.InvalidRuleTokenType:
|
|
7858
8018
|
case exports.EnumToken.InvalidAtRuleTokenType:
|
|
@@ -8007,6 +8167,8 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
8007
8167
|
case exports.EnumToken.NameSpaceAttributeTokenType:
|
|
8008
8168
|
return (token.l == null ? '' : renderToken(token.l, options, cache, reducer, errors)) + '|' +
|
|
8009
8169
|
renderToken(token.r, options, cache, reducer, errors);
|
|
8170
|
+
case exports.EnumToken.ComposesSelectorNodeType:
|
|
8171
|
+
return token.l.reduce((acc, curr) => acc + renderToken(curr, options, cache), '') + (token.r == null ? '' : ' from ' + renderToken(token.r, options, cache, reducer, errors));
|
|
8010
8172
|
case exports.EnumToken.BlockStartTokenType:
|
|
8011
8173
|
return '{';
|
|
8012
8174
|
case exports.EnumToken.BlockEndTokenType:
|
|
@@ -8377,23 +8539,27 @@ function* consumeString(quoteStr, buffer, parseInfo) {
|
|
|
8377
8539
|
}
|
|
8378
8540
|
}
|
|
8379
8541
|
function match$1(parseInfo, input) {
|
|
8380
|
-
|
|
8542
|
+
const position = parseInfo.currentPosition.ind - parseInfo.offset;
|
|
8543
|
+
return parseInfo.stream.slice(position + 1, position + input.length + 1) == input;
|
|
8381
8544
|
}
|
|
8382
8545
|
function peek(parseInfo, count = 1) {
|
|
8383
8546
|
if (count == 1) {
|
|
8384
|
-
return parseInfo.stream.charAt(parseInfo.currentPosition.ind + 1);
|
|
8547
|
+
return parseInfo.stream.charAt(parseInfo.currentPosition.ind - parseInfo.offset + 1);
|
|
8385
8548
|
}
|
|
8386
|
-
|
|
8549
|
+
const position = parseInfo.currentPosition.ind - parseInfo.offset;
|
|
8550
|
+
return parseInfo.stream.slice(position + 1, position + count + 1);
|
|
8387
8551
|
}
|
|
8388
8552
|
function prev(parseInfo) {
|
|
8389
|
-
return parseInfo.stream.charAt(parseInfo.currentPosition.ind - 1);
|
|
8553
|
+
return parseInfo.offset == parseInfo.currentPosition.ind ? parseInfo.buffer.slice(-1) : parseInfo.stream.charAt(parseInfo.currentPosition.ind - parseInfo.offset - 1);
|
|
8390
8554
|
}
|
|
8391
8555
|
function next(parseInfo, count = 1) {
|
|
8392
8556
|
let char = '';
|
|
8393
8557
|
let chr = '';
|
|
8394
|
-
|
|
8558
|
+
let position = parseInfo.currentPosition.ind - parseInfo.offset;
|
|
8559
|
+
while (count-- && (chr = parseInfo.stream.charAt(position + 1))) {
|
|
8395
8560
|
char += chr;
|
|
8396
|
-
const codepoint = parseInfo.stream.charCodeAt(++
|
|
8561
|
+
const codepoint = parseInfo.stream.charCodeAt(++position);
|
|
8562
|
+
++parseInfo.currentPosition.ind;
|
|
8397
8563
|
if (isNewLine(codepoint)) {
|
|
8398
8564
|
parseInfo.currentPosition.lin++;
|
|
8399
8565
|
parseInfo.currentPosition.col = 0;
|
|
@@ -8421,13 +8587,15 @@ function* tokenize$1(parseInfo, yieldEOFToken = true) {
|
|
|
8421
8587
|
yield pushToken(buffer, parseInfo);
|
|
8422
8588
|
buffer = '';
|
|
8423
8589
|
}
|
|
8590
|
+
buffer += value;
|
|
8424
8591
|
while (value = next(parseInfo)) {
|
|
8425
8592
|
charCode = value.charCodeAt(0);
|
|
8426
8593
|
if (!isWhiteSpace(charCode)) {
|
|
8427
8594
|
break;
|
|
8428
8595
|
}
|
|
8596
|
+
buffer += value;
|
|
8429
8597
|
}
|
|
8430
|
-
yield pushToken(
|
|
8598
|
+
yield pushToken(buffer, parseInfo, exports.EnumToken.WhitespaceTokenType);
|
|
8431
8599
|
buffer = '';
|
|
8432
8600
|
}
|
|
8433
8601
|
switch (charCode) {
|
|
@@ -8475,8 +8643,7 @@ function* tokenize$1(parseInfo, yieldEOFToken = true) {
|
|
|
8475
8643
|
buffer = '';
|
|
8476
8644
|
}
|
|
8477
8645
|
if (match$1(parseInfo, '=')) {
|
|
8478
|
-
yield pushToken(
|
|
8479
|
-
next(parseInfo);
|
|
8646
|
+
yield pushToken(value + next(parseInfo), parseInfo, exports.EnumToken.LteTokenType);
|
|
8480
8647
|
break;
|
|
8481
8648
|
}
|
|
8482
8649
|
buffer += value;
|
|
@@ -8531,8 +8698,7 @@ function* tokenize$1(parseInfo, yieldEOFToken = true) {
|
|
|
8531
8698
|
}
|
|
8532
8699
|
if (charCode == 124 /* TokenMap.PIPE */) {
|
|
8533
8700
|
if (match$1(parseInfo, '|')) {
|
|
8534
|
-
next(parseInfo);
|
|
8535
|
-
yield pushToken('', parseInfo, exports.EnumToken.ColumnCombinatorTokenType);
|
|
8701
|
+
yield pushToken(value + next(parseInfo), parseInfo, exports.EnumToken.ColumnCombinatorTokenType);
|
|
8536
8702
|
}
|
|
8537
8703
|
else if (match$1(parseInfo, '=')) {
|
|
8538
8704
|
buffer += next(parseInfo);
|
|
@@ -8586,11 +8752,10 @@ function* tokenize$1(parseInfo, yieldEOFToken = true) {
|
|
|
8586
8752
|
buffer = '';
|
|
8587
8753
|
}
|
|
8588
8754
|
if (match$1(parseInfo, '=')) {
|
|
8589
|
-
yield pushToken(
|
|
8590
|
-
next(parseInfo);
|
|
8755
|
+
yield pushToken(value + next(parseInfo), parseInfo, exports.EnumToken.GteTokenType);
|
|
8591
8756
|
}
|
|
8592
8757
|
else {
|
|
8593
|
-
yield pushToken(
|
|
8758
|
+
yield pushToken(value, parseInfo, exports.EnumToken.GtTokenType);
|
|
8594
8759
|
}
|
|
8595
8760
|
consumeWhiteSpace(parseInfo);
|
|
8596
8761
|
break;
|
|
@@ -8641,7 +8806,7 @@ function* tokenize$1(parseInfo, yieldEOFToken = true) {
|
|
|
8641
8806
|
yield pushToken(buffer, parseInfo);
|
|
8642
8807
|
buffer = '';
|
|
8643
8808
|
}
|
|
8644
|
-
yield pushToken(
|
|
8809
|
+
yield pushToken(value, parseInfo, exports.EnumToken.EndParensTokenType);
|
|
8645
8810
|
break;
|
|
8646
8811
|
case 40 /* TokenMap.OPEN_PAREN */:
|
|
8647
8812
|
if (buffer.length == 0) {
|
|
@@ -8707,7 +8872,7 @@ function* tokenize$1(parseInfo, yieldEOFToken = true) {
|
|
|
8707
8872
|
// ')'
|
|
8708
8873
|
if (charCode == 0x29) {
|
|
8709
8874
|
yield pushToken(buffer, parseInfo, hasNewLine ? exports.EnumToken.BadStringTokenType : exports.EnumToken.StringTokenType);
|
|
8710
|
-
yield pushToken(
|
|
8875
|
+
yield pushToken(value, parseInfo, exports.EnumToken.EndParensTokenType);
|
|
8711
8876
|
buffer = '';
|
|
8712
8877
|
break;
|
|
8713
8878
|
}
|
|
@@ -8731,7 +8896,7 @@ function* tokenize$1(parseInfo, yieldEOFToken = true) {
|
|
|
8731
8896
|
charCode = value.charCodeAt(0);
|
|
8732
8897
|
if (charCode == 0x29) { // ')'
|
|
8733
8898
|
yield pushToken(buffer, parseInfo, exports.EnumToken.UrlTokenTokenType);
|
|
8734
|
-
yield pushToken(
|
|
8899
|
+
yield pushToken(value, parseInfo, exports.EnumToken.EndParensTokenType);
|
|
8735
8900
|
buffer = '';
|
|
8736
8901
|
break;
|
|
8737
8902
|
}
|
|
@@ -8765,8 +8930,7 @@ function* tokenize$1(parseInfo, yieldEOFToken = true) {
|
|
|
8765
8930
|
buffer = '';
|
|
8766
8931
|
}
|
|
8767
8932
|
if (match$1(parseInfo, 'important')) {
|
|
8768
|
-
yield pushToken(
|
|
8769
|
-
next(parseInfo, 9);
|
|
8933
|
+
yield pushToken(value + next(parseInfo, 9), parseInfo, exports.EnumToken.ImportantTokenType);
|
|
8770
8934
|
buffer = '';
|
|
8771
8935
|
break;
|
|
8772
8936
|
}
|
|
@@ -8811,6 +8975,7 @@ async function* tokenizeStream(input) {
|
|
|
8811
8975
|
const parseInfo = {
|
|
8812
8976
|
stream: '',
|
|
8813
8977
|
buffer: '',
|
|
8978
|
+
offset: 0,
|
|
8814
8979
|
position: { ind: 0, lin: 1, col: 1 },
|
|
8815
8980
|
currentPosition: { ind: -1, lin: 1, col: 0 }
|
|
8816
8981
|
};
|
|
@@ -8818,7 +8983,17 @@ async function* tokenizeStream(input) {
|
|
|
8818
8983
|
const reader = input.getReader();
|
|
8819
8984
|
while (true) {
|
|
8820
8985
|
const { done, value } = await reader.read();
|
|
8821
|
-
|
|
8986
|
+
const stream = ArrayBuffer.isView(value) ? decoder.decode(value, { stream: true }) : value;
|
|
8987
|
+
if (!done) {
|
|
8988
|
+
if (parseInfo.stream.length > 2) {
|
|
8989
|
+
parseInfo.stream = parseInfo.stream.slice(-2) + stream;
|
|
8990
|
+
parseInfo.offset = parseInfo.currentPosition.ind - 1;
|
|
8991
|
+
}
|
|
8992
|
+
else {
|
|
8993
|
+
parseInfo.stream = stream;
|
|
8994
|
+
parseInfo.offset = Math.max(0, parseInfo.currentPosition.ind);
|
|
8995
|
+
}
|
|
8996
|
+
}
|
|
8822
8997
|
yield* tokenize$1(parseInfo, done);
|
|
8823
8998
|
if (done) {
|
|
8824
8999
|
break;
|
|
@@ -9581,7 +9756,7 @@ var declarations = {
|
|
|
9581
9756
|
syntax: "[ <counter-name> <integer>? ]+ | none"
|
|
9582
9757
|
},
|
|
9583
9758
|
cursor: {
|
|
9584
|
-
syntax: "[ [ <url> [ <x> <y> ]? , ]*
|
|
9759
|
+
syntax: "[ [ <url> [ <x> <y> ]? , ]* <cursor-predefined> ] [ [ <url> [ <x> <y> ]? , ]* [ auto | default | none | context-menu | help | pointer | progress | wait | cell | crosshair | text | vertical-text | alias | copy | move | no-drop | not-allowed | e-resize | n-resize | ne-resize | nw-resize | s-resize | se-resize | sw-resize | w-resize | ew-resize | ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | all-scroll | zoom-in | zoom-out | grab | grabbing | hand | -webkit-grab | -webkit-grabbing | -webkit-zoom-in | -webkit-zoom-out | -moz-grab | -moz-grabbing | -moz-zoom-in | -moz-zoom-out ] ]"
|
|
9585
9760
|
},
|
|
9586
9761
|
cx: {
|
|
9587
9762
|
syntax: "<length> | <percentage>"
|
|
@@ -10809,6 +10984,12 @@ var declarations = {
|
|
|
10809
10984
|
},
|
|
10810
10985
|
"white-space-trim": {
|
|
10811
10986
|
syntax: "none | discard-before || discard-after || discard-inner"
|
|
10987
|
+
},
|
|
10988
|
+
composes: {
|
|
10989
|
+
syntax: "<composes-selector>#"
|
|
10990
|
+
},
|
|
10991
|
+
"composes-selector": {
|
|
10992
|
+
syntax: "<ident>+ [from [global&&<string>]]?"
|
|
10812
10993
|
}
|
|
10813
10994
|
};
|
|
10814
10995
|
var functions = {
|
|
@@ -10834,7 +11015,7 @@ var functions = {
|
|
|
10834
11015
|
syntax: "atan2( <calc-sum>, <calc-sum> )"
|
|
10835
11016
|
},
|
|
10836
11017
|
attr: {
|
|
10837
|
-
syntax: "attr( <attr-name> <type
|
|
11018
|
+
syntax: "attr( <attr-name> <attr-type>? , <declaration-value>? )"
|
|
10838
11019
|
},
|
|
10839
11020
|
blur: {
|
|
10840
11021
|
syntax: "blur( <length>? )"
|
|
@@ -11187,7 +11368,7 @@ var syntaxes = {
|
|
|
11187
11368
|
syntax: "scroll | fixed | local"
|
|
11188
11369
|
},
|
|
11189
11370
|
"attr()": {
|
|
11190
|
-
syntax: "attr( <attr-name> <type
|
|
11371
|
+
syntax: "attr( <attr-name> <attr-type>? , <declaration-value>? )"
|
|
11191
11372
|
},
|
|
11192
11373
|
"attr-matcher": {
|
|
11193
11374
|
syntax: "[ '~' | '|' | '^' | '$' | '*' ]? '='"
|
|
@@ -11195,6 +11376,9 @@ var syntaxes = {
|
|
|
11195
11376
|
"attr-modifier": {
|
|
11196
11377
|
syntax: "i | s"
|
|
11197
11378
|
},
|
|
11379
|
+
"attr-type": {
|
|
11380
|
+
syntax: "type( <syntax> ) | raw-string | number | <attr-unit>"
|
|
11381
|
+
},
|
|
11198
11382
|
"attribute-selector": {
|
|
11199
11383
|
syntax: "'[' <wq-name> ']' | '[' <wq-name> <attr-matcher> [ <string-token> | <ident-token> ] <attr-modifier>? ']'"
|
|
11200
11384
|
},
|
|
@@ -11408,6 +11592,9 @@ var syntaxes = {
|
|
|
11408
11592
|
"cubic-bezier-easing-function": {
|
|
11409
11593
|
syntax: "ease | ease-in | ease-out | ease-in-out | cubic-bezier( <number [0,1]> , <number> , <number [0,1]> , <number> )"
|
|
11410
11594
|
},
|
|
11595
|
+
"cursor-predefined": {
|
|
11596
|
+
syntax: "auto | default | none | context-menu | help | pointer | progress | wait | cell | crosshair | text | vertical-text | alias | copy | move | no-drop | not-allowed | e-resize | n-resize | ne-resize | nw-resize | s-resize | se-resize | sw-resize | w-resize | ew-resize | ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | all-scroll | zoom-in | zoom-out | grab | grabbing"
|
|
11597
|
+
},
|
|
11411
11598
|
"custom-color-space": {
|
|
11412
11599
|
syntax: "<dashed-ident>"
|
|
11413
11600
|
},
|
|
@@ -13018,7 +13205,27 @@ var atRules = {
|
|
|
13018
13205
|
}
|
|
13019
13206
|
},
|
|
13020
13207
|
"@nest": {
|
|
13021
|
-
|
|
13208
|
+
},
|
|
13209
|
+
"@stylistic": {
|
|
13210
|
+
syntax: " @stylistic { <feature-value-declaration-list> } "
|
|
13211
|
+
},
|
|
13212
|
+
"@historical-forms": {
|
|
13213
|
+
syntax: " @historical-forms { <feature-value-declaration-list> } "
|
|
13214
|
+
},
|
|
13215
|
+
"@styleset": {
|
|
13216
|
+
syntax: " @styleset { <feature-value-declaration-list> } "
|
|
13217
|
+
},
|
|
13218
|
+
"@character-variant": {
|
|
13219
|
+
syntax: " @character-variant { <feature-value-declaration-list> } "
|
|
13220
|
+
},
|
|
13221
|
+
"@swash": {
|
|
13222
|
+
syntax: " @swash { <feature-value-declaration-list> } "
|
|
13223
|
+
},
|
|
13224
|
+
"@ornaments": {
|
|
13225
|
+
syntax: " @ornaments { <feature-value-declaration-list> } "
|
|
13226
|
+
},
|
|
13227
|
+
"@annotation": {
|
|
13228
|
+
syntax: " @annotation { <feature-value-declaration-list> } "
|
|
13022
13229
|
}
|
|
13023
13230
|
};
|
|
13024
13231
|
var config$3 = {
|
|
@@ -13081,7 +13288,6 @@ var ValidationSyntaxGroupEnum;
|
|
|
13081
13288
|
ValidationSyntaxGroupEnum["Selectors"] = "selectors";
|
|
13082
13289
|
ValidationSyntaxGroupEnum["AtRules"] = "atRules";
|
|
13083
13290
|
})(ValidationSyntaxGroupEnum || (ValidationSyntaxGroupEnum = {}));
|
|
13084
|
-
|
|
13085
13291
|
const skipped = [
|
|
13086
13292
|
ValidationTokenEnum.Star,
|
|
13087
13293
|
ValidationTokenEnum.HashMark,
|
|
@@ -14162,7 +14368,6 @@ function getParsedSyntax(group, key) {
|
|
|
14162
14368
|
const index = group + '.' + keys.join('.');
|
|
14163
14369
|
// @ts-ignore
|
|
14164
14370
|
if (!parsedSyntaxes.has(index)) {
|
|
14165
|
-
// @ts-ignore
|
|
14166
14371
|
const syntax = parseSyntax(obj.syntax);
|
|
14167
14372
|
// @ts-ignore
|
|
14168
14373
|
parsedSyntaxes.set(index, syntax.chi);
|
|
@@ -14311,8 +14516,7 @@ function validateCompoundSelector(tokens, root, options) {
|
|
|
14311
14516
|
node: root,
|
|
14312
14517
|
// @ts-ignore
|
|
14313
14518
|
syntax: null,
|
|
14314
|
-
error: 'expected selector'
|
|
14315
|
-
tokens
|
|
14519
|
+
error: 'expected selector'
|
|
14316
14520
|
};
|
|
14317
14521
|
}
|
|
14318
14522
|
tokens = tokens.slice();
|
|
@@ -14560,15 +14764,12 @@ function validateRelativeSelectorList(tokens, root, options) {
|
|
|
14560
14764
|
return result;
|
|
14561
14765
|
}
|
|
14562
14766
|
}
|
|
14767
|
+
// @ts-ignore
|
|
14563
14768
|
return {
|
|
14564
14769
|
valid: SyntaxValidationResult.Valid,
|
|
14565
|
-
matches: [],
|
|
14566
|
-
// @ts-ignore
|
|
14567
14770
|
node: root,
|
|
14568
|
-
// @ts-ignore
|
|
14569
14771
|
syntax: null,
|
|
14570
|
-
error: ''
|
|
14571
|
-
tokens
|
|
14772
|
+
error: ''
|
|
14572
14773
|
};
|
|
14573
14774
|
}
|
|
14574
14775
|
|
|
@@ -14622,6 +14823,9 @@ function dirname(path) {
|
|
|
14622
14823
|
//
|
|
14623
14824
|
// return path;
|
|
14624
14825
|
// }
|
|
14826
|
+
if (path === '') {
|
|
14827
|
+
return '';
|
|
14828
|
+
}
|
|
14625
14829
|
let i = 0;
|
|
14626
14830
|
let parts = [''];
|
|
14627
14831
|
for (; i < path.length; i++) {
|
|
@@ -14629,9 +14833,10 @@ function dirname(path) {
|
|
|
14629
14833
|
if (chr == '/') {
|
|
14630
14834
|
parts.push('');
|
|
14631
14835
|
}
|
|
14632
|
-
else if (chr == '?' || chr == '#') {
|
|
14633
|
-
|
|
14634
|
-
|
|
14836
|
+
// else if (chr == '?' || chr == '#') {
|
|
14837
|
+
//
|
|
14838
|
+
// break;
|
|
14839
|
+
// }
|
|
14635
14840
|
else {
|
|
14636
14841
|
parts[parts.length - 1] += chr;
|
|
14637
14842
|
}
|
|
@@ -14645,6 +14850,12 @@ function dirname(path) {
|
|
|
14645
14850
|
* @private
|
|
14646
14851
|
*/
|
|
14647
14852
|
function splitPath(result) {
|
|
14853
|
+
if (result.length == 0) {
|
|
14854
|
+
return { parts: [], i: 0 };
|
|
14855
|
+
}
|
|
14856
|
+
if (result === '/') {
|
|
14857
|
+
return { parts: ['/'], i: 0 };
|
|
14858
|
+
}
|
|
14648
14859
|
const parts = [''];
|
|
14649
14860
|
let i = 0;
|
|
14650
14861
|
for (; i < result.length; i++) {
|
|
@@ -14686,6 +14897,23 @@ function resolve(url, currentDirectory, cwd) {
|
|
|
14686
14897
|
relative: url
|
|
14687
14898
|
};
|
|
14688
14899
|
}
|
|
14900
|
+
cwd ??= '';
|
|
14901
|
+
currentDirectory ??= '';
|
|
14902
|
+
if (currentDirectory !== '' && url.startsWith(currentDirectory + '/')) {
|
|
14903
|
+
return {
|
|
14904
|
+
absolute: url,
|
|
14905
|
+
relative: url.slice(currentDirectory.length + 1)
|
|
14906
|
+
};
|
|
14907
|
+
}
|
|
14908
|
+
if (currentDirectory === '' && cwd !== '' && url.startsWith(cwd == '/' ? cwd : cwd + '/')) {
|
|
14909
|
+
cwd = normalize(cwd);
|
|
14910
|
+
const absolute = normalize(url);
|
|
14911
|
+
const prefix = cwd == '/' ? cwd : cwd + '/';
|
|
14912
|
+
return {
|
|
14913
|
+
absolute,
|
|
14914
|
+
relative: absolute.startsWith(prefix) ? absolute.slice(prefix.length) : diff$1(absolute, cwd)
|
|
14915
|
+
};
|
|
14916
|
+
}
|
|
14689
14917
|
if (matchUrl.test(currentDirectory)) {
|
|
14690
14918
|
const path = new URL(url, currentDirectory).href;
|
|
14691
14919
|
return {
|
|
@@ -14700,9 +14928,15 @@ function resolve(url, currentDirectory, cwd) {
|
|
|
14700
14928
|
else if (currentDirectory.charAt(0) == '/') {
|
|
14701
14929
|
result = dirname(currentDirectory) + '/' + url;
|
|
14702
14930
|
}
|
|
14703
|
-
|
|
14704
|
-
|
|
14705
|
-
|
|
14931
|
+
const absolute = normalize(result);
|
|
14932
|
+
return {
|
|
14933
|
+
absolute,
|
|
14934
|
+
relative: absolute === '' ? '' : diff$1(absolute, cwd ?? currentDirectory),
|
|
14935
|
+
};
|
|
14936
|
+
}
|
|
14937
|
+
function diff$1(path1, path2) {
|
|
14938
|
+
let { parts } = splitPath(path1);
|
|
14939
|
+
const { parts: dirs } = splitPath(path2);
|
|
14706
14940
|
for (const p of dirs) {
|
|
14707
14941
|
if (parts[0] == p) {
|
|
14708
14942
|
parts.shift();
|
|
@@ -14711,16 +14945,61 @@ function resolve(url, currentDirectory, cwd) {
|
|
|
14711
14945
|
parts.unshift('..');
|
|
14712
14946
|
}
|
|
14713
14947
|
}
|
|
14714
|
-
return
|
|
14715
|
-
|
|
14716
|
-
|
|
14717
|
-
|
|
14948
|
+
return parts.join('/');
|
|
14949
|
+
}
|
|
14950
|
+
function normalize(path) {
|
|
14951
|
+
let parts = [];
|
|
14952
|
+
let i = 0;
|
|
14953
|
+
for (; i < path.length; i++) {
|
|
14954
|
+
const chr = path.charAt(i);
|
|
14955
|
+
if (chr == '/') {
|
|
14956
|
+
if (parts.length == 0 || parts[parts.length - 1] !== '') {
|
|
14957
|
+
parts.push('');
|
|
14958
|
+
}
|
|
14959
|
+
}
|
|
14960
|
+
else if (chr == '?' || chr == '#') {
|
|
14961
|
+
break;
|
|
14962
|
+
}
|
|
14963
|
+
else {
|
|
14964
|
+
parts[parts.length - 1] += chr;
|
|
14965
|
+
}
|
|
14966
|
+
}
|
|
14967
|
+
let k = -1;
|
|
14968
|
+
while (++k < parts.length) {
|
|
14969
|
+
if (parts[k] == '.') {
|
|
14970
|
+
parts.splice(k--, 1);
|
|
14971
|
+
}
|
|
14972
|
+
else if (parts[k] == '..') {
|
|
14973
|
+
parts.splice(k - 1, 2);
|
|
14974
|
+
k -= 2;
|
|
14975
|
+
}
|
|
14976
|
+
}
|
|
14977
|
+
return (path.charAt(0) == '/' ? '/' : '') + parts.join('/');
|
|
14718
14978
|
}
|
|
14719
14979
|
|
|
14980
|
+
/**
|
|
14981
|
+
* response type
|
|
14982
|
+
*/
|
|
14983
|
+
exports.ResponseType = void 0;
|
|
14984
|
+
(function (ResponseType) {
|
|
14985
|
+
/**
|
|
14986
|
+
* return text
|
|
14987
|
+
*/
|
|
14988
|
+
ResponseType[ResponseType["Text"] = 0] = "Text";
|
|
14989
|
+
/**
|
|
14990
|
+
* return a readable stream
|
|
14991
|
+
*/
|
|
14992
|
+
ResponseType[ResponseType["ReadableStream"] = 1] = "ReadableStream";
|
|
14993
|
+
/**
|
|
14994
|
+
* return an arraybuffer
|
|
14995
|
+
*/
|
|
14996
|
+
ResponseType[ResponseType["ArrayBuffer"] = 2] = "ArrayBuffer";
|
|
14997
|
+
})(exports.ResponseType || (exports.ResponseType = {}));
|
|
14998
|
+
|
|
14720
14999
|
/**
|
|
14721
15000
|
* feature walk mode
|
|
14722
15001
|
*
|
|
14723
|
-
* @
|
|
15002
|
+
* @private
|
|
14724
15003
|
*/
|
|
14725
15004
|
exports.FeatureWalkMode = void 0;
|
|
14726
15005
|
(function (FeatureWalkMode) {
|
|
@@ -14737,6 +15016,116 @@ exports.FeatureWalkMode = void 0;
|
|
|
14737
15016
|
const config$2 = getSyntaxConfig();
|
|
14738
15017
|
// @ts-ignore
|
|
14739
15018
|
const allValues = getSyntaxConfig()["declarations" /* ValidationSyntaxGroupEnum.Declarations */].all.syntax.trim().split(/[\s|]+/g);
|
|
15019
|
+
/**
|
|
15020
|
+
* Check if a node is allowed as child in a given context
|
|
15021
|
+
* @param node
|
|
15022
|
+
* @param context
|
|
15023
|
+
*/
|
|
15024
|
+
function isNodeAllowedInContext(node, context) {
|
|
15025
|
+
if (node.typ == exports.EnumToken.CommentNodeType || context == null) {
|
|
15026
|
+
return true;
|
|
15027
|
+
}
|
|
15028
|
+
switch (context?.typ) {
|
|
15029
|
+
case exports.EnumToken.StyleSheetNodeType:
|
|
15030
|
+
case exports.EnumToken.RuleNodeType:
|
|
15031
|
+
return node.typ == exports.EnumToken.RuleNodeType ||
|
|
15032
|
+
node.typ == exports.EnumToken.AtRuleNodeType ||
|
|
15033
|
+
node.typ == exports.EnumToken.KeyframesAtRuleNodeType ||
|
|
15034
|
+
(node.typ == exports.EnumToken.DeclarationNodeType && context.typ == exports.EnumToken.RuleNodeType) ||
|
|
15035
|
+
(node.typ == exports.EnumToken.CDOCOMMNodeType && context.typ == exports.EnumToken.StyleSheetNodeType);
|
|
15036
|
+
case exports.EnumToken.KeyframesAtRuleNodeType:
|
|
15037
|
+
return node.typ == exports.EnumToken.KeyFramesRuleNodeType;
|
|
15038
|
+
case exports.EnumToken.KeyFramesRuleNodeType:
|
|
15039
|
+
return node.typ == exports.EnumToken.DeclarationNodeType;
|
|
15040
|
+
case exports.EnumToken.AtRuleNodeType:
|
|
15041
|
+
// @ts-ignore
|
|
15042
|
+
const syntax = getParsedSyntax("atRules" /* ValidationSyntaxGroupEnum.AtRules */, '@' + context.nam)?.[0].chi ?? null;
|
|
15043
|
+
//
|
|
15044
|
+
if (syntax == null) {
|
|
15045
|
+
// console.error(`syntax: Not found ${ValidationSyntaxGroupEnum.AtRules}@${(context as AstAtRule).nam}`);
|
|
15046
|
+
return true;
|
|
15047
|
+
}
|
|
15048
|
+
const stack = syntax.slice();
|
|
15049
|
+
for (const child of stack) {
|
|
15050
|
+
if (Array.isArray(child)) {
|
|
15051
|
+
stack.push(...child);
|
|
15052
|
+
continue;
|
|
15053
|
+
}
|
|
15054
|
+
if ('chi' in child && Array.isArray(child.chi)) {
|
|
15055
|
+
stack.push(...child.chi);
|
|
15056
|
+
continue;
|
|
15057
|
+
}
|
|
15058
|
+
// @ts-ignore
|
|
15059
|
+
if (child.l != null) {
|
|
15060
|
+
// @ts-ignore
|
|
15061
|
+
stack.push(child.l);
|
|
15062
|
+
// @ts-ignore
|
|
15063
|
+
if (child.r != null) {
|
|
15064
|
+
// @ts-ignore
|
|
15065
|
+
stack.push(...(Array.isArray(child.r) ? child.r : [child.r]));
|
|
15066
|
+
}
|
|
15067
|
+
continue;
|
|
15068
|
+
}
|
|
15069
|
+
if (node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
15070
|
+
if (child.typ == ValidationTokenEnum.DeclarationDefinitionToken) {
|
|
15071
|
+
if (node.nam == child.nam) {
|
|
15072
|
+
return true;
|
|
15073
|
+
}
|
|
15074
|
+
}
|
|
15075
|
+
}
|
|
15076
|
+
if (child.typ == ValidationTokenEnum.PropertyType) {
|
|
15077
|
+
if (['group-rule-body', 'block-contents', 'rule-list', 'stylesheet'].includes(child.val)) {
|
|
15078
|
+
if ((node.typ == exports.EnumToken.RuleNodeType ||
|
|
15079
|
+
node.typ == exports.EnumToken.AtRuleNodeType ||
|
|
15080
|
+
node.typ == exports.EnumToken.KeyframesAtRuleNodeType)) {
|
|
15081
|
+
return true;
|
|
15082
|
+
}
|
|
15083
|
+
if (node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
15084
|
+
let parent = node.parent;
|
|
15085
|
+
while (parent != null) {
|
|
15086
|
+
if (parent.parent?.typ == exports.EnumToken.RuleNodeType) {
|
|
15087
|
+
return true;
|
|
15088
|
+
}
|
|
15089
|
+
parent = parent.parent;
|
|
15090
|
+
}
|
|
15091
|
+
}
|
|
15092
|
+
}
|
|
15093
|
+
if (['declaration-list', 'feature-value-declaration'].includes(child.val) && node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
15094
|
+
return true;
|
|
15095
|
+
}
|
|
15096
|
+
if (child.val == 'page-body' && (node.typ == exports.EnumToken.DeclarationNodeType || (node.typ == exports.EnumToken.AtRuleNodeType && [
|
|
15097
|
+
'top-left-corner', 'top-left', 'top-center', 'top-right', 'top-right-corner',
|
|
15098
|
+
'bottom-left-corner', 'bottom-left', 'bottom-center', 'bottom-right', 'bottom-right-corner',
|
|
15099
|
+
'left-top', 'left-middle', 'left-bottom', 'right-top', 'right-middle', 'right-bottom'
|
|
15100
|
+
].includes(node.nam)))) {
|
|
15101
|
+
return true;
|
|
15102
|
+
}
|
|
15103
|
+
if (child.val == 'feature-value-block-list' &&
|
|
15104
|
+
(node.typ == exports.EnumToken.AtRuleNodeType && ['stylistic', 'historical-forms', 'styleset', 'character-variant', 'swash', 'ornaments', 'annotation'].includes(node.nam))) {
|
|
15105
|
+
return true;
|
|
15106
|
+
}
|
|
15107
|
+
if (['feature-value-declaration-list', 'feature-value-declaration'].includes(child.val) && node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
15108
|
+
return true;
|
|
15109
|
+
}
|
|
15110
|
+
if (child.val == 'page-body') {
|
|
15111
|
+
if (node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
15112
|
+
return true;
|
|
15113
|
+
}
|
|
15114
|
+
}
|
|
15115
|
+
// console.error(`isNodeAllowedInContext: Not found ${(child as ValidationPropertyToken).val}`, {
|
|
15116
|
+
// child,
|
|
15117
|
+
// node
|
|
15118
|
+
// });
|
|
15119
|
+
}
|
|
15120
|
+
}
|
|
15121
|
+
break;
|
|
15122
|
+
}
|
|
15123
|
+
return false;
|
|
15124
|
+
}
|
|
15125
|
+
/**
|
|
15126
|
+
* Create a syntax validation context from a list of tokens
|
|
15127
|
+
* @param input
|
|
15128
|
+
*/
|
|
14740
15129
|
function createContext(input) {
|
|
14741
15130
|
const values = input.slice();
|
|
14742
15131
|
const result = values.filter(token => token.typ != exports.EnumToken.CommentTokenType).slice();
|
|
@@ -14797,7 +15186,22 @@ function createContext(input) {
|
|
|
14797
15186
|
}
|
|
14798
15187
|
};
|
|
14799
15188
|
}
|
|
14800
|
-
|
|
15189
|
+
/**
|
|
15190
|
+
* Evaluate the validity of the syntax of a node
|
|
15191
|
+
* @param node
|
|
15192
|
+
* @param parent
|
|
15193
|
+
* @param options
|
|
15194
|
+
*/
|
|
15195
|
+
function evaluateSyntax(node, parent, options) {
|
|
15196
|
+
if (node.validSyntax) {
|
|
15197
|
+
return {
|
|
15198
|
+
valid: SyntaxValidationResult.Valid,
|
|
15199
|
+
node,
|
|
15200
|
+
syntax: null,
|
|
15201
|
+
error: '',
|
|
15202
|
+
context: []
|
|
15203
|
+
};
|
|
15204
|
+
}
|
|
14801
15205
|
let ast;
|
|
14802
15206
|
let result;
|
|
14803
15207
|
switch (node.typ) {
|
|
@@ -14805,25 +15209,34 @@ function evaluateSyntax(node, options) {
|
|
|
14805
15209
|
if (node.nam.startsWith('--')) {
|
|
14806
15210
|
break;
|
|
14807
15211
|
}
|
|
15212
|
+
let token = null;
|
|
15213
|
+
let values = node.val.slice();
|
|
14808
15214
|
ast = getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, node.nam);
|
|
14809
|
-
|
|
14810
|
-
|
|
14811
|
-
|
|
14812
|
-
|
|
14813
|
-
|
|
14814
|
-
|
|
15215
|
+
while (values.length > 0) {
|
|
15216
|
+
token = values.at(-1);
|
|
15217
|
+
if (token.typ == exports.EnumToken.WhitespaceTokenType || token.typ == exports.EnumToken.CommentTokenType) {
|
|
15218
|
+
values.pop();
|
|
15219
|
+
}
|
|
15220
|
+
else {
|
|
15221
|
+
if (token.typ == exports.EnumToken.ImportantTokenType) {
|
|
14815
15222
|
values.pop();
|
|
14816
|
-
|
|
14817
|
-
else {
|
|
14818
|
-
if (token.typ == exports.EnumToken.ImportantTokenType) {
|
|
15223
|
+
if (values.at(-1)?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
14819
15224
|
values.pop();
|
|
14820
|
-
if (values.at(-1)?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
14821
|
-
values.pop();
|
|
14822
|
-
}
|
|
14823
15225
|
}
|
|
14824
|
-
|
|
15226
|
+
}
|
|
15227
|
+
break;
|
|
15228
|
+
}
|
|
15229
|
+
}
|
|
15230
|
+
if (ast == null) {
|
|
15231
|
+
if (parent?.typ == exports.EnumToken.AtRuleNodeType) {
|
|
15232
|
+
ast = (getParsedSyntax("atRules" /* ValidationSyntaxGroupEnum.AtRules */, ['@' + parent.nam, 'descriptors', node.nam]));
|
|
15233
|
+
if (ast == null) {
|
|
15234
|
+
ast = (getParsedSyntax("atRules" /* ValidationSyntaxGroupEnum.AtRules */, ['@' + parent.nam, 'descriptors', node.nam]) ?? getParsedSyntax("atRules" /* ValidationSyntaxGroupEnum.AtRules */, '@' + parent.nam))?.[0]?.chi;
|
|
15235
|
+
values = [{ ...node, val: values }];
|
|
14825
15236
|
}
|
|
14826
15237
|
}
|
|
15238
|
+
}
|
|
15239
|
+
if (ast != null) {
|
|
14827
15240
|
result = doEvaluateSyntax(ast, createContext(values), { ...options, visited: new WeakMap() });
|
|
14828
15241
|
if (result.valid == SyntaxValidationResult.Valid && !result.context.done()) {
|
|
14829
15242
|
let token = null;
|
|
@@ -14915,7 +15328,7 @@ function doEvaluateSyntax(syntaxes, context, options) {
|
|
|
14915
15328
|
continue;
|
|
14916
15329
|
}
|
|
14917
15330
|
}
|
|
14918
|
-
else if (options.
|
|
15331
|
+
else if (options.occurrence !== false && syntax.occurence != null) {
|
|
14919
15332
|
result = matchOccurence(syntax, context, options);
|
|
14920
15333
|
}
|
|
14921
15334
|
else if (options.atLeastOnce !== false && syntax.atLeastOnce) {
|
|
@@ -15004,7 +15417,7 @@ function matchList(syntax, context, options) {
|
|
|
15004
15417
|
result = doEvaluateSyntax([syntax], createContext(tokens), {
|
|
15005
15418
|
...options,
|
|
15006
15419
|
isList: false,
|
|
15007
|
-
|
|
15420
|
+
occurrence: false
|
|
15008
15421
|
});
|
|
15009
15422
|
if (result.valid == SyntaxValidationResult.Valid) {
|
|
15010
15423
|
context = con.clone();
|
|
@@ -15039,7 +15452,7 @@ function matchOccurence(syntax, context, options) {
|
|
|
15039
15452
|
let counter = 0;
|
|
15040
15453
|
let result;
|
|
15041
15454
|
do {
|
|
15042
|
-
result = match(syntax, context.clone(), { ...options,
|
|
15455
|
+
result = match(syntax, context.clone(), { ...options, occurrence: false });
|
|
15043
15456
|
if (result.valid == SyntaxValidationResult.Drop) {
|
|
15044
15457
|
break;
|
|
15045
15458
|
}
|
|
@@ -15090,7 +15503,7 @@ function match(syntax, context, options) {
|
|
|
15090
15503
|
...options,
|
|
15091
15504
|
isRepeatable: null,
|
|
15092
15505
|
isList: null,
|
|
15093
|
-
|
|
15506
|
+
occurrence: null,
|
|
15094
15507
|
atLeastOnce: null
|
|
15095
15508
|
});
|
|
15096
15509
|
if (result.valid == SyntaxValidationResult.Valid) {
|
|
@@ -15102,7 +15515,7 @@ function match(syntax, context, options) {
|
|
|
15102
15515
|
case ValidationTokenEnum.Keyword:
|
|
15103
15516
|
success = (token.typ == exports.EnumToken.IdenTokenType || token.typ == exports.EnumToken.DashedIdenTokenType || isIdentColor(token)) &&
|
|
15104
15517
|
(token.val == syntax.val ||
|
|
15105
|
-
syntax.val === token.val?.toLowerCase?.() ||
|
|
15518
|
+
syntax.val.toLowerCase() === token.val?.toLowerCase?.() ||
|
|
15106
15519
|
// config.declarations.all
|
|
15107
15520
|
allValues.includes(token.val.toLowerCase()));
|
|
15108
15521
|
if (success) {
|
|
@@ -15141,7 +15554,7 @@ function match(syntax, context, options) {
|
|
|
15141
15554
|
...options,
|
|
15142
15555
|
isRepeatable: null,
|
|
15143
15556
|
isList: null,
|
|
15144
|
-
|
|
15557
|
+
occurrence: null,
|
|
15145
15558
|
atLeastOnce: null
|
|
15146
15559
|
});
|
|
15147
15560
|
case ValidationTokenEnum.Comma:
|
|
@@ -15176,7 +15589,7 @@ function match(syntax, context, options) {
|
|
|
15176
15589
|
...options,
|
|
15177
15590
|
isRepeatable: null,
|
|
15178
15591
|
isList: null,
|
|
15179
|
-
|
|
15592
|
+
occurrence: null,
|
|
15180
15593
|
atLeastOnce: null
|
|
15181
15594
|
}).valid == SyntaxValidationResult.Valid;
|
|
15182
15595
|
if (success) {
|
|
@@ -15199,18 +15612,20 @@ function match(syntax, context, options) {
|
|
|
15199
15612
|
}
|
|
15200
15613
|
function matchPropertyType(syntax, context, options) {
|
|
15201
15614
|
if (![
|
|
15202
|
-
'
|
|
15615
|
+
'color',
|
|
15203
15616
|
'integer',
|
|
15617
|
+
'bg-position',
|
|
15618
|
+
'composes-selector',
|
|
15204
15619
|
'length-percentage', 'flex', 'calc-sum', 'color',
|
|
15205
15620
|
'color-base', 'system-color', 'deprecated-system-color',
|
|
15206
|
-
'pseudo-class-selector', 'pseudo-element-selector'
|
|
15621
|
+
'pseudo-class-selector', 'pseudo-element-selector', 'feature-value-declaration'
|
|
15207
15622
|
].includes(syntax.val)) {
|
|
15208
15623
|
if (syntax.val in config$2["syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */]) {
|
|
15209
15624
|
return doEvaluateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, syntax.val), context, {
|
|
15210
15625
|
...options,
|
|
15211
15626
|
isRepeatable: null,
|
|
15212
15627
|
isList: null,
|
|
15213
|
-
|
|
15628
|
+
occurrence: null,
|
|
15214
15629
|
atLeastOnce: null
|
|
15215
15630
|
});
|
|
15216
15631
|
}
|
|
@@ -15222,7 +15637,7 @@ function matchPropertyType(syntax, context, options) {
|
|
|
15222
15637
|
...options,
|
|
15223
15638
|
isRepeatable: null,
|
|
15224
15639
|
isList: null,
|
|
15225
|
-
|
|
15640
|
+
occurrence: null,
|
|
15226
15641
|
atLeastOnce: null
|
|
15227
15642
|
});
|
|
15228
15643
|
if (result.valid == SyntaxValidationResult.Valid) {
|
|
@@ -15231,6 +15646,9 @@ function matchPropertyType(syntax, context, options) {
|
|
|
15231
15646
|
return { ...result, context };
|
|
15232
15647
|
}
|
|
15233
15648
|
switch (syntax.val) {
|
|
15649
|
+
case 'composes-selector':
|
|
15650
|
+
success = token.typ == exports.EnumToken.ComposesSelectorNodeType;
|
|
15651
|
+
break;
|
|
15234
15652
|
case 'bg-position': {
|
|
15235
15653
|
let val;
|
|
15236
15654
|
let keyworkMatchCount = 0;
|
|
@@ -15327,6 +15745,14 @@ function matchPropertyType(syntax, context, options) {
|
|
|
15327
15745
|
(token.typ == exports.EnumToken.IdenTokenType && typeof Math[token.val.toUpperCase()] == 'number') ||
|
|
15328
15746
|
[exports.EnumToken.BinaryExpressionTokenType, exports.EnumToken.NumberTokenType, exports.EnumToken.PercentageTokenType, exports.EnumToken.DimensionTokenType, exports.EnumToken.LengthTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.TimeTokenType, exports.EnumToken.ResolutionTokenType, exports.EnumToken.FrequencyTokenType].includes(token.typ);
|
|
15329
15747
|
break;
|
|
15748
|
+
case 'declaration':
|
|
15749
|
+
{
|
|
15750
|
+
success = token.typ == exports.EnumToken.DeclarationNodeType;
|
|
15751
|
+
if (success) {
|
|
15752
|
+
success = evaluateSyntax(token, null, options).valid == SyntaxValidationResult.Valid;
|
|
15753
|
+
}
|
|
15754
|
+
}
|
|
15755
|
+
break;
|
|
15330
15756
|
case 'declaration-value':
|
|
15331
15757
|
while (!context.done()) {
|
|
15332
15758
|
context.next();
|
|
@@ -15353,13 +15779,17 @@ function matchPropertyType(syntax, context, options) {
|
|
|
15353
15779
|
break;
|
|
15354
15780
|
case 'color':
|
|
15355
15781
|
case 'color-base':
|
|
15356
|
-
success = token.typ == exports.EnumToken.ColorTokenType ||
|
|
15782
|
+
success = token.typ == exports.EnumToken.ColorTokenType ||
|
|
15783
|
+
(token.typ == exports.EnumToken.IdenTokenType && 'currentcolor' === token.val.toLowerCase()) ||
|
|
15784
|
+
(token.typ == exports.EnumToken.IdenTokenType && 'transparent' === token.val.toLowerCase()) ||
|
|
15785
|
+
(token.typ == exports.EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val) ||
|
|
15786
|
+
isColor(token));
|
|
15357
15787
|
if (!success && token.typ == exports.EnumToken.FunctionTokenType && colorsFunc.includes(token.val)) {
|
|
15358
15788
|
success = doEvaluateSyntax(getParsedSyntax("functions" /* ValidationSyntaxGroupEnum.Functions */, token.val)?.[0]?.chi, createContext(token.chi), {
|
|
15359
15789
|
...options,
|
|
15360
15790
|
isRepeatable: null,
|
|
15361
15791
|
isList: null,
|
|
15362
|
-
|
|
15792
|
+
occurrence: null,
|
|
15363
15793
|
atLeastOnce: null
|
|
15364
15794
|
}).valid == SyntaxValidationResult.Valid;
|
|
15365
15795
|
}
|
|
@@ -15367,8 +15797,26 @@ function matchPropertyType(syntax, context, options) {
|
|
|
15367
15797
|
case 'hex-color':
|
|
15368
15798
|
success = (token.typ == exports.EnumToken.ColorTokenType && token.kin == exports.ColorType.HEX) || (token.typ == exports.EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val));
|
|
15369
15799
|
break;
|
|
15800
|
+
case 'feature-value-declaration':
|
|
15801
|
+
{
|
|
15802
|
+
let hasNumber = false;
|
|
15803
|
+
success = token.typ == exports.EnumToken.DeclarationNodeType && token.val.length > 0 && token.val.every((val) => {
|
|
15804
|
+
if (val.typ == exports.EnumToken.WhitespaceTokenType || val.typ == exports.EnumToken.CommentTokenType) {
|
|
15805
|
+
return true;
|
|
15806
|
+
}
|
|
15807
|
+
const success = (val.typ == exports.EnumToken.NumberTokenType && Number.isInteger(+val.val) && val.val > 0) || (val.typ == exports.EnumToken.FunctionTokenType && mathFuncs.includes(val.val.toLowerCase()) || (val.typ == exports.EnumToken.FunctionTokenType && wildCardFuncs.includes(val.val)));
|
|
15808
|
+
if (success) {
|
|
15809
|
+
hasNumber = true;
|
|
15810
|
+
}
|
|
15811
|
+
if ('range' in syntax) {
|
|
15812
|
+
return success && +val.val >= +syntax.range[0] && +val.val <= +syntax.range[1];
|
|
15813
|
+
}
|
|
15814
|
+
return success;
|
|
15815
|
+
}) && hasNumber;
|
|
15816
|
+
}
|
|
15817
|
+
break;
|
|
15370
15818
|
case 'integer':
|
|
15371
|
-
success = (token.typ == exports.EnumToken.NumberTokenType &&
|
|
15819
|
+
success = (token.typ == exports.EnumToken.NumberTokenType && /^[+-]?\d+$/.test(token.val.toString())) || (token.typ == exports.EnumToken.FunctionTokenType && mathFuncs.includes(token.val.toLowerCase()) || (token.typ == exports.EnumToken.FunctionTokenType && wildCardFuncs.includes(token.val)));
|
|
15372
15820
|
if ('range' in syntax) {
|
|
15373
15821
|
success = success && +token.val >= +syntax.range[0] && +token.val <= +syntax.range[1];
|
|
15374
15822
|
}
|
|
@@ -15432,7 +15880,7 @@ function matchPropertyType(syntax, context, options) {
|
|
|
15432
15880
|
...options,
|
|
15433
15881
|
isRepeatable: null,
|
|
15434
15882
|
isList: null,
|
|
15435
|
-
|
|
15883
|
+
occurrence: null,
|
|
15436
15884
|
atLeastOnce: null
|
|
15437
15885
|
}).valid == SyntaxValidationResult.Valid;
|
|
15438
15886
|
}
|
|
@@ -15448,7 +15896,7 @@ function matchPropertyType(syntax, context, options) {
|
|
|
15448
15896
|
...options,
|
|
15449
15897
|
isRepeatable: null,
|
|
15450
15898
|
isList: null,
|
|
15451
|
-
|
|
15899
|
+
occurrence: null,
|
|
15452
15900
|
atLeastOnce: null
|
|
15453
15901
|
}).valid == SyntaxValidationResult.Valid;
|
|
15454
15902
|
}
|
|
@@ -15595,7 +16043,6 @@ function allOf(syntax, context, options) {
|
|
|
15595
16043
|
i = -1;
|
|
15596
16044
|
}
|
|
15597
16045
|
}
|
|
15598
|
-
// console.error()
|
|
15599
16046
|
const success = syntax.length == 0;
|
|
15600
16047
|
return {
|
|
15601
16048
|
valid: success ? SyntaxValidationResult.Valid : SyntaxValidationResult.Drop,
|
|
@@ -15675,6 +16122,17 @@ function validateSelector(selector, options, root) {
|
|
|
15675
16122
|
}
|
|
15676
16123
|
|
|
15677
16124
|
function validateAtRuleMedia(atRule, options, root) {
|
|
16125
|
+
if (!Array.isArray(atRule.chi)) {
|
|
16126
|
+
// @ts-ignore
|
|
16127
|
+
return {
|
|
16128
|
+
valid: SyntaxValidationResult.Drop,
|
|
16129
|
+
matches: [],
|
|
16130
|
+
node: atRule,
|
|
16131
|
+
syntax: '@' + atRule.nam,
|
|
16132
|
+
error: 'expected supports body',
|
|
16133
|
+
tokens: []
|
|
16134
|
+
};
|
|
16135
|
+
}
|
|
15678
16136
|
// media-query-list
|
|
15679
16137
|
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
15680
16138
|
// @ts-ignore
|
|
@@ -15907,6 +16365,17 @@ function validateMediaFeature(token) {
|
|
|
15907
16365
|
}
|
|
15908
16366
|
|
|
15909
16367
|
function validateAtRuleCounterStyle(atRule, options, root) {
|
|
16368
|
+
if (!Array.isArray(atRule.chi)) {
|
|
16369
|
+
// @ts-ignore
|
|
16370
|
+
return {
|
|
16371
|
+
valid: SyntaxValidationResult.Drop,
|
|
16372
|
+
matches: [],
|
|
16373
|
+
node: atRule,
|
|
16374
|
+
syntax: '@' + atRule.nam,
|
|
16375
|
+
error: 'expected supports body',
|
|
16376
|
+
tokens: []
|
|
16377
|
+
};
|
|
16378
|
+
}
|
|
15910
16379
|
// media-query-list
|
|
15911
16380
|
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
15912
16381
|
// @ts-ignore
|
|
@@ -15976,6 +16445,17 @@ function validateAtRuleCounterStyle(atRule, options, root) {
|
|
|
15976
16445
|
}
|
|
15977
16446
|
|
|
15978
16447
|
function validateAtRulePage(atRule, options, root) {
|
|
16448
|
+
if (!Array.isArray(atRule.chi)) {
|
|
16449
|
+
// @ts-ignore
|
|
16450
|
+
return {
|
|
16451
|
+
valid: SyntaxValidationResult.Drop,
|
|
16452
|
+
matches: [],
|
|
16453
|
+
node: atRule,
|
|
16454
|
+
syntax: '@' + atRule.nam,
|
|
16455
|
+
error: 'expected supports body',
|
|
16456
|
+
tokens: []
|
|
16457
|
+
};
|
|
16458
|
+
}
|
|
15979
16459
|
// media-query-list
|
|
15980
16460
|
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
15981
16461
|
// @ts-ignore
|
|
@@ -16054,6 +16534,17 @@ function validateAtRulePage(atRule, options, root) {
|
|
|
16054
16534
|
}
|
|
16055
16535
|
|
|
16056
16536
|
function validateAtRulePageMarginBox(atRule, options, root) {
|
|
16537
|
+
if (!Array.isArray(atRule.chi)) {
|
|
16538
|
+
// @ts-ignore
|
|
16539
|
+
return {
|
|
16540
|
+
valid: SyntaxValidationResult.Drop,
|
|
16541
|
+
matches: [],
|
|
16542
|
+
node: atRule,
|
|
16543
|
+
syntax: '@' + atRule.nam,
|
|
16544
|
+
error: 'expected supports body',
|
|
16545
|
+
tokens: []
|
|
16546
|
+
};
|
|
16547
|
+
}
|
|
16057
16548
|
if (Array.isArray(atRule.tokens) && atRule.tokens.length > 0) {
|
|
16058
16549
|
// @ts-ignore
|
|
16059
16550
|
return {
|
|
@@ -16109,6 +16600,17 @@ function validateAtRuleSupports(atRule, options, root) {
|
|
|
16109
16600
|
tokens: []
|
|
16110
16601
|
};
|
|
16111
16602
|
}
|
|
16603
|
+
if (!Array.isArray(atRule.chi)) {
|
|
16604
|
+
// @ts-ignore
|
|
16605
|
+
return {
|
|
16606
|
+
valid: SyntaxValidationResult.Drop,
|
|
16607
|
+
matches: [],
|
|
16608
|
+
node: atRule,
|
|
16609
|
+
syntax: '@' + atRule.nam,
|
|
16610
|
+
error: 'expected supports body',
|
|
16611
|
+
tokens: []
|
|
16612
|
+
};
|
|
16613
|
+
}
|
|
16112
16614
|
const result = validateAtRuleSupportsConditions(atRule, atRule.tokens);
|
|
16113
16615
|
if (result) {
|
|
16114
16616
|
if (result.node == null) {
|
|
@@ -16501,6 +17003,17 @@ function validateAtRuleImport(atRule, options, root) {
|
|
|
16501
17003
|
}
|
|
16502
17004
|
|
|
16503
17005
|
function validateAtRuleLayer(atRule, options, root) {
|
|
17006
|
+
if (!Array.isArray(atRule.chi)) {
|
|
17007
|
+
// @ts-ignore
|
|
17008
|
+
return {
|
|
17009
|
+
valid: SyntaxValidationResult.Drop,
|
|
17010
|
+
matches: [],
|
|
17011
|
+
node: atRule,
|
|
17012
|
+
syntax: '@' + atRule.nam,
|
|
17013
|
+
error: 'expected supports body',
|
|
17014
|
+
tokens: []
|
|
17015
|
+
};
|
|
17016
|
+
}
|
|
16504
17017
|
// media-query-list
|
|
16505
17018
|
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
16506
17019
|
// @ts-ignore
|
|
@@ -16517,6 +17030,17 @@ function validateAtRuleLayer(atRule, options, root) {
|
|
|
16517
17030
|
}
|
|
16518
17031
|
|
|
16519
17032
|
function validateAtRuleFontFeatureValues(atRule, options, root) {
|
|
17033
|
+
if (!Array.isArray(atRule.chi)) {
|
|
17034
|
+
// @ts-ignore
|
|
17035
|
+
return {
|
|
17036
|
+
valid: SyntaxValidationResult.Drop,
|
|
17037
|
+
matches: [],
|
|
17038
|
+
node: atRule,
|
|
17039
|
+
syntax: '@' + atRule.nam,
|
|
17040
|
+
error: 'expected supports body',
|
|
17041
|
+
tokens: []
|
|
17042
|
+
};
|
|
17043
|
+
}
|
|
16520
17044
|
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
16521
17045
|
// @ts-ignore
|
|
16522
17046
|
return {
|
|
@@ -16700,6 +17224,17 @@ function validateAtRuleDocument(atRule, options, root) {
|
|
|
16700
17224
|
}
|
|
16701
17225
|
|
|
16702
17226
|
function validateAtRuleKeyframes(atRule, options, root) {
|
|
17227
|
+
if (!Array.isArray(atRule.chi)) {
|
|
17228
|
+
// @ts-ignore
|
|
17229
|
+
return {
|
|
17230
|
+
valid: SyntaxValidationResult.Drop,
|
|
17231
|
+
matches: [],
|
|
17232
|
+
node: atRule,
|
|
17233
|
+
syntax: '@' + atRule.nam,
|
|
17234
|
+
error: 'expected supports body',
|
|
17235
|
+
tokens: []
|
|
17236
|
+
};
|
|
17237
|
+
}
|
|
16703
17238
|
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
16704
17239
|
// @ts-ignore
|
|
16705
17240
|
return {
|
|
@@ -16745,6 +17280,17 @@ function validateAtRuleKeyframes(atRule, options, root) {
|
|
|
16745
17280
|
}
|
|
16746
17281
|
|
|
16747
17282
|
function validateAtRuleWhen(atRule, options, root) {
|
|
17283
|
+
if (!Array.isArray(atRule.chi)) {
|
|
17284
|
+
// @ts-ignore
|
|
17285
|
+
return {
|
|
17286
|
+
valid: SyntaxValidationResult.Drop,
|
|
17287
|
+
matches: [],
|
|
17288
|
+
node: atRule,
|
|
17289
|
+
syntax: '@' + atRule.nam,
|
|
17290
|
+
error: 'expected supports body',
|
|
17291
|
+
tokens: []
|
|
17292
|
+
};
|
|
17293
|
+
}
|
|
16748
17294
|
const slice = Array.isArray(atRule.tokens) ? atRule.tokens.slice() : [];
|
|
16749
17295
|
consumeWhitespace(slice);
|
|
16750
17296
|
if (slice.length == 0) {
|
|
@@ -16908,6 +17454,17 @@ const validateAtRuleElse = validateAtRuleWhen;
|
|
|
16908
17454
|
|
|
16909
17455
|
const validateContainerScrollStateFeature = validateContainerSizeFeature;
|
|
16910
17456
|
function validateAtRuleContainer(atRule, options, root) {
|
|
17457
|
+
if (!Array.isArray(atRule.chi)) {
|
|
17458
|
+
// @ts-ignore
|
|
17459
|
+
return {
|
|
17460
|
+
valid: SyntaxValidationResult.Drop,
|
|
17461
|
+
matches: [],
|
|
17462
|
+
node: atRule,
|
|
17463
|
+
syntax: '@' + atRule.nam,
|
|
17464
|
+
error: 'expected supports body',
|
|
17465
|
+
tokens: []
|
|
17466
|
+
};
|
|
17467
|
+
}
|
|
16911
17468
|
// media-query-list
|
|
16912
17469
|
if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
|
|
16913
17470
|
// @ts-ignore
|
|
@@ -17422,6 +17979,91 @@ function validateAtRule(atRule, options, root) {
|
|
|
17422
17979
|
};
|
|
17423
17980
|
}
|
|
17424
17981
|
|
|
17982
|
+
// Alphabet: a-z, A-Z, 0-9, _, -
|
|
17983
|
+
const LOWER = "abcdefghijklmnopqrstuvwxyz";
|
|
17984
|
+
const DIGITS = "0123456789";
|
|
17985
|
+
const FULL_ALPHABET = (LOWER + DIGITS).split(""); // 64 chars
|
|
17986
|
+
const FIRST_ALPHABET = (LOWER).split(""); // 54 chars (no digits)
|
|
17987
|
+
/**
|
|
17988
|
+
* supported hash algorithms
|
|
17989
|
+
*/
|
|
17990
|
+
const hashAlgorithms = ['hex', 'base64', 'base64url', 'sha1', 'sha256', 'sha384', 'sha512'];
|
|
17991
|
+
// simple deterministic hash → number
|
|
17992
|
+
function hashCode(str) {
|
|
17993
|
+
let hash = 0;
|
|
17994
|
+
let l = str.length;
|
|
17995
|
+
let i = 0;
|
|
17996
|
+
while (i < l) {
|
|
17997
|
+
hash = (hash * 31 + str.charCodeAt(i++)) >>> 0;
|
|
17998
|
+
}
|
|
17999
|
+
return hash;
|
|
18000
|
+
}
|
|
18001
|
+
/**
|
|
18002
|
+
* generate a hash id
|
|
18003
|
+
* @param input
|
|
18004
|
+
* @param length
|
|
18005
|
+
*/
|
|
18006
|
+
function hashId(input, length = 6) {
|
|
18007
|
+
let n = hashCode(input);
|
|
18008
|
+
const chars = [];
|
|
18009
|
+
// First character: must not be a digit
|
|
18010
|
+
chars.push(FIRST_ALPHABET[n % FIRST_ALPHABET.length]);
|
|
18011
|
+
// Remaining characters
|
|
18012
|
+
for (let i = 1; i < length; i++) {
|
|
18013
|
+
n = (n + chars.length + i) % FULL_ALPHABET.length;
|
|
18014
|
+
chars.push(FULL_ALPHABET[n]);
|
|
18015
|
+
}
|
|
18016
|
+
return chars.join("");
|
|
18017
|
+
}
|
|
18018
|
+
/**
|
|
18019
|
+
* convert input to hex
|
|
18020
|
+
* @param input
|
|
18021
|
+
*/
|
|
18022
|
+
function toHex(input) {
|
|
18023
|
+
let result = '';
|
|
18024
|
+
if (input instanceof ArrayBuffer || ArrayBuffer.isView(input)) {
|
|
18025
|
+
for (const byte of Array.from(new Uint8Array(input))) {
|
|
18026
|
+
result += byte.toString(16).padStart(2, '0');
|
|
18027
|
+
}
|
|
18028
|
+
}
|
|
18029
|
+
else {
|
|
18030
|
+
for (const char of String(input)) {
|
|
18031
|
+
result += char.charCodeAt(0).toString(16).padStart(2, '0');
|
|
18032
|
+
}
|
|
18033
|
+
}
|
|
18034
|
+
return result;
|
|
18035
|
+
}
|
|
18036
|
+
/**
|
|
18037
|
+
* generate a hash
|
|
18038
|
+
* @param input
|
|
18039
|
+
* @param length
|
|
18040
|
+
* @param algo
|
|
18041
|
+
*/
|
|
18042
|
+
async function hash(input, length = 6, algo) {
|
|
18043
|
+
let result;
|
|
18044
|
+
if (algo != null) {
|
|
18045
|
+
switch (algo) {
|
|
18046
|
+
case 'hex':
|
|
18047
|
+
return toHex(input).slice(0, length);
|
|
18048
|
+
case 'base64':
|
|
18049
|
+
case 'base64url':
|
|
18050
|
+
result = btoa(input);
|
|
18051
|
+
if (algo == 'base64url') {
|
|
18052
|
+
result = result.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
18053
|
+
}
|
|
18054
|
+
return result.slice(0, length);
|
|
18055
|
+
case 'sha1':
|
|
18056
|
+
case 'sha256':
|
|
18057
|
+
case 'sha384':
|
|
18058
|
+
case 'sha512':
|
|
18059
|
+
return toHex(await crypto.subtle.digest(algo.replace('sha', 'SHA-'), new TextEncoder().encode(input))).slice(0, length);
|
|
18060
|
+
default:
|
|
18061
|
+
throw new Error(`Unsupported hash algorithm: ${algo}`);
|
|
18062
|
+
}
|
|
18063
|
+
}
|
|
18064
|
+
return hashId(input, length);
|
|
18065
|
+
}
|
|
18066
|
+
|
|
17425
18067
|
const urlTokenMatcher = /^(["']?)[a-zA-Z0-9_/.-][a-zA-Z0-9_/:.#?-]+(\1)$/;
|
|
17426
18068
|
const trimWhiteSpace = [exports.EnumToken.CommentTokenType, exports.EnumToken.GtTokenType, exports.EnumToken.GteTokenType, exports.EnumToken.LtTokenType, exports.EnumToken.LteTokenType, exports.EnumToken.ColumnCombinatorTokenType];
|
|
17427
18069
|
const BadTokensTypes = [
|
|
@@ -17440,16 +18082,20 @@ const enumTokenHints = new Set([
|
|
|
17440
18082
|
function reject(reason) {
|
|
17441
18083
|
throw new Error(reason ?? 'Parsing aborted');
|
|
17442
18084
|
}
|
|
17443
|
-
|
|
17444
|
-
|
|
17445
|
-
|
|
18085
|
+
/**
|
|
18086
|
+
* replace token in its parent node
|
|
18087
|
+
* @param parent
|
|
18088
|
+
* @param value
|
|
18089
|
+
* @param replacement
|
|
18090
|
+
*/
|
|
17446
18091
|
function replaceToken(parent, value, replacement) {
|
|
17447
|
-
|
|
17448
|
-
|
|
17449
|
-
|
|
17450
|
-
|
|
17451
|
-
|
|
17452
|
-
|
|
18092
|
+
for (const node of (Array.isArray(replacement) ? replacement : [replacement])) {
|
|
18093
|
+
if ('parent' in value && value.parent != node.parent) {
|
|
18094
|
+
Object.defineProperty(node, 'parent', {
|
|
18095
|
+
...definedPropertySettings,
|
|
18096
|
+
value: value.parent
|
|
18097
|
+
});
|
|
18098
|
+
}
|
|
17453
18099
|
}
|
|
17454
18100
|
if (parent.typ == exports.EnumToken.BinaryExpressionTokenType) {
|
|
17455
18101
|
if (parent.l == value) {
|
|
@@ -17460,22 +18106,138 @@ function replaceToken(parent, value, replacement) {
|
|
|
17460
18106
|
}
|
|
17461
18107
|
}
|
|
17462
18108
|
else {
|
|
17463
|
-
// @ts-ignore
|
|
17464
18109
|
const target = 'val' in parent && Array.isArray(parent.val) ? parent.val : parent.chi;
|
|
17465
18110
|
// @ts-ignore
|
|
17466
18111
|
const index = target.indexOf(value);
|
|
17467
18112
|
if (index == -1) {
|
|
17468
18113
|
return;
|
|
17469
18114
|
}
|
|
17470
|
-
// @ts-ignore
|
|
17471
18115
|
target.splice(index, 1, ...(Array.isArray(replacement) ? replacement : [replacement]));
|
|
17472
18116
|
}
|
|
17473
18117
|
}
|
|
18118
|
+
/**
|
|
18119
|
+
* transform case of key name
|
|
18120
|
+
* @param key
|
|
18121
|
+
* @param how
|
|
18122
|
+
*
|
|
18123
|
+
* @throws Error
|
|
18124
|
+
* @private
|
|
18125
|
+
*/
|
|
18126
|
+
function getKeyName(key, how) {
|
|
18127
|
+
switch (how) {
|
|
18128
|
+
case exports.ModuleCaseTransformEnum.CamelCase:
|
|
18129
|
+
case exports.ModuleCaseTransformEnum.CamelCaseOnly:
|
|
18130
|
+
return camelize(key);
|
|
18131
|
+
case exports.ModuleCaseTransformEnum.DashCase:
|
|
18132
|
+
case exports.ModuleCaseTransformEnum.DashCaseOnly:
|
|
18133
|
+
return dasherize(key);
|
|
18134
|
+
}
|
|
18135
|
+
return key;
|
|
18136
|
+
}
|
|
18137
|
+
/**
|
|
18138
|
+
* generate scoped name
|
|
18139
|
+
* @param localName
|
|
18140
|
+
* @param filePath
|
|
18141
|
+
* @param pattern
|
|
18142
|
+
* @param hashLength
|
|
18143
|
+
*
|
|
18144
|
+
* @throws Error
|
|
18145
|
+
* @private
|
|
18146
|
+
*/
|
|
18147
|
+
async function generateScopedName(localName, filePath, pattern, hashLength = 5) {
|
|
18148
|
+
if (localName.startsWith('--')) {
|
|
18149
|
+
localName = localName.slice(2);
|
|
18150
|
+
}
|
|
18151
|
+
const matches = /.*?(([^/]+)\/)?([^/\\]*?)(\.([^?/]+))?([?].*)?$/.exec(filePath);
|
|
18152
|
+
const folder = matches?.[2]?.replace?.(/[^A-Za-z0-9_-]/g, "_") ?? '';
|
|
18153
|
+
const fileBase = matches?.[3] ?? '';
|
|
18154
|
+
const ext = matches?.[5] ?? '';
|
|
18155
|
+
const path = filePath.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
18156
|
+
// sanitize localName for safe char set (replace spaces/illegal chars)
|
|
18157
|
+
const safeLocal = localName.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
18158
|
+
const hashString = `${localName}::${filePath}`;
|
|
18159
|
+
let result = '';
|
|
18160
|
+
let inParens = 0;
|
|
18161
|
+
let key = '';
|
|
18162
|
+
let position = 0;
|
|
18163
|
+
// Compose final scoped name. Ensure the entire class doesn't start with digit:
|
|
18164
|
+
for (const char of pattern) {
|
|
18165
|
+
position += char.length;
|
|
18166
|
+
if (char == '[') {
|
|
18167
|
+
inParens++;
|
|
18168
|
+
if (inParens != 1) {
|
|
18169
|
+
throw new Error(`Unexpected character: '${char} at position ${position - 1}' in pattern '${pattern}'`);
|
|
18170
|
+
}
|
|
18171
|
+
continue;
|
|
18172
|
+
}
|
|
18173
|
+
if (char == ']') {
|
|
18174
|
+
inParens--;
|
|
18175
|
+
if (inParens != 0) {
|
|
18176
|
+
throw new Error(`Unexpected character: '${char}:${position - 1}'`);
|
|
18177
|
+
}
|
|
18178
|
+
let hashAlgo = null;
|
|
18179
|
+
let length = null;
|
|
18180
|
+
if (key.includes(':')) {
|
|
18181
|
+
const parts = key.split(':');
|
|
18182
|
+
if (parts.length == 2) {
|
|
18183
|
+
// @ts-ignore
|
|
18184
|
+
[key, length] = parts;
|
|
18185
|
+
// @ts-ignore
|
|
18186
|
+
if (key == 'hash' && hashAlgorithms.includes(length)) {
|
|
18187
|
+
// @ts-ignore
|
|
18188
|
+
hashAlgo = length;
|
|
18189
|
+
length = null;
|
|
18190
|
+
}
|
|
18191
|
+
}
|
|
18192
|
+
if (parts.length == 3) {
|
|
18193
|
+
// @ts-ignore
|
|
18194
|
+
[key, hashAlgo, length] = parts;
|
|
18195
|
+
}
|
|
18196
|
+
if (length != null && !Number.isInteger(+length)) {
|
|
18197
|
+
throw new Error(`Unsupported hash length: '${length}'. expecting format [hash:length] or [hash:hash-algo:length]`);
|
|
18198
|
+
}
|
|
18199
|
+
}
|
|
18200
|
+
switch (key) {
|
|
18201
|
+
case 'hash':
|
|
18202
|
+
result += await hash(hashString, length ?? hashLength, hashAlgo);
|
|
18203
|
+
break;
|
|
18204
|
+
case 'name':
|
|
18205
|
+
result += length != null ? fileBase.slice(0, +length) : fileBase;
|
|
18206
|
+
break;
|
|
18207
|
+
case 'local':
|
|
18208
|
+
result += length != null ? safeLocal.slice(0, +length) : localName;
|
|
18209
|
+
break;
|
|
18210
|
+
case 'ext':
|
|
18211
|
+
result += length != null ? ext.slice(0, +length) : ext;
|
|
18212
|
+
break;
|
|
18213
|
+
case 'path':
|
|
18214
|
+
result += length != null ? path.slice(0, +length) : path;
|
|
18215
|
+
break;
|
|
18216
|
+
case 'folder':
|
|
18217
|
+
result += length != null ? folder.slice(0, +length) : folder;
|
|
18218
|
+
break;
|
|
18219
|
+
default:
|
|
18220
|
+
throw new Error(`Unsupported key: '${key}'`);
|
|
18221
|
+
}
|
|
18222
|
+
key = '';
|
|
18223
|
+
continue;
|
|
18224
|
+
}
|
|
18225
|
+
if (inParens > 0) {
|
|
18226
|
+
key += char;
|
|
18227
|
+
}
|
|
18228
|
+
else {
|
|
18229
|
+
result += char;
|
|
18230
|
+
}
|
|
18231
|
+
}
|
|
18232
|
+
// if leading char is digit, prefix underscore (very rare)
|
|
18233
|
+
return (/^[0-9]/.test(result) ? '_' : '') + result;
|
|
18234
|
+
}
|
|
17474
18235
|
/**
|
|
17475
18236
|
* parse css string
|
|
17476
18237
|
* @param iter
|
|
17477
18238
|
* @param options
|
|
17478
18239
|
*
|
|
18240
|
+
* @throws Error
|
|
17479
18241
|
* @private
|
|
17480
18242
|
*/
|
|
17481
18243
|
async function doParse(iter, options = {}) {
|
|
@@ -17507,6 +18269,9 @@ async function doParse(iter, options = {}) {
|
|
|
17507
18269
|
if (typeof options.validation == 'boolean') {
|
|
17508
18270
|
options.validation = options.validation ? exports.ValidationLevel.All : exports.ValidationLevel.None;
|
|
17509
18271
|
}
|
|
18272
|
+
if (options.module) {
|
|
18273
|
+
options.expandNestingRules = true;
|
|
18274
|
+
}
|
|
17510
18275
|
if (options.expandNestingRules) {
|
|
17511
18276
|
options.nestingRules = false;
|
|
17512
18277
|
}
|
|
@@ -17520,6 +18285,8 @@ async function doParse(iter, options = {}) {
|
|
|
17520
18285
|
const stats = {
|
|
17521
18286
|
src: options.src ?? '',
|
|
17522
18287
|
bytesIn: 0,
|
|
18288
|
+
nodesCount: 0,
|
|
18289
|
+
tokensCount: 0,
|
|
17523
18290
|
importedBytesIn: 0,
|
|
17524
18291
|
parse: `0ms`,
|
|
17525
18292
|
minify: `0ms`,
|
|
@@ -17548,14 +18315,107 @@ async function doParse(iter, options = {}) {
|
|
|
17548
18315
|
src: ''
|
|
17549
18316
|
};
|
|
17550
18317
|
}
|
|
17551
|
-
let
|
|
17552
|
-
let
|
|
18318
|
+
let valuesHandlers;
|
|
18319
|
+
let preValuesHandlers;
|
|
18320
|
+
let postValuesHandlers;
|
|
18321
|
+
let preVisitorsHandlersMap;
|
|
18322
|
+
let visitorsHandlersMap;
|
|
18323
|
+
let postVisitorsHandlersMap;
|
|
17553
18324
|
const rawTokens = [];
|
|
17554
18325
|
const imports = [];
|
|
18326
|
+
let item;
|
|
18327
|
+
let node;
|
|
17555
18328
|
// @ts-ignore ignore error
|
|
17556
18329
|
let isAsync = typeof iter[Symbol.asyncIterator] === 'function';
|
|
18330
|
+
if (options.visitor != null) {
|
|
18331
|
+
valuesHandlers = new Map;
|
|
18332
|
+
preValuesHandlers = new Map;
|
|
18333
|
+
postValuesHandlers = new Map;
|
|
18334
|
+
preVisitorsHandlersMap = new Map;
|
|
18335
|
+
visitorsHandlersMap = new Map;
|
|
18336
|
+
postVisitorsHandlersMap = new Map;
|
|
18337
|
+
const visitors = Object.entries(options.visitor);
|
|
18338
|
+
let key;
|
|
18339
|
+
let value;
|
|
18340
|
+
let i;
|
|
18341
|
+
for (i = 0; i < visitors.length; i++) {
|
|
18342
|
+
key = visitors[i][0];
|
|
18343
|
+
value = visitors[i][1];
|
|
18344
|
+
if (Number.isInteger(+key)) {
|
|
18345
|
+
visitors.splice(i + 1, 0, ...Object.entries(value));
|
|
18346
|
+
continue;
|
|
18347
|
+
}
|
|
18348
|
+
if (Array.isArray(value)) {
|
|
18349
|
+
// @ts-ignore
|
|
18350
|
+
visitors.splice(i + 1, 0, ...value.map((item) => [key, item]));
|
|
18351
|
+
continue;
|
|
18352
|
+
}
|
|
18353
|
+
if (key in exports.EnumToken) {
|
|
18354
|
+
if (typeof value == 'function') {
|
|
18355
|
+
if (!valuesHandlers.has(exports.EnumToken[key])) {
|
|
18356
|
+
valuesHandlers.set(exports.EnumToken[key], []);
|
|
18357
|
+
}
|
|
18358
|
+
valuesHandlers.get(exports.EnumToken[key]).push(value);
|
|
18359
|
+
}
|
|
18360
|
+
else if (typeof value == 'object' && 'type' in value && 'handler' in value && value.type in exports.WalkerEvent) {
|
|
18361
|
+
if (value.type == exports.WalkerEvent.Enter) {
|
|
18362
|
+
if (!preValuesHandlers.has(exports.EnumToken[key])) {
|
|
18363
|
+
preValuesHandlers.set(exports.EnumToken[key], []);
|
|
18364
|
+
}
|
|
18365
|
+
preValuesHandlers.get(exports.EnumToken[key]).push(value.handler);
|
|
18366
|
+
}
|
|
18367
|
+
else if (value.type == exports.WalkerEvent.Leave) {
|
|
18368
|
+
if (!postValuesHandlers.has(exports.EnumToken[key])) {
|
|
18369
|
+
postValuesHandlers.set(exports.EnumToken[key], []);
|
|
18370
|
+
}
|
|
18371
|
+
postValuesHandlers.get(exports.EnumToken[key]).push(value.handler);
|
|
18372
|
+
}
|
|
18373
|
+
}
|
|
18374
|
+
else {
|
|
18375
|
+
errors.push({ action: 'ignore', message: `doParse: visitor.${key} is not a valid key name` });
|
|
18376
|
+
}
|
|
18377
|
+
}
|
|
18378
|
+
else if (['Declaration', 'Rule', 'AtRule', 'KeyframesRule', 'KeyframesAtRule'].includes(key)) {
|
|
18379
|
+
if (typeof value == 'function') {
|
|
18380
|
+
if (!visitorsHandlersMap.has(key)) {
|
|
18381
|
+
visitorsHandlersMap.set(key, []);
|
|
18382
|
+
}
|
|
18383
|
+
visitorsHandlersMap.get(key).push(value);
|
|
18384
|
+
}
|
|
18385
|
+
else if (typeof value == 'object') {
|
|
18386
|
+
if ('type' in value && 'handler' in value && value.type in exports.WalkerEvent) {
|
|
18387
|
+
if (value.type == exports.WalkerEvent.Enter) {
|
|
18388
|
+
if (!preVisitorsHandlersMap.has(key)) {
|
|
18389
|
+
preVisitorsHandlersMap.set(key, []);
|
|
18390
|
+
}
|
|
18391
|
+
preVisitorsHandlersMap.get(key).push(value.handler);
|
|
18392
|
+
}
|
|
18393
|
+
else if (value.type == exports.WalkerEvent.Leave) {
|
|
18394
|
+
if (!postVisitorsHandlersMap.has(key)) {
|
|
18395
|
+
postVisitorsHandlersMap.set(key, []);
|
|
18396
|
+
}
|
|
18397
|
+
postVisitorsHandlersMap.get(key).push(value.handler);
|
|
18398
|
+
}
|
|
18399
|
+
}
|
|
18400
|
+
else {
|
|
18401
|
+
if (!visitorsHandlersMap.has(key)) {
|
|
18402
|
+
visitorsHandlersMap.set(key, []);
|
|
18403
|
+
}
|
|
18404
|
+
visitorsHandlersMap.get(key).push(value);
|
|
18405
|
+
}
|
|
18406
|
+
}
|
|
18407
|
+
else {
|
|
18408
|
+
errors.push({ action: 'ignore', message: `doParse: visitor.${key} is not a valid key name` });
|
|
18409
|
+
}
|
|
18410
|
+
}
|
|
18411
|
+
else {
|
|
18412
|
+
errors.push({ action: 'ignore', message: `doParse: visitor.${key} is not a valid key name` });
|
|
18413
|
+
}
|
|
18414
|
+
}
|
|
18415
|
+
}
|
|
17557
18416
|
while (item = isAsync ? (await iter.next()).value : iter.next().value) {
|
|
17558
18417
|
stats.bytesIn = item.bytesIn;
|
|
18418
|
+
stats.tokensCount++;
|
|
17559
18419
|
rawTokens.push(item);
|
|
17560
18420
|
if (item.hint != null && BadTokensTypes.includes(item.hint)) {
|
|
17561
18421
|
const node = getTokenType(item.token, item.hint);
|
|
@@ -17583,7 +18443,7 @@ async function doParse(iter, options = {}) {
|
|
|
17583
18443
|
ast.loc.end = item.end;
|
|
17584
18444
|
}
|
|
17585
18445
|
if (item.token == ';' || item.token == '{') {
|
|
17586
|
-
node = parseNode(tokens, context, options, errors, src, map, rawTokens);
|
|
18446
|
+
node = parseNode(tokens, context, options, errors, src, map, rawTokens, stats);
|
|
17587
18447
|
rawTokens.length = 0;
|
|
17588
18448
|
if (node != null) {
|
|
17589
18449
|
if ('chi' in node) {
|
|
@@ -17627,7 +18487,7 @@ async function doParse(iter, options = {}) {
|
|
|
17627
18487
|
map = new Map;
|
|
17628
18488
|
}
|
|
17629
18489
|
else if (item.token == '}') {
|
|
17630
|
-
parseNode(tokens, context, options, errors, src, map, rawTokens);
|
|
18490
|
+
parseNode(tokens, context, options, errors, src, map, rawTokens, stats);
|
|
17631
18491
|
rawTokens.length = 0;
|
|
17632
18492
|
if (context.loc != null) {
|
|
17633
18493
|
context.loc.end = item.end;
|
|
@@ -17648,7 +18508,7 @@ async function doParse(iter, options = {}) {
|
|
|
17648
18508
|
}
|
|
17649
18509
|
}
|
|
17650
18510
|
if (tokens.length > 0) {
|
|
17651
|
-
node = parseNode(tokens, context, options, errors, src, map, rawTokens);
|
|
18511
|
+
node = parseNode(tokens, context, options, errors, src, map, rawTokens, stats);
|
|
17652
18512
|
rawTokens.length = 0;
|
|
17653
18513
|
if (node != null) {
|
|
17654
18514
|
if (node.typ == exports.EnumToken.AtRuleNodeType && node.nam == 'import') {
|
|
@@ -17677,6 +18537,7 @@ async function doParse(iter, options = {}) {
|
|
|
17677
18537
|
const root = await doParse(stream instanceof ReadableStream ? tokenizeStream(stream) : tokenize$1({
|
|
17678
18538
|
stream,
|
|
17679
18539
|
buffer: '',
|
|
18540
|
+
offset: 0,
|
|
17680
18541
|
position: { ind: 0, lin: 1, col: 1 },
|
|
17681
18542
|
currentPosition: { ind: -1, lin: 1, col: 0 }
|
|
17682
18543
|
}), Object.assign({}, options, {
|
|
@@ -17711,228 +18572,153 @@ async function doParse(iter, options = {}) {
|
|
|
17711
18572
|
if (options.expandNestingRules) {
|
|
17712
18573
|
ast = expand(ast);
|
|
17713
18574
|
}
|
|
17714
|
-
|
|
17715
|
-
|
|
17716
|
-
const postValuesHandlers = new Map;
|
|
17717
|
-
const preVisitorsHandlersMap = new Map;
|
|
17718
|
-
const visitorsHandlersMap = new Map;
|
|
17719
|
-
const postVisitorsHandlersMap = new Map;
|
|
17720
|
-
const allValuesHandlers = [];
|
|
18575
|
+
let replacement;
|
|
18576
|
+
let callable;
|
|
17721
18577
|
if (options.visitor != null) {
|
|
17722
|
-
for (const
|
|
17723
|
-
if (
|
|
17724
|
-
if (
|
|
17725
|
-
|
|
17726
|
-
|
|
17727
|
-
|
|
17728
|
-
|
|
17729
|
-
|
|
18578
|
+
for (const result of walk(ast)) {
|
|
18579
|
+
if (valuesHandlers.size > 0 || preVisitorsHandlersMap.size > 0 || visitorsHandlersMap.size > 0 || postVisitorsHandlersMap.size > 0) {
|
|
18580
|
+
if ((result.node.typ == exports.EnumToken.DeclarationNodeType &&
|
|
18581
|
+
(preVisitorsHandlersMap.has('Declaration') || visitorsHandlersMap.has('Declaration') || postVisitorsHandlersMap.has('Declaration'))) ||
|
|
18582
|
+
(result.node.typ == exports.EnumToken.AtRuleNodeType && (preVisitorsHandlersMap.has('AtRule') || visitorsHandlersMap.has('AtRule') || postVisitorsHandlersMap.has('AtRule'))) ||
|
|
18583
|
+
(result.node.typ == exports.EnumToken.KeyframesAtRuleNodeType && (preVisitorsHandlersMap.has('KeyframesAtRule') || visitorsHandlersMap.has('KeyframesAtRule') || postVisitorsHandlersMap.has('KeyframesAtRule')))) {
|
|
18584
|
+
const handlers = [];
|
|
18585
|
+
const key = result.node.typ == exports.EnumToken.DeclarationNodeType ? 'Declaration' : result.node.typ == exports.EnumToken.AtRuleNodeType ? 'AtRule' : 'KeyframesAtRule';
|
|
18586
|
+
if (preVisitorsHandlersMap.has(key)) {
|
|
18587
|
+
// @ts-ignore
|
|
18588
|
+
handlers.push(...preVisitorsHandlersMap.get(key));
|
|
17730
18589
|
}
|
|
17731
|
-
|
|
17732
|
-
|
|
18590
|
+
if (visitorsHandlersMap.has(key)) {
|
|
18591
|
+
// @ts-ignore
|
|
18592
|
+
handlers.push(...visitorsHandlersMap.get(key));
|
|
17733
18593
|
}
|
|
17734
|
-
|
|
17735
|
-
|
|
17736
|
-
|
|
17737
|
-
|
|
17738
|
-
|
|
17739
|
-
|
|
17740
|
-
|
|
17741
|
-
|
|
17742
|
-
|
|
17743
|
-
else if (typeof value == 'object') {
|
|
17744
|
-
if ('type' in value && 'handler' in value && value.type in exports.WalkerValueEvent) {
|
|
17745
|
-
if (exports.WalkerValueEvent[value.type] == exports.WalkerValueEvent.Enter) {
|
|
17746
|
-
preVisitorsHandlersMap.set(key, value.handler);
|
|
18594
|
+
if (postVisitorsHandlersMap.has(key)) {
|
|
18595
|
+
// @ts-ignore
|
|
18596
|
+
handlers.push(...postVisitorsHandlersMap.get(key));
|
|
18597
|
+
}
|
|
18598
|
+
let node = result.node;
|
|
18599
|
+
for (const handler of handlers) {
|
|
18600
|
+
callable = typeof handler == 'function' ? handler : handler[camelize(node.typ == exports.EnumToken.DeclarationNodeType || node.typ == exports.EnumToken.AtRuleNodeType ? node.nam : node.val)];
|
|
18601
|
+
if (callable == null) {
|
|
18602
|
+
continue;
|
|
17747
18603
|
}
|
|
17748
|
-
|
|
17749
|
-
|
|
18604
|
+
replacement = callable(node, result.parent);
|
|
18605
|
+
if (replacement == null) {
|
|
18606
|
+
continue;
|
|
18607
|
+
}
|
|
18608
|
+
isAsync = replacement instanceof Promise || Object.getPrototypeOf(replacement).constructor.name == 'AsyncFunction';
|
|
18609
|
+
if (replacement) {
|
|
18610
|
+
replacement = await replacement;
|
|
18611
|
+
}
|
|
18612
|
+
if (replacement == null || replacement == node) {
|
|
18613
|
+
continue;
|
|
18614
|
+
}
|
|
18615
|
+
// @ts-ignore
|
|
18616
|
+
node = replacement;
|
|
18617
|
+
//
|
|
18618
|
+
if (Array.isArray(node)) {
|
|
18619
|
+
break;
|
|
17750
18620
|
}
|
|
17751
18621
|
}
|
|
17752
|
-
|
|
17753
|
-
|
|
17754
|
-
|
|
17755
|
-
}
|
|
17756
|
-
else {
|
|
17757
|
-
console.warn(`doParse: visitor.${key} is not a valid key name`);
|
|
17758
|
-
}
|
|
17759
|
-
}
|
|
17760
|
-
else {
|
|
17761
|
-
console.warn(`doParse: visitor.${key} is not a valid key name`);
|
|
17762
|
-
}
|
|
17763
|
-
}
|
|
17764
|
-
if (preValuesHandlers.size > 0) {
|
|
17765
|
-
allValuesHandlers.push(preValuesHandlers);
|
|
17766
|
-
}
|
|
17767
|
-
if (valuesHandlers.size > 0) {
|
|
17768
|
-
allValuesHandlers.push(valuesHandlers);
|
|
17769
|
-
}
|
|
17770
|
-
if (postValuesHandlers.size > 0) {
|
|
17771
|
-
allValuesHandlers.push(postValuesHandlers);
|
|
17772
|
-
}
|
|
17773
|
-
}
|
|
17774
|
-
for (const result of walk(ast)) {
|
|
17775
|
-
// if (result.parent != null && !isNodeAllowedInContext(result.node, result.parent as AstNode)) {
|
|
17776
|
-
//
|
|
17777
|
-
// errors.push({
|
|
17778
|
-
// action: 'drop',
|
|
17779
|
-
// message: `${EnumToken[result.parent.typ]}: child ${EnumToken[result.node.typ]}${result.node.typ == EnumToken.DeclarationNodeType ? ` '${(result.node as AstDeclaration).nam}'` : result.node.typ == EnumToken.AtRuleNodeType || result.node.typ == EnumToken.KeyframesAtRuleNodeType ? ` '@${(result.node as AstAtRule).nam}'` : ''} not allowed in context${result.parent.typ == EnumToken.AtRuleNodeType ? ` '@${(result.parent as AstAtRule).nam}'` : result.parent.typ == EnumToken.StyleSheetNodeType ? ` 'stylesheet'` : ''}`,
|
|
17780
|
-
// // @ts-ignore
|
|
17781
|
-
// location: result.node.loc ?? map.get(result.node ) ?? null
|
|
17782
|
-
// });
|
|
17783
|
-
//
|
|
17784
|
-
// // @ts-ignore
|
|
17785
|
-
// removeNode(result.node, result.parent as AstNode);
|
|
17786
|
-
// continue;
|
|
17787
|
-
// }
|
|
17788
|
-
if (allValuesHandlers.length > 0 || preVisitorsHandlersMap.size > 0 || visitorsHandlersMap.size > 0 || postVisitorsHandlersMap.size > 0) {
|
|
17789
|
-
if ((result.node.typ == exports.EnumToken.DeclarationNodeType &&
|
|
17790
|
-
(preVisitorsHandlersMap.has('Declaration') || visitorsHandlersMap.has('Declaration') || postVisitorsHandlersMap.has('Declaration'))) ||
|
|
17791
|
-
(result.node.typ == exports.EnumToken.AtRuleNodeType && (preVisitorsHandlersMap.has('AtRule') || visitorsHandlersMap.has('AtRule') || postVisitorsHandlersMap.has('AtRule'))) ||
|
|
17792
|
-
(result.node.typ == exports.EnumToken.KeyframesAtRuleNodeType && (preVisitorsHandlersMap.has('KeyframesAtRule') || visitorsHandlersMap.has('KeyframesAtRule') || postVisitorsHandlersMap.has('KeyframesAtRule')))) {
|
|
17793
|
-
const handlers = [];
|
|
17794
|
-
const key = result.node.typ == exports.EnumToken.DeclarationNodeType ? 'Declaration' : result.node.typ == exports.EnumToken.AtRuleNodeType ? 'AtRule' : 'KeyframesAtRule';
|
|
17795
|
-
if (preVisitorsHandlersMap.has(key)) {
|
|
17796
|
-
// @ts-ignore
|
|
17797
|
-
handlers.push(preVisitorsHandlersMap.get(key));
|
|
17798
|
-
}
|
|
17799
|
-
if (visitorsHandlersMap.has(key)) {
|
|
17800
|
-
// @ts-ignore
|
|
17801
|
-
handlers.push(visitorsHandlersMap.get(key));
|
|
17802
|
-
}
|
|
17803
|
-
if (postVisitorsHandlersMap.has(key)) {
|
|
17804
|
-
// @ts-ignore
|
|
17805
|
-
handlers.push(postVisitorsHandlersMap.get(key));
|
|
17806
|
-
}
|
|
17807
|
-
let callable;
|
|
17808
|
-
let node = result.node;
|
|
17809
|
-
for (const handler of handlers) {
|
|
17810
|
-
callable = typeof handler == 'function' ? handler : handler[normalizeVisitorKeyName(node.typ == exports.EnumToken.DeclarationNodeType || node.typ == exports.EnumToken.AtRuleNodeType ? node.nam : node.val)];
|
|
17811
|
-
if (callable == null) {
|
|
17812
|
-
continue;
|
|
17813
|
-
}
|
|
17814
|
-
let replacement = callable(node, result.parent);
|
|
17815
|
-
if (replacement == null) {
|
|
17816
|
-
continue;
|
|
17817
|
-
}
|
|
17818
|
-
isAsync = replacement instanceof Promise || Object.getPrototypeOf(replacement).constructor.name == 'AsyncFunction';
|
|
17819
|
-
if (replacement) {
|
|
17820
|
-
replacement = await replacement;
|
|
17821
|
-
}
|
|
17822
|
-
if (replacement == null || replacement == node) {
|
|
17823
|
-
continue;
|
|
17824
|
-
}
|
|
17825
|
-
// @ts-ignore
|
|
17826
|
-
node = replacement;
|
|
17827
|
-
//
|
|
17828
|
-
if (Array.isArray(node)) {
|
|
17829
|
-
break;
|
|
18622
|
+
if (node != result.node) {
|
|
18623
|
+
// @ts-ignore
|
|
18624
|
+
replaceToken(result.parent, result.node, node);
|
|
17830
18625
|
}
|
|
17831
18626
|
}
|
|
17832
|
-
if (node
|
|
17833
|
-
|
|
17834
|
-
|
|
17835
|
-
|
|
17836
|
-
|
|
17837
|
-
|
|
17838
|
-
(result.node.typ == exports.EnumToken.KeyFramesRuleNodeType && (preVisitorsHandlersMap.has('KeyframesRule') || visitorsHandlersMap.has('KeyframesRule') || postVisitorsHandlersMap.has('KeyframesRule')))) {
|
|
17839
|
-
const handlers = [];
|
|
17840
|
-
const key = result.node.typ == exports.EnumToken.RuleNodeType ? 'Rule' : 'KeyframesRule';
|
|
17841
|
-
if (preVisitorsHandlersMap.has(key)) {
|
|
17842
|
-
// @ts-ignore
|
|
17843
|
-
handlers.push(preVisitorsHandlersMap.get(key));
|
|
17844
|
-
}
|
|
17845
|
-
if (visitorsHandlersMap.has(key)) {
|
|
17846
|
-
// @ts-ignore
|
|
17847
|
-
handlers.push(visitorsHandlersMap.get(key));
|
|
17848
|
-
}
|
|
17849
|
-
if (postVisitorsHandlersMap.has(key)) {
|
|
17850
|
-
// @ts-ignore
|
|
17851
|
-
handlers.push(postVisitorsHandlersMap.get(key));
|
|
17852
|
-
}
|
|
17853
|
-
let node = result.node;
|
|
17854
|
-
for (const callable of handlers) {
|
|
17855
|
-
// @ts-ignore
|
|
17856
|
-
let replacement = callable(node, result.parent);
|
|
17857
|
-
if (replacement == null) {
|
|
17858
|
-
continue;
|
|
18627
|
+
else if ((result.node.typ == exports.EnumToken.RuleNodeType && (preVisitorsHandlersMap.has('Rule') || visitorsHandlersMap.has('Rule') || postVisitorsHandlersMap.has('Rule'))) ||
|
|
18628
|
+
(result.node.typ == exports.EnumToken.KeyFramesRuleNodeType && (preVisitorsHandlersMap.has('KeyframesRule') || visitorsHandlersMap.has('KeyframesRule') || postVisitorsHandlersMap.has('KeyframesRule')))) {
|
|
18629
|
+
const handlers = [];
|
|
18630
|
+
const key = result.node.typ == exports.EnumToken.RuleNodeType ? 'Rule' : 'KeyframesRule';
|
|
18631
|
+
if (preVisitorsHandlersMap.has(key)) {
|
|
18632
|
+
handlers.push(...preVisitorsHandlersMap.get(key));
|
|
17859
18633
|
}
|
|
17860
|
-
|
|
17861
|
-
|
|
17862
|
-
replacement = await replacement;
|
|
18634
|
+
if (visitorsHandlersMap.has(key)) {
|
|
18635
|
+
handlers.push(...visitorsHandlersMap.get(key));
|
|
17863
18636
|
}
|
|
17864
|
-
if (
|
|
17865
|
-
|
|
17866
|
-
}
|
|
17867
|
-
// @ts-ignore
|
|
17868
|
-
node = replacement;
|
|
17869
|
-
//
|
|
17870
|
-
if (Array.isArray(node)) {
|
|
17871
|
-
break;
|
|
18637
|
+
if (postVisitorsHandlersMap.has(key)) {
|
|
18638
|
+
handlers.push(...postVisitorsHandlersMap.get(key));
|
|
17872
18639
|
}
|
|
17873
|
-
|
|
17874
|
-
|
|
17875
|
-
|
|
17876
|
-
// @ts-ignore
|
|
17877
|
-
replaceToken(result.parent, result.node, node);
|
|
17878
|
-
}
|
|
17879
|
-
}
|
|
17880
|
-
else if (allValuesHandlers.length > 0) {
|
|
17881
|
-
let callable;
|
|
17882
|
-
let node = null;
|
|
17883
|
-
node = result.node;
|
|
17884
|
-
for (const valueHandler of allValuesHandlers) {
|
|
17885
|
-
if (valueHandler.has(node.typ)) {
|
|
17886
|
-
callable = valueHandler.get(node.typ);
|
|
17887
|
-
let replacement = callable(node, result.parent);
|
|
18640
|
+
let node = result.node;
|
|
18641
|
+
for (const callable of handlers) {
|
|
18642
|
+
replacement = callable(node, result.parent);
|
|
17888
18643
|
if (replacement == null) {
|
|
17889
18644
|
continue;
|
|
17890
18645
|
}
|
|
17891
18646
|
isAsync = replacement instanceof Promise || Object.getPrototypeOf(replacement).constructor.name == 'AsyncFunction';
|
|
17892
|
-
if (
|
|
18647
|
+
if (replacement) {
|
|
17893
18648
|
replacement = await replacement;
|
|
17894
18649
|
}
|
|
17895
|
-
if (replacement
|
|
17896
|
-
|
|
18650
|
+
if (replacement == null || replacement == node) {
|
|
18651
|
+
continue;
|
|
18652
|
+
}
|
|
18653
|
+
// @ts-ignore
|
|
18654
|
+
node = replacement;
|
|
18655
|
+
//
|
|
18656
|
+
if (Array.isArray(node)) {
|
|
18657
|
+
break;
|
|
17897
18658
|
}
|
|
17898
18659
|
}
|
|
17899
|
-
}
|
|
17900
|
-
if (node != result.node) {
|
|
17901
18660
|
// @ts-ignore
|
|
17902
|
-
|
|
17903
|
-
|
|
17904
|
-
|
|
17905
|
-
|
|
17906
|
-
tokens.push(...result.node.val);
|
|
17907
|
-
}
|
|
17908
|
-
if (tokens.length == 0) {
|
|
17909
|
-
continue;
|
|
18661
|
+
if (node != result.node) {
|
|
18662
|
+
// @ts-ignore
|
|
18663
|
+
replaceToken(result.parent, result.node, node);
|
|
18664
|
+
}
|
|
17910
18665
|
}
|
|
17911
|
-
|
|
17912
|
-
node =
|
|
17913
|
-
|
|
17914
|
-
|
|
17915
|
-
|
|
17916
|
-
|
|
17917
|
-
|
|
18666
|
+
else if (valuesHandlers.size > 0) {
|
|
18667
|
+
let node = null;
|
|
18668
|
+
node = result.node;
|
|
18669
|
+
if (valuesHandlers.has(node.typ)) {
|
|
18670
|
+
for (const valueHandler of valuesHandlers.get(node.typ)) {
|
|
18671
|
+
callable = valueHandler;
|
|
18672
|
+
replacement = callable(node, result.parent);
|
|
18673
|
+
if (replacement == null) {
|
|
17918
18674
|
continue;
|
|
17919
18675
|
}
|
|
17920
|
-
isAsync =
|
|
18676
|
+
isAsync = replacement instanceof Promise || Object.getPrototypeOf(replacement).constructor.name == 'AsyncFunction';
|
|
17921
18677
|
if (isAsync) {
|
|
17922
|
-
|
|
18678
|
+
replacement = await replacement;
|
|
17923
18679
|
}
|
|
17924
|
-
if (
|
|
17925
|
-
node =
|
|
17926
|
-
}
|
|
17927
|
-
//
|
|
17928
|
-
if (Array.isArray(node)) {
|
|
17929
|
-
break;
|
|
18680
|
+
if (replacement != null && replacement != node) {
|
|
18681
|
+
node = replacement;
|
|
17930
18682
|
}
|
|
17931
18683
|
}
|
|
17932
18684
|
}
|
|
17933
|
-
if (node !=
|
|
18685
|
+
if (node != result.node) {
|
|
17934
18686
|
// @ts-ignore
|
|
17935
|
-
replaceToken(parent, value, node);
|
|
18687
|
+
replaceToken(result.parent, value, node);
|
|
18688
|
+
}
|
|
18689
|
+
const tokens = 'tokens' in result.node ? result.node.tokens : [];
|
|
18690
|
+
if ('val' in result.node && Array.isArray(result.node.val)) {
|
|
18691
|
+
tokens.push(...result.node.val);
|
|
18692
|
+
}
|
|
18693
|
+
if (tokens.length == 0) {
|
|
18694
|
+
continue;
|
|
18695
|
+
}
|
|
18696
|
+
for (const { value, parent, root } of walkValues(tokens, result.node)) {
|
|
18697
|
+
node = value;
|
|
18698
|
+
if (valuesHandlers.has(node.typ)) {
|
|
18699
|
+
for (const valueHandler of valuesHandlers.get(node.typ)) {
|
|
18700
|
+
callable = valueHandler;
|
|
18701
|
+
let result = callable(node, parent, root);
|
|
18702
|
+
if (result == null) {
|
|
18703
|
+
continue;
|
|
18704
|
+
}
|
|
18705
|
+
isAsync = result instanceof Promise || Object.getPrototypeOf(result).constructor.name == 'AsyncFunction';
|
|
18706
|
+
if (isAsync) {
|
|
18707
|
+
result = await result;
|
|
18708
|
+
}
|
|
18709
|
+
if (result != null && result != node) {
|
|
18710
|
+
node = result;
|
|
18711
|
+
}
|
|
18712
|
+
//
|
|
18713
|
+
if (Array.isArray(node)) {
|
|
18714
|
+
break;
|
|
18715
|
+
}
|
|
18716
|
+
}
|
|
18717
|
+
}
|
|
18718
|
+
if (node != value) {
|
|
18719
|
+
// @ts-ignore
|
|
18720
|
+
replaceToken(parent, value, node);
|
|
18721
|
+
}
|
|
17936
18722
|
}
|
|
17937
18723
|
}
|
|
17938
18724
|
}
|
|
@@ -17946,12 +18732,9 @@ async function doParse(iter, options = {}) {
|
|
|
17946
18732
|
}
|
|
17947
18733
|
}
|
|
17948
18734
|
}
|
|
17949
|
-
const endTime = performance.now();
|
|
17950
|
-
if (options.signal != null) {
|
|
17951
|
-
options.signal.removeEventListener('abort', reject);
|
|
17952
|
-
}
|
|
17953
18735
|
stats.bytesIn += stats.importedBytesIn;
|
|
17954
|
-
|
|
18736
|
+
let endTime = performance.now();
|
|
18737
|
+
const result = {
|
|
17955
18738
|
ast,
|
|
17956
18739
|
errors,
|
|
17957
18740
|
stats: {
|
|
@@ -17961,6 +18744,503 @@ async function doParse(iter, options = {}) {
|
|
|
17961
18744
|
total: `${(endTime - startTime).toFixed(2)}ms`
|
|
17962
18745
|
}
|
|
17963
18746
|
};
|
|
18747
|
+
if (options.module) {
|
|
18748
|
+
const moduleSettings = {
|
|
18749
|
+
hashLength: 5,
|
|
18750
|
+
filePath: '',
|
|
18751
|
+
scoped: exports.ModuleScopeEnumOptions.Local,
|
|
18752
|
+
naming: exports.ModuleCaseTransformEnum.IgnoreCase,
|
|
18753
|
+
pattern: '',
|
|
18754
|
+
generateScopedName,
|
|
18755
|
+
...(typeof options.module != 'object' ? {} : options.module)
|
|
18756
|
+
};
|
|
18757
|
+
const parseModuleTime = performance.now();
|
|
18758
|
+
const namesMapping = {};
|
|
18759
|
+
const global = new Set;
|
|
18760
|
+
const processed = new Set;
|
|
18761
|
+
const pattern = typeof options.module == 'boolean' ? null : moduleSettings.pattern;
|
|
18762
|
+
const importMapping = {};
|
|
18763
|
+
const cssVariablesMap = {};
|
|
18764
|
+
const importedCssVariables = {};
|
|
18765
|
+
let mapping = {};
|
|
18766
|
+
let revMapping = {};
|
|
18767
|
+
let filePath = typeof options.module == 'boolean' ? options.src : (moduleSettings.filePath ?? options.src);
|
|
18768
|
+
filePath = filePath === '' ? options.src : options.resolve(filePath, options.dirname(options.src), options.cwd).relative;
|
|
18769
|
+
if (typeof options.module == 'number') {
|
|
18770
|
+
if (options.module & exports.ModuleCaseTransformEnum.CamelCase) {
|
|
18771
|
+
moduleSettings.naming = exports.ModuleCaseTransformEnum.CamelCase;
|
|
18772
|
+
}
|
|
18773
|
+
else if (options.module & exports.ModuleCaseTransformEnum.CamelCaseOnly) {
|
|
18774
|
+
moduleSettings.naming = exports.ModuleCaseTransformEnum.CamelCaseOnly;
|
|
18775
|
+
}
|
|
18776
|
+
else if (options.module & exports.ModuleCaseTransformEnum.DashCase) {
|
|
18777
|
+
moduleSettings.naming = exports.ModuleCaseTransformEnum.DashCase;
|
|
18778
|
+
}
|
|
18779
|
+
else if (options.module & exports.ModuleCaseTransformEnum.DashCaseOnly) {
|
|
18780
|
+
moduleSettings.naming = exports.ModuleCaseTransformEnum.DashCaseOnly;
|
|
18781
|
+
}
|
|
18782
|
+
if (options.module & exports.ModuleScopeEnumOptions.Global) {
|
|
18783
|
+
moduleSettings.scoped = exports.ModuleScopeEnumOptions.Global;
|
|
18784
|
+
}
|
|
18785
|
+
if (options.module & exports.ModuleScopeEnumOptions.Pure) {
|
|
18786
|
+
// @ts-ignore
|
|
18787
|
+
moduleSettings.scoped |= exports.ModuleScopeEnumOptions.Pure;
|
|
18788
|
+
}
|
|
18789
|
+
if (options.module & exports.ModuleScopeEnumOptions.ICSS) {
|
|
18790
|
+
// @ts-ignore
|
|
18791
|
+
moduleSettings.scoped |= exports.ModuleScopeEnumOptions.ICSS;
|
|
18792
|
+
}
|
|
18793
|
+
}
|
|
18794
|
+
if (typeof moduleSettings.scoped == 'boolean') {
|
|
18795
|
+
moduleSettings.scoped = moduleSettings.scoped ? exports.ModuleScopeEnumOptions.Local : exports.ModuleScopeEnumOptions.Global;
|
|
18796
|
+
}
|
|
18797
|
+
moduleSettings.filePath = filePath;
|
|
18798
|
+
moduleSettings.pattern = pattern != null && pattern !== '' ? pattern : (filePath === '' ? `[local]_[hash]` : `[local]_[hash]_[name]`);
|
|
18799
|
+
for (const { node, parent } of walk(ast)) {
|
|
18800
|
+
if (node.typ == exports.EnumToken.CssVariableImportTokenType) {
|
|
18801
|
+
const url = node.val.find(t => t.typ == exports.EnumToken.StringTokenType).val.slice(1, -1);
|
|
18802
|
+
const src = options.resolve(url, options.dirname(options.src), options.cwd);
|
|
18803
|
+
const result = options.load(url, options.src);
|
|
18804
|
+
const stream = result instanceof Promise || Object.getPrototypeOf(result).constructor.name == 'AsyncFunction' ? await result : result;
|
|
18805
|
+
const root = await doParse(stream instanceof ReadableStream ? tokenizeStream(stream) : tokenize$1({
|
|
18806
|
+
stream,
|
|
18807
|
+
buffer: '',
|
|
18808
|
+
offset: 0,
|
|
18809
|
+
position: { ind: 0, lin: 1, col: 1 },
|
|
18810
|
+
currentPosition: { ind: -1, lin: 1, col: 0 }
|
|
18811
|
+
}), Object.assign({}, options, {
|
|
18812
|
+
minify: false,
|
|
18813
|
+
setParent: false,
|
|
18814
|
+
src: src.relative
|
|
18815
|
+
}));
|
|
18816
|
+
cssVariablesMap[node.nam] = root.cssModuleVariables;
|
|
18817
|
+
parent.chi.splice(parent.chi.indexOf(node), 1);
|
|
18818
|
+
continue;
|
|
18819
|
+
}
|
|
18820
|
+
if (node.typ == exports.EnumToken.CssVariableDeclarationMapTokenType) {
|
|
18821
|
+
const from = node.from.find(t => t.typ == exports.EnumToken.IdenTokenType || isIdentColor(t));
|
|
18822
|
+
if (!(from.val in cssVariablesMap)) {
|
|
18823
|
+
errors.push({
|
|
18824
|
+
node,
|
|
18825
|
+
message: `could not resolve @value import from '${from.val}'`,
|
|
18826
|
+
action: 'drop'
|
|
18827
|
+
});
|
|
18828
|
+
}
|
|
18829
|
+
else {
|
|
18830
|
+
for (const token of node.vars) {
|
|
18831
|
+
if (token.typ == exports.EnumToken.IdenTokenType || isIdentColor(token)) {
|
|
18832
|
+
if (!(token.val in cssVariablesMap[from.val])) {
|
|
18833
|
+
errors.push({
|
|
18834
|
+
node,
|
|
18835
|
+
message: `value '${token.val}' is not exported from '${from.val}'`,
|
|
18836
|
+
action: 'drop'
|
|
18837
|
+
});
|
|
18838
|
+
continue;
|
|
18839
|
+
}
|
|
18840
|
+
result.cssModuleVariables ??= {};
|
|
18841
|
+
result.cssModuleVariables[token.val] = importedCssVariables[token.val] = cssVariablesMap[from.val][token.val];
|
|
18842
|
+
}
|
|
18843
|
+
}
|
|
18844
|
+
}
|
|
18845
|
+
parent.chi.splice(parent.chi.indexOf(node), 1);
|
|
18846
|
+
continue;
|
|
18847
|
+
}
|
|
18848
|
+
if (node.typ == exports.EnumToken.CssVariableTokenType) {
|
|
18849
|
+
if (parent?.typ == exports.EnumToken.StyleSheetNodeType) {
|
|
18850
|
+
if (result.cssModuleVariables == null) {
|
|
18851
|
+
result.cssModuleVariables = {};
|
|
18852
|
+
}
|
|
18853
|
+
result.cssModuleVariables[node.nam] = node;
|
|
18854
|
+
}
|
|
18855
|
+
parent.chi.splice(parent.chi.indexOf(node), 1);
|
|
18856
|
+
continue;
|
|
18857
|
+
}
|
|
18858
|
+
if (node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
18859
|
+
if (node.nam.startsWith('--')) {
|
|
18860
|
+
if (!(node.nam in namesMapping)) {
|
|
18861
|
+
let result = (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Global) ? node.nam : moduleSettings.generateScopedName(node.nam, moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
18862
|
+
let value = result instanceof Promise ? await result : result;
|
|
18863
|
+
mapping[node.nam] = '--' + (moduleSettings.naming & exports.ModuleCaseTransformEnum.DashCaseOnly || moduleSettings.naming & exports.ModuleCaseTransformEnum.CamelCaseOnly ? getKeyName(value, moduleSettings.naming) : value);
|
|
18864
|
+
revMapping[node.nam] = node.nam;
|
|
18865
|
+
}
|
|
18866
|
+
node.nam = mapping[node.nam];
|
|
18867
|
+
}
|
|
18868
|
+
if ('composes' == node.nam.toLowerCase()) {
|
|
18869
|
+
const tokens = [];
|
|
18870
|
+
let isValid = true;
|
|
18871
|
+
for (const token of node.val) {
|
|
18872
|
+
if (token.typ == exports.EnumToken.ComposesSelectorNodeType) {
|
|
18873
|
+
if (!(token.r == null || token.r.typ == exports.EnumToken.StringTokenType || token.r.typ == exports.EnumToken.IdenTokenType)) {
|
|
18874
|
+
errors.push({
|
|
18875
|
+
action: 'drop',
|
|
18876
|
+
message: `composes '${exports.EnumToken[token.r.typ]}' is not supported`,
|
|
18877
|
+
node
|
|
18878
|
+
});
|
|
18879
|
+
isValid = false;
|
|
18880
|
+
break;
|
|
18881
|
+
}
|
|
18882
|
+
tokens.push(token);
|
|
18883
|
+
}
|
|
18884
|
+
}
|
|
18885
|
+
// find parent rule
|
|
18886
|
+
let parentRule = node.parent;
|
|
18887
|
+
while (parentRule != null && parentRule.typ != exports.EnumToken.RuleNodeType) {
|
|
18888
|
+
parentRule = parentRule.parent;
|
|
18889
|
+
}
|
|
18890
|
+
if (!isValid || tokens.length == 0) {
|
|
18891
|
+
if (tokens.length == 0) {
|
|
18892
|
+
errors.push({
|
|
18893
|
+
action: 'drop',
|
|
18894
|
+
message: `composes is empty`,
|
|
18895
|
+
node
|
|
18896
|
+
});
|
|
18897
|
+
}
|
|
18898
|
+
parentRule.chi.splice(parentRule.chi.indexOf(node), 1);
|
|
18899
|
+
continue;
|
|
18900
|
+
}
|
|
18901
|
+
for (const token of tokens) {
|
|
18902
|
+
// composes: a b c;
|
|
18903
|
+
if (token.r == null) {
|
|
18904
|
+
for (const rule of token.l) {
|
|
18905
|
+
if (rule.typ == exports.EnumToken.WhitespaceTokenType || rule.typ == exports.EnumToken.CommentTokenType) {
|
|
18906
|
+
continue;
|
|
18907
|
+
}
|
|
18908
|
+
if (!(rule.val in mapping)) {
|
|
18909
|
+
let result = (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Global) ? rule.val : moduleSettings.generateScopedName(rule.val, moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
18910
|
+
let value = result instanceof Promise ? await result : result;
|
|
18911
|
+
mapping[rule.val] = (rule.typ == exports.EnumToken.DashedIdenTokenType ? '--' : '') + (moduleSettings.naming & exports.ModuleCaseTransformEnum.DashCaseOnly || moduleSettings.naming & exports.ModuleCaseTransformEnum.CamelCaseOnly ? getKeyName(value, moduleSettings.naming) : value);
|
|
18912
|
+
revMapping[mapping[rule.val]] = rule.val;
|
|
18913
|
+
}
|
|
18914
|
+
if (parentRule != null) {
|
|
18915
|
+
for (const tk of parentRule.tokens) {
|
|
18916
|
+
if (tk.typ == exports.EnumToken.ClassSelectorTokenType) {
|
|
18917
|
+
const val = tk.val.slice(1);
|
|
18918
|
+
if (val in revMapping) {
|
|
18919
|
+
const key = revMapping[val];
|
|
18920
|
+
mapping[key] = [...new Set([...mapping[key].split(' '), mapping[rule.val]])].join(' ');
|
|
18921
|
+
}
|
|
18922
|
+
}
|
|
18923
|
+
}
|
|
18924
|
+
}
|
|
18925
|
+
}
|
|
18926
|
+
}
|
|
18927
|
+
// composes: a b c from 'file.css';
|
|
18928
|
+
else if (token.r.typ == exports.EnumToken.String) {
|
|
18929
|
+
const url = token.r.val.slice(1, -1);
|
|
18930
|
+
const src = options.resolve(url, options.dirname(options.src), options.cwd);
|
|
18931
|
+
const result = options.load(url, options.src);
|
|
18932
|
+
const stream = result instanceof Promise || Object.getPrototypeOf(result).constructor.name == 'AsyncFunction' ? await result : result;
|
|
18933
|
+
const root = await doParse(stream instanceof ReadableStream ? tokenizeStream(stream) : tokenize$1({
|
|
18934
|
+
stream,
|
|
18935
|
+
buffer: '',
|
|
18936
|
+
offset: 0,
|
|
18937
|
+
position: { ind: 0, lin: 1, col: 1 },
|
|
18938
|
+
currentPosition: { ind: -1, lin: 1, col: 0 }
|
|
18939
|
+
}), Object.assign({}, options, {
|
|
18940
|
+
minify: false,
|
|
18941
|
+
setParent: false,
|
|
18942
|
+
src: src.relative
|
|
18943
|
+
}));
|
|
18944
|
+
const srcIndex = (src.relative.startsWith('/') || src.relative.startsWith('../') ? '' : './') + src.relative;
|
|
18945
|
+
if (Object.keys(root.mapping).length > 0) {
|
|
18946
|
+
importMapping[srcIndex] = {};
|
|
18947
|
+
}
|
|
18948
|
+
if (parentRule != null) {
|
|
18949
|
+
for (const tk of parentRule.tokens) {
|
|
18950
|
+
if (tk.typ == exports.EnumToken.ClassSelectorTokenType) {
|
|
18951
|
+
const val = tk.val.slice(1);
|
|
18952
|
+
if (val in revMapping) {
|
|
18953
|
+
const key = revMapping[val];
|
|
18954
|
+
const values = [];
|
|
18955
|
+
for (const iden of token.l) {
|
|
18956
|
+
if (iden.typ != exports.EnumToken.IdenTokenType && iden.typ != exports.EnumToken.DashedIdenTokenType) {
|
|
18957
|
+
continue;
|
|
18958
|
+
}
|
|
18959
|
+
if (!(iden.val in root.mapping)) {
|
|
18960
|
+
const result = (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Global) ? iden.val : moduleSettings.generateScopedName(iden.val, srcIndex, moduleSettings.pattern, moduleSettings.hashLength);
|
|
18961
|
+
let value = result instanceof Promise ? await result : result;
|
|
18962
|
+
root.mapping[iden.val] = (moduleSettings.naming & exports.ModuleCaseTransformEnum.DashCaseOnly || moduleSettings.naming & exports.ModuleCaseTransformEnum.CamelCaseOnly ? getKeyName(value, moduleSettings.naming) : value);
|
|
18963
|
+
root.revMapping[root.mapping[iden.val]] = iden.val;
|
|
18964
|
+
}
|
|
18965
|
+
importMapping[srcIndex][iden.val] = root.mapping[iden.val];
|
|
18966
|
+
values.push(root.mapping[iden.val]);
|
|
18967
|
+
}
|
|
18968
|
+
mapping[key] = [...new Set([...mapping[key].split(' '), ...values])].join(' ');
|
|
18969
|
+
}
|
|
18970
|
+
}
|
|
18971
|
+
}
|
|
18972
|
+
}
|
|
18973
|
+
}
|
|
18974
|
+
// composes: a b c from global;
|
|
18975
|
+
else if (token.r.typ == exports.EnumToken.IdenTokenType) {
|
|
18976
|
+
// global
|
|
18977
|
+
if (parentRule != null) {
|
|
18978
|
+
if ('global' == token.r.val.toLowerCase()) {
|
|
18979
|
+
for (const tk of parentRule.tokens) {
|
|
18980
|
+
if (tk.typ == exports.EnumToken.ClassSelectorTokenType) {
|
|
18981
|
+
const val = tk.val.slice(1);
|
|
18982
|
+
if (val in revMapping) {
|
|
18983
|
+
const key = revMapping[val];
|
|
18984
|
+
mapping[key] = [...new Set([...mapping[key].split(' '), ...(token.l.reduce((acc, curr) => {
|
|
18985
|
+
if (curr.typ == exports.EnumToken.IdenTokenType) {
|
|
18986
|
+
acc.push(curr.val);
|
|
18987
|
+
}
|
|
18988
|
+
return acc;
|
|
18989
|
+
}, []))])].join(' ');
|
|
18990
|
+
}
|
|
18991
|
+
}
|
|
18992
|
+
}
|
|
18993
|
+
}
|
|
18994
|
+
else {
|
|
18995
|
+
errors.push({
|
|
18996
|
+
action: 'drop',
|
|
18997
|
+
message: `composes '${token.r.val}' is not supported`,
|
|
18998
|
+
node
|
|
18999
|
+
});
|
|
19000
|
+
}
|
|
19001
|
+
}
|
|
19002
|
+
}
|
|
19003
|
+
}
|
|
19004
|
+
parentRule.chi.splice(parentRule.chi.indexOf(node), 1);
|
|
19005
|
+
}
|
|
19006
|
+
if (node.typ == exports.EnumToken.DeclarationNodeType && ['grid-column', 'grid-column-start', 'grid-column-end', 'grid-row', 'grid-row-start', 'grid-row-end', 'grid-template', 'grid-template-columns', 'grid-template-rows'].includes(node.nam)) {
|
|
19007
|
+
for (const { value } of walkValues(node.val, node)) {
|
|
19008
|
+
if (value.typ != exports.EnumToken.IdenTokenType) {
|
|
19009
|
+
continue;
|
|
19010
|
+
}
|
|
19011
|
+
let idenToken = value.val;
|
|
19012
|
+
let suffix = '';
|
|
19013
|
+
if (idenToken.endsWith('-start')) {
|
|
19014
|
+
suffix = '-start';
|
|
19015
|
+
idenToken = idenToken.slice(0, -6);
|
|
19016
|
+
}
|
|
19017
|
+
else if (idenToken.endsWith('-end')) {
|
|
19018
|
+
suffix = '-end';
|
|
19019
|
+
idenToken = idenToken.slice(0, -4);
|
|
19020
|
+
}
|
|
19021
|
+
if (!(idenToken in mapping)) {
|
|
19022
|
+
let result = (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Global) ? idenToken : moduleSettings.generateScopedName(idenToken, moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
19023
|
+
if (result instanceof Promise) {
|
|
19024
|
+
result = await result;
|
|
19025
|
+
}
|
|
19026
|
+
mapping[idenToken] = result;
|
|
19027
|
+
revMapping[result] = idenToken;
|
|
19028
|
+
if (suffix !== '') {
|
|
19029
|
+
idenToken += suffix;
|
|
19030
|
+
if (!(idenToken in mapping)) {
|
|
19031
|
+
mapping[idenToken] = result + suffix;
|
|
19032
|
+
revMapping[result + suffix] = idenToken;
|
|
19033
|
+
}
|
|
19034
|
+
}
|
|
19035
|
+
}
|
|
19036
|
+
value.val = mapping[idenToken];
|
|
19037
|
+
}
|
|
19038
|
+
}
|
|
19039
|
+
else if (node.nam == 'grid-template-areas' || node.nam == 'grid-template') {
|
|
19040
|
+
for (let i = 0; i < node.val.length; i++) {
|
|
19041
|
+
if (node.val[i].typ == exports.EnumToken.String) {
|
|
19042
|
+
const tokens = parseString(node.val[i].val.slice(1, -1), { location: true });
|
|
19043
|
+
for (const { value } of walkValues(tokens)) {
|
|
19044
|
+
if (value.typ == exports.EnumToken.IdenTokenType || value.typ == exports.EnumToken.DashedIdenTokenType) {
|
|
19045
|
+
if (value.val in mapping) {
|
|
19046
|
+
value.val = mapping[value.val];
|
|
19047
|
+
}
|
|
19048
|
+
else {
|
|
19049
|
+
let result = (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Global) ? value.val : moduleSettings.generateScopedName(value.val, moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
19050
|
+
if (result instanceof Promise) {
|
|
19051
|
+
result = await result;
|
|
19052
|
+
}
|
|
19053
|
+
mapping[value.val] = result;
|
|
19054
|
+
revMapping[result] = value.val;
|
|
19055
|
+
value.val = result;
|
|
19056
|
+
}
|
|
19057
|
+
}
|
|
19058
|
+
}
|
|
19059
|
+
node.val[i].val = node.val[i].val.charAt(0) + tokens.reduce((acc, curr) => acc + renderToken(curr), '') + node.val[i].val.charAt(node.val[i].val.length - 1);
|
|
19060
|
+
}
|
|
19061
|
+
}
|
|
19062
|
+
}
|
|
19063
|
+
else if (node.nam == 'animation' || node.nam == 'animation-name') {
|
|
19064
|
+
for (const { value } of walkValues(node.val, node)) {
|
|
19065
|
+
if (value.typ == exports.EnumToken.IdenTokenType && ![
|
|
19066
|
+
'none', 'infinite', 'normal', 'reverse', 'alternate',
|
|
19067
|
+
'alternate-reverse', 'forwards', 'backwards', 'both',
|
|
19068
|
+
'running', 'paused', 'linear', 'ease', 'ease-in', 'ease-out', 'ease-in-out',
|
|
19069
|
+
'step-start', 'step-end', 'jump-start', 'jump-end',
|
|
19070
|
+
'jump-none', 'jump-both', 'start', 'end',
|
|
19071
|
+
'inherit', 'initial', 'unset'
|
|
19072
|
+
].includes(value.val)) {
|
|
19073
|
+
if (!(value.val in mapping)) {
|
|
19074
|
+
const result = (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Global) ? value.val : moduleSettings.generateScopedName(value.val, moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
19075
|
+
mapping[value.val] = result instanceof Promise ? await result : result;
|
|
19076
|
+
revMapping[mapping[value.val]] = value.val;
|
|
19077
|
+
}
|
|
19078
|
+
value.val = mapping[value.val];
|
|
19079
|
+
}
|
|
19080
|
+
}
|
|
19081
|
+
}
|
|
19082
|
+
for (const { value, parent } of walkValues(node.val, node)) {
|
|
19083
|
+
if (value.typ == exports.EnumToken.DashedIdenTokenType) {
|
|
19084
|
+
if (!(value.val in mapping)) {
|
|
19085
|
+
const result = (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Global) ? value.val : moduleSettings.generateScopedName(value.val, moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
19086
|
+
let val = result instanceof Promise ? await result : result;
|
|
19087
|
+
mapping[value.val] = '--' + (moduleSettings.naming & exports.ModuleCaseTransformEnum.DashCaseOnly || moduleSettings.naming & exports.ModuleCaseTransformEnum.CamelCaseOnly ? getKeyName(val, moduleSettings.naming) : val);
|
|
19088
|
+
revMapping[mapping[value.val]] = value.val;
|
|
19089
|
+
}
|
|
19090
|
+
value.val = mapping[value.val];
|
|
19091
|
+
}
|
|
19092
|
+
else if ((value.typ == exports.EnumToken.IdenTokenType || isIdentColor(value)) && value.val in importedCssVariables) {
|
|
19093
|
+
replaceToken(parent, value, importedCssVariables[value.val].val);
|
|
19094
|
+
}
|
|
19095
|
+
}
|
|
19096
|
+
}
|
|
19097
|
+
else if (node.typ == exports.EnumToken.RuleNodeType) {
|
|
19098
|
+
if (node.tokens == null) {
|
|
19099
|
+
Object.defineProperty(node, 'tokens', {
|
|
19100
|
+
...definedPropertySettings,
|
|
19101
|
+
value: parseSelector(parseString(node.sel, { location: true }))
|
|
19102
|
+
});
|
|
19103
|
+
}
|
|
19104
|
+
let hasIdOrClass = false;
|
|
19105
|
+
for (const { value } of walkValues(node.tokens, node,
|
|
19106
|
+
// @ts-ignore
|
|
19107
|
+
(value, parent) => {
|
|
19108
|
+
if (value.typ == exports.EnumToken.PseudoClassTokenType) {
|
|
19109
|
+
const val = value.val.toLowerCase();
|
|
19110
|
+
switch (val) {
|
|
19111
|
+
case ':local':
|
|
19112
|
+
case ':global':
|
|
19113
|
+
{
|
|
19114
|
+
let index = parent.tokens.indexOf(value);
|
|
19115
|
+
parent.tokens.splice(index, 1);
|
|
19116
|
+
if (parent.tokens[index]?.typ == exports.EnumToken.WhitespaceTokenType || parent.tokens[index]?.typ == exports.EnumToken.DescendantCombinatorTokenType) {
|
|
19117
|
+
parent.tokens.splice(index, 1);
|
|
19118
|
+
}
|
|
19119
|
+
if (val == ':global') {
|
|
19120
|
+
for (; index < parent.tokens.length; index++) {
|
|
19121
|
+
if (parent.tokens[index].typ == exports.EnumToken.CommaTokenType ||
|
|
19122
|
+
([exports.EnumToken.PseudoClassFuncTokenType, exports.EnumToken.PseudoClassTokenType].includes(parent.tokens[index].typ) &&
|
|
19123
|
+
[':global', ':local'].includes(parent.tokens[index].val.toLowerCase()))) {
|
|
19124
|
+
break;
|
|
19125
|
+
}
|
|
19126
|
+
global.add(parent.tokens[index]);
|
|
19127
|
+
}
|
|
19128
|
+
}
|
|
19129
|
+
}
|
|
19130
|
+
break;
|
|
19131
|
+
}
|
|
19132
|
+
}
|
|
19133
|
+
else if (value.typ == exports.EnumToken.PseudoClassFuncTokenType) {
|
|
19134
|
+
switch (value.val.toLowerCase()) {
|
|
19135
|
+
case ':global':
|
|
19136
|
+
for (const token of value.chi) {
|
|
19137
|
+
global.add(token);
|
|
19138
|
+
}
|
|
19139
|
+
parent.tokens.splice(parent.tokens.indexOf(value), 1, ...value.chi);
|
|
19140
|
+
break;
|
|
19141
|
+
case ':local':
|
|
19142
|
+
parent.tokens.splice(parent.tokens.indexOf(value), 1, ...value.chi);
|
|
19143
|
+
break;
|
|
19144
|
+
}
|
|
19145
|
+
}
|
|
19146
|
+
})) {
|
|
19147
|
+
if (value.typ == exports.EnumToken.HashTokenType || value.typ == exports.EnumToken.ClassSelectorTokenType) {
|
|
19148
|
+
hasIdOrClass = true;
|
|
19149
|
+
}
|
|
19150
|
+
if (processed.has(value)) {
|
|
19151
|
+
continue;
|
|
19152
|
+
}
|
|
19153
|
+
processed.add(value);
|
|
19154
|
+
if (value.typ == exports.EnumToken.PseudoClassTokenType) ;
|
|
19155
|
+
else if (value.typ == exports.EnumToken.PseudoClassFuncTokenType) ;
|
|
19156
|
+
else {
|
|
19157
|
+
if (global.has(value)) {
|
|
19158
|
+
continue;
|
|
19159
|
+
}
|
|
19160
|
+
if (value.typ == exports.EnumToken.ClassSelectorTokenType) {
|
|
19161
|
+
const val = value.val.slice(1);
|
|
19162
|
+
if (!(val in mapping)) {
|
|
19163
|
+
const result = (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Global) ? val : moduleSettings.generateScopedName(val, moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
19164
|
+
let value = result instanceof Promise ? await result : result;
|
|
19165
|
+
mapping[val] = (moduleSettings.naming & exports.ModuleCaseTransformEnum.DashCaseOnly || moduleSettings.naming & exports.ModuleCaseTransformEnum.CamelCaseOnly ? getKeyName(value, moduleSettings.naming) : value);
|
|
19166
|
+
revMapping[mapping[val]] = val;
|
|
19167
|
+
}
|
|
19168
|
+
value.val = '.' + mapping[val];
|
|
19169
|
+
}
|
|
19170
|
+
}
|
|
19171
|
+
}
|
|
19172
|
+
if (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Pure) {
|
|
19173
|
+
if (!hasIdOrClass) {
|
|
19174
|
+
throw new Error(`pure module: No id or class found in selector '${node.sel}' at '${node.loc?.src ?? ''}':${node.loc?.sta?.lin ?? ''}:${node.loc?.sta?.col ?? ''}`);
|
|
19175
|
+
}
|
|
19176
|
+
}
|
|
19177
|
+
node.sel = '';
|
|
19178
|
+
for (const token of node.tokens) {
|
|
19179
|
+
node.sel += renderToken(token);
|
|
19180
|
+
}
|
|
19181
|
+
}
|
|
19182
|
+
else if (node.typ == exports.EnumToken.AtRuleNodeType || node.typ == exports.EnumToken.KeyframesAtRuleNodeType) {
|
|
19183
|
+
const val = node.nam.toLowerCase();
|
|
19184
|
+
if (node.tokens == null) {
|
|
19185
|
+
Object.defineProperty(node, 'tokens', {
|
|
19186
|
+
...definedPropertySettings,
|
|
19187
|
+
// @ts-ignore
|
|
19188
|
+
value: parseAtRulePrelude(parseString(node.val), node)
|
|
19189
|
+
});
|
|
19190
|
+
}
|
|
19191
|
+
if (val == 'property' || val == 'keyframes') {
|
|
19192
|
+
const prefix = val == 'property' ? '--' : '';
|
|
19193
|
+
for (const value of node.tokens) {
|
|
19194
|
+
if ((prefix == '--' && value.typ == exports.EnumToken.DashedIdenTokenType) || (prefix == '' && value.typ == exports.EnumToken.IdenTokenType)) {
|
|
19195
|
+
if (!(value.val in mapping)) {
|
|
19196
|
+
const result = (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Global) ? value.val : moduleSettings.generateScopedName(value.val, moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
|
|
19197
|
+
let val = result instanceof Promise ? await result : result;
|
|
19198
|
+
mapping[value.val] = prefix + (moduleSettings.naming & exports.ModuleCaseTransformEnum.DashCaseOnly || moduleSettings.naming & exports.ModuleCaseTransformEnum.CamelCaseOnly ? getKeyName(val, moduleSettings.naming) : val);
|
|
19199
|
+
revMapping[mapping[value.val]] = value.val;
|
|
19200
|
+
}
|
|
19201
|
+
value.val = mapping[value.val];
|
|
19202
|
+
}
|
|
19203
|
+
}
|
|
19204
|
+
node.val = node.tokens.reduce((a, b) => a + renderToken(b), '');
|
|
19205
|
+
}
|
|
19206
|
+
else {
|
|
19207
|
+
let isReplaced = false;
|
|
19208
|
+
for (const { value, parent } of walkValues(node.tokens, node)) {
|
|
19209
|
+
if (exports.EnumToken.MediaQueryConditionTokenType == parent.typ && value != parent.l) {
|
|
19210
|
+
if ((value.typ == exports.EnumToken.IdenTokenType || isIdentColor(value)) && value.val in importedCssVariables) {
|
|
19211
|
+
isReplaced = true;
|
|
19212
|
+
parent.r.splice(parent.r.indexOf(value), 1, ...importedCssVariables[value.val].val);
|
|
19213
|
+
}
|
|
19214
|
+
}
|
|
19215
|
+
}
|
|
19216
|
+
if (isReplaced) {
|
|
19217
|
+
node.val = node.tokens.reduce((a, b) => a + renderToken(b), '');
|
|
19218
|
+
}
|
|
19219
|
+
}
|
|
19220
|
+
}
|
|
19221
|
+
}
|
|
19222
|
+
if (moduleSettings.naming != exports.ModuleCaseTransformEnum.IgnoreCase) {
|
|
19223
|
+
revMapping = {};
|
|
19224
|
+
mapping = Object.entries(mapping).reduce((acc, [key, value]) => {
|
|
19225
|
+
const keyName = getKeyName(key, moduleSettings.naming);
|
|
19226
|
+
acc[keyName] = value;
|
|
19227
|
+
revMapping[value] = keyName;
|
|
19228
|
+
return acc;
|
|
19229
|
+
}, {});
|
|
19230
|
+
}
|
|
19231
|
+
result.mapping = mapping;
|
|
19232
|
+
result.revMapping = revMapping;
|
|
19233
|
+
if ((moduleSettings.scoped & exports.ModuleScopeEnumOptions.ICSS) && Object.keys(importMapping).length > 0) {
|
|
19234
|
+
result.importMapping = importMapping;
|
|
19235
|
+
}
|
|
19236
|
+
endTime = performance.now();
|
|
19237
|
+
result.stats.module = `${(endTime - parseModuleTime).toFixed(2)}ms`;
|
|
19238
|
+
result.stats.total = `${(endTime - startTime).toFixed(2)}ms`;
|
|
19239
|
+
}
|
|
19240
|
+
if (options.signal != null) {
|
|
19241
|
+
options.signal.removeEventListener('abort', reject);
|
|
19242
|
+
}
|
|
19243
|
+
return result;
|
|
17964
19244
|
}
|
|
17965
19245
|
function getLastNode(context) {
|
|
17966
19246
|
let i = context.chi.length;
|
|
@@ -17972,7 +19252,7 @@ function getLastNode(context) {
|
|
|
17972
19252
|
}
|
|
17973
19253
|
return null;
|
|
17974
19254
|
}
|
|
17975
|
-
function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
19255
|
+
function parseNode(results, context, options, errors, src, map, rawTokens, stats) {
|
|
17976
19256
|
let tokens = [];
|
|
17977
19257
|
for (const t of results) {
|
|
17978
19258
|
const node = getTokenType(t.token, t.hint);
|
|
@@ -17995,9 +19275,12 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
17995
19275
|
}
|
|
17996
19276
|
loc = location;
|
|
17997
19277
|
context.chi.push(tokens[i]);
|
|
17998
|
-
|
|
17999
|
-
|
|
18000
|
-
|
|
19278
|
+
stats.nodesCount++;
|
|
19279
|
+
Object.defineProperty(tokens[i], 'loc', {
|
|
19280
|
+
...definedPropertySettings,
|
|
19281
|
+
value: loc,
|
|
19282
|
+
enumerable: options.sourcemap !== false
|
|
19283
|
+
});
|
|
18001
19284
|
}
|
|
18002
19285
|
else if (tokens[i].typ != exports.EnumToken.WhitespaceTokenType) {
|
|
18003
19286
|
break;
|
|
@@ -18138,10 +19421,10 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
18138
19421
|
}
|
|
18139
19422
|
}
|
|
18140
19423
|
const t = parseAtRulePrelude(parseTokens(tokens, { minify: options.minify }), atRule);
|
|
18141
|
-
const raw =
|
|
18142
|
-
|
|
18143
|
-
|
|
18144
|
-
}
|
|
19424
|
+
const raw = [];
|
|
19425
|
+
for (const curr of t) {
|
|
19426
|
+
raw.push(renderToken(curr, { removeComments: true, convertColor: false }));
|
|
19427
|
+
}
|
|
18145
19428
|
const nam = renderToken(atRule, { removeComments: true });
|
|
18146
19429
|
// @ts-ignore
|
|
18147
19430
|
const node = {
|
|
@@ -18157,10 +19440,12 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
18157
19440
|
node.chi = [];
|
|
18158
19441
|
}
|
|
18159
19442
|
loc = map.get(atRule);
|
|
18160
|
-
|
|
18161
|
-
|
|
18162
|
-
|
|
18163
|
-
|
|
19443
|
+
Object.defineProperty(node, 'loc', {
|
|
19444
|
+
...definedPropertySettings,
|
|
19445
|
+
value: loc,
|
|
19446
|
+
enumerable: options.sourcemap !== false
|
|
19447
|
+
});
|
|
19448
|
+
node.loc.end = { ...map.get(delim).end };
|
|
18164
19449
|
let isValid = true;
|
|
18165
19450
|
if (node.nam == 'else') {
|
|
18166
19451
|
const prev = getLastNode(context);
|
|
@@ -18173,21 +19458,173 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
18173
19458
|
isValid = false;
|
|
18174
19459
|
}
|
|
18175
19460
|
}
|
|
19461
|
+
if (node.nam == 'value') {
|
|
19462
|
+
let i = 0;
|
|
19463
|
+
while (i < tokens.length) {
|
|
19464
|
+
if (tokens[i].typ == exports.EnumToken.WhitespaceTokenType || tokens[i].typ == exports.EnumToken.CommentTokenType) {
|
|
19465
|
+
i++;
|
|
19466
|
+
continue;
|
|
19467
|
+
}
|
|
19468
|
+
break;
|
|
19469
|
+
}
|
|
19470
|
+
if (i < tokens.length) {
|
|
19471
|
+
if (tokens[i].typ == exports.EnumToken.IdenTokenType || isIdentColor(tokens[i])) {
|
|
19472
|
+
let k = i + 1;
|
|
19473
|
+
while (k < tokens.length) {
|
|
19474
|
+
if (tokens[k].typ == exports.EnumToken.WhitespaceTokenType || tokens[k].typ == exports.EnumToken.CommentTokenType) {
|
|
19475
|
+
k++;
|
|
19476
|
+
continue;
|
|
19477
|
+
}
|
|
19478
|
+
// var or import
|
|
19479
|
+
if (tokens[k].typ == exports.EnumToken.ColonTokenType) {
|
|
19480
|
+
let j = k;
|
|
19481
|
+
while (++j < tokens.length) {
|
|
19482
|
+
if (tokens[j].typ != exports.EnumToken.WhitespaceTokenType && tokens[j].typ != exports.EnumToken.CommentTokenType) {
|
|
19483
|
+
break;
|
|
19484
|
+
}
|
|
19485
|
+
}
|
|
19486
|
+
let offset = k + 1;
|
|
19487
|
+
while (offset < tokens.length && tokens[offset].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
19488
|
+
offset++;
|
|
19489
|
+
}
|
|
19490
|
+
if (tokens[j].typ == exports.EnumToken.StringTokenType) {
|
|
19491
|
+
Object.assign(node, {
|
|
19492
|
+
typ: exports.EnumToken.CssVariableImportTokenType,
|
|
19493
|
+
nam: tokens[i].val,
|
|
19494
|
+
val: tokens.slice(offset)
|
|
19495
|
+
});
|
|
19496
|
+
delete node.tokens;
|
|
19497
|
+
// @ts-ignore
|
|
19498
|
+
delete node.raw;
|
|
19499
|
+
context.chi.push(node);
|
|
19500
|
+
return null;
|
|
19501
|
+
}
|
|
19502
|
+
Object.assign(node, {
|
|
19503
|
+
typ: exports.EnumToken.CssVariableTokenType,
|
|
19504
|
+
nam: tokens[i].val,
|
|
19505
|
+
val: tokens.slice(offset)
|
|
19506
|
+
});
|
|
19507
|
+
context.chi.push(node);
|
|
19508
|
+
return null;
|
|
19509
|
+
}
|
|
19510
|
+
if (tokens[k].typ == exports.EnumToken.PseudoClassTokenType) {
|
|
19511
|
+
Object.assign(tokens[k], {
|
|
19512
|
+
typ: exports.EnumToken.IdenTokenType,
|
|
19513
|
+
val: tokens[k].val.slice(1)
|
|
19514
|
+
});
|
|
19515
|
+
Object.assign(node, {
|
|
19516
|
+
typ: exports.EnumToken.CssVariableTokenType,
|
|
19517
|
+
nam: tokens[i].val,
|
|
19518
|
+
val: tokens.slice(k)
|
|
19519
|
+
});
|
|
19520
|
+
context.chi.push(node);
|
|
19521
|
+
return null;
|
|
19522
|
+
}
|
|
19523
|
+
if (tokens[k].typ == exports.EnumToken.CommaTokenType) {
|
|
19524
|
+
let j = i;
|
|
19525
|
+
while (++j < tokens.length) {
|
|
19526
|
+
if (tokens[j].typ == exports.EnumToken.IdenTokenType && tokens[j].val.toLowerCase() == 'from') {
|
|
19527
|
+
const vars = tokens.slice(i, j);
|
|
19528
|
+
const from = tokens.slice(j + 1);
|
|
19529
|
+
let l = 0;
|
|
19530
|
+
let expect = exports.EnumToken.IdenTokenType;
|
|
19531
|
+
for (; l < vars.length; l++) {
|
|
19532
|
+
if (vars[l].typ == exports.EnumToken.WhitespaceTokenType || vars[l].typ == exports.EnumToken.CommentTokenType) {
|
|
19533
|
+
continue;
|
|
19534
|
+
}
|
|
19535
|
+
if (expect == vars[l].typ || (expect == exports.EnumToken.IdenTokenType && isIdentColor(vars[l]))) {
|
|
19536
|
+
expect = expect == exports.EnumToken.CommaTokenType ? exports.EnumToken.IdenTokenType : exports.EnumToken.CommaTokenType;
|
|
19537
|
+
continue;
|
|
19538
|
+
}
|
|
19539
|
+
errors.push({
|
|
19540
|
+
action: 'drop',
|
|
19541
|
+
node: node,
|
|
19542
|
+
location: map.get(vars[l]) ?? location,
|
|
19543
|
+
message: `expecting '${exports.EnumToken[expect]}' but found ${renderToken(vars[l])}`
|
|
19544
|
+
});
|
|
19545
|
+
return null;
|
|
19546
|
+
}
|
|
19547
|
+
l = 0;
|
|
19548
|
+
expect = exports.EnumToken.IdenTokenType;
|
|
19549
|
+
for (; l < from.length; l++) {
|
|
19550
|
+
if (from[l].typ == exports.EnumToken.WhitespaceTokenType || from[l].typ == exports.EnumToken.CommentTokenType) {
|
|
19551
|
+
continue;
|
|
19552
|
+
}
|
|
19553
|
+
if (expect == from[l].typ || isIdentColor(from[l])) {
|
|
19554
|
+
while (++l < from.length) {
|
|
19555
|
+
if (from[l].typ == exports.EnumToken.WhitespaceTokenType || from[l].typ == exports.EnumToken.CommentTokenType) {
|
|
19556
|
+
continue;
|
|
19557
|
+
}
|
|
19558
|
+
errors.push({
|
|
19559
|
+
action: 'drop',
|
|
19560
|
+
node: node,
|
|
19561
|
+
location: map.get(from[l]) ?? location,
|
|
19562
|
+
message: `unexpected '${renderToken(from[l])}'`
|
|
19563
|
+
});
|
|
19564
|
+
return null;
|
|
19565
|
+
}
|
|
19566
|
+
break;
|
|
19567
|
+
}
|
|
19568
|
+
errors.push({
|
|
19569
|
+
action: 'drop',
|
|
19570
|
+
node: node,
|
|
19571
|
+
location: map.get(from[l]) ?? location,
|
|
19572
|
+
message: `expecting <string> but found ${renderToken(from[l])}`
|
|
19573
|
+
});
|
|
19574
|
+
return null;
|
|
19575
|
+
}
|
|
19576
|
+
// @ts-ignore
|
|
19577
|
+
delete node.nam;
|
|
19578
|
+
// @ts-ignore
|
|
19579
|
+
delete node.val;
|
|
19580
|
+
Object.assign(node, {
|
|
19581
|
+
typ: exports.EnumToken.CssVariableDeclarationMapTokenType,
|
|
19582
|
+
vars,
|
|
19583
|
+
from
|
|
19584
|
+
});
|
|
19585
|
+
context.chi.push(node);
|
|
19586
|
+
return null;
|
|
19587
|
+
}
|
|
19588
|
+
}
|
|
19589
|
+
}
|
|
19590
|
+
k++;
|
|
19591
|
+
}
|
|
19592
|
+
Object.assign(node, {
|
|
19593
|
+
typ: exports.EnumToken.CssVariableTokenType,
|
|
19594
|
+
nam: tokens[i].val,
|
|
19595
|
+
val: tokens.slice(k)
|
|
19596
|
+
});
|
|
19597
|
+
context.chi.push(node);
|
|
19598
|
+
return null;
|
|
19599
|
+
}
|
|
19600
|
+
}
|
|
19601
|
+
}
|
|
19602
|
+
// @ts-ignore
|
|
19603
|
+
const skipValidate = (options.validation & exports.ValidationLevel.AtRule) == 0;
|
|
19604
|
+
const isAllowed = skipValidate || isNodeAllowedInContext(node, context);
|
|
18176
19605
|
// @ts-ignore
|
|
18177
|
-
const valid =
|
|
19606
|
+
const valid = skipValidate ? {
|
|
18178
19607
|
valid: SyntaxValidationResult.Valid,
|
|
18179
19608
|
error: '',
|
|
18180
19609
|
node,
|
|
18181
19610
|
syntax: '@' + node.nam
|
|
18182
|
-
} :
|
|
19611
|
+
} : !isAllowed ? {
|
|
19612
|
+
valid: SyntaxValidationResult.Drop,
|
|
19613
|
+
node,
|
|
19614
|
+
syntax: '@' + node.nam,
|
|
19615
|
+
error: `${exports.EnumToken[context.typ]}: child ${exports.EnumToken[node.typ]} not allowed in context${context.typ == exports.EnumToken.AtRuleNodeType ? ` '@${context.nam}'` : context.typ == exports.EnumToken.StyleSheetNodeType ? ` 'stylesheet'` : ''}`} : isValid ? (node.typ == exports.EnumToken.KeyframesAtRuleNodeType ? validateAtRuleKeyframes(node) : validateAtRule(node, options, context)) : {
|
|
18183
19616
|
valid: SyntaxValidationResult.Drop,
|
|
18184
19617
|
node,
|
|
18185
19618
|
syntax: '@' + node.nam,
|
|
18186
19619
|
error: '@' + node.nam + ' not allowed here'};
|
|
18187
19620
|
if (valid.valid == SyntaxValidationResult.Drop) {
|
|
19621
|
+
let message = '';
|
|
19622
|
+
for (const token of tokens) {
|
|
19623
|
+
message += renderToken(token, { minify: false });
|
|
19624
|
+
}
|
|
18188
19625
|
errors.push({
|
|
18189
19626
|
action: 'drop',
|
|
18190
|
-
message: valid.error + ' - "' +
|
|
19627
|
+
message: valid.error + ' - "' + message + '"',
|
|
18191
19628
|
node,
|
|
18192
19629
|
// @ts-ignore
|
|
18193
19630
|
location: { src, ...(map.get(valid.node) ?? location) }
|
|
@@ -18196,13 +19633,17 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
18196
19633
|
node.typ = exports.EnumToken.InvalidAtRuleTokenType;
|
|
18197
19634
|
}
|
|
18198
19635
|
else {
|
|
18199
|
-
node.val =
|
|
18200
|
-
|
|
18201
|
-
|
|
18202
|
-
|
|
18203
|
-
|
|
19636
|
+
node.val = '';
|
|
19637
|
+
for (const token of node.tokens) {
|
|
19638
|
+
node.val += renderToken(token, {
|
|
19639
|
+
minify: false,
|
|
19640
|
+
convertColor: false,
|
|
19641
|
+
removeComments: true
|
|
19642
|
+
});
|
|
19643
|
+
}
|
|
18204
19644
|
}
|
|
18205
19645
|
context.chi.push(node);
|
|
19646
|
+
stats.nodesCount++;
|
|
18206
19647
|
Object.defineProperties(node, {
|
|
18207
19648
|
parent: { ...definedPropertySettings, value: context },
|
|
18208
19649
|
validSyntax: { ...definedPropertySettings, value: valid.valid == SyntaxValidationResult.Valid }
|
|
@@ -18300,16 +19741,23 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
18300
19741
|
value: tokens.slice()
|
|
18301
19742
|
});
|
|
18302
19743
|
loc = location;
|
|
18303
|
-
|
|
18304
|
-
|
|
18305
|
-
|
|
18306
|
-
|
|
19744
|
+
Object.defineProperty(node, 'loc', {
|
|
19745
|
+
...definedPropertySettings,
|
|
19746
|
+
value: loc,
|
|
19747
|
+
enumerable: options.sourcemap !== false
|
|
19748
|
+
});
|
|
18307
19749
|
context.chi.push(node);
|
|
18308
19750
|
Object.defineProperty(node, 'parent', { ...definedPropertySettings, value: context });
|
|
18309
19751
|
// @ts-ignore
|
|
18310
|
-
const
|
|
19752
|
+
const skipValidate = (options.validation & exports.ValidationLevel.Selector) == 0;
|
|
19753
|
+
const isAllowed = skipValidate || isNodeAllowedInContext(node, context);
|
|
19754
|
+
// @ts-ignore
|
|
19755
|
+
const valid = skipValidate ? {
|
|
18311
19756
|
valid: SyntaxValidationResult.Valid,
|
|
18312
19757
|
error: null
|
|
19758
|
+
} : !isAllowed ? {
|
|
19759
|
+
valid: SyntaxValidationResult.Drop,
|
|
19760
|
+
error: `${exports.EnumToken[context.typ]}: child ${exports.EnumToken[node.typ]} not allowed in context${context.typ == exports.EnumToken.AtRuleNodeType ? ` '@${context.nam}'` : context.typ == exports.EnumToken.StyleSheetNodeType ? ` 'stylesheet'` : ''}`
|
|
18313
19761
|
} : ruleType == exports.EnumToken.KeyFramesRuleNodeType ? validateKeyframeSelector(tokens) : validateSelector(tokens, options, context);
|
|
18314
19762
|
if (valid.valid != SyntaxValidationResult.Valid) {
|
|
18315
19763
|
// @ts-ignore
|
|
@@ -18419,11 +19867,13 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
18419
19867
|
nam,
|
|
18420
19868
|
val: []
|
|
18421
19869
|
};
|
|
18422
|
-
|
|
18423
|
-
|
|
18424
|
-
|
|
18425
|
-
|
|
19870
|
+
Object.defineProperty(node, 'loc', {
|
|
19871
|
+
...definedPropertySettings,
|
|
19872
|
+
value: location,
|
|
19873
|
+
enumerable: options.sourcemap !== false
|
|
19874
|
+
});
|
|
18426
19875
|
context.chi.push(node);
|
|
19876
|
+
stats.nodesCount++;
|
|
18427
19877
|
}
|
|
18428
19878
|
return null;
|
|
18429
19879
|
}
|
|
@@ -18447,22 +19897,31 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
18447
19897
|
nam,
|
|
18448
19898
|
val: value
|
|
18449
19899
|
};
|
|
18450
|
-
|
|
18451
|
-
|
|
18452
|
-
|
|
18453
|
-
|
|
19900
|
+
Object.defineProperty(node, 'loc', {
|
|
19901
|
+
...definedPropertySettings,
|
|
19902
|
+
value: location,
|
|
19903
|
+
enumerable: options.sourcemap !== false
|
|
19904
|
+
});
|
|
19905
|
+
node.loc.end = { ...map.get(delim).end };
|
|
18454
19906
|
// do not allow declarations in style sheets
|
|
18455
19907
|
if (context.typ == exports.EnumToken.StyleSheetNodeType && options.lenient) {
|
|
18456
|
-
|
|
18457
|
-
node.typ = exports.EnumToken.InvalidDeclarationNodeType;
|
|
19908
|
+
Object.assign(node, { typ: exports.EnumToken.InvalidDeclarationNodeType });
|
|
18458
19909
|
context.chi.push(node);
|
|
19910
|
+
stats.nodesCount++;
|
|
18459
19911
|
return null;
|
|
18460
19912
|
}
|
|
18461
19913
|
const result = parseDeclarationNode(node, errors, location);
|
|
18462
19914
|
Object.defineProperty(result, 'parent', { ...definedPropertySettings, value: context });
|
|
18463
19915
|
if (result != null) {
|
|
18464
|
-
if (options.validation
|
|
18465
|
-
const
|
|
19916
|
+
if (options.validation & exports.ValidationLevel.Declaration) {
|
|
19917
|
+
const isAllowed = isNodeAllowedInContext(node, context);
|
|
19918
|
+
// @ts-ignore
|
|
19919
|
+
const valid = !isAllowed ? {
|
|
19920
|
+
valid: SyntaxValidationResult.Drop,
|
|
19921
|
+
error: `${exports.EnumToken[node.typ]} not allowed in context${context.typ == exports.EnumToken.AtRuleNodeType ? ` '@${context.nam}'` : context.typ == exports.EnumToken.StyleSheetNodeType ? ` 'stylesheet'` : ''}`,
|
|
19922
|
+
node,
|
|
19923
|
+
syntax: null
|
|
19924
|
+
} : evaluateSyntax(result, context, options);
|
|
18466
19925
|
Object.defineProperty(result, 'validSyntax', {
|
|
18467
19926
|
...definedPropertySettings,
|
|
18468
19927
|
value: valid.valid == SyntaxValidationResult.Valid
|
|
@@ -18478,11 +19937,11 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
18478
19937
|
if (!options.lenient) {
|
|
18479
19938
|
return null;
|
|
18480
19939
|
}
|
|
18481
|
-
|
|
18482
|
-
node.typ = exports.EnumToken.InvalidDeclarationNodeType;
|
|
19940
|
+
Object.assign(node, { typ: exports.EnumToken.InvalidDeclarationNodeType });
|
|
18483
19941
|
}
|
|
18484
19942
|
}
|
|
18485
19943
|
context.chi.push(result);
|
|
19944
|
+
stats.nodesCount++;
|
|
18486
19945
|
}
|
|
18487
19946
|
return null;
|
|
18488
19947
|
}
|
|
@@ -18494,7 +19953,6 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
|
|
|
18494
19953
|
* @param atRule
|
|
18495
19954
|
*/
|
|
18496
19955
|
function parseAtRulePrelude(tokens, atRule) {
|
|
18497
|
-
// @ts-ignore
|
|
18498
19956
|
for (const { value, parent } of walkValues(tokens, null, null, true)) {
|
|
18499
19957
|
if (value.typ == exports.EnumToken.CommentTokenType ||
|
|
18500
19958
|
value.typ == exports.EnumToken.WhitespaceTokenType ||
|
|
@@ -18530,16 +19988,14 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
18530
19988
|
}
|
|
18531
19989
|
if (atRule.val == 'page' && value.typ == exports.EnumToken.PseudoClassTokenType) {
|
|
18532
19990
|
if ([':left', ':right', ':first', ':blank'].includes(value.val)) {
|
|
18533
|
-
|
|
18534
|
-
value.typ = exports.EnumToken.PseudoPageTokenType;
|
|
19991
|
+
Object.assign(value, { typ: exports.EnumToken.PseudoPageTokenType });
|
|
18535
19992
|
}
|
|
18536
19993
|
}
|
|
18537
19994
|
if (atRule.val == 'layer') {
|
|
18538
19995
|
if (parent == null && value.typ == exports.EnumToken.LiteralTokenType) {
|
|
18539
19996
|
if (value.val.charAt(0) == '.') {
|
|
18540
19997
|
if (isIdent(value.val.slice(1))) {
|
|
18541
|
-
|
|
18542
|
-
value.typ = exports.EnumToken.ClassSelectorTokenType;
|
|
19998
|
+
Object.assign(value, { typ: exports.EnumToken.ClassSelectorTokenType });
|
|
18543
19999
|
}
|
|
18544
20000
|
}
|
|
18545
20001
|
}
|
|
@@ -18548,8 +20004,7 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
18548
20004
|
if (value.typ == exports.EnumToken.IdenTokenType) {
|
|
18549
20005
|
if (parent == null && mediaTypes.some((t) => {
|
|
18550
20006
|
if (val === t) {
|
|
18551
|
-
|
|
18552
|
-
value.typ = exports.EnumToken.MediaFeatureTokenType;
|
|
20007
|
+
Object.assign(value, { typ: exports.EnumToken.MediaFeatureTokenType });
|
|
18553
20008
|
return true;
|
|
18554
20009
|
}
|
|
18555
20010
|
return false;
|
|
@@ -18557,18 +20012,15 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
18557
20012
|
continue;
|
|
18558
20013
|
}
|
|
18559
20014
|
if (value.typ == exports.EnumToken.IdenTokenType && 'and' === val) {
|
|
18560
|
-
|
|
18561
|
-
value.typ = exports.EnumToken.MediaFeatureAndTokenType;
|
|
20015
|
+
Object.assign(value, { typ: exports.EnumToken.MediaFeatureAndTokenType });
|
|
18562
20016
|
continue;
|
|
18563
20017
|
}
|
|
18564
20018
|
if (value.typ == exports.EnumToken.IdenTokenType && 'or' === val) {
|
|
18565
|
-
|
|
18566
|
-
value.typ = exports.EnumToken.MediaFeatureOrTokenType;
|
|
20019
|
+
Object.assign(value, { typ: exports.EnumToken.MediaFeatureOrTokenType });
|
|
18567
20020
|
continue;
|
|
18568
20021
|
}
|
|
18569
20022
|
if (value.typ == exports.EnumToken.IdenTokenType &&
|
|
18570
20023
|
['not', 'only'].some((t) => val === t)) {
|
|
18571
|
-
// @ts-ignore
|
|
18572
20024
|
const array = parent?.chi ?? tokens;
|
|
18573
20025
|
const startIndex = array.indexOf(value);
|
|
18574
20026
|
let index = startIndex + 1;
|
|
@@ -18613,12 +20065,15 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
18613
20065
|
if (value.chi[i].typ == exports.EnumToken.CommentTokenType || value.chi[i].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18614
20066
|
continue;
|
|
18615
20067
|
}
|
|
18616
|
-
if (value.chi[i].typ == exports.EnumToken.LiteralTokenType && value.chi[i].val.startsWith(':')
|
|
18617
|
-
value.chi.
|
|
18618
|
-
|
|
18619
|
-
|
|
18620
|
-
|
|
18621
|
-
|
|
20068
|
+
if (value.chi[i].typ == exports.EnumToken.LiteralTokenType && value.chi[i].val.startsWith(':')) {
|
|
20069
|
+
const dimension = parseDimension(value.chi[i].val.slice(1));
|
|
20070
|
+
if (dimension != null) {
|
|
20071
|
+
value.chi.splice(i, 1, {
|
|
20072
|
+
typ: exports.EnumToken.ColonTokenType,
|
|
20073
|
+
}, Object.assign(value.chi[i], dimension));
|
|
20074
|
+
i--;
|
|
20075
|
+
continue;
|
|
20076
|
+
}
|
|
18622
20077
|
}
|
|
18623
20078
|
if (nameIndex != -1 && value.chi[i].typ == exports.EnumToken.PseudoClassTokenType) {
|
|
18624
20079
|
value.chi.splice(i, 1, {
|
|
@@ -18645,11 +20100,10 @@ function parseAtRulePrelude(tokens, atRule) {
|
|
|
18645
20100
|
const val = value.chi.splice(valueIndex, 1)[0];
|
|
18646
20101
|
const node = value.chi.splice(nameIndex, 1)[0];
|
|
18647
20102
|
// 'background'
|
|
18648
|
-
// @ts-ignore
|
|
18649
20103
|
if (node.typ == exports.EnumToken.ColorTokenType && node.kin == exports.ColorType.DPSYS) {
|
|
20104
|
+
Object.assign(node, { typ: exports.EnumToken.IdenTokenType });
|
|
18650
20105
|
// @ts-ignore
|
|
18651
20106
|
delete node.kin;
|
|
18652
|
-
node.typ = exports.EnumToken.IdenTokenType;
|
|
18653
20107
|
}
|
|
18654
20108
|
while (value.chi[0]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
18655
20109
|
value.chi.shift();
|
|
@@ -18683,6 +20137,7 @@ async function parseDeclarations(declaration) {
|
|
|
18683
20137
|
return doParse(tokenize$1({
|
|
18684
20138
|
stream: `.x{${declaration}}`,
|
|
18685
20139
|
buffer: '',
|
|
20140
|
+
offset: 0,
|
|
18686
20141
|
position: { ind: 0, lin: 1, col: 1 },
|
|
18687
20142
|
currentPosition: { ind: -1, lin: 1, col: 0 }
|
|
18688
20143
|
}), { setParent: false, minify: false, validation: false }).then(result => {
|
|
@@ -18704,43 +20159,35 @@ function parseSelector(tokens) {
|
|
|
18704
20159
|
}
|
|
18705
20160
|
if (parent == null) {
|
|
18706
20161
|
if (value.typ == exports.EnumToken.GtTokenType) {
|
|
18707
|
-
|
|
18708
|
-
value.typ = exports.EnumToken.ChildCombinatorTokenType;
|
|
20162
|
+
Object.assign(value, { typ: exports.EnumToken.ChildCombinatorTokenType });
|
|
18709
20163
|
}
|
|
18710
20164
|
else if (value.typ == exports.EnumToken.LiteralTokenType) {
|
|
18711
20165
|
if (value.val.charAt(0) == '&') {
|
|
18712
|
-
|
|
18713
|
-
value.typ = exports.EnumToken.NestingSelectorTokenType;
|
|
20166
|
+
Object.assign(value, { typ: exports.EnumToken.NestingSelectorTokenType });
|
|
18714
20167
|
// @ts-ignore
|
|
18715
20168
|
delete value.val;
|
|
18716
20169
|
}
|
|
18717
20170
|
else if (value.val.charAt(0) == '.') {
|
|
18718
20171
|
if (!isIdent(value.val.slice(1))) {
|
|
18719
|
-
|
|
18720
|
-
value.typ = exports.EnumToken.InvalidClassSelectorTokenType;
|
|
20172
|
+
Object.assign(value, { typ: exports.EnumToken.InvalidClassSelectorTokenType });
|
|
18721
20173
|
}
|
|
18722
20174
|
else {
|
|
18723
|
-
|
|
18724
|
-
value.typ = exports.EnumToken.ClassSelectorTokenType;
|
|
20175
|
+
Object.assign(value, { typ: exports.EnumToken.ClassSelectorTokenType });
|
|
18725
20176
|
}
|
|
18726
20177
|
}
|
|
18727
20178
|
if (['*', '>', '+', '~'].includes(value.val)) {
|
|
18728
20179
|
switch (value.val) {
|
|
18729
20180
|
case '*':
|
|
18730
|
-
|
|
18731
|
-
value.typ = exports.EnumToken.UniversalSelectorTokenType;
|
|
20181
|
+
Object.assign(value, { typ: exports.EnumToken.UniversalSelectorTokenType });
|
|
18732
20182
|
break;
|
|
18733
20183
|
case '>':
|
|
18734
|
-
|
|
18735
|
-
value.typ = exports.EnumToken.ChildCombinatorTokenType;
|
|
20184
|
+
Object.assign(value, { typ: exports.EnumToken.ChildCombinatorTokenType });
|
|
18736
20185
|
break;
|
|
18737
20186
|
case '+':
|
|
18738
|
-
|
|
18739
|
-
value.typ = exports.EnumToken.NextSiblingCombinatorTokenType;
|
|
20187
|
+
Object.assign(value, { typ: exports.EnumToken.NextSiblingCombinatorTokenType });
|
|
18740
20188
|
break;
|
|
18741
20189
|
case '~':
|
|
18742
|
-
|
|
18743
|
-
value.typ = exports.EnumToken.SubsequentSiblingCombinatorTokenType;
|
|
20190
|
+
Object.assign(value, { typ: exports.EnumToken.SubsequentSiblingCombinatorTokenType });
|
|
18744
20191
|
break;
|
|
18745
20192
|
}
|
|
18746
20193
|
// @ts-ignore
|
|
@@ -18753,12 +20200,10 @@ function parseSelector(tokens) {
|
|
|
18753
20200
|
if (!isIdent(value.val.slice(1))) {
|
|
18754
20201
|
continue;
|
|
18755
20202
|
}
|
|
18756
|
-
|
|
18757
|
-
value.typ = exports.EnumToken.HashTokenType;
|
|
20203
|
+
Object.assign(value, { typ: exports.EnumToken.HashTokenType });
|
|
18758
20204
|
}
|
|
18759
20205
|
else {
|
|
18760
|
-
|
|
18761
|
-
value.typ = exports.EnumToken.IdenTokenType;
|
|
20206
|
+
Object.assign(value, { typ: exports.EnumToken.IdenTokenType });
|
|
18762
20207
|
}
|
|
18763
20208
|
// @ts-ignore
|
|
18764
20209
|
delete value.kin;
|
|
@@ -18813,6 +20258,7 @@ function parseString(src, options = { location: false }) {
|
|
|
18813
20258
|
const parseInfo = {
|
|
18814
20259
|
stream: src,
|
|
18815
20260
|
buffer: '',
|
|
20261
|
+
offset: 0,
|
|
18816
20262
|
position: { ind: 0, lin: 1, col: 1 },
|
|
18817
20263
|
currentPosition: { ind: -1, lin: 1, col: 0 }
|
|
18818
20264
|
};
|
|
@@ -18821,15 +20267,17 @@ function parseString(src, options = { location: false }) {
|
|
|
18821
20267
|
return acc;
|
|
18822
20268
|
}
|
|
18823
20269
|
const token = getTokenType(t.token, t.hint);
|
|
18824
|
-
|
|
18825
|
-
|
|
18826
|
-
|
|
20270
|
+
Object.defineProperty(token, 'loc', {
|
|
20271
|
+
...definedPropertySettings,
|
|
20272
|
+
value: { sta: t.sta },
|
|
20273
|
+
enumerable: options.location !== false
|
|
20274
|
+
});
|
|
18827
20275
|
acc.push(token);
|
|
18828
20276
|
return acc;
|
|
18829
20277
|
}, []));
|
|
18830
20278
|
}
|
|
18831
20279
|
/**
|
|
18832
|
-
* get token type from a string
|
|
20280
|
+
* get the token type from a string
|
|
18833
20281
|
* @param val
|
|
18834
20282
|
* @param hint
|
|
18835
20283
|
*/
|
|
@@ -18865,7 +20313,7 @@ function getTokenType(val, hint) {
|
|
|
18865
20313
|
case '>':
|
|
18866
20314
|
return { typ: exports.EnumToken.GtTokenType };
|
|
18867
20315
|
}
|
|
18868
|
-
if (isPseudo(val)) {
|
|
20316
|
+
if (val.charAt(0) == ':' && isPseudo(val)) {
|
|
18869
20317
|
return val.endsWith('(') ? {
|
|
18870
20318
|
typ: exports.EnumToken.PseudoClassFuncTokenType,
|
|
18871
20319
|
val: val.slice(0, -1),
|
|
@@ -18882,13 +20330,13 @@ function getTokenType(val, hint) {
|
|
|
18882
20330
|
val
|
|
18883
20331
|
});
|
|
18884
20332
|
}
|
|
18885
|
-
if (isAtKeyword(val)) {
|
|
20333
|
+
if (val.charAt(0) == '@' && isAtKeyword(val)) {
|
|
18886
20334
|
return {
|
|
18887
20335
|
typ: exports.EnumToken.AtRuleTokenType,
|
|
18888
20336
|
val: val.slice(1)
|
|
18889
20337
|
};
|
|
18890
20338
|
}
|
|
18891
|
-
if (isFunction(val)) {
|
|
20339
|
+
if (val.endsWith('(') && isFunction(val)) {
|
|
18892
20340
|
val = val.slice(0, -1);
|
|
18893
20341
|
if (val == 'url') {
|
|
18894
20342
|
return {
|
|
@@ -18936,14 +20384,9 @@ function getTokenType(val, hint) {
|
|
|
18936
20384
|
val: +val.slice(0, -1)
|
|
18937
20385
|
};
|
|
18938
20386
|
}
|
|
18939
|
-
|
|
18940
|
-
|
|
18941
|
-
|
|
18942
|
-
val: +val.slice(0, -2)
|
|
18943
|
-
};
|
|
18944
|
-
}
|
|
18945
|
-
if (isDimension(val)) {
|
|
18946
|
-
return parseDimension(val);
|
|
20387
|
+
const dimension = parseDimension(val);
|
|
20388
|
+
if (dimension != null) {
|
|
20389
|
+
return dimension;
|
|
18947
20390
|
}
|
|
18948
20391
|
const v = val.toLowerCase();
|
|
18949
20392
|
if (v == 'currentcolor' || v == 'transparent' || v in COLORS_NAMES) {
|
|
@@ -18973,6 +20416,12 @@ function getTokenType(val, hint) {
|
|
|
18973
20416
|
val
|
|
18974
20417
|
};
|
|
18975
20418
|
}
|
|
20419
|
+
if (val.charAt(0) == '.' && isIdent(val.slice(1))) {
|
|
20420
|
+
return {
|
|
20421
|
+
typ: exports.EnumToken.ClassSelectorTokenType,
|
|
20422
|
+
val
|
|
20423
|
+
};
|
|
20424
|
+
}
|
|
18976
20425
|
if (val.charAt(0) == '#' && isHexColor(val)) {
|
|
18977
20426
|
return {
|
|
18978
20427
|
typ: exports.EnumToken.ColorTokenType,
|
|
@@ -19020,6 +20469,55 @@ function getTokenType(val, hint) {
|
|
|
19020
20469
|
function parseTokens(tokens, options = {}) {
|
|
19021
20470
|
for (let i = 0; i < tokens.length; i++) {
|
|
19022
20471
|
const t = tokens[i];
|
|
20472
|
+
if (t.typ == exports.EnumToken.IdenTokenType && t.val == 'from' && i > 0) {
|
|
20473
|
+
const left = [];
|
|
20474
|
+
const right = [];
|
|
20475
|
+
let foundLeft = 0;
|
|
20476
|
+
let foundRight = 0;
|
|
20477
|
+
let k = i;
|
|
20478
|
+
let l = i;
|
|
20479
|
+
while (k > 0) {
|
|
20480
|
+
if (tokens[k - 1].typ == exports.EnumToken.CommentTokenType || tokens[k - 1].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
20481
|
+
left.push(tokens[--k]);
|
|
20482
|
+
continue;
|
|
20483
|
+
}
|
|
20484
|
+
if (tokens[k - 1].typ == exports.EnumToken.IdenTokenType || tokens[k - 1].typ == exports.EnumToken.DashedIdenTokenType) {
|
|
20485
|
+
foundLeft++;
|
|
20486
|
+
left.push(tokens[--k]);
|
|
20487
|
+
continue;
|
|
20488
|
+
}
|
|
20489
|
+
break;
|
|
20490
|
+
}
|
|
20491
|
+
while (++l < tokens.length) {
|
|
20492
|
+
if (tokens[l].typ == exports.EnumToken.CommentTokenType || tokens[l].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
20493
|
+
right.push(tokens[l]);
|
|
20494
|
+
continue;
|
|
20495
|
+
}
|
|
20496
|
+
if (tokens[l].typ == exports.EnumToken.IdenTokenType || tokens[l].typ == exports.EnumToken.StringTokenType) {
|
|
20497
|
+
foundRight++;
|
|
20498
|
+
right.push(tokens[l]);
|
|
20499
|
+
continue;
|
|
20500
|
+
}
|
|
20501
|
+
break;
|
|
20502
|
+
}
|
|
20503
|
+
if (foundLeft > 0 && foundRight == 1) {
|
|
20504
|
+
while (left?.[0].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
20505
|
+
left.shift();
|
|
20506
|
+
}
|
|
20507
|
+
while (left.at(-1)?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
20508
|
+
left.pop();
|
|
20509
|
+
}
|
|
20510
|
+
tokens.splice(k, l - k + 1, {
|
|
20511
|
+
typ: exports.EnumToken.ComposesSelectorNodeType,
|
|
20512
|
+
l: left,
|
|
20513
|
+
r: right.reduce((a, b) => {
|
|
20514
|
+
return a == null ? b : b.typ == exports.EnumToken.IdenTokenType || b.typ == exports.EnumToken.StringTokenType ? b : a;
|
|
20515
|
+
}, null)
|
|
20516
|
+
});
|
|
20517
|
+
i = k;
|
|
20518
|
+
continue;
|
|
20519
|
+
}
|
|
20520
|
+
}
|
|
19023
20521
|
if (t.typ == exports.EnumToken.WhitespaceTokenType && ((i == 0 ||
|
|
19024
20522
|
i + 1 == tokens.length ||
|
|
19025
20523
|
[exports.EnumToken.CommaTokenType, exports.EnumToken.GteTokenType, exports.EnumToken.LteTokenType, exports.EnumToken.ColumnCombinatorTokenType].includes(tokens[i + 1].typ)) ||
|
|
@@ -19353,28 +20851,28 @@ exports.WalkerOptionEnum = void 0;
|
|
|
19353
20851
|
*/
|
|
19354
20852
|
WalkerOptionEnum[WalkerOptionEnum["Stop"] = 2] = "Stop";
|
|
19355
20853
|
/**
|
|
19356
|
-
* ignore node and process children
|
|
20854
|
+
* ignore the current node and process its children
|
|
19357
20855
|
*/
|
|
19358
20856
|
WalkerOptionEnum[WalkerOptionEnum["Children"] = 4] = "Children";
|
|
19359
20857
|
/**
|
|
19360
|
-
* ignore children
|
|
20858
|
+
* ignore the current node children
|
|
19361
20859
|
*/
|
|
19362
20860
|
WalkerOptionEnum[WalkerOptionEnum["IgnoreChildren"] = 8] = "IgnoreChildren";
|
|
19363
20861
|
})(exports.WalkerOptionEnum || (exports.WalkerOptionEnum = {}));
|
|
19364
20862
|
/**
|
|
19365
20863
|
* event types for the walkValues function
|
|
19366
20864
|
*/
|
|
19367
|
-
exports.
|
|
19368
|
-
(function (
|
|
20865
|
+
exports.WalkerEvent = void 0;
|
|
20866
|
+
(function (WalkerEvent) {
|
|
19369
20867
|
/**
|
|
19370
20868
|
* enter node
|
|
19371
20869
|
*/
|
|
19372
|
-
|
|
20870
|
+
WalkerEvent[WalkerEvent["Enter"] = 1] = "Enter";
|
|
19373
20871
|
/**
|
|
19374
20872
|
* leave node
|
|
19375
20873
|
*/
|
|
19376
|
-
|
|
19377
|
-
})(exports.
|
|
20874
|
+
WalkerEvent[WalkerEvent["Leave"] = 2] = "Leave";
|
|
20875
|
+
})(exports.WalkerEvent || (exports.WalkerEvent = {}));
|
|
19378
20876
|
/**
|
|
19379
20877
|
* walk ast nodes
|
|
19380
20878
|
* @param node initial node
|
|
@@ -19405,11 +20903,10 @@ exports.WalkerValueEvent = void 0;
|
|
|
19405
20903
|
* }
|
|
19406
20904
|
* ```
|
|
19407
20905
|
*
|
|
19408
|
-
* Using a filter to control the
|
|
20906
|
+
* Using a {@link filter} function to control the ast traversal. the filter function returns a value of type {@link WalkerOption}.
|
|
19409
20907
|
*
|
|
19410
20908
|
* ```ts
|
|
19411
|
-
*
|
|
19412
|
-
* import {walk} from '@tbela99/css-parser';
|
|
20909
|
+
* import {EnumToken, transform, walk, WalkerOptionEnum} from '@tbela99/css-parser';
|
|
19413
20910
|
*
|
|
19414
20911
|
* const css = `
|
|
19415
20912
|
* body { color: color(from var(--base-color) display-p3 r calc(g + 0.24) calc(b + 0.15)); }
|
|
@@ -19425,17 +20922,28 @@ exports.WalkerValueEvent = void 0;
|
|
|
19425
20922
|
* }
|
|
19426
20923
|
* `;
|
|
19427
20924
|
*
|
|
19428
|
-
*
|
|
20925
|
+
* function filter(node) {
|
|
19429
20926
|
*
|
|
19430
20927
|
* if (node.typ == EnumToken.AstRule && node.sel.includes('html')) {
|
|
19431
20928
|
*
|
|
19432
20929
|
* // skip the children of the current node
|
|
19433
20930
|
* return WalkerOptionEnum.IgnoreChildren;
|
|
19434
20931
|
* }
|
|
19435
|
-
* }
|
|
20932
|
+
* }
|
|
19436
20933
|
*
|
|
19437
|
-
*
|
|
20934
|
+
* const result = await transform(css);
|
|
20935
|
+
* for (const {node} of walk(result.ast, filter)) {
|
|
20936
|
+
*
|
|
20937
|
+
* console.error([EnumToken[node.typ]]);
|
|
19438
20938
|
* }
|
|
20939
|
+
*
|
|
20940
|
+
* // [ "StyleSheetNodeType" ]
|
|
20941
|
+
* // [ "RuleNodeType" ]
|
|
20942
|
+
* // [ "DeclarationNodeType" ]
|
|
20943
|
+
* // [ "RuleNodeType" ]
|
|
20944
|
+
* // [ "DeclarationNodeType" ]
|
|
20945
|
+
* // [ "RuleNodeType" ]
|
|
20946
|
+
* // [ "DeclarationNodeType" ]
|
|
19439
20947
|
* ```
|
|
19440
20948
|
*/
|
|
19441
20949
|
function* walk(node, filter, reverse) {
|
|
@@ -19443,7 +20951,8 @@ function* walk(node, filter, reverse) {
|
|
|
19443
20951
|
const root = node;
|
|
19444
20952
|
const map = new Map;
|
|
19445
20953
|
let isNumeric = false;
|
|
19446
|
-
|
|
20954
|
+
let i = 0;
|
|
20955
|
+
while ((node = parents[i++])) {
|
|
19447
20956
|
let option = null;
|
|
19448
20957
|
if (filter != null) {
|
|
19449
20958
|
option = filter(node);
|
|
@@ -19462,8 +20971,8 @@ function* walk(node, filter, reverse) {
|
|
|
19462
20971
|
yield { node, parent: map.get(node), root };
|
|
19463
20972
|
}
|
|
19464
20973
|
if ('chi' in node && (!isNumeric || ((option & exports.WalkerOptionEnum.IgnoreChildren) === 0))) {
|
|
19465
|
-
parents.
|
|
19466
|
-
for (const child of node.chi
|
|
20974
|
+
parents.splice(i, 0, ...node.chi[reverse ? 'reverse' : 'slice']());
|
|
20975
|
+
for (const child of node.chi) {
|
|
19467
20976
|
map.set(child, node);
|
|
19468
20977
|
}
|
|
19469
20978
|
}
|
|
@@ -19480,55 +20989,68 @@ function* walk(node, filter, reverse) {
|
|
|
19480
20989
|
*
|
|
19481
20990
|
* ```ts
|
|
19482
20991
|
*
|
|
19483
|
-
* import {EnumToken,
|
|
20992
|
+
* import {AstDeclaration, EnumToken, transform, walkValues} from '@tbela99/css-parser';
|
|
19484
20993
|
*
|
|
19485
20994
|
* const css = `
|
|
19486
20995
|
* body { color: color(from var(--base-color) display-p3 r calc(g + 0.24) calc(b + 0.15)); }
|
|
19487
|
-
*
|
|
19488
|
-
* html,
|
|
19489
|
-
* body {
|
|
19490
|
-
* line-height: 1.474;
|
|
19491
|
-
* }
|
|
19492
|
-
*
|
|
19493
|
-
* .ruler {
|
|
19494
|
-
*
|
|
19495
|
-
* height: 10px;
|
|
19496
|
-
* }
|
|
19497
20996
|
* `;
|
|
19498
20997
|
*
|
|
19499
|
-
*
|
|
20998
|
+
* const result = await transform(css);
|
|
20999
|
+
* const declaration = result.ast.chi[0].chi[0] as AstDeclaration;
|
|
21000
|
+
*
|
|
21001
|
+
* // walk the node attribute's tokens in reverse order
|
|
21002
|
+
* for (const {value} of walkValues(declaration.val, null, null,true)) {
|
|
19500
21003
|
*
|
|
19501
21004
|
* console.error([EnumToken[value.typ], value.val]);
|
|
19502
21005
|
* }
|
|
19503
21006
|
*
|
|
21007
|
+
* // [ "Color", "color" ]
|
|
21008
|
+
* // [ "FunctionTokenType", "calc" ]
|
|
21009
|
+
* // [ "Number", 0.15 ]
|
|
21010
|
+
* // [ "Add", undefined ]
|
|
21011
|
+
* // [ "Iden", "b" ]
|
|
21012
|
+
* // [ "Whitespace", undefined ]
|
|
21013
|
+
* // [ "FunctionTokenType", "calc" ]
|
|
21014
|
+
* // [ "Number", 0.24 ]
|
|
21015
|
+
* // [ "Add", undefined ]
|
|
21016
|
+
* // [ "Iden", "g" ]
|
|
21017
|
+
* // [ "Whitespace", undefined ]
|
|
21018
|
+
* // [ "Iden", "r" ]
|
|
21019
|
+
* // [ "Whitespace", undefined ]
|
|
21020
|
+
* // [ "Iden", "display-p3" ]
|
|
21021
|
+
* // [ "Whitespace", undefined ]
|
|
21022
|
+
* // [ "FunctionTokenType", "var" ]
|
|
21023
|
+
* // [ "DashedIden", "--base-color" ]
|
|
21024
|
+
* // [ "Whitespace", undefined ]
|
|
21025
|
+
* // [ "Iden", "from" ]
|
|
21026
|
+
* ```
|
|
19504
21027
|
*/
|
|
19505
21028
|
function* walkValues(values, root = null, filter, reverse) {
|
|
19506
|
-
// const set = new Set<Token>();
|
|
19507
21029
|
const stack = values.slice();
|
|
19508
21030
|
const map = new Map;
|
|
19509
21031
|
let previous = null;
|
|
19510
21032
|
if (filter != null && typeof filter == 'function') {
|
|
19511
21033
|
filter = {
|
|
19512
|
-
event: exports.
|
|
21034
|
+
event: exports.WalkerEvent.Enter,
|
|
19513
21035
|
fn: filter
|
|
19514
21036
|
};
|
|
19515
21037
|
}
|
|
19516
21038
|
else if (filter == null) {
|
|
19517
21039
|
filter = {
|
|
19518
|
-
event: exports.
|
|
21040
|
+
event: exports.WalkerEvent.Enter
|
|
19519
21041
|
};
|
|
19520
21042
|
}
|
|
19521
21043
|
let isNumeric = false;
|
|
19522
|
-
const eventType = filter.event ?? exports.
|
|
21044
|
+
const eventType = filter.event ?? exports.WalkerEvent.Enter;
|
|
19523
21045
|
while (stack.length > 0) {
|
|
19524
21046
|
let value = reverse ? stack.pop() : stack.shift();
|
|
19525
21047
|
let option = null;
|
|
19526
|
-
if (filter.fn != null && (eventType & exports.
|
|
21048
|
+
if (filter.fn != null && (eventType & exports.WalkerEvent.Enter)) {
|
|
19527
21049
|
const isValid = filter.type == null || value.typ == filter.type ||
|
|
19528
21050
|
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
19529
21051
|
(typeof filter.type == 'function' && filter.type(value));
|
|
19530
21052
|
if (isValid) {
|
|
19531
|
-
option = filter.fn(value, map.get(value) ?? root, exports.
|
|
21053
|
+
option = filter.fn(value, map.get(value) ?? root, exports.WalkerEvent.Enter);
|
|
19532
21054
|
isNumeric = typeof option == 'number';
|
|
19533
21055
|
if (isNumeric && (option & exports.WalkerOptionEnum.Stop)) {
|
|
19534
21056
|
return;
|
|
@@ -19537,12 +21059,15 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
19537
21059
|
continue;
|
|
19538
21060
|
}
|
|
19539
21061
|
// @ts-ignore
|
|
19540
|
-
if (option != null && typeof option == 'object' && 'typ' in option) {
|
|
19541
|
-
|
|
21062
|
+
if (option != null && typeof option == 'object' && ('typ' in option || Array.isArray(option))) {
|
|
21063
|
+
const op = Array.isArray(option) ? option : [option];
|
|
21064
|
+
for (const o of op) {
|
|
21065
|
+
map.set(o, map.get(value) ?? root);
|
|
21066
|
+
}
|
|
21067
|
+
stack[reverse ? 'push' : 'unshift'](...op);
|
|
19542
21068
|
}
|
|
19543
21069
|
}
|
|
19544
21070
|
}
|
|
19545
|
-
// if ((eventType & WalkerValueEvent.Enter) && (!isNumeric || ((option as number) & WalkerOptionEnum.Children) === 0)) {
|
|
19546
21071
|
yield {
|
|
19547
21072
|
value,
|
|
19548
21073
|
parent: map.get(value) ?? root,
|
|
@@ -19551,7 +21076,6 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
19551
21076
|
// @ts-ignore
|
|
19552
21077
|
root: root ?? null
|
|
19553
21078
|
};
|
|
19554
|
-
// }
|
|
19555
21079
|
if ('chi' in value && (!isNumeric || (option & exports.WalkerOptionEnum.IgnoreChildren) === 0)) {
|
|
19556
21080
|
const sliced = value.chi.slice();
|
|
19557
21081
|
for (const child of sliced) {
|
|
@@ -19563,12 +21087,12 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
19563
21087
|
const values = [];
|
|
19564
21088
|
if ('l' in value && value.l != null) {
|
|
19565
21089
|
// @ts-ignore
|
|
19566
|
-
values
|
|
21090
|
+
values.push(value.l);
|
|
19567
21091
|
// @ts-ignore
|
|
19568
21092
|
map.set(value.l, value);
|
|
19569
21093
|
}
|
|
19570
21094
|
if ('op' in value && typeof value.op == 'object') {
|
|
19571
|
-
values
|
|
21095
|
+
values.push(value.op);
|
|
19572
21096
|
// @ts-ignore
|
|
19573
21097
|
map.set(value.op, value);
|
|
19574
21098
|
}
|
|
@@ -19576,14 +21100,14 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
19576
21100
|
if (Array.isArray(value.r)) {
|
|
19577
21101
|
for (const r of value.r) {
|
|
19578
21102
|
// @ts-ignore
|
|
19579
|
-
values
|
|
21103
|
+
values.push(r);
|
|
19580
21104
|
// @ts-ignore
|
|
19581
21105
|
map.set(r, value);
|
|
19582
21106
|
}
|
|
19583
21107
|
}
|
|
19584
21108
|
else {
|
|
19585
21109
|
// @ts-ignore
|
|
19586
|
-
values
|
|
21110
|
+
values.push(value.r);
|
|
19587
21111
|
// @ts-ignore
|
|
19588
21112
|
map.set(value.r, value);
|
|
19589
21113
|
}
|
|
@@ -19592,29 +21116,22 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
19592
21116
|
stack[reverse ? 'push' : 'unshift'](...values);
|
|
19593
21117
|
}
|
|
19594
21118
|
}
|
|
19595
|
-
if ((eventType & exports.
|
|
21119
|
+
if ((eventType & exports.WalkerEvent.Leave) && filter.fn != null) {
|
|
19596
21120
|
const isValid = filter.type == null || value.typ == filter.type ||
|
|
19597
21121
|
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
19598
21122
|
(typeof filter.type == 'function' && filter.type(value));
|
|
19599
21123
|
if (isValid) {
|
|
19600
|
-
option = filter.fn(value, map.get(value), exports.
|
|
21124
|
+
option = filter.fn(value, map.get(value), exports.WalkerEvent.Leave);
|
|
19601
21125
|
// @ts-ignore
|
|
19602
|
-
if (option != null && 'typ' in option) {
|
|
19603
|
-
|
|
21126
|
+
if (option != null && ('typ' in option || Array.isArray(option))) {
|
|
21127
|
+
const op = Array.isArray(option) ? option : [option];
|
|
21128
|
+
for (const o of op) {
|
|
21129
|
+
map.set(o, map.get(value) ?? root);
|
|
21130
|
+
}
|
|
21131
|
+
stack[reverse ? 'push' : 'unshift'](...op);
|
|
19604
21132
|
}
|
|
19605
21133
|
}
|
|
19606
21134
|
}
|
|
19607
|
-
// if ((eventType & WalkerValueEvent.Leave) && (!isNumeric && ((option as number) & WalkerOptionEnum.Children) === 0)) {
|
|
19608
|
-
//
|
|
19609
|
-
// yield {
|
|
19610
|
-
// value,
|
|
19611
|
-
// parent: <FunctionToken | ParensToken>map.get(value) ?? root,
|
|
19612
|
-
// previousValue: previous,
|
|
19613
|
-
// nextValue: <Token>stack[0] ?? null,
|
|
19614
|
-
// // @ts-ignore
|
|
19615
|
-
// root: root ?? null
|
|
19616
|
-
// };
|
|
19617
|
-
// }
|
|
19618
21135
|
previous = value;
|
|
19619
21136
|
}
|
|
19620
21137
|
}
|
|
@@ -19725,6 +21242,7 @@ class ComputePrefixFeature {
|
|
|
19725
21242
|
}
|
|
19726
21243
|
}
|
|
19727
21244
|
}
|
|
21245
|
+
// @ts-ignore
|
|
19728
21246
|
if (SyntaxValidationResult.Valid == evaluateSyntax({ ...node, val: nodes }, {}).valid) {
|
|
19729
21247
|
node.val = nodes;
|
|
19730
21248
|
}
|
|
@@ -19790,6 +21308,7 @@ function replace(node, variableScope) {
|
|
|
19790
21308
|
}
|
|
19791
21309
|
}
|
|
19792
21310
|
class InlineCssVariablesFeature {
|
|
21311
|
+
accept = new Set([exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType]);
|
|
19793
21312
|
get ordering() {
|
|
19794
21313
|
return 0;
|
|
19795
21314
|
}
|
|
@@ -19803,9 +21322,10 @@ class InlineCssVariablesFeature {
|
|
|
19803
21322
|
}
|
|
19804
21323
|
}
|
|
19805
21324
|
run(ast, options = {}, parent, context) {
|
|
19806
|
-
if (!('chi' in ast)) {
|
|
19807
|
-
|
|
19808
|
-
|
|
21325
|
+
// if (!('chi' in ast)) {
|
|
21326
|
+
//
|
|
21327
|
+
// return null;
|
|
21328
|
+
// }
|
|
19809
21329
|
if (!('variableScope' in context)) {
|
|
19810
21330
|
context.variableScope = new Map;
|
|
19811
21331
|
}
|
|
@@ -20686,8 +22206,13 @@ class PropertyList {
|
|
|
20686
22206
|
});
|
|
20687
22207
|
}
|
|
20688
22208
|
add(...declarations) {
|
|
22209
|
+
let name;
|
|
20689
22210
|
for (const declaration of declarations) {
|
|
20690
|
-
|
|
22211
|
+
name = declaration.typ != exports.EnumToken.DeclarationNodeType ? null : declaration.nam.toLowerCase();
|
|
22212
|
+
if (declaration.typ != exports.EnumToken.DeclarationNodeType ||
|
|
22213
|
+
'composes' === name ||
|
|
22214
|
+
(typeof this.options.removeDuplicateDeclarations === 'string' && this.options.removeDuplicateDeclarations === name) ||
|
|
22215
|
+
(Array.isArray(this.options.removeDuplicateDeclarations) ? this.options.removeDuplicateDeclarations.includes(declaration.nam) : !this.options.removeDuplicateDeclarations)) {
|
|
20691
22216
|
this.declarations.set(Number(Math.random().toString().slice(2)).toString(36), declaration);
|
|
20692
22217
|
continue;
|
|
20693
22218
|
}
|
|
@@ -20772,6 +22297,7 @@ class PropertyList {
|
|
|
20772
22297
|
}
|
|
20773
22298
|
|
|
20774
22299
|
class ComputeShorthandFeature {
|
|
22300
|
+
accept = new Set([exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyFramesRuleNodeType]);
|
|
20775
22301
|
get ordering() {
|
|
20776
22302
|
return 3;
|
|
20777
22303
|
}
|
|
@@ -20824,6 +22350,7 @@ class ComputeShorthandFeature {
|
|
|
20824
22350
|
}
|
|
20825
22351
|
|
|
20826
22352
|
class ComputeCalcExpressionFeature {
|
|
22353
|
+
accept = new Set([exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType]);
|
|
20827
22354
|
get ordering() {
|
|
20828
22355
|
return 1;
|
|
20829
22356
|
}
|
|
@@ -20846,7 +22373,7 @@ class ComputeCalcExpressionFeature {
|
|
|
20846
22373
|
}
|
|
20847
22374
|
const set = new Set;
|
|
20848
22375
|
for (const { value, parent } of walkValues(node.val, node, {
|
|
20849
|
-
event: exports.
|
|
22376
|
+
event: exports.WalkerEvent.Enter,
|
|
20850
22377
|
// @ts-ignore
|
|
20851
22378
|
fn(node, parent) {
|
|
20852
22379
|
if (parent != null &&
|
|
@@ -20923,7 +22450,7 @@ class ComputeCalcExpressionFeature {
|
|
|
20923
22450
|
|
|
20924
22451
|
function translateX(x, from) {
|
|
20925
22452
|
const matrix = identity();
|
|
20926
|
-
matrix[3 * 4
|
|
22453
|
+
matrix[3 * 4] = x;
|
|
20927
22454
|
return multiply(from, matrix);
|
|
20928
22455
|
}
|
|
20929
22456
|
function translateY(y, from) {
|
|
@@ -20938,13 +22465,13 @@ function translateZ(z, from) {
|
|
|
20938
22465
|
}
|
|
20939
22466
|
function translate(translate, from) {
|
|
20940
22467
|
const matrix = identity();
|
|
20941
|
-
matrix[3 * 4
|
|
22468
|
+
matrix[3 * 4] = translate[0];
|
|
20942
22469
|
matrix[3 * 4 + 1] = translate[1] ?? 0;
|
|
20943
22470
|
return multiply(from, matrix);
|
|
20944
22471
|
}
|
|
20945
22472
|
function translate3d(translate, from) {
|
|
20946
22473
|
const matrix = identity();
|
|
20947
|
-
matrix[3 * 4
|
|
22474
|
+
matrix[3 * 4] = translate[0];
|
|
20948
22475
|
matrix[3 * 4 + 1] = translate[1];
|
|
20949
22476
|
matrix[3 * 4 + 2] = translate[2];
|
|
20950
22477
|
return multiply(from, matrix);
|
|
@@ -20967,34 +22494,34 @@ function rotate3D(angle, x, y, z, from) {
|
|
|
20967
22494
|
x *= unit;
|
|
20968
22495
|
y *= unit;
|
|
20969
22496
|
z *= unit;
|
|
20970
|
-
matrix[0
|
|
20971
|
-
matrix[
|
|
20972
|
-
matrix[
|
|
20973
|
-
matrix[
|
|
20974
|
-
matrix[
|
|
20975
|
-
matrix[
|
|
20976
|
-
matrix[2 * 4
|
|
22497
|
+
matrix[0] = 1 - 2 * (y * y + z * z) * sq;
|
|
22498
|
+
matrix[1] = 2 * (x * y * sq + z * sc);
|
|
22499
|
+
matrix[2] = 2 * (x * z * sq - y * sc);
|
|
22500
|
+
matrix[4] = 2 * (x * y * sq - z * sc);
|
|
22501
|
+
matrix[4 + 1] = 1 - 2 * (x * x + z * z) * sq;
|
|
22502
|
+
matrix[4 + 2] = 2 * (y * z * sq + x * sc);
|
|
22503
|
+
matrix[2 * 4] = 2 * (x * z * sq + y * sc);
|
|
20977
22504
|
matrix[2 * 4 + 1] = 2 * (y * z * sq - x * sc);
|
|
20978
22505
|
matrix[2 * 4 + 2] = 1 - 2 * (x * x + y * y) * sq;
|
|
20979
22506
|
return multiply(from, matrix);
|
|
20980
22507
|
}
|
|
20981
22508
|
function rotate(angle, from) {
|
|
20982
22509
|
const matrix = identity();
|
|
20983
|
-
matrix[0
|
|
20984
|
-
matrix[
|
|
20985
|
-
matrix[
|
|
20986
|
-
matrix[
|
|
22510
|
+
matrix[0] = Math.cos(angle);
|
|
22511
|
+
matrix[1] = Math.sin(angle);
|
|
22512
|
+
matrix[4] = -Math.sin(angle);
|
|
22513
|
+
matrix[4 + 1] = Math.cos(angle);
|
|
20987
22514
|
return multiply(from, matrix);
|
|
20988
22515
|
}
|
|
20989
22516
|
|
|
20990
22517
|
function scaleX(x, from) {
|
|
20991
22518
|
const matrix = identity();
|
|
20992
|
-
matrix[0
|
|
22519
|
+
matrix[0] = x;
|
|
20993
22520
|
return multiply(from, matrix);
|
|
20994
22521
|
}
|
|
20995
22522
|
function scaleY(y, from) {
|
|
20996
22523
|
const matrix = identity();
|
|
20997
|
-
matrix[
|
|
22524
|
+
matrix[4 + 1] = y;
|
|
20998
22525
|
return multiply(from, matrix);
|
|
20999
22526
|
}
|
|
21000
22527
|
function scaleZ(z, from) {
|
|
@@ -21004,14 +22531,14 @@ function scaleZ(z, from) {
|
|
|
21004
22531
|
}
|
|
21005
22532
|
function scale(x, y, from) {
|
|
21006
22533
|
const matrix = identity();
|
|
21007
|
-
matrix[0
|
|
21008
|
-
matrix[
|
|
22534
|
+
matrix[0] = x;
|
|
22535
|
+
matrix[4 + 1] = y;
|
|
21009
22536
|
return multiply(from, matrix);
|
|
21010
22537
|
}
|
|
21011
22538
|
function scale3d(x, y, z, from) {
|
|
21012
22539
|
const matrix = identity();
|
|
21013
|
-
matrix[0
|
|
21014
|
-
matrix[
|
|
22540
|
+
matrix[0] = x;
|
|
22541
|
+
matrix[4 + 1] = y;
|
|
21015
22542
|
matrix[2 * 4 + 2] = z;
|
|
21016
22543
|
return multiply(from, matrix);
|
|
21017
22544
|
}
|
|
@@ -21036,27 +22563,27 @@ function parseMatrix(mat) {
|
|
|
21036
22563
|
function matrix(values) {
|
|
21037
22564
|
const matrix = identity();
|
|
21038
22565
|
if (values.length === 6) {
|
|
21039
|
-
matrix[0
|
|
21040
|
-
matrix[
|
|
21041
|
-
matrix[
|
|
21042
|
-
matrix[
|
|
21043
|
-
matrix[3 * 4
|
|
22566
|
+
matrix[0] = values[0];
|
|
22567
|
+
matrix[1] = values[1];
|
|
22568
|
+
matrix[4] = values[2];
|
|
22569
|
+
matrix[4 + 1] = values[3];
|
|
22570
|
+
matrix[3 * 4] = values[4];
|
|
21044
22571
|
matrix[3 * 4 + 1] = values[5];
|
|
21045
22572
|
}
|
|
21046
22573
|
else if (values.length === 16) {
|
|
21047
|
-
matrix[0
|
|
21048
|
-
matrix[
|
|
21049
|
-
matrix[
|
|
21050
|
-
matrix[
|
|
21051
|
-
matrix[
|
|
21052
|
-
matrix[
|
|
21053
|
-
matrix[
|
|
21054
|
-
matrix[
|
|
21055
|
-
matrix[2 * 4
|
|
22574
|
+
matrix[0] = values[0];
|
|
22575
|
+
matrix[1] = values[1];
|
|
22576
|
+
matrix[2] = values[2];
|
|
22577
|
+
matrix[3] = values[3];
|
|
22578
|
+
matrix[4] = values[4];
|
|
22579
|
+
matrix[4 + 1] = values[5];
|
|
22580
|
+
matrix[4 + 2] = values[6];
|
|
22581
|
+
matrix[4 + 3] = values[7];
|
|
22582
|
+
matrix[2 * 4] = values[8];
|
|
21056
22583
|
matrix[2 * 4 + 1] = values[9];
|
|
21057
22584
|
matrix[2 * 4 + 2] = values[10];
|
|
21058
22585
|
matrix[2 * 4 + 3] = values[11];
|
|
21059
|
-
matrix[3 * 4
|
|
22586
|
+
matrix[3 * 4] = values[12];
|
|
21060
22587
|
matrix[3 * 4 + 1] = values[13];
|
|
21061
22588
|
matrix[3 * 4 + 2] = values[14];
|
|
21062
22589
|
matrix[3 * 4 + 3] = values[15];
|
|
@@ -21081,11 +22608,11 @@ function serialize(matrix) {
|
|
|
21081
22608
|
typ: exports.EnumToken.FunctionTokenType,
|
|
21082
22609
|
val: 'matrix',
|
|
21083
22610
|
chi: [
|
|
21084
|
-
matrix[0
|
|
21085
|
-
matrix[
|
|
21086
|
-
matrix[
|
|
21087
|
-
matrix[
|
|
21088
|
-
matrix[3 * 4
|
|
22611
|
+
matrix[0],
|
|
22612
|
+
matrix[1],
|
|
22613
|
+
matrix[4],
|
|
22614
|
+
matrix[4 + 1],
|
|
22615
|
+
matrix[3 * 4],
|
|
21089
22616
|
matrix[3 * 4 + 1]
|
|
21090
22617
|
].reduce((acc, t) => {
|
|
21091
22618
|
if (acc.length > 0) {
|
|
@@ -21268,10 +22795,6 @@ function minify$1(matrix) {
|
|
|
21268
22795
|
}
|
|
21269
22796
|
}
|
|
21270
22797
|
if (transforms.has('skew')) {
|
|
21271
|
-
// if (round(decomposed.skew[0]) == 0) {
|
|
21272
|
-
//
|
|
21273
|
-
// skew.delete('x');
|
|
21274
|
-
// }
|
|
21275
22798
|
if (round(decomposed.skew[1]) == 0) {
|
|
21276
22799
|
skew.delete('y');
|
|
21277
22800
|
}
|
|
@@ -21311,7 +22834,7 @@ function minify$1(matrix) {
|
|
|
21311
22834
|
scales.delete('x');
|
|
21312
22835
|
}
|
|
21313
22836
|
if (scales.size == 1) {
|
|
21314
|
-
let prefix = scales.has('x') ? '' : scales.has('y') ? 'Y' : 'Z';
|
|
22837
|
+
let prefix = scales.has('x') ? 'X' : scales.has('y') ? 'Y' : 'Z';
|
|
21315
22838
|
result.push({
|
|
21316
22839
|
typ: exports.EnumToken.FunctionTokenType,
|
|
21317
22840
|
val: 'scale' + prefix,
|
|
@@ -21354,13 +22877,9 @@ function minify$1(matrix) {
|
|
|
21354
22877
|
] : result;
|
|
21355
22878
|
}
|
|
21356
22879
|
function eqMatrix(a, b) {
|
|
21357
|
-
// console.error(JSON.stringify({a, b}, null, 1));
|
|
21358
22880
|
let mat = identity();
|
|
21359
22881
|
let tmp = identity();
|
|
21360
|
-
// @ts-ignore
|
|
21361
22882
|
const data = (Array.isArray(a) ? a : parseMatrix(a));
|
|
21362
|
-
// toZero(data);
|
|
21363
|
-
// console.error({data});
|
|
21364
22883
|
for (const transform of b) {
|
|
21365
22884
|
tmp = computeMatrix([transform], identity());
|
|
21366
22885
|
if (tmp == null) {
|
|
@@ -21368,8 +22887,6 @@ function eqMatrix(a, b) {
|
|
|
21368
22887
|
}
|
|
21369
22888
|
mat = multiply(mat, tmp);
|
|
21370
22889
|
}
|
|
21371
|
-
// toZero(mat);
|
|
21372
|
-
// console.error({mat});
|
|
21373
22890
|
if (mat == null) {
|
|
21374
22891
|
return false;
|
|
21375
22892
|
}
|
|
@@ -21382,23 +22899,126 @@ function eqMatrix(a, b) {
|
|
|
21382
22899
|
}
|
|
21383
22900
|
return true;
|
|
21384
22901
|
}
|
|
22902
|
+
function minifyTransformFunctions(transform) {
|
|
22903
|
+
const name = transform.val.toLowerCase();
|
|
22904
|
+
if ('skewx' == name) {
|
|
22905
|
+
transform.val = 'skew';
|
|
22906
|
+
return transform;
|
|
22907
|
+
}
|
|
22908
|
+
if (!['translate', 'translate3d', 'scale', 'scale3d'].includes(name)) {
|
|
22909
|
+
return transform;
|
|
22910
|
+
}
|
|
22911
|
+
const values = [];
|
|
22912
|
+
for (const token of transform.chi) {
|
|
22913
|
+
if (token.typ == exports.EnumToken.CommentTokenType || token.typ == exports.EnumToken.WhitespaceTokenType || token.typ == exports.EnumToken.CommaTokenType) {
|
|
22914
|
+
continue;
|
|
22915
|
+
}
|
|
22916
|
+
if (![exports.EnumToken.NumberTokenType, exports.EnumToken.LengthTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.PercentageTokenType].includes(token.typ)) {
|
|
22917
|
+
return transform;
|
|
22918
|
+
}
|
|
22919
|
+
if (token.typ == exports.EnumToken.PercentageTokenType && typeof token.val == 'number' && name.startsWith('scale')) {
|
|
22920
|
+
Object.assign(token, { typ: exports.EnumToken.NumberTokenType, val: token.val / 100 });
|
|
22921
|
+
}
|
|
22922
|
+
values.push(token);
|
|
22923
|
+
}
|
|
22924
|
+
if ((name == 'translate' || name == 'scale') && values.length > 2) {
|
|
22925
|
+
return transform;
|
|
22926
|
+
}
|
|
22927
|
+
const ignoredValue = name.startsWith('scale') ? 1 : 0;
|
|
22928
|
+
const t = new Set(['x', 'y', 'z']);
|
|
22929
|
+
let i = 3;
|
|
22930
|
+
while (i--) {
|
|
22931
|
+
if (values.length <= i || values[i].val == ignoredValue) {
|
|
22932
|
+
t.delete(i == 0 ? 'x' : i == 1 ? 'y' : 'z');
|
|
22933
|
+
}
|
|
22934
|
+
}
|
|
22935
|
+
if (name == 'translate3d' || name == 'translate') {
|
|
22936
|
+
if (t.size == 0) {
|
|
22937
|
+
return {
|
|
22938
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
22939
|
+
val: 'translate',
|
|
22940
|
+
chi: [
|
|
22941
|
+
{ typ: exports.EnumToken.NumberTokenType, val: 0 }
|
|
22942
|
+
]
|
|
22943
|
+
};
|
|
22944
|
+
}
|
|
22945
|
+
if (t.size == 1) {
|
|
22946
|
+
return {
|
|
22947
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
22948
|
+
val: 'translate' + (t.has('x') ? '' : t.has('y') ? 'Y' : 'Z'),
|
|
22949
|
+
chi: [
|
|
22950
|
+
values[t.has('x') ? 0 : t.has('y') ? 1 : 2]
|
|
22951
|
+
]
|
|
22952
|
+
};
|
|
22953
|
+
}
|
|
22954
|
+
if (t.size == 2) {
|
|
22955
|
+
if (t.has('z')) {
|
|
22956
|
+
return transform;
|
|
22957
|
+
}
|
|
22958
|
+
return {
|
|
22959
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
22960
|
+
val: 'translate',
|
|
22961
|
+
chi: [
|
|
22962
|
+
values[0],
|
|
22963
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
22964
|
+
values[1]
|
|
22965
|
+
]
|
|
22966
|
+
};
|
|
22967
|
+
}
|
|
22968
|
+
}
|
|
22969
|
+
if (name == 'scale3d' || name == 'scale') {
|
|
22970
|
+
if (t.size == 0) {
|
|
22971
|
+
return {
|
|
22972
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
22973
|
+
val: 'scale',
|
|
22974
|
+
chi: [
|
|
22975
|
+
{ typ: exports.EnumToken.NumberTokenType, val: 1 }
|
|
22976
|
+
]
|
|
22977
|
+
};
|
|
22978
|
+
}
|
|
22979
|
+
if (t.size == 1) {
|
|
22980
|
+
return {
|
|
22981
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
22982
|
+
val: 'scale' + (t.has('x') ? 'X' : t.has('y') ? 'Y' : 'Z'),
|
|
22983
|
+
chi: [
|
|
22984
|
+
values[t.has('x') ? 0 : t.has('y') ? 1 : 2]
|
|
22985
|
+
]
|
|
22986
|
+
};
|
|
22987
|
+
}
|
|
22988
|
+
if (t.size == 2) {
|
|
22989
|
+
if (t.has('z')) {
|
|
22990
|
+
return transform;
|
|
22991
|
+
}
|
|
22992
|
+
return {
|
|
22993
|
+
typ: exports.EnumToken.FunctionTokenType,
|
|
22994
|
+
val: 'scale',
|
|
22995
|
+
chi: [
|
|
22996
|
+
values[0],
|
|
22997
|
+
{ typ: exports.EnumToken.CommaTokenType },
|
|
22998
|
+
values[1]
|
|
22999
|
+
]
|
|
23000
|
+
};
|
|
23001
|
+
}
|
|
23002
|
+
}
|
|
23003
|
+
return transform;
|
|
23004
|
+
}
|
|
21385
23005
|
|
|
21386
23006
|
function skewX(x, from) {
|
|
21387
23007
|
const matrix = identity();
|
|
21388
|
-
matrix[
|
|
23008
|
+
matrix[4] = Math.tan(x);
|
|
21389
23009
|
return multiply(from, matrix);
|
|
21390
23010
|
}
|
|
21391
23011
|
function skewY(y, from) {
|
|
21392
23012
|
const matrix = identity();
|
|
21393
|
-
matrix[
|
|
23013
|
+
matrix[1] = Math.tan(y);
|
|
21394
23014
|
return multiply(from, matrix);
|
|
21395
23015
|
}
|
|
21396
23016
|
// convert angle to radian
|
|
21397
23017
|
function skew(values, from) {
|
|
21398
23018
|
const matrix = identity();
|
|
21399
|
-
matrix[
|
|
23019
|
+
matrix[4] = Math.tan(values[0]);
|
|
21400
23020
|
if (values.length > 1) {
|
|
21401
|
-
matrix[
|
|
23021
|
+
matrix[1] = Math.tan(values[1]);
|
|
21402
23022
|
}
|
|
21403
23023
|
return multiply(from, matrix);
|
|
21404
23024
|
}
|
|
@@ -21437,8 +23057,6 @@ function compute(transformLists) {
|
|
|
21437
23057
|
});
|
|
21438
23058
|
}
|
|
21439
23059
|
}
|
|
21440
|
-
// console.error({matrix});
|
|
21441
|
-
// matrix = toZero(matrix) as Matrix;
|
|
21442
23060
|
return {
|
|
21443
23061
|
matrix: serialize(toZero(matrix)),
|
|
21444
23062
|
cumulative,
|
|
@@ -21462,7 +23080,7 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
21462
23080
|
{
|
|
21463
23081
|
values.length = 0;
|
|
21464
23082
|
const children = stripCommaToken(transformList[i].chi.slice());
|
|
21465
|
-
const valCount = transformList[i].val == 'translate3d'
|
|
23083
|
+
const valCount = transformList[i].val == 'translate3d' ? 3 : transformList[i].val == 'translate' ? 2 : 1;
|
|
21466
23084
|
for (let j = 0; j < children.length; j++) {
|
|
21467
23085
|
if (children[j].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
21468
23086
|
continue;
|
|
@@ -21549,7 +23167,7 @@ function computeMatrix(transformList, matrixVar) {
|
|
|
21549
23167
|
const children = stripCommaToken(transformList[i].chi.slice());
|
|
21550
23168
|
for (let k = 0; k < children.length; k++) {
|
|
21551
23169
|
child = children[k];
|
|
21552
|
-
if (child.typ != exports.EnumToken.NumberTokenType) {
|
|
23170
|
+
if (child.typ != exports.EnumToken.NumberTokenType && child.typ != exports.EnumToken.PercentageTokenType) {
|
|
21553
23171
|
return null;
|
|
21554
23172
|
}
|
|
21555
23173
|
values.push(getNumber(child));
|
|
@@ -21703,6 +23321,7 @@ function splitTransformList(transformList) {
|
|
|
21703
23321
|
}
|
|
21704
23322
|
|
|
21705
23323
|
class TransformCssFeature {
|
|
23324
|
+
accept = new Set([exports.EnumToken.RuleNodeType, exports.EnumToken.KeyFramesRuleNodeType]);
|
|
21706
23325
|
get ordering() {
|
|
21707
23326
|
return 4;
|
|
21708
23327
|
}
|
|
@@ -21729,28 +23348,21 @@ class TransformCssFeature {
|
|
|
21729
23348
|
if (node.typ != exports.EnumToken.DeclarationNodeType || !node.nam.match(/^(-[a-z]+-)?transform$/)) {
|
|
21730
23349
|
continue;
|
|
21731
23350
|
}
|
|
21732
|
-
const children =
|
|
21733
|
-
|
|
21734
|
-
|
|
21735
|
-
|
|
21736
|
-
curr.chi.length = 1;
|
|
21737
|
-
curr.val = 'skew';
|
|
21738
|
-
}
|
|
21739
|
-
else if (curr.chi[0].val == 0) {
|
|
21740
|
-
curr.chi = [curr.chi[2]];
|
|
21741
|
-
curr.val = 'skewY';
|
|
21742
|
-
}
|
|
21743
|
-
}
|
|
21744
|
-
}
|
|
21745
|
-
acc.push(curr);
|
|
21746
|
-
return acc;
|
|
21747
|
-
}, []);
|
|
23351
|
+
const children = [];
|
|
23352
|
+
for (const child of node.val) {
|
|
23353
|
+
children.push(child.typ == exports.EnumToken.FunctionTokenType ? minifyTransformFunctions(child) : child);
|
|
23354
|
+
}
|
|
21748
23355
|
consumeWhitespace(children);
|
|
21749
|
-
let { matrix, cumulative, minified } = compute(children) ?? {
|
|
23356
|
+
let { matrix, cumulative, minified } = compute(children) ?? {
|
|
23357
|
+
matrix: null,
|
|
23358
|
+
cumulative: null,
|
|
23359
|
+
minified: null
|
|
23360
|
+
};
|
|
21750
23361
|
if (matrix == null || cumulative == null || minified == null) {
|
|
23362
|
+
node.val = children;
|
|
21751
23363
|
continue;
|
|
21752
23364
|
}
|
|
21753
|
-
let r = [filterValues(
|
|
23365
|
+
let r = [filterValues(children)];
|
|
21754
23366
|
if (eqMatrix(matrix, cumulative)) {
|
|
21755
23367
|
r.push(cumulative);
|
|
21756
23368
|
}
|
|
@@ -21829,7 +23441,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
|
|
|
21829
23441
|
}
|
|
21830
23442
|
replacement = parent;
|
|
21831
23443
|
for (const feature of options.features) {
|
|
21832
|
-
if ((feature.processMode & exports.FeatureWalkMode.Pre) === 0) {
|
|
23444
|
+
if ((feature.processMode & exports.FeatureWalkMode.Pre) === 0 || (feature.accept != null && !feature.accept.has(parent.typ))) {
|
|
21833
23445
|
continue;
|
|
21834
23446
|
}
|
|
21835
23447
|
const result = feature.run(replacement, options, parent.parent ?? ast, context, exports.FeatureWalkMode.Pre);
|
|
@@ -21868,7 +23480,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
|
|
|
21868
23480
|
replacement = parent;
|
|
21869
23481
|
if (postprocess) {
|
|
21870
23482
|
for (const feature of options.features) {
|
|
21871
|
-
if ((feature.processMode & exports.FeatureWalkMode.Post) === 0) {
|
|
23483
|
+
if ((feature.processMode & exports.FeatureWalkMode.Post) === 0 || (feature.accept != null && !feature.accept.has(parent.typ))) {
|
|
21872
23484
|
continue;
|
|
21873
23485
|
}
|
|
21874
23486
|
const result = feature.run(replacement, options, parent.parent ?? ast, context, exports.FeatureWalkMode.Post);
|
|
@@ -21999,6 +23611,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
21999
23611
|
continue;
|
|
22000
23612
|
}
|
|
22001
23613
|
if (previous?.typ == exports.EnumToken.AtRuleNodeType &&
|
|
23614
|
+
node.nam != 'font-face' &&
|
|
22002
23615
|
previous.nam == node.nam &&
|
|
22003
23616
|
previous.val == node.val) {
|
|
22004
23617
|
if ('chi' in node) {
|
|
@@ -22147,7 +23760,9 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
22147
23760
|
break;
|
|
22148
23761
|
}
|
|
22149
23762
|
if (shouldMerge) {
|
|
23763
|
+
// @ts-ignore
|
|
22150
23764
|
if (((node.typ == exports.EnumToken.RuleNodeType || node.typ == exports.EnumToken.KeyFramesRuleNodeType) && node.sel == previous.sel) ||
|
|
23765
|
+
// @ts-ignore
|
|
22151
23766
|
(node.typ == exports.EnumToken.AtRuleNodeType) && node.val != 'font-face' && node.val == previous.val) {
|
|
22152
23767
|
// @ts-ignore
|
|
22153
23768
|
node.chi.unshift(...previous.chi);
|
|
@@ -22204,7 +23819,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
22204
23819
|
nodeIndex = i;
|
|
22205
23820
|
}
|
|
22206
23821
|
if (recursive && node != null && ('chi' in node)) {
|
|
22207
|
-
if (node.typ == exports.EnumToken.KeyframesAtRuleNodeType || !node.chi.some(n => n.typ == exports.EnumToken.DeclarationNodeType)) {
|
|
23822
|
+
if (node.typ == exports.EnumToken.KeyframesAtRuleNodeType || !node.chi.some((n) => n.typ == exports.EnumToken.DeclarationNodeType)) {
|
|
22208
23823
|
if (!(node.typ == exports.EnumToken.AtRuleNodeType && node.nam != 'font-face')) {
|
|
22209
23824
|
doMinify(node, options, recursive, errors, nestingContent, context);
|
|
22210
23825
|
}
|
|
@@ -22815,14 +24430,11 @@ function reduceRuleSelector(node) {
|
|
|
22815
24430
|
*/
|
|
22816
24431
|
function expand(ast) {
|
|
22817
24432
|
const result = { ...ast, chi: [] };
|
|
22818
|
-
// @ts-ignore
|
|
22819
24433
|
for (let i = 0; i < ast.chi.length; i++) {
|
|
22820
|
-
// @ts-ignore
|
|
22821
24434
|
const node = ast.chi[i];
|
|
22822
24435
|
if (node.typ == exports.EnumToken.RuleNodeType) {
|
|
22823
24436
|
// @ts-ignore
|
|
22824
24437
|
result.chi.push(...expandRule(node));
|
|
22825
|
-
// i += expanded.length - 1;
|
|
22826
24438
|
}
|
|
22827
24439
|
else if (node.typ == exports.EnumToken.AtRuleNodeType && 'chi' in node) {
|
|
22828
24440
|
let hasRule = false;
|
|
@@ -22837,6 +24449,10 @@ function expand(ast) {
|
|
|
22837
24449
|
// @ts-ignore
|
|
22838
24450
|
result.chi.push({ ...(hasRule ? expand(node) : node) });
|
|
22839
24451
|
}
|
|
24452
|
+
else {
|
|
24453
|
+
// @ts-ignore
|
|
24454
|
+
result.chi.push(node);
|
|
24455
|
+
}
|
|
22840
24456
|
}
|
|
22841
24457
|
return result;
|
|
22842
24458
|
}
|
|
@@ -23019,41 +24635,51 @@ function replaceCompoundLiteral(selector, replace) {
|
|
|
23019
24635
|
return 1;
|
|
23020
24636
|
}
|
|
23021
24637
|
return b == '&' ? -1 : 0;
|
|
23022
|
-
}).reduce((acc, curr) =>
|
|
23023
|
-
// if (acc.length > 0 && curr == '&' && (replace.charAt(0) != '.' || replace.includes(' '))) {
|
|
23024
|
-
//
|
|
23025
|
-
// return acc + ':is(' + replace + ')';
|
|
23026
|
-
// }
|
|
23027
|
-
return acc + (curr == '&' ? replace : curr);
|
|
23028
|
-
}, '');
|
|
24638
|
+
}).reduce((acc, curr) => acc + (curr == '&' ? replace : curr), '');
|
|
23029
24639
|
}
|
|
23030
24640
|
|
|
23031
24641
|
/**
|
|
23032
24642
|
* load file or url as stream
|
|
23033
24643
|
* @param url
|
|
23034
24644
|
* @param currentFile
|
|
24645
|
+
* @param responseType
|
|
23035
24646
|
* @throws Error file not found
|
|
23036
24647
|
*
|
|
23037
24648
|
* @private
|
|
23038
24649
|
*/
|
|
23039
|
-
async function load(url, currentFile = '.') {
|
|
24650
|
+
async function load(url, currentFile = '.', responseType = false) {
|
|
23040
24651
|
const resolved = resolve(url, currentFile);
|
|
23041
|
-
|
|
24652
|
+
if (typeof responseType == 'boolean') {
|
|
24653
|
+
responseType = responseType ? exports.ResponseType.ReadableStream : exports.ResponseType.Text;
|
|
24654
|
+
}
|
|
23042
24655
|
if (matchUrl.test(resolved.absolute)) {
|
|
23043
|
-
return fetch(resolved.absolute).then((response) => {
|
|
24656
|
+
return fetch(resolved.absolute).then(async (response) => {
|
|
23044
24657
|
if (!response.ok) {
|
|
23045
24658
|
throw new Error(`${response.status} ${response.statusText} ${response.url}`);
|
|
23046
24659
|
}
|
|
23047
|
-
|
|
24660
|
+
if (responseType == exports.ResponseType.ArrayBuffer) {
|
|
24661
|
+
return response.arrayBuffer();
|
|
24662
|
+
}
|
|
24663
|
+
return responseType == exports.ResponseType.ReadableStream ? response.body : await response.text();
|
|
23048
24664
|
});
|
|
23049
24665
|
}
|
|
23050
24666
|
try {
|
|
24667
|
+
if (responseType == exports.ResponseType.Text) {
|
|
24668
|
+
return promises.readFile(resolved.absolute, 'utf-8');
|
|
24669
|
+
}
|
|
24670
|
+
if (responseType == exports.ResponseType.ArrayBuffer) {
|
|
24671
|
+
return promises.readFile(resolved.absolute).then(buffer => buffer.buffer);
|
|
24672
|
+
}
|
|
23051
24673
|
const stats = await promises.lstat(resolved.absolute);
|
|
23052
24674
|
if (stats.isFile()) {
|
|
23053
|
-
return node_stream.Readable.toWeb(node_fs.createReadStream(resolved.absolute
|
|
24675
|
+
return node_stream.Readable.toWeb(node_fs.createReadStream(resolved.absolute, {
|
|
24676
|
+
encoding: 'utf-8',
|
|
24677
|
+
highWaterMark: 64 * 1024
|
|
24678
|
+
}));
|
|
23054
24679
|
}
|
|
23055
24680
|
}
|
|
23056
24681
|
catch (error) {
|
|
24682
|
+
console.warn(error);
|
|
23057
24683
|
}
|
|
23058
24684
|
throw new Error(`File not found: '${resolved.absolute || url}'`);
|
|
23059
24685
|
}
|
|
@@ -23061,6 +24687,7 @@ async function load(url, currentFile = '.') {
|
|
|
23061
24687
|
* render the ast tree
|
|
23062
24688
|
* @param data
|
|
23063
24689
|
* @param options
|
|
24690
|
+
* @param mapping
|
|
23064
24691
|
*
|
|
23065
24692
|
* Example:
|
|
23066
24693
|
*
|
|
@@ -23085,13 +24712,14 @@ async function load(url, currentFile = '.') {
|
|
|
23085
24712
|
* // }
|
|
23086
24713
|
* ```
|
|
23087
24714
|
*/
|
|
23088
|
-
function render(data, options = {}) {
|
|
23089
|
-
return doRender(data, Object.assign(options, { resolve, dirname, cwd: options.cwd ?? process.cwd() }));
|
|
24715
|
+
function render(data, options = {}, mapping) {
|
|
24716
|
+
return doRender(data, Object.assign(options, { resolve, dirname, cwd: options.cwd ?? process.cwd() }), mapping);
|
|
23090
24717
|
}
|
|
23091
24718
|
/**
|
|
23092
24719
|
* parse css file
|
|
23093
24720
|
* @param file url or path
|
|
23094
24721
|
* @param options
|
|
24722
|
+
* @param asStream load file as stream
|
|
23095
24723
|
*
|
|
23096
24724
|
* @throws Error file not found
|
|
23097
24725
|
*
|
|
@@ -23110,8 +24738,8 @@ function render(data, options = {}) {
|
|
|
23110
24738
|
* console.log(result.ast);
|
|
23111
24739
|
* ```
|
|
23112
24740
|
*/
|
|
23113
|
-
async function parseFile(file, options = {}) {
|
|
23114
|
-
return load(file).then(stream => parse(stream, { src: file, ...options }));
|
|
24741
|
+
async function parseFile(file, options = {}, asStream = false) {
|
|
24742
|
+
return Promise.resolve((options.load ?? load)(file, '.', asStream)).then(stream => parse(stream, { src: file, ...options }));
|
|
23115
24743
|
}
|
|
23116
24744
|
/**
|
|
23117
24745
|
* parse css
|
|
@@ -23160,14 +24788,24 @@ async function parse(stream, options = {}) {
|
|
|
23160
24788
|
return doParse(stream instanceof ReadableStream ? tokenizeStream(stream) : tokenize$1({
|
|
23161
24789
|
stream,
|
|
23162
24790
|
buffer: '',
|
|
24791
|
+
offset: 0,
|
|
23163
24792
|
position: { ind: 0, lin: 1, col: 1 },
|
|
23164
24793
|
currentPosition: { ind: -1, lin: 1, col: 0 }
|
|
23165
|
-
}), Object.assign(options, {
|
|
24794
|
+
}), Object.assign(options, {
|
|
24795
|
+
load,
|
|
24796
|
+
resolve,
|
|
24797
|
+
dirname,
|
|
24798
|
+
cwd: options.cwd ?? process.cwd()
|
|
24799
|
+
})).then(result => {
|
|
24800
|
+
const { revMapping, ...res } = result;
|
|
24801
|
+
return res;
|
|
24802
|
+
});
|
|
23166
24803
|
}
|
|
23167
24804
|
/**
|
|
23168
24805
|
* transform css file
|
|
23169
24806
|
* @param file url or path
|
|
23170
24807
|
* @param options
|
|
24808
|
+
* @param asStream load file as stream
|
|
23171
24809
|
*
|
|
23172
24810
|
* @throws Error file not found
|
|
23173
24811
|
*
|
|
@@ -23186,8 +24824,8 @@ async function parse(stream, options = {}) {
|
|
|
23186
24824
|
* console.log(result.code);
|
|
23187
24825
|
* ```
|
|
23188
24826
|
*/
|
|
23189
|
-
async function transformFile(file, options = {}) {
|
|
23190
|
-
return load(file).then(stream => transform(stream, { src: file, ...options }));
|
|
24827
|
+
async function transformFile(file, options = {}, asStream = false) {
|
|
24828
|
+
return Promise.resolve((options.load ?? load)(file, '.', asStream)).then(stream => transform(stream, { src: file, ...options }));
|
|
23191
24829
|
}
|
|
23192
24830
|
/**
|
|
23193
24831
|
* transform css
|
|
@@ -23236,8 +24874,21 @@ async function transform(css, options = {}) {
|
|
|
23236
24874
|
options = { minify: true, removeEmpty: true, removeCharset: true, ...options };
|
|
23237
24875
|
const startTime = performance.now();
|
|
23238
24876
|
return parse(css, options).then((parseResult) => {
|
|
24877
|
+
let mapping = null;
|
|
24878
|
+
let importMapping = null;
|
|
24879
|
+
if (typeof options.module == 'number' && (options.module & exports.ModuleScopeEnumOptions.ICSS)) {
|
|
24880
|
+
mapping = parseResult.mapping;
|
|
24881
|
+
importMapping = parseResult.importMapping;
|
|
24882
|
+
}
|
|
24883
|
+
else if (typeof options.module == 'object' && typeof options.module.scoped == 'number' && (options.module.scoped & exports.ModuleScopeEnumOptions.ICSS)) {
|
|
24884
|
+
mapping = parseResult.mapping;
|
|
24885
|
+
importMapping = parseResult.importMapping;
|
|
24886
|
+
}
|
|
23239
24887
|
// ast already expanded by parse
|
|
23240
|
-
const rendered = render(parseResult.ast, {
|
|
24888
|
+
const rendered = render(parseResult.ast, {
|
|
24889
|
+
...options,
|
|
24890
|
+
expandNestingRules: false
|
|
24891
|
+
}, mapping != null ? { mapping, importMapping } : null);
|
|
23241
24892
|
return {
|
|
23242
24893
|
...parseResult,
|
|
23243
24894
|
...rendered,
|