@tbela99/css-parser 0.9.0 → 0.9.1
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/README.md +8 -5
- package/dist/index-umd-web.js +469 -1946
- package/dist/index.cjs +459 -1936
- package/dist/index.d.ts +25 -12
- package/dist/lib/ast/expand.js +15 -2
- package/dist/lib/ast/minify.js +1 -1
- package/dist/lib/ast/types.js +1 -0
- package/dist/lib/parser/parse.js +66 -40
- package/dist/lib/renderer/color/color.js +2 -2
- package/dist/lib/renderer/color/lab.js +2 -1
- package/dist/lib/renderer/color/prophotoRgb.js +2 -2
- package/dist/lib/renderer/color/prophotorgb.js +2 -2
- package/dist/lib/renderer/color/xyz.js +2 -18
- package/dist/lib/renderer/color/xyzd50.js +20 -2
- package/dist/lib/renderer/render.js +3 -2
- package/dist/lib/renderer/sourcemap/sourcemap.js +1 -1
- package/dist/lib/syntax/syntax.js +2 -1
- package/dist/lib/validation/at-rules/document.js +40 -60
- package/dist/lib/validation/at-rules/import.js +61 -59
- package/dist/lib/validation/at-rules/media.js +2 -1
- package/dist/lib/validation/at-rules/supports.js +40 -9
- package/dist/lib/validation/config.json.js +83 -35
- package/dist/lib/validation/declaration.js +2 -10
- package/dist/lib/validation/parser/parse.js +1 -95
- package/dist/lib/validation/parser/types.js +1 -2
- package/dist/lib/validation/syntax.js +39 -5
- package/dist/lib/validation/syntaxes/compound-selector.js +2 -2
- package/dist/lib/validation/syntaxes/layer-name.js +5 -16
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -106,6 +106,7 @@ exports.EnumToken = void 0;
|
|
|
106
106
|
EnumToken[EnumToken["MediaFeatureAndTokenType"] = 89] = "MediaFeatureAndTokenType";
|
|
107
107
|
EnumToken[EnumToken["MediaFeatureOrTokenType"] = 90] = "MediaFeatureOrTokenType";
|
|
108
108
|
EnumToken[EnumToken["PseudoPageTokenType"] = 91] = "PseudoPageTokenType";
|
|
109
|
+
EnumToken[EnumToken["PseudoElementTokenType"] = 92] = "PseudoElementTokenType";
|
|
109
110
|
/* aliases */
|
|
110
111
|
EnumToken[EnumToken["Time"] = 25] = "Time";
|
|
111
112
|
EnumToken[EnumToken["Iden"] = 7] = "Iden";
|
|
@@ -464,22 +465,6 @@ function getComponents(token) {
|
|
|
464
465
|
.filter((t) => ![exports.EnumToken.LiteralTokenType, exports.EnumToken.CommentTokenType, exports.EnumToken.CommaTokenType, exports.EnumToken.WhitespaceTokenType].includes(t.typ));
|
|
465
466
|
}
|
|
466
467
|
|
|
467
|
-
function xyzd502srgb(x, y, z) {
|
|
468
|
-
// @ts-ignore
|
|
469
|
-
return lsrgb2srgbvalues(
|
|
470
|
-
/* r: */
|
|
471
|
-
x * 3.1341359569958707 -
|
|
472
|
-
y * 1.6173863321612538 -
|
|
473
|
-
0.4906619460083532 * z,
|
|
474
|
-
/* g: */
|
|
475
|
-
x * -0.978795502912089 +
|
|
476
|
-
y * 1.916254567259524 +
|
|
477
|
-
0.03344273116131949 * z,
|
|
478
|
-
/* b: */
|
|
479
|
-
x * 0.07195537988411677 -
|
|
480
|
-
y * 0.2289768264158322 +
|
|
481
|
-
1.405386058324125 * z);
|
|
482
|
-
}
|
|
483
468
|
function XYZ_to_lin_sRGB(x, y, z) {
|
|
484
469
|
// convert XYZ to linear-light sRGB
|
|
485
470
|
const M = [
|
|
@@ -748,6 +733,45 @@ function OKLab_to_sRGB(l, a, b) {
|
|
|
748
733
|
1.7076147009309444 * S);
|
|
749
734
|
}
|
|
750
735
|
|
|
736
|
+
/*
|
|
737
|
+
*/
|
|
738
|
+
function xyzd502lch(x, y, z, alpha) {
|
|
739
|
+
// @ts-ignore
|
|
740
|
+
const [l, a, b] = xyz2lab(...XYZ_D50_to_D65(x, y, z));
|
|
741
|
+
// L in range [0,100]. For use in CSS, add a percent
|
|
742
|
+
return lab2lchvalues(l, a, b, alpha);
|
|
743
|
+
}
|
|
744
|
+
function XYZ_D65_to_D50(x, y, z) {
|
|
745
|
+
// Bradford chromatic adaptation from D65 to D50
|
|
746
|
+
// The matrix below is the result of three operations:
|
|
747
|
+
// - convert from XYZ to retinal cone domain
|
|
748
|
+
// - scale components from one reference white to another
|
|
749
|
+
// - convert back to XYZ
|
|
750
|
+
// see https://github.com/LeaVerou/color.js/pull/354/files
|
|
751
|
+
var M = [
|
|
752
|
+
[1.0479297925449969, 0.022946870601609652, -0.05019226628920524],
|
|
753
|
+
[0.02962780877005599, 0.9904344267538799, -0.017073799063418826],
|
|
754
|
+
[-0.009243040646204504, 0.015055191490298152, 0.7518742814281371]
|
|
755
|
+
];
|
|
756
|
+
return multiplyMatrices(M, [x, y, z]);
|
|
757
|
+
}
|
|
758
|
+
function xyzd502srgb(x, y, z) {
|
|
759
|
+
// @ts-ignore
|
|
760
|
+
return lsrgb2srgbvalues(
|
|
761
|
+
/* r: */
|
|
762
|
+
x * 3.1341359569958707 -
|
|
763
|
+
y * 1.6173863321612538 -
|
|
764
|
+
0.4906619460083532 * z,
|
|
765
|
+
/* g: */
|
|
766
|
+
x * -0.978795502912089 +
|
|
767
|
+
y * 1.916254567259524 +
|
|
768
|
+
0.03344273116131949 * z,
|
|
769
|
+
/* b: */
|
|
770
|
+
x * 0.07195537988411677 -
|
|
771
|
+
y * 0.2289768264158322 +
|
|
772
|
+
1.405386058324125 * z);
|
|
773
|
+
}
|
|
774
|
+
|
|
751
775
|
// L: 0% = 0.0, 100% = 100.0
|
|
752
776
|
// for a and b: -100% = -125, 100% = 125
|
|
753
777
|
function hex2lab(token) {
|
|
@@ -1360,28 +1384,6 @@ function hsl2hwbvalues(h, s, l, a = null) {
|
|
|
1360
1384
|
return hsv2hwb(...hsl2hsv(h, s, l, a));
|
|
1361
1385
|
}
|
|
1362
1386
|
|
|
1363
|
-
function xyzd502lch(x, y, z, alpha) {
|
|
1364
|
-
// @ts-ignore
|
|
1365
|
-
const [l, a, b] = xyz2lab(...XYZ_D50_to_D65(x, y, z));
|
|
1366
|
-
// L in range [0,100]. For use in CSS, add a percent
|
|
1367
|
-
// @ts-ignore
|
|
1368
|
-
return lab2lchvalues(l, a, b, alpha);
|
|
1369
|
-
}
|
|
1370
|
-
function XYZ_D65_to_D50(x, y, z) {
|
|
1371
|
-
// Bradford chromatic adaptation from D65 to D50
|
|
1372
|
-
// The matrix below is the result of three operations:
|
|
1373
|
-
// - convert from XYZ to retinal cone domain
|
|
1374
|
-
// - scale components from one reference white to another
|
|
1375
|
-
// - convert back to XYZ
|
|
1376
|
-
// see https://github.com/LeaVerou/color.js/pull/354/files
|
|
1377
|
-
var M = [
|
|
1378
|
-
[1.0479297925449969, 0.022946870601609652, -0.05019226628920524],
|
|
1379
|
-
[0.02962780877005599, 0.9904344267538799, -0.017073799063418826],
|
|
1380
|
-
[-0.009243040646204504, 0.015055191490298152, 0.7518742814281371]
|
|
1381
|
-
];
|
|
1382
|
-
return multiplyMatrices(M, [x, y, z]);
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
1387
|
function prophotorgb2srgbvalues(r, g, b, a = null) {
|
|
1386
1388
|
// @ts-ignore
|
|
1387
1389
|
return xyzd502srgb(...prophotorgb2xyz50(r, g, b, a));
|
|
@@ -3248,11 +3250,11 @@ function encode_integer(num) {
|
|
|
3248
3250
|
}
|
|
3249
3251
|
|
|
3250
3252
|
class SourceMap {
|
|
3253
|
+
lastLocation = null;
|
|
3251
3254
|
#version = 3;
|
|
3252
3255
|
#sources = [];
|
|
3253
3256
|
#map = new Map;
|
|
3254
3257
|
#line = -1;
|
|
3255
|
-
lastLocation = null;
|
|
3256
3258
|
add(source, original) {
|
|
3257
3259
|
if (original.src !== '') {
|
|
3258
3260
|
if (!this.#sources.includes(original.src)) {
|
|
@@ -3880,8 +3882,9 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
3880
3882
|
return '';
|
|
3881
3883
|
}
|
|
3882
3884
|
case exports.EnumToken.PseudoClassTokenType:
|
|
3885
|
+
case exports.EnumToken.PseudoElementTokenType:
|
|
3883
3886
|
// https://www.w3.org/TR/selectors-4/#single-colon-pseudos
|
|
3884
|
-
if (token.typ == exports.EnumToken.
|
|
3887
|
+
if (token.typ == exports.EnumToken.PseudoElementTokenType && pseudoElements.includes(token.val.slice(1))) {
|
|
3885
3888
|
return token.val.slice(1);
|
|
3886
3889
|
}
|
|
3887
3890
|
case exports.EnumToken.UrlTokenTokenType:
|
|
@@ -3962,6 +3965,7 @@ const mediaTypes = ['all', 'print', 'screen',
|
|
|
3962
3965
|
'aural', 'braille', 'embossed', 'handheld', 'projection', 'tty', 'tv', 'speech'];
|
|
3963
3966
|
// https://www.w3.org/TR/css-values-4/#math-function
|
|
3964
3967
|
const mathFuncs = ['calc', 'clamp', 'min', 'max', 'round', 'mod', 'rem', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2', 'pow', 'sqrt', 'hypot', 'log', 'exp', 'abs', 'sign'];
|
|
3968
|
+
const pseudoElements = [':before', ':after', ':first-line', ':first-letter'];
|
|
3965
3969
|
const webkitPseudoAliasMap = {
|
|
3966
3970
|
'-webkit-autofill': 'autofill',
|
|
3967
3971
|
'-webkit-any': 'is',
|
|
@@ -6218,13 +6222,13 @@ var map = {
|
|
|
6218
6222
|
shorthand: "background"
|
|
6219
6223
|
}
|
|
6220
6224
|
};
|
|
6221
|
-
var config$
|
|
6225
|
+
var config$3 = {
|
|
6222
6226
|
properties: properties,
|
|
6223
6227
|
map: map
|
|
6224
6228
|
};
|
|
6225
6229
|
|
|
6226
|
-
Object.freeze(config$
|
|
6227
|
-
const getConfig = () => config$
|
|
6230
|
+
Object.freeze(config$3);
|
|
6231
|
+
const getConfig = () => config$3;
|
|
6228
6232
|
|
|
6229
6233
|
function matchType(val, properties) {
|
|
6230
6234
|
if (val.typ == exports.EnumToken.IdenTokenType && properties.keywords.includes(val.val) ||
|
|
@@ -7251,7 +7255,7 @@ var declarations = {
|
|
|
7251
7255
|
syntax: "auto || <ratio>"
|
|
7252
7256
|
},
|
|
7253
7257
|
"backdrop-filter": {
|
|
7254
|
-
syntax: "none | <filter-
|
|
7258
|
+
syntax: "none | <filter-value-list>"
|
|
7255
7259
|
},
|
|
7256
7260
|
"backface-visibility": {
|
|
7257
7261
|
syntax: "visible | hidden"
|
|
@@ -7665,7 +7669,7 @@ var declarations = {
|
|
|
7665
7669
|
syntax: "nonzero | evenodd"
|
|
7666
7670
|
},
|
|
7667
7671
|
filter: {
|
|
7668
|
-
syntax: "none | <filter-
|
|
7672
|
+
syntax: "none | <filter-value-list>"
|
|
7669
7673
|
},
|
|
7670
7674
|
flex: {
|
|
7671
7675
|
syntax: "none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]"
|
|
@@ -8121,7 +8125,7 @@ var declarations = {
|
|
|
8121
8125
|
syntax: "<integer>"
|
|
8122
8126
|
},
|
|
8123
8127
|
outline: {
|
|
8124
|
-
syntax: "
|
|
8128
|
+
syntax: "<'outline-width'> || <'outline-style'> || <'outline-color'>"
|
|
8125
8129
|
},
|
|
8126
8130
|
"outline-color": {
|
|
8127
8131
|
syntax: "auto | <color>"
|
|
@@ -8550,7 +8554,7 @@ var declarations = {
|
|
|
8550
8554
|
syntax: "space-all | normal | space-first | trim-start"
|
|
8551
8555
|
},
|
|
8552
8556
|
"text-transform": {
|
|
8553
|
-
syntax: "none | capitalize | uppercase | lowercase
|
|
8557
|
+
syntax: "none | [ capitalize | uppercase | lowercase ] || full-width || full-size-kana | math-auto"
|
|
8554
8558
|
},
|
|
8555
8559
|
"text-underline-offset": {
|
|
8556
8560
|
syntax: "auto | <length> | <percentage> "
|
|
@@ -8640,7 +8644,7 @@ var declarations = {
|
|
|
8640
8644
|
syntax: "visible | hidden | collapse"
|
|
8641
8645
|
},
|
|
8642
8646
|
"white-space": {
|
|
8643
|
-
syntax: "normal | pre |
|
|
8647
|
+
syntax: "normal | pre | pre-wrap | pre-line | <'white-space-collapse'> || <'text-wrap-mode'>"
|
|
8644
8648
|
},
|
|
8645
8649
|
"white-space-collapse": {
|
|
8646
8650
|
syntax: "collapse | preserve | preserve-breaks | preserve-spaces | break-spaces"
|
|
@@ -8676,7 +8680,7 @@ var declarations = {
|
|
|
8676
8680
|
syntax: "auto | <integer>"
|
|
8677
8681
|
},
|
|
8678
8682
|
zoom: {
|
|
8679
|
-
syntax: "normal | reset | <number>
|
|
8683
|
+
syntax: "normal | reset | <number [0,∞]> || <percentage [0,∞]>"
|
|
8680
8684
|
}
|
|
8681
8685
|
};
|
|
8682
8686
|
var functions = {
|
|
@@ -8717,7 +8721,7 @@ var functions = {
|
|
|
8717
8721
|
syntax: "calc-size( <calc-size-basis>, <calc-sum> )"
|
|
8718
8722
|
},
|
|
8719
8723
|
circle: {
|
|
8720
|
-
syntax: "circle(
|
|
8724
|
+
syntax: "circle( <radial-size>? [ at <position> ]? )"
|
|
8721
8725
|
},
|
|
8722
8726
|
clamp: {
|
|
8723
8727
|
syntax: "clamp( <calc-sum>#{3} )"
|
|
@@ -8753,7 +8757,7 @@ var functions = {
|
|
|
8753
8757
|
syntax: "element( <id-selector> )"
|
|
8754
8758
|
},
|
|
8755
8759
|
ellipse: {
|
|
8756
|
-
syntax: "ellipse(
|
|
8760
|
+
syntax: "ellipse( <radial-size>? [ at <position> ]? )"
|
|
8757
8761
|
},
|
|
8758
8762
|
env: {
|
|
8759
8763
|
syntax: "env( <custom-ident> , <declaration-value>? )"
|
|
@@ -8768,16 +8772,16 @@ var functions = {
|
|
|
8768
8772
|
syntax: "grayscale( [ <number> | <percentage> ]? )"
|
|
8769
8773
|
},
|
|
8770
8774
|
hsl: {
|
|
8771
|
-
syntax: "hsl( <hue
|
|
8775
|
+
syntax: "hsl( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsl( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )"
|
|
8772
8776
|
},
|
|
8773
8777
|
hsla: {
|
|
8774
|
-
syntax: "hsla( <hue
|
|
8778
|
+
syntax: "hsla( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsla( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )"
|
|
8775
8779
|
},
|
|
8776
8780
|
"hue-rotate": {
|
|
8777
8781
|
syntax: "hue-rotate( [ <angle> | <zero> ]? )"
|
|
8778
8782
|
},
|
|
8779
8783
|
hwb: {
|
|
8780
|
-
syntax: "hwb( [<hue> | none] [<percentage> | none] [<percentage> | none] [ / [<alpha-value> | none] ]? )"
|
|
8784
|
+
syntax: "hwb( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )"
|
|
8781
8785
|
},
|
|
8782
8786
|
hypot: {
|
|
8783
8787
|
syntax: "hypot( <calc-sum># )"
|
|
@@ -8866,6 +8870,9 @@ var functions = {
|
|
|
8866
8870
|
ray: {
|
|
8867
8871
|
syntax: "ray( <angle> && <ray-size>? && contain? && [at <position>]? )"
|
|
8868
8872
|
},
|
|
8873
|
+
rect: {
|
|
8874
|
+
syntax: "rect( [ <length-percentage> | auto ]{4} [ round <'border-radius'> ]? )"
|
|
8875
|
+
},
|
|
8869
8876
|
rem: {
|
|
8870
8877
|
syntax: "rem( <calc-sum>, <calc-sum> )"
|
|
8871
8878
|
},
|
|
@@ -8879,10 +8886,10 @@ var functions = {
|
|
|
8879
8886
|
syntax: "repeating-radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )"
|
|
8880
8887
|
},
|
|
8881
8888
|
rgb: {
|
|
8882
|
-
syntax: "rgb( <percentage
|
|
8889
|
+
syntax: "rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? ) | rgb( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? )"
|
|
8883
8890
|
},
|
|
8884
8891
|
rgba: {
|
|
8885
|
-
syntax: "rgba( <percentage
|
|
8892
|
+
syntax: "rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? ) | rgba( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? )"
|
|
8886
8893
|
},
|
|
8887
8894
|
rotate: {
|
|
8888
8895
|
syntax: "rotate( [ <angle> | <zero> ] )"
|
|
@@ -8944,6 +8951,9 @@ var functions = {
|
|
|
8944
8951
|
sqrt: {
|
|
8945
8952
|
syntax: "sqrt( <calc-sum> )"
|
|
8946
8953
|
},
|
|
8954
|
+
symbols: {
|
|
8955
|
+
syntax: "symbols( <symbols-type>? [ <string> | <image> ]+ )"
|
|
8956
|
+
},
|
|
8947
8957
|
tan: {
|
|
8948
8958
|
syntax: "tan( <calc-sum> )"
|
|
8949
8959
|
},
|
|
@@ -8976,6 +8986,9 @@ var functions = {
|
|
|
8976
8986
|
},
|
|
8977
8987
|
view: {
|
|
8978
8988
|
syntax: "view([<axis> || <'view-timeline-inset'>]?)"
|
|
8989
|
+
},
|
|
8990
|
+
xywh: {
|
|
8991
|
+
syntax: "xywh( <length-percentage>{2} <length-percentage [0,∞]>{2} [ round <'border-radius'> ]? )"
|
|
8979
8992
|
}
|
|
8980
8993
|
};
|
|
8981
8994
|
var syntaxes = {
|
|
@@ -8991,6 +9004,9 @@ var syntaxes = {
|
|
|
8991
9004
|
"alpha-value": {
|
|
8992
9005
|
syntax: "<number> | <percentage>"
|
|
8993
9006
|
},
|
|
9007
|
+
"an+b": {
|
|
9008
|
+
syntax: "odd | even | <integer> | <n-dimension> | '+'?† n | -n | <ndashdigit-dimension> | '+'?† <ndashdigit-ident> | <dashndashdigit-ident> | <n-dimension> <signed-integer> | '+'?† n <signed-integer> | -n <signed-integer> | <ndash-dimension> <signless-integer> | '+'?† n- <signless-integer> | -n- <signless-integer> | <n-dimension> ['+' | '-'] <signless-integer> | '+'?† n ['+' | '-'] <signless-integer> | -n ['+' | '-'] <signless-integer>"
|
|
9009
|
+
},
|
|
8994
9010
|
"anchor()": {
|
|
8995
9011
|
syntax: "anchor( <anchor-name>? && <anchor-side>, <length-percentage>? )"
|
|
8996
9012
|
},
|
|
@@ -9112,7 +9128,7 @@ var syntaxes = {
|
|
|
9112
9128
|
syntax: "<percentage>? && <image>"
|
|
9113
9129
|
},
|
|
9114
9130
|
"circle()": {
|
|
9115
|
-
syntax: "circle(
|
|
9131
|
+
syntax: "circle( <radial-size>? [ at <position> ]? )"
|
|
9116
9132
|
},
|
|
9117
9133
|
"clamp()": {
|
|
9118
9134
|
syntax: "clamp( <calc-sum>#{3} )"
|
|
@@ -9126,15 +9142,15 @@ var syntaxes = {
|
|
|
9126
9142
|
color: {
|
|
9127
9143
|
syntax: "<color-base> | currentColor | <system-color> | <light-dark()> | <deprecated-system-color>"
|
|
9128
9144
|
},
|
|
9145
|
+
"color()": {
|
|
9146
|
+
syntax: "color( [ from <color> ]? <colorspace-params> [ / [ <alpha-value> | none ] ]? )"
|
|
9147
|
+
},
|
|
9129
9148
|
"color-base": {
|
|
9130
9149
|
syntax: "<hex-color> | <color-function> | <named-color> | <color-mix()> | transparent"
|
|
9131
9150
|
},
|
|
9132
9151
|
"color-function": {
|
|
9133
9152
|
syntax: "<rgb()> | <rgba()> | <hsl()> | <hsla()> | <hwb()> | <lab()> | <lch()> | <oklab()> | <oklch()> | <color()>"
|
|
9134
9153
|
},
|
|
9135
|
-
"color()": {
|
|
9136
|
-
syntax: "color( [from <color>]? <colorspace-params> [ / [ <alpha-value> | none ] ]? )"
|
|
9137
|
-
},
|
|
9138
9154
|
"color-interpolation-method": {
|
|
9139
9155
|
syntax: "in [ <rectangular-color-space> | <polar-color-space> <hue-interpolation-method>? | <custom-color-space> ]"
|
|
9140
9156
|
},
|
|
@@ -9243,6 +9259,9 @@ var syntaxes = {
|
|
|
9243
9259
|
dasharray: {
|
|
9244
9260
|
syntax: "[ [ <length-percentage> | <number> ]+ ]#"
|
|
9245
9261
|
},
|
|
9262
|
+
"dashndashdigit-ident": {
|
|
9263
|
+
syntax: "<ident-token>"
|
|
9264
|
+
},
|
|
9246
9265
|
"deprecated-system-color": {
|
|
9247
9266
|
syntax: "ActiveBorder | ActiveCaption | AppWorkspace | Background | ButtonHighlight | ButtonShadow | CaptionText | InactiveBorder | InactiveCaption | InactiveCaptionText | InfoBackground | InfoText | Menu | MenuText | Scrollbar | ThreeDDarkShadow | ThreeDFace | ThreeDHighlight | ThreeDLightShadow | ThreeDShadow | Window | WindowFrame | WindowText"
|
|
9248
9267
|
},
|
|
@@ -9283,7 +9302,7 @@ var syntaxes = {
|
|
|
9283
9302
|
syntax: "element( <id-selector> )"
|
|
9284
9303
|
},
|
|
9285
9304
|
"ellipse()": {
|
|
9286
|
-
syntax: "ellipse(
|
|
9305
|
+
syntax: "ellipse( <radial-size>? [ at <position> ]? )"
|
|
9287
9306
|
},
|
|
9288
9307
|
"ending-shape": {
|
|
9289
9308
|
syntax: "circle | ellipse"
|
|
@@ -9324,7 +9343,7 @@ var syntaxes = {
|
|
|
9324
9343
|
"filter-function": {
|
|
9325
9344
|
syntax: "<blur()> | <brightness()> | <contrast()> | <drop-shadow()> | <grayscale()> | <hue-rotate()> | <invert()> | <opacity()> | <saturate()> | <sepia()>"
|
|
9326
9345
|
},
|
|
9327
|
-
"filter-
|
|
9346
|
+
"filter-value-list": {
|
|
9328
9347
|
syntax: "[ <filter-function> | <url> ]+"
|
|
9329
9348
|
},
|
|
9330
9349
|
"final-bg-layer": {
|
|
@@ -9379,10 +9398,10 @@ var syntaxes = {
|
|
|
9379
9398
|
syntax: "[ historical-ligatures | no-historical-ligatures ]"
|
|
9380
9399
|
},
|
|
9381
9400
|
"hsl()": {
|
|
9382
|
-
syntax: "hsl( <hue
|
|
9401
|
+
syntax: "hsl( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsl( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )"
|
|
9383
9402
|
},
|
|
9384
9403
|
"hsla()": {
|
|
9385
|
-
syntax: "hsla( <hue
|
|
9404
|
+
syntax: "hsla( <hue>, <percentage>, <percentage>, <alpha-value>? ) | hsla( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )"
|
|
9386
9405
|
},
|
|
9387
9406
|
hue: {
|
|
9388
9407
|
syntax: "<number> | <angle>"
|
|
@@ -9394,7 +9413,7 @@ var syntaxes = {
|
|
|
9394
9413
|
syntax: "hue-rotate( [ <angle> | <zero> ]? )"
|
|
9395
9414
|
},
|
|
9396
9415
|
"hwb()": {
|
|
9397
|
-
syntax: "hwb( [<hue> | none] [<percentage> | none] [<percentage> | none] [ / [<alpha-value> | none] ]? )"
|
|
9416
|
+
syntax: "hwb( [ <hue> | none ] [ <percentage> | <number> | none ] [ <percentage> | <number> | none ] [ / [ <alpha-value> | none ] ]? )"
|
|
9398
9417
|
},
|
|
9399
9418
|
"hypot()": {
|
|
9400
9419
|
syntax: "hypot( <calc-sum># )"
|
|
@@ -9402,6 +9421,9 @@ var syntaxes = {
|
|
|
9402
9421
|
"id-selector": {
|
|
9403
9422
|
syntax: "<hash-token>"
|
|
9404
9423
|
},
|
|
9424
|
+
integer: {
|
|
9425
|
+
syntax: "<number-token>"
|
|
9426
|
+
},
|
|
9405
9427
|
image: {
|
|
9406
9428
|
syntax: "<url> | <image()> | <image-set()> | <element()> | <paint()> | <cross-fade()> | <gradient>"
|
|
9407
9429
|
},
|
|
@@ -9567,6 +9589,18 @@ var syntaxes = {
|
|
|
9567
9589
|
"mod()": {
|
|
9568
9590
|
syntax: "mod( <calc-sum>, <calc-sum> )"
|
|
9569
9591
|
},
|
|
9592
|
+
"n-dimension": {
|
|
9593
|
+
syntax: "<dimension-token>"
|
|
9594
|
+
},
|
|
9595
|
+
"ndash-dimension": {
|
|
9596
|
+
syntax: "<dimension-token>"
|
|
9597
|
+
},
|
|
9598
|
+
"ndashdigit-dimension": {
|
|
9599
|
+
syntax: "<dimension-token>"
|
|
9600
|
+
},
|
|
9601
|
+
"ndashdigit-ident": {
|
|
9602
|
+
syntax: "<ident-token>"
|
|
9603
|
+
},
|
|
9570
9604
|
"name-repeat": {
|
|
9571
9605
|
syntax: "repeat( [ <integer [1,∞]> | auto-fill ], <line-names>+ )"
|
|
9572
9606
|
},
|
|
@@ -9579,9 +9613,6 @@ var syntaxes = {
|
|
|
9579
9613
|
"ns-prefix": {
|
|
9580
9614
|
syntax: "[ <ident-token> | '*' ]? '|'"
|
|
9581
9615
|
},
|
|
9582
|
-
nth: {
|
|
9583
|
-
syntax: "<an-plus-b> | even | odd"
|
|
9584
|
-
},
|
|
9585
9616
|
"number-percentage": {
|
|
9586
9617
|
syntax: "<number> | <percentage>"
|
|
9587
9618
|
},
|
|
@@ -9690,9 +9721,15 @@ var syntaxes = {
|
|
|
9690
9721
|
quote: {
|
|
9691
9722
|
syntax: "open-quote | close-quote | no-open-quote | no-close-quote"
|
|
9692
9723
|
},
|
|
9724
|
+
"radial-extent": {
|
|
9725
|
+
syntax: "closest-corner | closest-side | farthest-corner | farthest-side"
|
|
9726
|
+
},
|
|
9693
9727
|
"radial-gradient()": {
|
|
9694
9728
|
syntax: "radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )"
|
|
9695
9729
|
},
|
|
9730
|
+
"radial-size": {
|
|
9731
|
+
syntax: "<radial-extent> | <length [0,∞]> | <length-percentage [0,∞]>{2}"
|
|
9732
|
+
},
|
|
9696
9733
|
ratio: {
|
|
9697
9734
|
syntax: "<number [0,∞]> [ / <number [0,∞]> ]?"
|
|
9698
9735
|
},
|
|
@@ -9714,6 +9751,9 @@ var syntaxes = {
|
|
|
9714
9751
|
"relative-size": {
|
|
9715
9752
|
syntax: "larger | smaller"
|
|
9716
9753
|
},
|
|
9754
|
+
"rect()": {
|
|
9755
|
+
syntax: "rect( [ <length-percentage> | auto ]{4} [ round <'border-radius'> ]? )"
|
|
9756
|
+
},
|
|
9717
9757
|
"rem()": {
|
|
9718
9758
|
syntax: "rem( <calc-sum>, <calc-sum> )"
|
|
9719
9759
|
},
|
|
@@ -9733,10 +9773,10 @@ var syntaxes = {
|
|
|
9733
9773
|
syntax: "reversed( <counter-name> )"
|
|
9734
9774
|
},
|
|
9735
9775
|
"rgb()": {
|
|
9736
|
-
syntax: "rgb( <percentage
|
|
9776
|
+
syntax: "rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? ) | rgb( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? )"
|
|
9737
9777
|
},
|
|
9738
9778
|
"rgba()": {
|
|
9739
|
-
syntax: "rgba( <percentage
|
|
9779
|
+
syntax: "rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? ) | rgba( [ <number> | <percentage> | none ]{3} [ / [ <alpha-value> | none ] ]? )"
|
|
9740
9780
|
},
|
|
9741
9781
|
"rotate()": {
|
|
9742
9782
|
syntax: "rotate( [ <angle> | <zero> ] )"
|
|
@@ -9810,15 +9850,18 @@ var syntaxes = {
|
|
|
9810
9850
|
"shape-box": {
|
|
9811
9851
|
syntax: "<visual-box> | margin-box"
|
|
9812
9852
|
},
|
|
9813
|
-
"shape-radius": {
|
|
9814
|
-
syntax: "<length-percentage> | closest-side | farthest-side"
|
|
9815
|
-
},
|
|
9816
9853
|
"side-or-corner": {
|
|
9817
9854
|
syntax: "[ left | right ] || [ top | bottom ]"
|
|
9818
9855
|
},
|
|
9819
9856
|
"sign()": {
|
|
9820
9857
|
syntax: "sign( <calc-sum> )"
|
|
9821
9858
|
},
|
|
9859
|
+
"signed-integer": {
|
|
9860
|
+
syntax: "<number-token>"
|
|
9861
|
+
},
|
|
9862
|
+
"signless-integer": {
|
|
9863
|
+
syntax: "<number-token>"
|
|
9864
|
+
},
|
|
9822
9865
|
"sin()": {
|
|
9823
9866
|
syntax: "sin( <calc-sum> )"
|
|
9824
9867
|
},
|
|
@@ -9891,6 +9934,12 @@ var syntaxes = {
|
|
|
9891
9934
|
symbol: {
|
|
9892
9935
|
syntax: "<string> | <image> | <custom-ident>"
|
|
9893
9936
|
},
|
|
9937
|
+
"symbols()": {
|
|
9938
|
+
syntax: "symbols( <symbols-type>? [ <string> | <image> ]+ )"
|
|
9939
|
+
},
|
|
9940
|
+
"symbols-type": {
|
|
9941
|
+
syntax: "cyclic | numeric | alphabetic | symbolic | fixed"
|
|
9942
|
+
},
|
|
9894
9943
|
"system-color": {
|
|
9895
9944
|
syntax: "AccentColor | AccentColorText | ActiveText | ButtonBorder | ButtonFace | ButtonText | Canvas | CanvasText | Field | FieldText | GrayText | Highlight | HighlightText | LinkText | Mark | MarkText | SelectedItem | SelectedItemText | VisitedText"
|
|
9896
9945
|
},
|
|
@@ -9981,6 +10030,9 @@ var syntaxes = {
|
|
|
9981
10030
|
"wq-name": {
|
|
9982
10031
|
syntax: "<ns-prefix>? <ident-token>"
|
|
9983
10032
|
},
|
|
10033
|
+
"xywh()": {
|
|
10034
|
+
syntax: "xywh( <length-percentage>{2} <length-percentage [0,∞]>{2} [ round <'border-radius'> ]? )"
|
|
10035
|
+
},
|
|
9984
10036
|
xyz: {
|
|
9985
10037
|
syntax: "xyz | xyz-d50 | xyz-d65"
|
|
9986
10038
|
},
|
|
@@ -10116,16 +10168,16 @@ var selectors = {
|
|
|
10116
10168
|
syntax: ":not( <complex-selector-list> )"
|
|
10117
10169
|
},
|
|
10118
10170
|
":nth-child()": {
|
|
10119
|
-
syntax: ":nth-child( <
|
|
10171
|
+
syntax: ":nth-child( <an+b> [ of <complex-selector-list> ]? )"
|
|
10120
10172
|
},
|
|
10121
10173
|
":nth-last-child()": {
|
|
10122
|
-
syntax: ":nth-last-child( <
|
|
10174
|
+
syntax: ":nth-last-child( <an+b> [ of <complex-selector-list> ]? )"
|
|
10123
10175
|
},
|
|
10124
10176
|
":nth-last-of-type()": {
|
|
10125
|
-
syntax: ":nth-last-of-type( <
|
|
10177
|
+
syntax: ":nth-last-of-type( <an+b> )"
|
|
10126
10178
|
},
|
|
10127
10179
|
":nth-of-type()": {
|
|
10128
|
-
syntax: ":nth-of-type( <
|
|
10180
|
+
syntax: ":nth-of-type( <an+b> )"
|
|
10129
10181
|
},
|
|
10130
10182
|
":only-child": {
|
|
10131
10183
|
syntax: ":only-child"
|
|
@@ -10408,7 +10460,7 @@ var atRules = {
|
|
|
10408
10460
|
syntax: "normal | <percentage>"
|
|
10409
10461
|
},
|
|
10410
10462
|
"font-display": {
|
|
10411
|
-
syntax: "
|
|
10463
|
+
syntax: "auto | block | swap | fallback | optional"
|
|
10412
10464
|
},
|
|
10413
10465
|
"font-family": {
|
|
10414
10466
|
syntax: "<family-name>"
|
|
@@ -10529,7 +10581,7 @@ var atRules = {
|
|
|
10529
10581
|
}
|
|
10530
10582
|
}
|
|
10531
10583
|
};
|
|
10532
|
-
var config$
|
|
10584
|
+
var config$2 = {
|
|
10533
10585
|
declarations: declarations,
|
|
10534
10586
|
functions: functions,
|
|
10535
10587
|
syntaxes: syntaxes,
|
|
@@ -10537,7 +10589,6 @@ var config$3 = {
|
|
|
10537
10589
|
atRules: atRules
|
|
10538
10590
|
};
|
|
10539
10591
|
|
|
10540
|
-
const specialValues = ['inherit', 'initial', 'unset', 'revert', 'revert-layer'];
|
|
10541
10592
|
var ValidationTokenEnum;
|
|
10542
10593
|
(function (ValidationTokenEnum) {
|
|
10543
10594
|
ValidationTokenEnum[ValidationTokenEnum["Root"] = 0] = "Root";
|
|
@@ -11539,100 +11590,6 @@ function move(position, chr) {
|
|
|
11539
11590
|
}
|
|
11540
11591
|
return position;
|
|
11541
11592
|
}
|
|
11542
|
-
function renderSyntax(token, parent) {
|
|
11543
|
-
let glue;
|
|
11544
|
-
switch (token.typ) {
|
|
11545
|
-
case ValidationTokenEnum.Root:
|
|
11546
|
-
return token.chi.reduce((acc, curr) => acc + renderSyntax(curr), '');
|
|
11547
|
-
case ValidationTokenEnum.Whitespace:
|
|
11548
|
-
return ' ';
|
|
11549
|
-
case ValidationTokenEnum.ValidationFunctionDefinition:
|
|
11550
|
-
return '<' + token.val + '()>';
|
|
11551
|
-
case ValidationTokenEnum.HashMark:
|
|
11552
|
-
return '#';
|
|
11553
|
-
case ValidationTokenEnum.Pipe:
|
|
11554
|
-
return '|';
|
|
11555
|
-
case ValidationTokenEnum.Column:
|
|
11556
|
-
return '||';
|
|
11557
|
-
case ValidationTokenEnum.PipeToken:
|
|
11558
|
-
return token.chi.reduce((acc, curr) => acc + (acc.trim().length > 0 ? '|' : '') + curr.reduce((acc, curr) => acc + renderSyntax(curr), ''), '');
|
|
11559
|
-
case ValidationTokenEnum.ColumnToken:
|
|
11560
|
-
case ValidationTokenEnum.AmpersandToken:
|
|
11561
|
-
glue = token.typ == ValidationTokenEnum.ColumnToken ? '||' : '&&';
|
|
11562
|
-
return token.l.reduce((acc, curr) => acc + renderSyntax(curr), '') +
|
|
11563
|
-
glue +
|
|
11564
|
-
token.r.reduce((acc, curr) => acc + renderSyntax(curr), '');
|
|
11565
|
-
case ValidationTokenEnum.Function:
|
|
11566
|
-
case ValidationTokenEnum.PseudoClassFunctionToken:
|
|
11567
|
-
case ValidationTokenEnum.Parens:
|
|
11568
|
-
return token.val + '(' + token.chi.reduce((acc, curr) => acc + renderSyntax(curr), '') + ')' + renderAttributes(token);
|
|
11569
|
-
case ValidationTokenEnum.Comma:
|
|
11570
|
-
return ',';
|
|
11571
|
-
case ValidationTokenEnum.Keyword:
|
|
11572
|
-
return token.val + renderAttributes(token);
|
|
11573
|
-
case ValidationTokenEnum.OpenBracket:
|
|
11574
|
-
return '[';
|
|
11575
|
-
case ValidationTokenEnum.Ampersand:
|
|
11576
|
-
return '&&';
|
|
11577
|
-
case ValidationTokenEnum.QuestionMark:
|
|
11578
|
-
return '?';
|
|
11579
|
-
case ValidationTokenEnum.Separator:
|
|
11580
|
-
return '/';
|
|
11581
|
-
case ValidationTokenEnum.Bracket:
|
|
11582
|
-
return '[' + token.chi.reduce((acc, curr) => acc + renderSyntax(curr), '') + ']' + renderAttributes(token);
|
|
11583
|
-
case ValidationTokenEnum.PropertyType:
|
|
11584
|
-
return '<' + token.val + '>' + renderAttributes(token);
|
|
11585
|
-
case ValidationTokenEnum.DeclarationType:
|
|
11586
|
-
return "<'" + token.val + "'>" + renderAttributes(token);
|
|
11587
|
-
case ValidationTokenEnum.Number:
|
|
11588
|
-
case ValidationTokenEnum.PseudoClassToken:
|
|
11589
|
-
case ValidationTokenEnum.StringToken:
|
|
11590
|
-
return token.val + '';
|
|
11591
|
-
case ValidationTokenEnum.SemiColon:
|
|
11592
|
-
return ';';
|
|
11593
|
-
case ValidationTokenEnum.AtRule:
|
|
11594
|
-
return '@' + token.val;
|
|
11595
|
-
case ValidationTokenEnum.AtRuleDefinition:
|
|
11596
|
-
return '@' + token.val +
|
|
11597
|
-
(token.prelude == null ? '' : ' ' + token.prelude.reduce((acc, curr) => acc + renderSyntax(curr), '')) +
|
|
11598
|
-
(token.chi == null ? '' : ' {\n' + token.chi.reduce((acc, curr) => acc + renderSyntax(curr), '')).slice(1, -1) + '\n}';
|
|
11599
|
-
case ValidationTokenEnum.Block:
|
|
11600
|
-
return '{' + token.chi.reduce((acc, t) => acc + renderSyntax(t), '') + '}';
|
|
11601
|
-
case ValidationTokenEnum.DeclarationDefinitionToken:
|
|
11602
|
-
return token.nam + ': ' + renderSyntax(token.val);
|
|
11603
|
-
case ValidationTokenEnum.ColumnArrayToken:
|
|
11604
|
-
return token.chi.reduce((acc, curr) => acc + (acc.trim().length > 0 ? '||' : '') + renderSyntax(curr), '');
|
|
11605
|
-
default:
|
|
11606
|
-
throw new Error('Unhandled token: ' + JSON.stringify({ token }));
|
|
11607
|
-
}
|
|
11608
|
-
}
|
|
11609
|
-
function renderAttributes(token) {
|
|
11610
|
-
let result = '';
|
|
11611
|
-
if (token.isList) {
|
|
11612
|
-
result += '#';
|
|
11613
|
-
}
|
|
11614
|
-
if (token.isOptional) {
|
|
11615
|
-
result += '?';
|
|
11616
|
-
}
|
|
11617
|
-
if (token.isRepeatableGroup) {
|
|
11618
|
-
result += '!';
|
|
11619
|
-
}
|
|
11620
|
-
if (token.isRepeatable) {
|
|
11621
|
-
result += '*';
|
|
11622
|
-
}
|
|
11623
|
-
if (token.atLeastOnce) {
|
|
11624
|
-
result += '+';
|
|
11625
|
-
}
|
|
11626
|
-
if (token.occurence != null) {
|
|
11627
|
-
if (token.occurence.max == 0 || token.occurence.max == token.occurence.min || Number.isNaN(token.occurence.max)) {
|
|
11628
|
-
result += '{' + token.occurence.min + '}';
|
|
11629
|
-
}
|
|
11630
|
-
else {
|
|
11631
|
-
result += '{' + token.occurence.min + ',' + token.occurence.max + '}';
|
|
11632
|
-
}
|
|
11633
|
-
}
|
|
11634
|
-
return result;
|
|
11635
|
-
}
|
|
11636
11593
|
function minify$1(ast) {
|
|
11637
11594
|
if (Array.isArray(ast)) {
|
|
11638
11595
|
// @ts-ignore
|
|
@@ -11734,14 +11691,14 @@ function* walkValidationToken(token, parent, callback, key) {
|
|
|
11734
11691
|
}
|
|
11735
11692
|
|
|
11736
11693
|
const parsedSyntaxes = new Map();
|
|
11737
|
-
Object.freeze(config$
|
|
11694
|
+
Object.freeze(config$2);
|
|
11738
11695
|
function getSyntaxConfig() {
|
|
11739
11696
|
// @ts-ignore
|
|
11740
|
-
return config$
|
|
11697
|
+
return config$2;
|
|
11741
11698
|
}
|
|
11742
11699
|
function getParsedSyntax(group, key) {
|
|
11743
11700
|
// @ts-ignore
|
|
11744
|
-
let obj = config$
|
|
11701
|
+
let obj = config$2[group];
|
|
11745
11702
|
const keys = Array.isArray(key) ? key : [key];
|
|
11746
11703
|
for (let i = 0; i < keys.length; i++) {
|
|
11747
11704
|
key = keys[i];
|
|
@@ -11779,7 +11736,7 @@ function validateLayerName(tokens) {
|
|
|
11779
11736
|
acc[acc.length - 1].push(curr);
|
|
11780
11737
|
}
|
|
11781
11738
|
return acc;
|
|
11782
|
-
}, [[]])
|
|
11739
|
+
}, [[]]);
|
|
11783
11740
|
for (let i = 0; i < slice.length; i++) {
|
|
11784
11741
|
if (slice[i].length == 0) {
|
|
11785
11742
|
// @ts-ignore
|
|
@@ -11792,26 +11749,15 @@ function validateLayerName(tokens) {
|
|
|
11792
11749
|
tokens
|
|
11793
11750
|
};
|
|
11794
11751
|
}
|
|
11795
|
-
|
|
11796
|
-
|
|
11797
|
-
return {
|
|
11798
|
-
valid: ValidationLevel.Drop,
|
|
11799
|
-
matches: tokens,
|
|
11800
|
-
node: slice[i][0],
|
|
11801
|
-
syntax: 'ident',
|
|
11802
|
-
error: 'expecting ident',
|
|
11803
|
-
tokens
|
|
11804
|
-
};
|
|
11805
|
-
}
|
|
11806
|
-
for (let j = 1; j < slice[i].length; j++) {
|
|
11807
|
-
if (slice[i][j].typ != exports.EnumToken.ClassSelectorTokenType) {
|
|
11752
|
+
for (let j = 0; j < slice[i].length; j++) {
|
|
11753
|
+
if (slice[i][j].typ != exports.EnumToken.IdenTokenType && slice[i][j].typ != exports.EnumToken.ClassSelectorTokenType) {
|
|
11808
11754
|
// @ts-ignore
|
|
11809
11755
|
return {
|
|
11810
11756
|
valid: ValidationLevel.Drop,
|
|
11811
11757
|
matches: tokens,
|
|
11812
11758
|
node: slice[i][j],
|
|
11813
|
-
syntax: 'layer-name',
|
|
11814
|
-
error: 'expecting class selector',
|
|
11759
|
+
syntax: '<layer-name>',
|
|
11760
|
+
error: 'expecting ident or class selector',
|
|
11815
11761
|
tokens
|
|
11816
11762
|
};
|
|
11817
11763
|
}
|
|
@@ -12008,8 +11954,8 @@ function validateCompoundSelector(tokens, root, options) {
|
|
|
12008
11954
|
tokens.shift();
|
|
12009
11955
|
consumeWhitespace(tokens);
|
|
12010
11956
|
}
|
|
12011
|
-
while (tokens.length > 0 && tokens[0].typ == exports.EnumToken.PseudoClassTokenType) {
|
|
12012
|
-
const isPseudoElement = tokens[0].
|
|
11957
|
+
while (tokens.length > 0 && (tokens[0].typ == exports.EnumToken.PseudoElementTokenType || tokens[0].typ == exports.EnumToken.PseudoClassTokenType)) {
|
|
11958
|
+
const isPseudoElement = tokens[0].typ == exports.EnumToken.PseudoElementTokenType;
|
|
12013
11959
|
if (
|
|
12014
11960
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions#pseudo-elements
|
|
12015
11961
|
!(isPseudoElement && tokens[0].val.startsWith('::-webkit-')) &&
|
|
@@ -12440,1463 +12386,104 @@ function validateKeyframeBlockList(tokens, atRule, options) {
|
|
|
12440
12386
|
return validateKeyframeSelector(i == j ? tokens.slice(i) : tokens.slice(j, i + 1), atRule);
|
|
12441
12387
|
}
|
|
12442
12388
|
|
|
12443
|
-
const
|
|
12444
|
-
function
|
|
12445
|
-
|
|
12446
|
-
|
|
12447
|
-
|
|
12448
|
-
|
|
12389
|
+
const matchUrl = /^(https?:)?\/\//;
|
|
12390
|
+
function dirname(path) {
|
|
12391
|
+
if (path == '/' || path === '') {
|
|
12392
|
+
return path;
|
|
12393
|
+
}
|
|
12394
|
+
let i = 0;
|
|
12395
|
+
let parts = [''];
|
|
12396
|
+
for (; i < path.length; i++) {
|
|
12397
|
+
const chr = path.charAt(i);
|
|
12398
|
+
if (chr == '/') {
|
|
12399
|
+
parts.push('');
|
|
12400
|
+
}
|
|
12401
|
+
else if (chr == '?' || chr == '#') {
|
|
12402
|
+
break;
|
|
12403
|
+
}
|
|
12404
|
+
else {
|
|
12405
|
+
parts[parts.length - 1] += chr;
|
|
12406
|
+
}
|
|
12407
|
+
}
|
|
12408
|
+
parts.pop();
|
|
12409
|
+
return parts.length == 0 ? '/' : parts.join('/');
|
|
12449
12410
|
}
|
|
12450
|
-
function
|
|
12451
|
-
|
|
12452
|
-
|
|
12411
|
+
function splitPath(result) {
|
|
12412
|
+
const parts = [''];
|
|
12413
|
+
let i = 0;
|
|
12414
|
+
for (; i < result.length; i++) {
|
|
12415
|
+
const chr = result.charAt(i);
|
|
12416
|
+
if (chr == '/') {
|
|
12417
|
+
parts.push('');
|
|
12418
|
+
}
|
|
12419
|
+
else if (chr == '?' || chr == '#') {
|
|
12420
|
+
break;
|
|
12421
|
+
}
|
|
12422
|
+
else {
|
|
12423
|
+
parts[parts.length - 1] += chr;
|
|
12424
|
+
}
|
|
12453
12425
|
}
|
|
12454
|
-
|
|
12455
|
-
|
|
12456
|
-
|
|
12457
|
-
|
|
12426
|
+
let k = -1;
|
|
12427
|
+
while (++k < parts.length) {
|
|
12428
|
+
if (parts[k] == '.') {
|
|
12429
|
+
parts.splice(k--, 1);
|
|
12430
|
+
}
|
|
12431
|
+
else if (parts[k] == '..') {
|
|
12432
|
+
parts.splice(k - 1, 2);
|
|
12433
|
+
k -= 2;
|
|
12434
|
+
}
|
|
12458
12435
|
}
|
|
12459
|
-
return
|
|
12436
|
+
return { parts, i };
|
|
12460
12437
|
}
|
|
12461
|
-
function
|
|
12462
|
-
|
|
12463
|
-
syntax: syntaxes.reduce((acc, curr) => acc + renderSyntax(curr), ''),
|
|
12464
|
-
syntaxes,
|
|
12465
|
-
tokens,
|
|
12466
|
-
s: new Error('bar').stack
|
|
12467
|
-
}, null, 1));
|
|
12468
|
-
if (syntaxes == null) {
|
|
12469
|
-
// @ts-ignore
|
|
12438
|
+
function resolve(url, currentDirectory, cwd) {
|
|
12439
|
+
if (matchUrl.test(url)) {
|
|
12470
12440
|
return {
|
|
12471
|
-
|
|
12472
|
-
|
|
12473
|
-
node: tokens[0] ?? null,
|
|
12474
|
-
syntax: null,
|
|
12475
|
-
error: 'no matching syntaxes found',
|
|
12476
|
-
tokens
|
|
12441
|
+
absolute: url,
|
|
12442
|
+
relative: url
|
|
12477
12443
|
};
|
|
12478
12444
|
}
|
|
12479
|
-
|
|
12480
|
-
|
|
12481
|
-
|
|
12482
|
-
|
|
12483
|
-
|
|
12484
|
-
|
|
12485
|
-
tokens = tokens.slice();
|
|
12486
|
-
syntaxes = syntaxes.slice();
|
|
12487
|
-
tokens = tokens.slice();
|
|
12488
|
-
if (context.cache == null) {
|
|
12489
|
-
context.cache = new WeakMap;
|
|
12445
|
+
if (matchUrl.test(currentDirectory)) {
|
|
12446
|
+
const path = new URL(url, currentDirectory).href;
|
|
12447
|
+
return {
|
|
12448
|
+
absolute: path,
|
|
12449
|
+
relative: path
|
|
12450
|
+
};
|
|
12490
12451
|
}
|
|
12491
|
-
|
|
12492
|
-
|
|
12452
|
+
let result;
|
|
12453
|
+
if (url.charAt(0) == '/') {
|
|
12454
|
+
result = url;
|
|
12493
12455
|
}
|
|
12494
|
-
|
|
12495
|
-
|
|
12496
|
-
|
|
12497
|
-
|
|
12498
|
-
|
|
12499
|
-
|
|
12500
|
-
|
|
12501
|
-
|
|
12502
|
-
|
|
12503
|
-
|
|
12504
|
-
|
|
12505
|
-
|
|
12506
|
-
|
|
12507
|
-
|
|
12508
|
-
|
|
12509
|
-
|
|
12510
|
-
|
|
12511
|
-
|
|
12512
|
-
|
|
12513
|
-
|
|
12514
|
-
|
|
12515
|
-
|
|
12516
|
-
}
|
|
12517
|
-
continue;
|
|
12518
|
-
}
|
|
12519
|
-
else if (syntax.typ == ValidationTokenEnum.Whitespace) {
|
|
12520
|
-
syntaxes.shift();
|
|
12521
|
-
if (token.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
12522
|
-
tokens.shift();
|
|
12523
|
-
}
|
|
12524
|
-
continue;
|
|
12456
|
+
else if (currentDirectory.charAt(0) == '/') {
|
|
12457
|
+
result = dirname(currentDirectory) + '/' + url;
|
|
12458
|
+
}
|
|
12459
|
+
else if (currentDirectory === '' || dirname(currentDirectory) === '') {
|
|
12460
|
+
result = url;
|
|
12461
|
+
}
|
|
12462
|
+
else {
|
|
12463
|
+
result = dirname(currentDirectory) + '/' + url;
|
|
12464
|
+
}
|
|
12465
|
+
let { parts, i } = splitPath(result);
|
|
12466
|
+
if (parts.length == 0) {
|
|
12467
|
+
const path = result.charAt(0) == '/' ? '/' : '';
|
|
12468
|
+
return {
|
|
12469
|
+
absolute: path,
|
|
12470
|
+
relative: path
|
|
12471
|
+
};
|
|
12472
|
+
}
|
|
12473
|
+
const absolute = parts.join('/');
|
|
12474
|
+
const { parts: dirs } = splitPath(cwd ?? currentDirectory);
|
|
12475
|
+
for (const p of dirs) {
|
|
12476
|
+
if (parts[0] == p) {
|
|
12477
|
+
parts.shift();
|
|
12525
12478
|
}
|
|
12526
|
-
else
|
|
12527
|
-
|
|
12528
|
-
tokens.shift();
|
|
12529
|
-
// @ts-ignore
|
|
12530
|
-
matches.push(token);
|
|
12531
|
-
continue;
|
|
12479
|
+
else {
|
|
12480
|
+
parts.unshift('..');
|
|
12532
12481
|
}
|
|
12533
|
-
if (syntax.isOptional) {
|
|
12534
|
-
if (!context.cache.has(token)) {
|
|
12535
|
-
context.cache.set(token, new Map);
|
|
12536
|
-
}
|
|
12537
|
-
if (context.cache.get(token).has(syntax.text)) {
|
|
12538
|
-
result = context.cache.get(token).get(syntax.text);
|
|
12539
|
-
return { ...result, tokens, node: result.valid == ValidationLevel.Valid ? null : token };
|
|
12540
|
-
}
|
|
12541
|
-
// @ts-ignore
|
|
12542
|
-
const { isOptional, ...c } = syntax;
|
|
12543
|
-
// @ts-ignore
|
|
12544
|
-
let result2;
|
|
12545
|
-
// @ts-ignore
|
|
12546
|
-
result2 = validateSyntax([c], tokens, root, options, context);
|
|
12547
|
-
if (result2.valid == ValidationLevel.Valid && result2.matches.length > 0) {
|
|
12548
|
-
tokens = result2.tokens;
|
|
12549
|
-
// splice(tokens, result2.matches);
|
|
12550
|
-
// tokens = result2.tokens;
|
|
12551
|
-
// @ts-ignore
|
|
12552
|
-
matches.push(...result2.matches);
|
|
12553
|
-
matched = true;
|
|
12554
|
-
result = result2;
|
|
12555
|
-
}
|
|
12556
|
-
else {
|
|
12557
|
-
syntaxes.shift();
|
|
12558
|
-
continue;
|
|
12559
|
-
}
|
|
12560
|
-
syntaxes.shift();
|
|
12561
|
-
if (syntaxes.length == 0) {
|
|
12562
|
-
// @ts-ignore
|
|
12563
|
-
return {
|
|
12564
|
-
valid: ValidationLevel.Valid,
|
|
12565
|
-
matches: result2.matches,
|
|
12566
|
-
node: result2.node,
|
|
12567
|
-
syntax: result2.syntax,
|
|
12568
|
-
error: result2.error,
|
|
12569
|
-
tokens
|
|
12570
|
-
};
|
|
12571
|
-
}
|
|
12572
|
-
continue;
|
|
12573
|
-
}
|
|
12574
|
-
if (syntax.isList) {
|
|
12575
|
-
let index = -1;
|
|
12576
|
-
// @ts-ignore
|
|
12577
|
-
let { isList, ...c } = syntax;
|
|
12578
|
-
// const c: ValidationToken = {...syntaxes, isList: false} as ValidationToken;
|
|
12579
|
-
let result2 = null;
|
|
12580
|
-
validSyntax = false;
|
|
12581
|
-
do {
|
|
12582
|
-
for (let i = index + 1; i < tokens.length; i++) {
|
|
12583
|
-
if (tokens[i].typ == exports.EnumToken.CommaTokenType) {
|
|
12584
|
-
index = i;
|
|
12585
|
-
break;
|
|
12586
|
-
}
|
|
12587
|
-
}
|
|
12588
|
-
if (tokens[index + 1]?.typ == exports.EnumToken.CommaTokenType) {
|
|
12589
|
-
return {
|
|
12590
|
-
valid: ValidationLevel.Drop,
|
|
12591
|
-
matches,
|
|
12592
|
-
node: tokens[0],
|
|
12593
|
-
syntax,
|
|
12594
|
-
error: 'unexpected token',
|
|
12595
|
-
tokens
|
|
12596
|
-
};
|
|
12597
|
-
}
|
|
12598
|
-
if (index == -1) {
|
|
12599
|
-
index = tokens.length;
|
|
12600
|
-
}
|
|
12601
|
-
if (index == 0) {
|
|
12602
|
-
break;
|
|
12603
|
-
}
|
|
12604
|
-
// @ts-ignore
|
|
12605
|
-
result2 = validateSyntax([c], tokens.slice(0, index), root, options, context);
|
|
12606
|
-
matched = result2.valid == ValidationLevel.Valid && result2.matches.length > 0;
|
|
12607
|
-
if (matched) {
|
|
12608
|
-
const l = tokens.length;
|
|
12609
|
-
validSyntax = true;
|
|
12610
|
-
// @ts-ignore
|
|
12611
|
-
// matches.push(...result2.matches);
|
|
12612
|
-
// splice(tokens, result2.matches);
|
|
12613
|
-
if (tokens.length == 1 && tokens[0].typ == exports.EnumToken.CommaTokenType) {
|
|
12614
|
-
return {
|
|
12615
|
-
valid: ValidationLevel.Drop,
|
|
12616
|
-
matches,
|
|
12617
|
-
node: tokens[0],
|
|
12618
|
-
syntax,
|
|
12619
|
-
error: 'unexpected token',
|
|
12620
|
-
tokens
|
|
12621
|
-
};
|
|
12622
|
-
}
|
|
12623
|
-
tokens = tokens.slice(index);
|
|
12624
|
-
result = result2;
|
|
12625
|
-
// @ts-ignore
|
|
12626
|
-
matches.push(...result2.matches);
|
|
12627
|
-
if (result.tokens.length > 0) {
|
|
12628
|
-
if (index == -1) {
|
|
12629
|
-
tokens = result.tokens;
|
|
12630
|
-
}
|
|
12631
|
-
else {
|
|
12632
|
-
tokens = tokens.slice(index - result.tokens.length);
|
|
12633
|
-
}
|
|
12634
|
-
}
|
|
12635
|
-
else if (index > 0) {
|
|
12636
|
-
tokens = tokens.slice(index);
|
|
12637
|
-
}
|
|
12638
|
-
index = -1;
|
|
12639
|
-
if (l == tokens.length) {
|
|
12640
|
-
break;
|
|
12641
|
-
}
|
|
12642
|
-
}
|
|
12643
|
-
else {
|
|
12644
|
-
break;
|
|
12645
|
-
}
|
|
12646
|
-
} while (tokens.length > 0);
|
|
12647
|
-
// if (level == 0) {
|
|
12648
|
-
// }
|
|
12649
|
-
if (!matched) {
|
|
12650
|
-
return {
|
|
12651
|
-
valid: ValidationLevel.Drop,
|
|
12652
|
-
// @ts-ignore
|
|
12653
|
-
matches: [...new Set(matches)],
|
|
12654
|
-
node: token,
|
|
12655
|
-
syntax,
|
|
12656
|
-
error: 'unexpected token',
|
|
12657
|
-
tokens
|
|
12658
|
-
};
|
|
12659
|
-
}
|
|
12660
|
-
syntaxes.shift();
|
|
12661
|
-
continue;
|
|
12662
|
-
}
|
|
12663
|
-
if (syntax.isRepeatable) {
|
|
12664
|
-
// @ts-ignore
|
|
12665
|
-
let { isRepeatable, ...c } = syntax;
|
|
12666
|
-
let result2 = null;
|
|
12667
|
-
validSyntax = false;
|
|
12668
|
-
let l = tokens.length;
|
|
12669
|
-
let tok = null;
|
|
12670
|
-
do {
|
|
12671
|
-
// @ts-ignore
|
|
12672
|
-
result2 = validateSyntax([c], tokens, root, options, context);
|
|
12673
|
-
if (result2.matches.length == 0 && result2.error.length > 0) {
|
|
12674
|
-
syntaxes.shift();
|
|
12675
|
-
break main;
|
|
12676
|
-
}
|
|
12677
|
-
if (result2.valid == ValidationLevel.Valid) {
|
|
12678
|
-
tokens = result2.tokens;
|
|
12679
|
-
// @ts-ignore
|
|
12680
|
-
matches.push(...result2.matches);
|
|
12681
|
-
result = result2;
|
|
12682
|
-
if (l == tokens.length) {
|
|
12683
|
-
if (tok == tokens[0]) {
|
|
12684
|
-
break;
|
|
12685
|
-
}
|
|
12686
|
-
if (result2.matches.length == 0 && tokens.length > 0) {
|
|
12687
|
-
tokens = result2.tokens;
|
|
12688
|
-
tok = tokens[0];
|
|
12689
|
-
continue;
|
|
12690
|
-
}
|
|
12691
|
-
break;
|
|
12692
|
-
}
|
|
12693
|
-
if (matches.length == 0) {
|
|
12694
|
-
tokens = result2.tokens;
|
|
12695
|
-
}
|
|
12696
|
-
l = tokens.length;
|
|
12697
|
-
continue;
|
|
12698
|
-
}
|
|
12699
|
-
break;
|
|
12700
|
-
} while (result2.valid == ValidationLevel.Valid && tokens.length > 0);
|
|
12701
|
-
// if (lastResult != null) {
|
|
12702
|
-
//
|
|
12703
|
-
// splice(tokens, lastResult.matches);
|
|
12704
|
-
// // tokens = lastResult.tokens;
|
|
12705
|
-
// }
|
|
12706
|
-
syntaxes.shift();
|
|
12707
|
-
continue;
|
|
12708
|
-
}
|
|
12709
|
-
// at least one match
|
|
12710
|
-
if (syntax.isRepeatableGroup) {
|
|
12711
|
-
validSyntax = false;
|
|
12712
|
-
let count = 0;
|
|
12713
|
-
let l = tokens.length;
|
|
12714
|
-
let result2 = null;
|
|
12715
|
-
do {
|
|
12716
|
-
// @ts-ignore
|
|
12717
|
-
const { isRepeatableGroup, ...c } = syntax;
|
|
12718
|
-
// @ts-ignore
|
|
12719
|
-
result2 = validateSyntax([c], tokens, root, options, context);
|
|
12720
|
-
if (result2.valid == ValidationLevel.Drop || result2.matches.length == 0) {
|
|
12721
|
-
if (count > 0) {
|
|
12722
|
-
syntaxes.shift();
|
|
12723
|
-
// if (result2.matches.length == 0) {
|
|
12724
|
-
tokens = result2.tokens;
|
|
12725
|
-
// break main;
|
|
12726
|
-
if (syntaxes.length == 0) {
|
|
12727
|
-
return result2;
|
|
12728
|
-
}
|
|
12729
|
-
break main;
|
|
12730
|
-
}
|
|
12731
|
-
return result2;
|
|
12732
|
-
}
|
|
12733
|
-
if (result2.valid == ValidationLevel.Valid && result2.matches.length > 0) {
|
|
12734
|
-
count++;
|
|
12735
|
-
// lastResult = result;
|
|
12736
|
-
validSyntax = true;
|
|
12737
|
-
tokens = result2.tokens;
|
|
12738
|
-
// splice(tokens, result2.matches);
|
|
12739
|
-
// tokens = result2.tokens;
|
|
12740
|
-
// @ts-ignore
|
|
12741
|
-
matches.push(...result2.matches);
|
|
12742
|
-
result = result2;
|
|
12743
|
-
if (l == tokens.length) {
|
|
12744
|
-
break;
|
|
12745
|
-
}
|
|
12746
|
-
l = tokens.length;
|
|
12747
|
-
}
|
|
12748
|
-
else {
|
|
12749
|
-
break;
|
|
12750
|
-
}
|
|
12751
|
-
} while (tokens.length > 0 && result.valid == ValidationLevel.Valid);
|
|
12752
|
-
// if (lastResult != null) {
|
|
12753
|
-
//
|
|
12754
|
-
// splice(tokens, lastResult.matches);
|
|
12755
|
-
// // tokens = lastResult.tokens;
|
|
12756
|
-
// }
|
|
12757
|
-
// at least one match is expected
|
|
12758
|
-
if (!validSyntax /* || result.matches.length == 0 */) {
|
|
12759
|
-
// @ts-ignore
|
|
12760
|
-
return {
|
|
12761
|
-
valid: ValidationLevel.Drop,
|
|
12762
|
-
node: token,
|
|
12763
|
-
tokens,
|
|
12764
|
-
syntax,
|
|
12765
|
-
error: 'unexpected token',
|
|
12766
|
-
matches: []
|
|
12767
|
-
};
|
|
12768
|
-
}
|
|
12769
|
-
syntaxes.shift();
|
|
12770
|
-
continue;
|
|
12771
|
-
}
|
|
12772
|
-
if (syntax.atLeastOnce) {
|
|
12773
|
-
const { atLeastOnce, ...c } = syntax;
|
|
12774
|
-
result = validateSyntax([c], tokens, root, options, context);
|
|
12775
|
-
if (result.valid == ValidationLevel.Drop) {
|
|
12776
|
-
return result;
|
|
12777
|
-
}
|
|
12778
|
-
splice(tokens, result.matches);
|
|
12779
|
-
// tokens = result.tokens;
|
|
12780
|
-
// @ts-ignore
|
|
12781
|
-
matches.push(...result.matches);
|
|
12782
|
-
let l = tokens.length;
|
|
12783
|
-
let r = validateSyntax([c], tokens, root, options, context);
|
|
12784
|
-
while (r.valid == ValidationLevel.Valid) {
|
|
12785
|
-
splice(tokens, r.matches);
|
|
12786
|
-
// tokens = r.tokens;
|
|
12787
|
-
r = validateSyntax([c], tokens, root, options, context);
|
|
12788
|
-
if (l == tokens.length) {
|
|
12789
|
-
break;
|
|
12790
|
-
}
|
|
12791
|
-
if (r.valid == ValidationLevel.Valid && r.matches.length > 0) {
|
|
12792
|
-
// @ts-ignore
|
|
12793
|
-
matches.push(...result.matches);
|
|
12794
|
-
}
|
|
12795
|
-
l = tokens.length;
|
|
12796
|
-
}
|
|
12797
|
-
syntaxes.shift();
|
|
12798
|
-
continue;
|
|
12799
|
-
}
|
|
12800
|
-
// @ts-ignore
|
|
12801
|
-
if (syntax.occurence != null) {
|
|
12802
|
-
// @ts-ignore
|
|
12803
|
-
const { occurence, ...c } = syntax;
|
|
12804
|
-
// && syntaxes.occurence.max != null
|
|
12805
|
-
// consume all tokens
|
|
12806
|
-
let match = 1;
|
|
12807
|
-
// @ts-ignore
|
|
12808
|
-
result = validateSyntax([c], tokens, root, options, context);
|
|
12809
|
-
if (result.valid == ValidationLevel.Drop) {
|
|
12810
|
-
return result;
|
|
12811
|
-
}
|
|
12812
|
-
if (result.matches.length == 0) {
|
|
12813
|
-
syntaxes.shift();
|
|
12814
|
-
continue;
|
|
12815
|
-
}
|
|
12816
|
-
// splice(tokens, result.matches);
|
|
12817
|
-
// tokens = result.tokens;
|
|
12818
|
-
// @ts-ignore
|
|
12819
|
-
matches.push(...result.matches);
|
|
12820
|
-
matched = true;
|
|
12821
|
-
tokens = result.tokens;
|
|
12822
|
-
while (occurence.max == null || match < occurence.max) {
|
|
12823
|
-
// trim whitespace
|
|
12824
|
-
if (tokens[0]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
12825
|
-
tokens.shift();
|
|
12826
|
-
}
|
|
12827
|
-
// @ts-ignore
|
|
12828
|
-
let r = validateSyntax([c], tokens, root, options, context);
|
|
12829
|
-
if (r.valid != ValidationLevel.Valid || r.matches.length == 0) {
|
|
12830
|
-
break;
|
|
12831
|
-
}
|
|
12832
|
-
result = r;
|
|
12833
|
-
// splice(tokens, r.matches);
|
|
12834
|
-
// tokens = r.tokens;
|
|
12835
|
-
// @ts-ignore
|
|
12836
|
-
matches.push(...result.matches);
|
|
12837
|
-
match++;
|
|
12838
|
-
tokens = r.tokens;
|
|
12839
|
-
result = r;
|
|
12840
|
-
if (tokens.length == 0 || (occurence.max != null && match >= occurence.max)) {
|
|
12841
|
-
break;
|
|
12842
|
-
}
|
|
12843
|
-
// @ts-ignore
|
|
12844
|
-
// r = validateSyntax([c], tokens, root, options, context);
|
|
12845
|
-
}
|
|
12846
|
-
syntaxes.shift();
|
|
12847
|
-
continue;
|
|
12848
|
-
}
|
|
12849
|
-
// @ts-ignore
|
|
12850
|
-
if (syntax.typ == ValidationTokenEnum.Whitespace) {
|
|
12851
|
-
if (token.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
12852
|
-
tokens.shift();
|
|
12853
|
-
}
|
|
12854
|
-
syntaxes.shift();
|
|
12855
|
-
continue;
|
|
12856
|
-
}
|
|
12857
|
-
// @ts-ignore
|
|
12858
|
-
if (token.val != null && specialValues.includes(token.val)) {
|
|
12859
|
-
matched = true;
|
|
12860
|
-
result = {
|
|
12861
|
-
valid: ValidationLevel.Valid,
|
|
12862
|
-
matches: [token],
|
|
12863
|
-
node: null,
|
|
12864
|
-
syntax,
|
|
12865
|
-
error: '',
|
|
12866
|
-
tokens
|
|
12867
|
-
};
|
|
12868
|
-
// @ts-ignore
|
|
12869
|
-
matches.push(...result.matches);
|
|
12870
|
-
}
|
|
12871
|
-
else {
|
|
12872
|
-
result = doValidateSyntax(syntax, token, tokens, root, options, context);
|
|
12873
|
-
matched = result.valid == ValidationLevel.Valid && result.matches.length > 0;
|
|
12874
|
-
if (matched) {
|
|
12875
|
-
// splice(tokens, result.matches);
|
|
12876
|
-
tokens = result.tokens;
|
|
12877
|
-
// @ts-ignore
|
|
12878
|
-
matches.push(...result.matches);
|
|
12879
|
-
}
|
|
12880
|
-
}
|
|
12881
|
-
if (result.valid == ValidationLevel.Drop) {
|
|
12882
|
-
// @ts-ignore
|
|
12883
|
-
return { ...result, matches, tokens, node: result.valid == ValidationLevel.Valid ? null : token };
|
|
12884
|
-
}
|
|
12885
|
-
consumeSyntax(syntaxes);
|
|
12886
|
-
if (tokens.length == 0) {
|
|
12887
|
-
return result;
|
|
12888
|
-
}
|
|
12889
|
-
}
|
|
12890
|
-
if (result?.valid == ValidationLevel.Valid) {
|
|
12891
|
-
// splice(tokens, result.matches);
|
|
12892
|
-
tokens = result.tokens;
|
|
12893
|
-
// @ts-ignore
|
|
12894
|
-
matches.push(...result.matches);
|
|
12895
|
-
}
|
|
12896
|
-
if ( /* result == null && */tokens.length == 0 && syntaxes.length > 0) {
|
|
12897
|
-
validSyntax = isOptionalSyntax(syntaxes);
|
|
12898
|
-
}
|
|
12899
|
-
if (result == null) {
|
|
12900
|
-
result = {
|
|
12901
|
-
valid: validSyntax ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
12902
|
-
matches,
|
|
12903
|
-
node: validSyntax ? null : tokens[0] ?? null,
|
|
12904
|
-
// @ts-ignore
|
|
12905
|
-
syntax,
|
|
12906
|
-
error: validSyntax ? '' : 'unexpected token',
|
|
12907
|
-
tokens
|
|
12908
|
-
};
|
|
12909
|
-
}
|
|
12910
|
-
if (token != null) {
|
|
12911
|
-
if (!context.cache.has(token)) {
|
|
12912
|
-
context.cache.set(token, new Map);
|
|
12913
|
-
}
|
|
12914
|
-
context.cache.get(token).set(syntax.text, result);
|
|
12915
|
-
}
|
|
12916
|
-
if (result != null) {
|
|
12917
|
-
// @ts-ignore
|
|
12918
|
-
return { ...result, matches: [...(new Set(matches))] };
|
|
12919
|
-
}
|
|
12920
|
-
return result;
|
|
12921
|
-
}
|
|
12922
|
-
function isOptionalSyntax(syntaxes) {
|
|
12923
|
-
return syntaxes.length > 0 && syntaxes.every(t => t.typ == ValidationTokenEnum.Whitespace || t.isOptional || t.isRepeatable || (t.typ == ValidationTokenEnum.PropertyType && isOptionalSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, t.val) ?? getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, t.val) ?? [])));
|
|
12924
|
-
}
|
|
12925
|
-
function doValidateSyntax(syntax, token, tokens, root, options, context) {
|
|
12926
|
-
let valid = false;
|
|
12927
|
-
let result;
|
|
12928
|
-
let children;
|
|
12929
|
-
let queue;
|
|
12930
|
-
let matches;
|
|
12931
|
-
let child;
|
|
12932
|
-
let astNodes = new Set;
|
|
12933
|
-
if (token.typ == exports.EnumToken.NestingSelectorTokenType && syntax.typ == 2) {
|
|
12934
|
-
valid = root != null && 'relative-selector' == syntax.val;
|
|
12935
|
-
return {
|
|
12936
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
12937
|
-
matches: valid ? [token] : [],
|
|
12938
|
-
node: valid ? null : token,
|
|
12939
|
-
syntax,
|
|
12940
|
-
error: valid ? '' : 'unexpected token',
|
|
12941
|
-
tokens
|
|
12942
|
-
};
|
|
12943
|
-
}
|
|
12944
|
-
switch (syntax.typ) {
|
|
12945
|
-
case ValidationTokenEnum.Comma:
|
|
12946
|
-
valid = token.typ === exports.EnumToken.CommaTokenType;
|
|
12947
|
-
// @ts-ignore
|
|
12948
|
-
result = {
|
|
12949
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
12950
|
-
matches: valid ? [token] : [],
|
|
12951
|
-
node: valid ? null : token,
|
|
12952
|
-
syntax,
|
|
12953
|
-
error: valid ? '' : 'unexpected token',
|
|
12954
|
-
tokens
|
|
12955
|
-
};
|
|
12956
|
-
break;
|
|
12957
|
-
case ValidationTokenEnum.AtRule:
|
|
12958
|
-
if (token.typ != exports.EnumToken.AtRuleNodeType) {
|
|
12959
|
-
// @ts-ignore
|
|
12960
|
-
return {
|
|
12961
|
-
valid: ValidationLevel.Drop,
|
|
12962
|
-
matches: [],
|
|
12963
|
-
node: token,
|
|
12964
|
-
syntax,
|
|
12965
|
-
error: 'expecting at-rule',
|
|
12966
|
-
tokens
|
|
12967
|
-
};
|
|
12968
|
-
}
|
|
12969
|
-
if (token.nam != syntax.val) {
|
|
12970
|
-
// @ts-ignore
|
|
12971
|
-
return {
|
|
12972
|
-
valid: ValidationLevel.Drop,
|
|
12973
|
-
matches: [],
|
|
12974
|
-
node: token,
|
|
12975
|
-
syntax,
|
|
12976
|
-
error: `expecting '@${syntax.val}' but found '@${token.nam}'`,
|
|
12977
|
-
tokens
|
|
12978
|
-
};
|
|
12979
|
-
}
|
|
12980
|
-
if (root == null) {
|
|
12981
|
-
return {
|
|
12982
|
-
valid: ValidationLevel.Valid,
|
|
12983
|
-
matches: [token],
|
|
12984
|
-
node: null,
|
|
12985
|
-
syntax,
|
|
12986
|
-
error: '',
|
|
12987
|
-
tokens
|
|
12988
|
-
};
|
|
12989
|
-
}
|
|
12990
|
-
if (root.typ != exports.EnumToken.AtRuleNodeType) {
|
|
12991
|
-
// @ts-ignore
|
|
12992
|
-
return {
|
|
12993
|
-
valid: ValidationLevel.Drop,
|
|
12994
|
-
matches: [],
|
|
12995
|
-
node: token,
|
|
12996
|
-
syntax,
|
|
12997
|
-
error: 'not allowed here',
|
|
12998
|
-
tokens
|
|
12999
|
-
};
|
|
13000
|
-
}
|
|
13001
|
-
if (!('chi' in token)) {
|
|
13002
|
-
// @ts-ignore
|
|
13003
|
-
return {
|
|
13004
|
-
valid: ValidationLevel.Drop,
|
|
13005
|
-
matches: [],
|
|
13006
|
-
node: token,
|
|
13007
|
-
syntax,
|
|
13008
|
-
error: '@at-rule must have children',
|
|
13009
|
-
tokens
|
|
13010
|
-
};
|
|
13011
|
-
}
|
|
13012
|
-
// @ts-ignore
|
|
13013
|
-
result = {
|
|
13014
|
-
valid: ValidationLevel.Valid,
|
|
13015
|
-
matches: [token],
|
|
13016
|
-
node: null,
|
|
13017
|
-
syntax,
|
|
13018
|
-
error: '',
|
|
13019
|
-
tokens
|
|
13020
|
-
};
|
|
13021
|
-
break;
|
|
13022
|
-
case ValidationTokenEnum.AtRuleDefinition:
|
|
13023
|
-
if (token.typ != exports.EnumToken.AtRuleNodeType) {
|
|
13024
|
-
// @ts-ignore
|
|
13025
|
-
return {
|
|
13026
|
-
valid: ValidationLevel.Drop,
|
|
13027
|
-
matches: [],
|
|
13028
|
-
node: token,
|
|
13029
|
-
syntax,
|
|
13030
|
-
error: 'expecting at-rule',
|
|
13031
|
-
tokens
|
|
13032
|
-
};
|
|
13033
|
-
}
|
|
13034
|
-
if ('chi' in syntax && !('chi' in token)) {
|
|
13035
|
-
// @ts-ignore
|
|
13036
|
-
return {
|
|
13037
|
-
valid: ValidationLevel.Drop,
|
|
13038
|
-
matches: [],
|
|
13039
|
-
node: token,
|
|
13040
|
-
syntax,
|
|
13041
|
-
error: '@at-rule must have children',
|
|
13042
|
-
tokens
|
|
13043
|
-
};
|
|
13044
|
-
}
|
|
13045
|
-
if ('chi' in token && !('chi' in token)) {
|
|
13046
|
-
// @ts-ignore
|
|
13047
|
-
return {
|
|
13048
|
-
valid: ValidationLevel.Drop,
|
|
13049
|
-
matches: [],
|
|
13050
|
-
node: token,
|
|
13051
|
-
syntax,
|
|
13052
|
-
error: 'children not allowed here',
|
|
13053
|
-
tokens
|
|
13054
|
-
};
|
|
13055
|
-
}
|
|
13056
|
-
const s = getParsedSyntax("atRules" /* ValidationSyntaxGroupEnum.AtRules */, '@' + token.nam);
|
|
13057
|
-
if ('prelude' in syntax) {
|
|
13058
|
-
if (!('tokens' in token)) {
|
|
13059
|
-
// @ts-ignore
|
|
13060
|
-
return {
|
|
13061
|
-
valid: ValidationLevel.Drop,
|
|
13062
|
-
matches: [],
|
|
13063
|
-
node: token,
|
|
13064
|
-
syntax,
|
|
13065
|
-
error: 'expected at-rule prelude',
|
|
13066
|
-
tokens
|
|
13067
|
-
};
|
|
13068
|
-
}
|
|
13069
|
-
result = validateSyntax(s[0].prelude, token.tokens, root, options, {
|
|
13070
|
-
...context,
|
|
13071
|
-
tokens: null,
|
|
13072
|
-
level: context.level + 1
|
|
13073
|
-
});
|
|
13074
|
-
if (result.valid == ValidationLevel.Drop) {
|
|
13075
|
-
return result;
|
|
13076
|
-
}
|
|
13077
|
-
}
|
|
13078
|
-
const hasBody = 'chi' in s[0];
|
|
13079
|
-
if ('chi' in token) {
|
|
13080
|
-
if (!hasBody) {
|
|
13081
|
-
// @ts-ignore
|
|
13082
|
-
return {
|
|
13083
|
-
valid: ValidationLevel.Drop,
|
|
13084
|
-
matches: [],
|
|
13085
|
-
node: token,
|
|
13086
|
-
syntax,
|
|
13087
|
-
error: 'unexpected at-rule body',
|
|
13088
|
-
tokens
|
|
13089
|
-
};
|
|
13090
|
-
}
|
|
13091
|
-
}
|
|
13092
|
-
else if (hasBody) {
|
|
13093
|
-
// @ts-ignore
|
|
13094
|
-
return {
|
|
13095
|
-
valid: ValidationLevel.Drop,
|
|
13096
|
-
matches: [],
|
|
13097
|
-
node: token,
|
|
13098
|
-
syntax,
|
|
13099
|
-
error: 'expecting at-rule body',
|
|
13100
|
-
tokens
|
|
13101
|
-
};
|
|
13102
|
-
}
|
|
13103
|
-
break;
|
|
13104
|
-
case ValidationTokenEnum.DeclarationType:
|
|
13105
|
-
// @ts-ignore
|
|
13106
|
-
result = validateSyntax(getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, syntax.val), [token], root, options, context);
|
|
13107
|
-
break;
|
|
13108
|
-
case ValidationTokenEnum.Keyword:
|
|
13109
|
-
valid = (token.typ == exports.EnumToken.IdenTokenType && token.val.localeCompare(syntax.val, 'en', { sensitivity: 'base' }) == 0) ||
|
|
13110
|
-
(token.typ == exports.EnumToken.ColorTokenType && token.kin == 'lit' && syntax.val.localeCompare(token.val, 'en', { sensitivity: 'base' }) == 0);
|
|
13111
|
-
result = {
|
|
13112
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13113
|
-
matches: valid ? [token] : [],
|
|
13114
|
-
node: valid ? null : token,
|
|
13115
|
-
syntax,
|
|
13116
|
-
error: valid ? '' : 'unexpected token',
|
|
13117
|
-
tokens
|
|
13118
|
-
};
|
|
13119
|
-
break;
|
|
13120
|
-
case ValidationTokenEnum.SemiColon:
|
|
13121
|
-
valid = root == null || [exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType, exports.EnumToken.StyleSheetNodeType].includes(root.typ);
|
|
13122
|
-
result = {
|
|
13123
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13124
|
-
matches: valid ? [token] : [],
|
|
13125
|
-
node: valid ? null : token,
|
|
13126
|
-
syntax,
|
|
13127
|
-
error: valid ? '' : 'unexpected token',
|
|
13128
|
-
tokens
|
|
13129
|
-
};
|
|
13130
|
-
break;
|
|
13131
|
-
case ValidationTokenEnum.Separator:
|
|
13132
|
-
valid = token.typ == exports.EnumToken.LiteralTokenType && token.val != '/';
|
|
13133
|
-
result = {
|
|
13134
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13135
|
-
matches: valid ? [token] : [],
|
|
13136
|
-
node: valid ? null : token,
|
|
13137
|
-
syntax,
|
|
13138
|
-
error: valid ? '' : 'unexpected token',
|
|
13139
|
-
tokens
|
|
13140
|
-
};
|
|
13141
|
-
break;
|
|
13142
|
-
case ValidationTokenEnum.PropertyType:
|
|
13143
|
-
//
|
|
13144
|
-
if ('image' == syntax.val) {
|
|
13145
|
-
valid = token.typ == exports.EnumToken.UrlFunctionTokenType || token.typ == exports.EnumToken.ImageFunctionTokenType;
|
|
13146
|
-
if (!valid) {
|
|
13147
|
-
return {
|
|
13148
|
-
valid: ValidationLevel.Drop,
|
|
13149
|
-
matches: [],
|
|
13150
|
-
node: token,
|
|
13151
|
-
syntax,
|
|
13152
|
-
error: 'unexpected <image>',
|
|
13153
|
-
tokens
|
|
13154
|
-
};
|
|
13155
|
-
}
|
|
13156
|
-
result = validateImage(token);
|
|
13157
|
-
}
|
|
13158
|
-
else if (['media-feature', 'mf-plain'].includes(syntax.val)) {
|
|
13159
|
-
valid = token.typ == exports.EnumToken.DeclarationNodeType;
|
|
13160
|
-
result = {
|
|
13161
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13162
|
-
matches: valid ? [token] : [],
|
|
13163
|
-
node: valid ? null : token,
|
|
13164
|
-
syntax,
|
|
13165
|
-
error: valid ? '' : 'unexpected token',
|
|
13166
|
-
tokens
|
|
13167
|
-
};
|
|
13168
|
-
}
|
|
13169
|
-
else if (syntax.val == 'pseudo-page') {
|
|
13170
|
-
valid = token.typ == exports.EnumToken.PseudoClassTokenType && [':left', ':right', ':first', ':blank'].includes(token.val);
|
|
13171
|
-
result = {
|
|
13172
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13173
|
-
matches: valid ? [token] : [],
|
|
13174
|
-
node: valid ? null : token,
|
|
13175
|
-
syntax,
|
|
13176
|
-
error: valid ? '' : 'unexpected token',
|
|
13177
|
-
tokens
|
|
13178
|
-
};
|
|
13179
|
-
}
|
|
13180
|
-
else if (syntax.val == 'page-body') {
|
|
13181
|
-
if (token.typ == exports.EnumToken.DeclarationNodeType) {
|
|
13182
|
-
valid = true;
|
|
13183
|
-
// @ts-ignore
|
|
13184
|
-
result = {
|
|
13185
|
-
valid: ValidationLevel.Valid,
|
|
13186
|
-
matches: [token],
|
|
13187
|
-
node: null,
|
|
13188
|
-
syntax,
|
|
13189
|
-
error: '',
|
|
13190
|
-
tokens
|
|
13191
|
-
};
|
|
13192
|
-
while (tokens.length > 0 && [exports.EnumToken.DeclarationNodeType].includes(tokens[0].typ)) {
|
|
13193
|
-
// @ts-ignore
|
|
13194
|
-
result.matches.push(tokens.shift());
|
|
13195
|
-
}
|
|
13196
|
-
}
|
|
13197
|
-
else if (token.typ == exports.EnumToken.AtRuleNodeType) {
|
|
13198
|
-
result = validateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, 'page-margin-box-type'), [token], root, options, context);
|
|
13199
|
-
}
|
|
13200
|
-
}
|
|
13201
|
-
else if (syntax.val == 'group-rule-body') {
|
|
13202
|
-
valid = [exports.EnumToken.AtRuleNodeType, exports.EnumToken.RuleNodeType].includes(token.typ);
|
|
13203
|
-
if (!valid && token.typ == exports.EnumToken.DeclarationNodeType && root?.typ == exports.EnumToken.AtRuleNodeType && root.nam == 'media') {
|
|
13204
|
-
// allowed only if nested rule
|
|
13205
|
-
let parent = root;
|
|
13206
|
-
while (parent != null) {
|
|
13207
|
-
if (parent.typ == exports.EnumToken.RuleNodeType) {
|
|
13208
|
-
valid = true;
|
|
13209
|
-
break;
|
|
13210
|
-
}
|
|
13211
|
-
// @ts-ignore
|
|
13212
|
-
parent = parent.parent;
|
|
13213
|
-
}
|
|
13214
|
-
}
|
|
13215
|
-
// @ts-ignore
|
|
13216
|
-
result = {
|
|
13217
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13218
|
-
matches: [],
|
|
13219
|
-
node: valid ? null : token,
|
|
13220
|
-
syntax,
|
|
13221
|
-
error: valid ? '' : 'token is not allowed as a child',
|
|
13222
|
-
tokens
|
|
13223
|
-
};
|
|
13224
|
-
if (!valid) {
|
|
13225
|
-
return result;
|
|
13226
|
-
}
|
|
13227
|
-
}
|
|
13228
|
-
//
|
|
13229
|
-
else if ('type-selector' == syntax.val) {
|
|
13230
|
-
valid = (token.typ == exports.EnumToken.UniversalSelectorTokenType) ||
|
|
13231
|
-
token.typ == exports.EnumToken.IdenTokenType || (token.typ == exports.EnumToken.NameSpaceAttributeTokenType &&
|
|
13232
|
-
(token.l == null || token.l.typ == exports.EnumToken.IdenTokenType ||
|
|
13233
|
-
(token.l.typ == exports.EnumToken.LiteralTokenType && token.l.val == '*')) &&
|
|
13234
|
-
token.r.typ == exports.EnumToken.IdenTokenType);
|
|
13235
|
-
result = {
|
|
13236
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13237
|
-
matches: valid ? [token] : [],
|
|
13238
|
-
node: token,
|
|
13239
|
-
syntax,
|
|
13240
|
-
error: valid ? '' : 'unexpected token',
|
|
13241
|
-
tokens
|
|
13242
|
-
};
|
|
13243
|
-
}
|
|
13244
|
-
else if ('wq-name' == syntax.val) {
|
|
13245
|
-
valid = token.typ == exports.EnumToken.IdenTokenType || (token.typ == exports.EnumToken.NameSpaceAttributeTokenType &&
|
|
13246
|
-
(token.l == null || token.l.typ == exports.EnumToken.IdenTokenType || (token.l.typ == exports.EnumToken.LiteralTokenType && token.l.val == '*')) &&
|
|
13247
|
-
token.r.typ == exports.EnumToken.IdenTokenType);
|
|
13248
|
-
result = {
|
|
13249
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13250
|
-
matches: valid ? [token] : [],
|
|
13251
|
-
node: token,
|
|
13252
|
-
syntax,
|
|
13253
|
-
error: valid ? '' : 'unexpected token',
|
|
13254
|
-
tokens
|
|
13255
|
-
};
|
|
13256
|
-
}
|
|
13257
|
-
else if (exports.EnumToken.UniversalSelectorTokenType == token.typ && 'subclass-selector' == syntax.val) {
|
|
13258
|
-
valid = true;
|
|
13259
|
-
result = {
|
|
13260
|
-
valid: ValidationLevel.Valid,
|
|
13261
|
-
matches: [token],
|
|
13262
|
-
node: null,
|
|
13263
|
-
syntax,
|
|
13264
|
-
error: '',
|
|
13265
|
-
tokens
|
|
13266
|
-
};
|
|
13267
|
-
}
|
|
13268
|
-
else if ('attribute-selector' == syntax.val) {
|
|
13269
|
-
valid = token.typ == exports.EnumToken.AttrTokenType && token.chi.length > 0;
|
|
13270
|
-
if (valid) {
|
|
13271
|
-
const children = token.chi.filter(t => t.typ != exports.EnumToken.WhitespaceTokenType && t.typ != exports.EnumToken.CommaTokenType);
|
|
13272
|
-
valid = children.length == 1 && [
|
|
13273
|
-
exports.EnumToken.IdenTokenType,
|
|
13274
|
-
exports.EnumToken.NameSpaceAttributeTokenType,
|
|
13275
|
-
exports.EnumToken.MatchExpressionTokenType
|
|
13276
|
-
].includes(children[0].typ);
|
|
13277
|
-
if (valid && children[0].typ == exports.EnumToken.MatchExpressionTokenType) {
|
|
13278
|
-
const t = children[0];
|
|
13279
|
-
valid = [
|
|
13280
|
-
exports.EnumToken.IdenTokenType,
|
|
13281
|
-
exports.EnumToken.NameSpaceAttributeTokenType
|
|
13282
|
-
].includes(t.l.typ) &&
|
|
13283
|
-
(t.op == null || ([
|
|
13284
|
-
exports.EnumToken.DelimTokenType, exports.EnumToken.DashMatchTokenType,
|
|
13285
|
-
exports.EnumToken.StartMatchTokenType, exports.EnumToken.ContainMatchTokenType,
|
|
13286
|
-
exports.EnumToken.EndMatchTokenType, exports.EnumToken.IncludeMatchTokenType
|
|
13287
|
-
].includes(t.op.typ) &&
|
|
13288
|
-
t.r != null &&
|
|
13289
|
-
[
|
|
13290
|
-
exports.EnumToken.StringTokenType,
|
|
13291
|
-
exports.EnumToken.IdenTokenType
|
|
13292
|
-
].includes(t.r.typ)));
|
|
13293
|
-
if (valid && t.attr != null) {
|
|
13294
|
-
const s = getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, 'attr-modifier')[0];
|
|
13295
|
-
valid = s.chi.some((l) => l.some((r) => r.val == t.attr));
|
|
13296
|
-
}
|
|
13297
|
-
}
|
|
13298
|
-
}
|
|
13299
|
-
result = {
|
|
13300
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13301
|
-
matches: valid ? [token] : [],
|
|
13302
|
-
node: valid ? null : token,
|
|
13303
|
-
syntax,
|
|
13304
|
-
error: valid ? '' : 'unexpected token',
|
|
13305
|
-
tokens
|
|
13306
|
-
};
|
|
13307
|
-
if (!valid) {
|
|
13308
|
-
return result;
|
|
13309
|
-
}
|
|
13310
|
-
}
|
|
13311
|
-
else if ('combinator' == syntax.val) {
|
|
13312
|
-
valid = [
|
|
13313
|
-
exports.EnumToken.DescendantCombinatorTokenType,
|
|
13314
|
-
exports.EnumToken.SubsequentSiblingCombinatorTokenType,
|
|
13315
|
-
exports.EnumToken.NextSiblingCombinatorTokenType,
|
|
13316
|
-
exports.EnumToken.ChildCombinatorTokenType,
|
|
13317
|
-
exports.EnumToken.ColumnCombinatorTokenType
|
|
13318
|
-
].includes(token.typ);
|
|
13319
|
-
if (valid) {
|
|
13320
|
-
// @ts-ignore
|
|
13321
|
-
const position = context.tokens.indexOf(token);
|
|
13322
|
-
if (root == null) {
|
|
13323
|
-
valid = position > 0 && context.tokens[position - 1]?.typ != exports.EnumToken.CommaTokenType;
|
|
13324
|
-
}
|
|
13325
|
-
}
|
|
13326
|
-
result = {
|
|
13327
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13328
|
-
matches: valid ? [token] : [],
|
|
13329
|
-
node: valid ? null : token,
|
|
13330
|
-
syntax,
|
|
13331
|
-
error: valid ? '' : 'unexpected token',
|
|
13332
|
-
tokens
|
|
13333
|
-
};
|
|
13334
|
-
if (!valid) {
|
|
13335
|
-
return result;
|
|
13336
|
-
}
|
|
13337
|
-
}
|
|
13338
|
-
else if ('ident-token' == syntax.val) {
|
|
13339
|
-
valid = token.typ == exports.EnumToken.IdenTokenType;
|
|
13340
|
-
result = {
|
|
13341
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13342
|
-
matches: valid ? [token] : [],
|
|
13343
|
-
node: valid ? null : token,
|
|
13344
|
-
syntax,
|
|
13345
|
-
error: valid ? '' : 'unexpected token',
|
|
13346
|
-
tokens
|
|
13347
|
-
};
|
|
13348
|
-
}
|
|
13349
|
-
else if ('hex-color' == syntax.val) {
|
|
13350
|
-
valid = token.typ == exports.EnumToken.ColorTokenType && token.kin == 'hex';
|
|
13351
|
-
result = {
|
|
13352
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13353
|
-
matches: valid ? [token] : [],
|
|
13354
|
-
node: valid ? null : token,
|
|
13355
|
-
syntax,
|
|
13356
|
-
error: valid ? '' : 'unexpected token',
|
|
13357
|
-
tokens
|
|
13358
|
-
};
|
|
13359
|
-
}
|
|
13360
|
-
else if ('resolution' == syntax.val) {
|
|
13361
|
-
valid = token.typ == exports.EnumToken.ResolutionTokenType;
|
|
13362
|
-
result = {
|
|
13363
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13364
|
-
matches: valid ? [token] : [],
|
|
13365
|
-
node: valid ? null : token,
|
|
13366
|
-
syntax,
|
|
13367
|
-
error: valid ? '' : 'unexpected token',
|
|
13368
|
-
tokens
|
|
13369
|
-
};
|
|
13370
|
-
}
|
|
13371
|
-
else if ('angle' == syntax.val) {
|
|
13372
|
-
valid = token.typ == exports.EnumToken.AngleTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val == '0');
|
|
13373
|
-
result = {
|
|
13374
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13375
|
-
matches: valid ? [token] : [],
|
|
13376
|
-
node: valid ? null : token,
|
|
13377
|
-
syntax,
|
|
13378
|
-
error: valid ? '' : 'unexpected token',
|
|
13379
|
-
tokens
|
|
13380
|
-
};
|
|
13381
|
-
}
|
|
13382
|
-
else if ('time' == syntax.val) {
|
|
13383
|
-
valid = token.typ == exports.EnumToken.TimingFunctionTokenType;
|
|
13384
|
-
result = {
|
|
13385
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13386
|
-
matches: valid ? [token] : [],
|
|
13387
|
-
node: valid ? null : token,
|
|
13388
|
-
syntax,
|
|
13389
|
-
error: valid ? '' : 'unexpected token',
|
|
13390
|
-
tokens
|
|
13391
|
-
};
|
|
13392
|
-
}
|
|
13393
|
-
else if ('ident' == syntax.val) {
|
|
13394
|
-
valid = token.typ == exports.EnumToken.IdenTokenType;
|
|
13395
|
-
result = {
|
|
13396
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13397
|
-
matches: valid ? [token] : [],
|
|
13398
|
-
node: valid ? null : token,
|
|
13399
|
-
syntax,
|
|
13400
|
-
error: valid ? '' : 'unexpected token',
|
|
13401
|
-
tokens
|
|
13402
|
-
};
|
|
13403
|
-
}
|
|
13404
|
-
else if (['id-selector', 'hash-token'].includes(syntax.val)) {
|
|
13405
|
-
valid = token.typ == exports.EnumToken.HashTokenType;
|
|
13406
|
-
result = {
|
|
13407
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13408
|
-
matches: valid ? [token] : [],
|
|
13409
|
-
node: valid ? null : token,
|
|
13410
|
-
syntax,
|
|
13411
|
-
error: valid ? '' : 'unexpected token',
|
|
13412
|
-
tokens
|
|
13413
|
-
};
|
|
13414
|
-
}
|
|
13415
|
-
else if (['integer', 'number'].includes(syntax.val)) {
|
|
13416
|
-
// valid = token.typ == EnumToken.NumberTokenType;
|
|
13417
|
-
valid = token.typ == exports.EnumToken.NumberTokenType && ('integer' != syntax.val || Number.isInteger(+token.val));
|
|
13418
|
-
if (valid && 'range' in syntax) {
|
|
13419
|
-
const value = Number(token.val);
|
|
13420
|
-
const range = syntax.range;
|
|
13421
|
-
valid = value >= range[0] && (range[1] == null || value <= range[1]);
|
|
13422
|
-
}
|
|
13423
|
-
result = {
|
|
13424
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13425
|
-
matches: valid ? [token] : [],
|
|
13426
|
-
node: valid ? null : token,
|
|
13427
|
-
syntax,
|
|
13428
|
-
error: valid ? '' : 'unexpected token',
|
|
13429
|
-
tokens
|
|
13430
|
-
};
|
|
13431
|
-
}
|
|
13432
|
-
else if ('length' == syntax.val) {
|
|
13433
|
-
valid = isLength(token) || (token.typ == exports.EnumToken.NumberTokenType && token.val == '0');
|
|
13434
|
-
// @ts-ignore
|
|
13435
|
-
result = {
|
|
13436
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13437
|
-
matches: valid ? [token] : [],
|
|
13438
|
-
node: valid ? null : token,
|
|
13439
|
-
syntax,
|
|
13440
|
-
error: valid ? '' : 'unexpected token',
|
|
13441
|
-
tokens
|
|
13442
|
-
};
|
|
13443
|
-
}
|
|
13444
|
-
else if ('percentage' == syntax.val) {
|
|
13445
|
-
valid = token.typ == exports.EnumToken.PercentageTokenType || (token.typ == exports.EnumToken.NumberTokenType && token.val == '0');
|
|
13446
|
-
result = {
|
|
13447
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13448
|
-
matches: valid ? [token] : [],
|
|
13449
|
-
node: valid ? null : token,
|
|
13450
|
-
syntax,
|
|
13451
|
-
error: valid ? '' : 'unexpected token',
|
|
13452
|
-
tokens
|
|
13453
|
-
};
|
|
13454
|
-
}
|
|
13455
|
-
else if ('dashed-ident' == syntax.val) {
|
|
13456
|
-
valid = token.typ == exports.EnumToken.DashedIdenTokenType;
|
|
13457
|
-
result = {
|
|
13458
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13459
|
-
matches: valid ? [token] : [],
|
|
13460
|
-
node: valid ? null : token,
|
|
13461
|
-
syntax,
|
|
13462
|
-
error: valid ? '' : 'unexpected token',
|
|
13463
|
-
tokens
|
|
13464
|
-
};
|
|
13465
|
-
}
|
|
13466
|
-
else if ('custom-ident' == syntax.val) {
|
|
13467
|
-
valid = token.typ == exports.EnumToken.DashedIdenTokenType || token.typ == exports.EnumToken.IdenTokenType;
|
|
13468
|
-
result = {
|
|
13469
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13470
|
-
matches: valid ? [token] : [],
|
|
13471
|
-
node: valid ? null : token,
|
|
13472
|
-
syntax,
|
|
13473
|
-
error: valid ? '' : 'unexpected token',
|
|
13474
|
-
tokens
|
|
13475
|
-
};
|
|
13476
|
-
}
|
|
13477
|
-
else if ('custom-property-name' == syntax.val) {
|
|
13478
|
-
valid = token.typ == exports.EnumToken.DashedIdenTokenType;
|
|
13479
|
-
result = {
|
|
13480
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13481
|
-
matches: valid ? [token] : [],
|
|
13482
|
-
node: valid ? null : token,
|
|
13483
|
-
syntax,
|
|
13484
|
-
error: valid ? '' : 'unexpected token',
|
|
13485
|
-
tokens
|
|
13486
|
-
};
|
|
13487
|
-
}
|
|
13488
|
-
else if ('string' == syntax.val) {
|
|
13489
|
-
valid = token.typ == exports.EnumToken.StringTokenType;
|
|
13490
|
-
result = {
|
|
13491
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13492
|
-
matches: valid ? [token] : [],
|
|
13493
|
-
node: valid ? null : token,
|
|
13494
|
-
syntax,
|
|
13495
|
-
error: valid ? '' : 'unexpected token',
|
|
13496
|
-
tokens
|
|
13497
|
-
};
|
|
13498
|
-
}
|
|
13499
|
-
else if ('declaration-value' == syntax.val) {
|
|
13500
|
-
valid = token.typ != exports.EnumToken.LiteralTokenType;
|
|
13501
|
-
result = {
|
|
13502
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13503
|
-
matches: valid ? [token] : [],
|
|
13504
|
-
node: valid ? null : token,
|
|
13505
|
-
syntax,
|
|
13506
|
-
error: valid ? '' : 'unexpected token',
|
|
13507
|
-
tokens
|
|
13508
|
-
};
|
|
13509
|
-
}
|
|
13510
|
-
else if ('url' == syntax.val) {
|
|
13511
|
-
valid = token.typ == exports.EnumToken.UrlFunctionTokenType || token.typ == exports.EnumToken.StringTokenType;
|
|
13512
|
-
result = {
|
|
13513
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13514
|
-
matches: valid ? [token] : [],
|
|
13515
|
-
node: valid ? null : token,
|
|
13516
|
-
syntax,
|
|
13517
|
-
error: valid ? '' : 'unexpected token',
|
|
13518
|
-
tokens
|
|
13519
|
-
};
|
|
13520
|
-
}
|
|
13521
|
-
else if ('declaration' == syntax.val) {
|
|
13522
|
-
valid = token.typ == exports.EnumToken.DeclarationNodeType && (token.nam.startsWith(('--')) || token.nam in config$2.declarations || token.nam in config$2.syntaxes);
|
|
13523
|
-
if (!valid) {
|
|
13524
|
-
// @ts-ignore
|
|
13525
|
-
result = {
|
|
13526
|
-
valid: ValidationLevel.Drop,
|
|
13527
|
-
matches: [],
|
|
13528
|
-
node: token,
|
|
13529
|
-
syntax,
|
|
13530
|
-
error: 'unexpected token',
|
|
13531
|
-
tokens
|
|
13532
|
-
};
|
|
13533
|
-
}
|
|
13534
|
-
else if (token.nam.startsWith(('--'))) {
|
|
13535
|
-
result = {
|
|
13536
|
-
valid: ValidationLevel.Valid,
|
|
13537
|
-
matches: [token],
|
|
13538
|
-
node: null,
|
|
13539
|
-
syntax,
|
|
13540
|
-
error: '',
|
|
13541
|
-
tokens
|
|
13542
|
-
};
|
|
13543
|
-
}
|
|
13544
|
-
else {
|
|
13545
|
-
result = validateSyntax(getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, token.nam) ?? getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, token.nam), token.val, token, options, {
|
|
13546
|
-
...context,
|
|
13547
|
-
tokens: null,
|
|
13548
|
-
level: 0
|
|
13549
|
-
});
|
|
13550
|
-
if (result.valid == ValidationLevel.Valid && result.error.length == 0) {
|
|
13551
|
-
tokens = result.tokens;
|
|
13552
|
-
}
|
|
13553
|
-
}
|
|
13554
|
-
}
|
|
13555
|
-
else if ('class-selector' == syntax.val) {
|
|
13556
|
-
valid = exports.EnumToken.ClassSelectorTokenType == token.typ || exports.EnumToken.UniversalSelectorTokenType == token.typ;
|
|
13557
|
-
result = {
|
|
13558
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13559
|
-
matches: valid ? [token] : [],
|
|
13560
|
-
node: token,
|
|
13561
|
-
syntax,
|
|
13562
|
-
error: valid ? '' : 'unexpected token',
|
|
13563
|
-
tokens
|
|
13564
|
-
};
|
|
13565
|
-
}
|
|
13566
|
-
// else if ('complex-selector' == (syntaxes as ValidationPropertyToken).val) {
|
|
13567
|
-
//
|
|
13568
|
-
// result = validateSyntax(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (syntaxes as ValidationPropertyToken).val) as ValidationToken[], tokens, root as AstNode, options, context);
|
|
13569
|
-
//
|
|
13570
|
-
// }
|
|
13571
|
-
else if (['pseudo-element-selector', 'pseudo-class-selector'].includes(syntax.val)) {
|
|
13572
|
-
valid = false;
|
|
13573
|
-
if (token.typ == exports.EnumToken.PseudoClassTokenType) {
|
|
13574
|
-
let val = token.val;
|
|
13575
|
-
if (val == ':before' || val == ':after') {
|
|
13576
|
-
val = ':' + val;
|
|
13577
|
-
}
|
|
13578
|
-
valid = val in config$2.selectors;
|
|
13579
|
-
if (!valid && val.match(/^:?:-/) != null) {
|
|
13580
|
-
const match = token.val.match(/^(:?:)(-[^-]+-)(.*)$/);
|
|
13581
|
-
if (match != null) {
|
|
13582
|
-
valid = true;
|
|
13583
|
-
}
|
|
13584
|
-
}
|
|
13585
|
-
result = {
|
|
13586
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13587
|
-
matches: valid ? [token] : [],
|
|
13588
|
-
node: valid ? null : token,
|
|
13589
|
-
syntax,
|
|
13590
|
-
error: valid ? '' : 'invalid pseudo class',
|
|
13591
|
-
tokens
|
|
13592
|
-
};
|
|
13593
|
-
}
|
|
13594
|
-
else if (token.typ == exports.EnumToken.PseudoClassFuncTokenType) {
|
|
13595
|
-
let key = token.val in config$2.selectors ? token.val : token.val + '()';
|
|
13596
|
-
valid = key in config$2.selectors;
|
|
13597
|
-
if (!valid && token.val.match(/^:?:-/)) {
|
|
13598
|
-
const match = token.val.match(/^(:?:)(-[^-]+-)(.*)$/);
|
|
13599
|
-
if (match != null) {
|
|
13600
|
-
key = match[1] + match[3] in config$2.selectors ? match[1] + match[3] : match[1] + match[3] + '()';
|
|
13601
|
-
valid = key in config$2.selectors;
|
|
13602
|
-
}
|
|
13603
|
-
}
|
|
13604
|
-
const s = getParsedSyntax("selectors" /* ValidationSyntaxGroupEnum.Selectors */, key);
|
|
13605
|
-
if (s != null) {
|
|
13606
|
-
const r = s[0];
|
|
13607
|
-
if (r.typ != ValidationTokenEnum.PseudoClassFunctionToken) {
|
|
13608
|
-
valid = false;
|
|
13609
|
-
}
|
|
13610
|
-
else {
|
|
13611
|
-
result = validateSyntax(s[0].chi, token.chi, root, options, {
|
|
13612
|
-
...context,
|
|
13613
|
-
tokens: null,
|
|
13614
|
-
level: context.level + 1
|
|
13615
|
-
});
|
|
13616
|
-
break;
|
|
13617
|
-
}
|
|
13618
|
-
}
|
|
13619
|
-
}
|
|
13620
|
-
result = {
|
|
13621
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13622
|
-
matches: valid ? [token] : [],
|
|
13623
|
-
node: token,
|
|
13624
|
-
syntax,
|
|
13625
|
-
error: valid ? '' : 'unexpected token',
|
|
13626
|
-
tokens
|
|
13627
|
-
};
|
|
13628
|
-
}
|
|
13629
|
-
// <relative-selector-list>
|
|
13630
|
-
// <complex-selector-list>
|
|
13631
|
-
else if ('relative-selector' == syntax.val) {
|
|
13632
|
-
if (tokens.length == 1 && token.typ == exports.EnumToken.NestingSelectorTokenType) {
|
|
13633
|
-
return {
|
|
13634
|
-
valid: ValidationLevel.Valid,
|
|
13635
|
-
matches: [token],
|
|
13636
|
-
node: token,
|
|
13637
|
-
syntax,
|
|
13638
|
-
error: '',
|
|
13639
|
-
tokens
|
|
13640
|
-
};
|
|
13641
|
-
}
|
|
13642
|
-
result = validateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, syntax.val), token.typ == exports.EnumToken.NestingSelectorTokenType ? tokens.slice(1) : tokens, root, options, context);
|
|
13643
|
-
}
|
|
13644
|
-
// <relative-selector-list>
|
|
13645
|
-
// <complex-selector-list>
|
|
13646
|
-
else if (['forgiving-selector-list', 'forgiving-relative-selector-list'].includes(syntax.val)) {
|
|
13647
|
-
// @ts-ignore
|
|
13648
|
-
result = { tokens: tokens.slice(), ...validateSelector(tokens, options, root) };
|
|
13649
|
-
}
|
|
13650
|
-
// https://github.com/mdn/data/pull/186#issuecomment-369604537
|
|
13651
|
-
else if (syntax.val.endsWith('-token')) {
|
|
13652
|
-
const val = syntax.val;
|
|
13653
|
-
valid = true;
|
|
13654
|
-
switch (val) {
|
|
13655
|
-
case 'function-token':
|
|
13656
|
-
valid = token.typ != exports.EnumToken.ParensTokenType && funcLike.includes(token.typ);
|
|
13657
|
-
break;
|
|
13658
|
-
case 'ident-token':
|
|
13659
|
-
valid = token.typ == exports.EnumToken.DashedIdenTokenType || token.typ == exports.EnumToken.IdenTokenType;
|
|
13660
|
-
break;
|
|
13661
|
-
case 'hash-token':
|
|
13662
|
-
valid = token.typ == exports.EnumToken.HashTokenType;
|
|
13663
|
-
break;
|
|
13664
|
-
case 'string-token':
|
|
13665
|
-
valid = token.typ == exports.EnumToken.StringTokenType;
|
|
13666
|
-
break;
|
|
13667
|
-
default:
|
|
13668
|
-
console.error(new Error(`unhandled syntax: '<${val}>'`));
|
|
13669
|
-
break;
|
|
13670
|
-
}
|
|
13671
|
-
result = {
|
|
13672
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13673
|
-
matches: valid ? [token] : [],
|
|
13674
|
-
node: valid ? null : token,
|
|
13675
|
-
syntax,
|
|
13676
|
-
error: valid ? '' : 'unexpected token',
|
|
13677
|
-
tokens
|
|
13678
|
-
};
|
|
13679
|
-
}
|
|
13680
|
-
else if ('wq-name' == syntax.val) {
|
|
13681
|
-
valid = token.typ == exports.EnumToken.IdenTokenType || (token.typ == exports.EnumToken.NameSpaceAttributeTokenType &&
|
|
13682
|
-
(token.l == null || token.l.typ == exports.EnumToken.IdenTokenType || (token.l.typ == exports.EnumToken.LiteralTokenType && token.l.val == '*')) &&
|
|
13683
|
-
token.r.typ == exports.EnumToken.IdenTokenType);
|
|
13684
|
-
result = {
|
|
13685
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13686
|
-
matches: valid ? [token] : [],
|
|
13687
|
-
node: token,
|
|
13688
|
-
syntax,
|
|
13689
|
-
error: valid ? '' : 'unexpected token',
|
|
13690
|
-
tokens
|
|
13691
|
-
};
|
|
13692
|
-
}
|
|
13693
|
-
else {
|
|
13694
|
-
const val = syntax.val;
|
|
13695
|
-
// https://github.com/mdn/data/pull/186#issuecomment-369604537
|
|
13696
|
-
if (val == 'any-value') {
|
|
13697
|
-
return {
|
|
13698
|
-
valid: ValidationLevel.Valid,
|
|
13699
|
-
matches: [token],
|
|
13700
|
-
node: null,
|
|
13701
|
-
syntax,
|
|
13702
|
-
error: '',
|
|
13703
|
-
tokens
|
|
13704
|
-
};
|
|
13705
|
-
}
|
|
13706
|
-
else if (val in config$2.declarations || val in config$2.syntaxes) {
|
|
13707
|
-
result = validateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, val) ?? getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, val), tokens, root, options, context);
|
|
13708
|
-
}
|
|
13709
|
-
else {
|
|
13710
|
-
// @ts-ignore
|
|
13711
|
-
result = {
|
|
13712
|
-
valid: ValidationLevel.Drop,
|
|
13713
|
-
matches: [],
|
|
13714
|
-
node: token,
|
|
13715
|
-
syntax,
|
|
13716
|
-
error: 'unexpected token',
|
|
13717
|
-
tokens
|
|
13718
|
-
};
|
|
13719
|
-
}
|
|
13720
|
-
}
|
|
13721
|
-
break;
|
|
13722
|
-
case ValidationTokenEnum.Parens:
|
|
13723
|
-
case ValidationTokenEnum.Function:
|
|
13724
|
-
if (syntax.typ == ValidationTokenEnum.Parens) {
|
|
13725
|
-
valid = token.typ == exports.EnumToken.ParensTokenType;
|
|
13726
|
-
}
|
|
13727
|
-
else {
|
|
13728
|
-
valid = 'chi' in token && 'val' in token &&
|
|
13729
|
-
token.val.localeCompare(syntax.val, 'en', { sensitivity: 'base' }) == 0;
|
|
13730
|
-
}
|
|
13731
|
-
result = !valid ?
|
|
13732
|
-
// @ts-ignore
|
|
13733
|
-
{
|
|
13734
|
-
valid: ValidationLevel.Drop,
|
|
13735
|
-
matches: [],
|
|
13736
|
-
node: token,
|
|
13737
|
-
syntax,
|
|
13738
|
-
error: 'unexpected token',
|
|
13739
|
-
tokens
|
|
13740
|
-
} : validateSyntax(syntax.chi, token.chi, root, options, {
|
|
13741
|
-
...context,
|
|
13742
|
-
tokens: null,
|
|
13743
|
-
level: context.level + 1
|
|
13744
|
-
});
|
|
13745
|
-
break;
|
|
13746
|
-
case ValidationTokenEnum.ValidationFunctionDefinition:
|
|
13747
|
-
valid = 'val' in token && 'chi' in token;
|
|
13748
|
-
result = {
|
|
13749
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13750
|
-
matches: valid ? [token] : [],
|
|
13751
|
-
node: valid ? null : token,
|
|
13752
|
-
syntax,
|
|
13753
|
-
error: '',
|
|
13754
|
-
tokens
|
|
13755
|
-
};
|
|
13756
|
-
if (result.valid == ValidationLevel.Valid) {
|
|
13757
|
-
valid = token.val.localeCompare(syntax.val, 'en', { sensitivity: 'base' }) == 0;
|
|
13758
|
-
result = {
|
|
13759
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13760
|
-
matches: valid ? [token] : [],
|
|
13761
|
-
node: valid ? null : token,
|
|
13762
|
-
error: '',
|
|
13763
|
-
syntax,
|
|
13764
|
-
tokens
|
|
13765
|
-
};
|
|
13766
|
-
if (result.valid == ValidationLevel.Valid) {
|
|
13767
|
-
const s = getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, syntax.val + '()'); // config[ValidationSyntaxGroupEnum.Syntaxes][(syntaxes as ValidationFunctionDefinitionToken).val + '()'] as ValidationSyntaxNode;
|
|
13768
|
-
result = validateSyntax(s, tokens, root, options, context);
|
|
13769
|
-
}
|
|
13770
|
-
}
|
|
13771
|
-
break;
|
|
13772
|
-
case ValidationTokenEnum.Bracket:
|
|
13773
|
-
result = validateSyntax(syntax.chi, tokens, root, options, context);
|
|
13774
|
-
break;
|
|
13775
|
-
case ValidationTokenEnum.PipeToken:
|
|
13776
|
-
for (const lines of syntax.chi) {
|
|
13777
|
-
result = validateSyntax(lines, tokens, root, options, context);
|
|
13778
|
-
if (result.valid == ValidationLevel.Valid) {
|
|
13779
|
-
break;
|
|
13780
|
-
}
|
|
13781
|
-
}
|
|
13782
|
-
break;
|
|
13783
|
-
case ValidationTokenEnum.AmpersandToken:
|
|
13784
|
-
children = [...syntax.l.slice(), ...syntax.r.slice()];
|
|
13785
|
-
matches = [];
|
|
13786
|
-
queue = [];
|
|
13787
|
-
let m = [];
|
|
13788
|
-
for (let j = 0; j < children.length; j++) {
|
|
13789
|
-
const res = validateSyntax([children[j]], tokens, root, options, context);
|
|
13790
|
-
// @ts-ignore
|
|
13791
|
-
if (res.valid == ValidationLevel.Valid) {
|
|
13792
|
-
m.push(...res.matches);
|
|
13793
|
-
matches.push(...children.splice(j, 1));
|
|
13794
|
-
j = 0;
|
|
13795
|
-
// @ts-ignore
|
|
13796
|
-
astNodes.delete(token);
|
|
13797
|
-
consumeToken(tokens);
|
|
13798
|
-
token = tokens[0];
|
|
13799
|
-
if (token == null) {
|
|
13800
|
-
break;
|
|
13801
|
-
}
|
|
13802
|
-
// @ts-ignore
|
|
13803
|
-
astNodes.add(token);
|
|
13804
|
-
}
|
|
13805
|
-
}
|
|
13806
|
-
if (astNodes.size > 0) {
|
|
13807
|
-
// @ts-ignore
|
|
13808
|
-
tokens.unshift(...astNodes);
|
|
13809
|
-
astNodes = new Set();
|
|
13810
|
-
}
|
|
13811
|
-
valid = matches.length > 0;
|
|
13812
|
-
result = {
|
|
13813
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13814
|
-
matches: m,
|
|
13815
|
-
node: valid ? null : token,
|
|
13816
|
-
syntax,
|
|
13817
|
-
error: valid ? '' : 'expecting token',
|
|
13818
|
-
tokens
|
|
13819
|
-
};
|
|
13820
|
-
break;
|
|
13821
|
-
case ValidationTokenEnum.ColumnToken:
|
|
13822
|
-
children = [...syntax.l.slice(), ...syntax.r.slice()];
|
|
13823
|
-
matches = [];
|
|
13824
|
-
queue = [];
|
|
13825
|
-
while ((child = children.shift())) {
|
|
13826
|
-
const res = validateSyntax([child], tokens, root, options, context);
|
|
13827
|
-
if (res.valid == ValidationLevel.Valid) {
|
|
13828
|
-
matches.push(child);
|
|
13829
|
-
consumeToken(tokens);
|
|
13830
|
-
token = tokens[0];
|
|
13831
|
-
if (queue.length > 0) {
|
|
13832
|
-
children.unshift(...queue);
|
|
13833
|
-
queue = [];
|
|
13834
|
-
}
|
|
13835
|
-
if (token == null) {
|
|
13836
|
-
break;
|
|
13837
|
-
}
|
|
13838
|
-
}
|
|
13839
|
-
else {
|
|
13840
|
-
queue.push(child);
|
|
13841
|
-
}
|
|
13842
|
-
}
|
|
13843
|
-
valid = matches.length > 0;
|
|
13844
|
-
result = {
|
|
13845
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13846
|
-
matches: valid ? [token] : [],
|
|
13847
|
-
node: valid ? null : token,
|
|
13848
|
-
syntax,
|
|
13849
|
-
error: valid ? '' : 'expecting token',
|
|
13850
|
-
tokens
|
|
13851
|
-
};
|
|
13852
|
-
break;
|
|
13853
|
-
case ValidationTokenEnum.StringToken:
|
|
13854
|
-
valid = token.typ == exports.EnumToken.StringTokenType && syntax.val.slice(1, -1) == token.val.slice(1, -1);
|
|
13855
|
-
return {
|
|
13856
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13857
|
-
matches: valid ? [token] : [],
|
|
13858
|
-
node: valid ? null : token,
|
|
13859
|
-
syntax,
|
|
13860
|
-
error: valid ? '' : 'expecting token',
|
|
13861
|
-
tokens
|
|
13862
|
-
};
|
|
13863
|
-
case ValidationTokenEnum.PseudoClassFunctionToken:
|
|
13864
|
-
valid = token.typ == exports.EnumToken.PseudoClassFuncTokenType;
|
|
13865
|
-
if (valid) {
|
|
13866
|
-
let key = token.val in config$2.selectors ? token.val : token.val + '()';
|
|
13867
|
-
const s = getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, key);
|
|
13868
|
-
valid = s != null && validateSyntax(s, token.chi, root, options, {
|
|
13869
|
-
...context,
|
|
13870
|
-
tokens: null,
|
|
13871
|
-
level: context.level + 1
|
|
13872
|
-
}).valid == ValidationLevel.Valid;
|
|
13873
|
-
}
|
|
13874
|
-
result = {
|
|
13875
|
-
valid: valid ? ValidationLevel.Valid : ValidationLevel.Drop,
|
|
13876
|
-
matches: valid ? [token] : [],
|
|
13877
|
-
node: valid ? null : token,
|
|
13878
|
-
syntax,
|
|
13879
|
-
error: valid ? '' : 'invalid token',
|
|
13880
|
-
tokens
|
|
13881
|
-
};
|
|
13882
|
-
break;
|
|
13883
|
-
case ValidationTokenEnum.DeclarationDefinitionToken:
|
|
13884
|
-
if (token.typ != exports.EnumToken.DeclarationNodeType || token.nam != syntax.nam) {
|
|
13885
|
-
return {
|
|
13886
|
-
valid: ValidationLevel.Drop,
|
|
13887
|
-
matches: [],
|
|
13888
|
-
node: token,
|
|
13889
|
-
syntax,
|
|
13890
|
-
error: '',
|
|
13891
|
-
tokens
|
|
13892
|
-
};
|
|
13893
|
-
}
|
|
13894
|
-
return validateSyntax([syntax.val], token.val, root, options, context);
|
|
13895
|
-
default:
|
|
13896
|
-
throw new Error('not implemented: ' + JSON.stringify({ syntax, token, tokens }, null, 1));
|
|
13897
12482
|
}
|
|
13898
|
-
|
|
13899
|
-
|
|
12483
|
+
return {
|
|
12484
|
+
absolute,
|
|
12485
|
+
relative: parts.join('/') + (i < result.length ? result.slice(i) : '')
|
|
12486
|
+
};
|
|
13900
12487
|
}
|
|
13901
12488
|
|
|
13902
12489
|
function validateURL(token) {
|
|
@@ -13964,23 +12551,6 @@ function validateURL(token) {
|
|
|
13964
12551
|
};
|
|
13965
12552
|
}
|
|
13966
12553
|
|
|
13967
|
-
function validateImage(token) {
|
|
13968
|
-
if (token.typ == exports.EnumToken.UrlFunctionTokenType) {
|
|
13969
|
-
return validateURL(token);
|
|
13970
|
-
}
|
|
13971
|
-
if (token.typ == exports.EnumToken.ImageFunctionTokenType) {
|
|
13972
|
-
return validateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, token.val + '()'), token.chi);
|
|
13973
|
-
}
|
|
13974
|
-
return {
|
|
13975
|
-
valid: ValidationLevel.Drop,
|
|
13976
|
-
matches: [],
|
|
13977
|
-
node: token,
|
|
13978
|
-
syntax: 'image()',
|
|
13979
|
-
error: 'expected <image> or <url>',
|
|
13980
|
-
tokens: []
|
|
13981
|
-
};
|
|
13982
|
-
}
|
|
13983
|
-
|
|
13984
12554
|
const validateSelectorList = validateComplexSelectorList;
|
|
13985
12555
|
|
|
13986
12556
|
function validateSelector(selector, options, root) {
|
|
@@ -14225,7 +12795,7 @@ function validateMediaCondition(token, atRule) {
|
|
|
14225
12795
|
if (token.typ == exports.EnumToken.MediaFeatureNotTokenType) {
|
|
14226
12796
|
return validateMediaCondition(token.val, atRule);
|
|
14227
12797
|
}
|
|
14228
|
-
if (token.typ != exports.EnumToken.ParensTokenType && !(['when', 'else'].includes(atRule.nam) && token.typ == exports.EnumToken.FunctionTokenType && ['media', 'supports'].includes(token.val))) {
|
|
12798
|
+
if (token.typ != exports.EnumToken.ParensTokenType && !(['when', 'else', 'import'].includes(atRule.nam) && token.typ == exports.EnumToken.FunctionTokenType && ['media', 'supports', 'selector'].includes(token.val))) {
|
|
14229
12799
|
return false;
|
|
14230
12800
|
}
|
|
14231
12801
|
const chi = token.chi.filter((t) => t.typ != exports.EnumToken.CommentTokenType && t.typ != exports.EnumToken.WhitespaceTokenType);
|
|
@@ -14241,6 +12811,7 @@ function validateMediaCondition(token, atRule) {
|
|
|
14241
12811
|
if (chi[0].typ == exports.EnumToken.MediaQueryConditionTokenType) {
|
|
14242
12812
|
return chi[0].l.typ == exports.EnumToken.IdenTokenType;
|
|
14243
12813
|
}
|
|
12814
|
+
console.error(chi[0].parent);
|
|
14244
12815
|
return false;
|
|
14245
12816
|
}
|
|
14246
12817
|
function validateMediaFeature(token) {
|
|
@@ -14487,6 +13058,7 @@ function validateAtRuleSupports(atRule, options, root) {
|
|
|
14487
13058
|
};
|
|
14488
13059
|
}
|
|
14489
13060
|
function validateAtRuleSupportsConditions(atRule, tokenList) {
|
|
13061
|
+
let result = null;
|
|
14490
13062
|
for (const tokens of splitTokenList(tokenList)) {
|
|
14491
13063
|
if (tokens.length == 0) {
|
|
14492
13064
|
// @ts-ignore
|
|
@@ -14500,22 +13072,46 @@ function validateAtRuleSupportsConditions(atRule, tokenList) {
|
|
|
14500
13072
|
};
|
|
14501
13073
|
}
|
|
14502
13074
|
let previousToken = null;
|
|
14503
|
-
let result = null;
|
|
14504
13075
|
while (tokens.length > 0) {
|
|
14505
13076
|
result = validateSupportCondition(atRule, tokens[0]);
|
|
14506
13077
|
// supports-condition
|
|
14507
|
-
if (result
|
|
13078
|
+
if (result.valid == ValidationLevel.Valid) {
|
|
14508
13079
|
previousToken = tokens[0];
|
|
14509
13080
|
tokens.shift();
|
|
14510
13081
|
}
|
|
14511
13082
|
else {
|
|
14512
13083
|
result = validateSupportFeature(tokens[0]);
|
|
14513
|
-
if (result == null || result.valid == ValidationLevel.Valid) {
|
|
13084
|
+
if ( /*result == null || */result.valid == ValidationLevel.Valid) {
|
|
14514
13085
|
previousToken = tokens[0];
|
|
14515
13086
|
tokens.shift();
|
|
14516
13087
|
}
|
|
14517
13088
|
else {
|
|
14518
|
-
|
|
13089
|
+
if (tokens[0].typ == exports.EnumToken.ParensTokenType) {
|
|
13090
|
+
result = validateAtRuleSupportsConditions(atRule, tokens[0].chi);
|
|
13091
|
+
if ( /* result == null || */result.valid == ValidationLevel.Valid) {
|
|
13092
|
+
previousToken = tokens[0];
|
|
13093
|
+
tokens.shift();
|
|
13094
|
+
// continue;
|
|
13095
|
+
}
|
|
13096
|
+
else {
|
|
13097
|
+
return result;
|
|
13098
|
+
}
|
|
13099
|
+
}
|
|
13100
|
+
else {
|
|
13101
|
+
return result;
|
|
13102
|
+
}
|
|
13103
|
+
// if (result!= null && result.valid == ValidationLevel.Drop) {
|
|
13104
|
+
//
|
|
13105
|
+
// return {
|
|
13106
|
+
// valid: ValidationLevel.Drop,
|
|
13107
|
+
// matches: [],
|
|
13108
|
+
// node: tokens[0] ?? atRule,
|
|
13109
|
+
// syntax: '@' + atRule.nam,
|
|
13110
|
+
// // @ts-ignore
|
|
13111
|
+
// error: result.error as string ?? 'unexpected token',
|
|
13112
|
+
// tokens: []
|
|
13113
|
+
// };
|
|
13114
|
+
// }
|
|
14519
13115
|
}
|
|
14520
13116
|
}
|
|
14521
13117
|
if (tokens.length == 0) {
|
|
@@ -14570,7 +13166,14 @@ function validateAtRuleSupportsConditions(atRule, tokenList) {
|
|
|
14570
13166
|
}
|
|
14571
13167
|
}
|
|
14572
13168
|
}
|
|
14573
|
-
return
|
|
13169
|
+
return {
|
|
13170
|
+
valid: ValidationLevel.Valid,
|
|
13171
|
+
matches: [],
|
|
13172
|
+
node: atRule,
|
|
13173
|
+
syntax: '@' + atRule.nam,
|
|
13174
|
+
error: '',
|
|
13175
|
+
tokens: []
|
|
13176
|
+
};
|
|
14574
13177
|
}
|
|
14575
13178
|
function validateSupportCondition(atRule, token) {
|
|
14576
13179
|
if (token.typ == exports.EnumToken.MediaFeatureNotTokenType) {
|
|
@@ -14637,7 +13240,7 @@ function validateSupportCondition(atRule, token) {
|
|
|
14637
13240
|
function validateSupportFeature(token) {
|
|
14638
13241
|
if (token.typ == exports.EnumToken.FunctionTokenType) {
|
|
14639
13242
|
if (token.val.localeCompare('selector', undefined, { sensitivity: 'base' }) == 0) {
|
|
14640
|
-
return
|
|
13243
|
+
return validateComplexSelector(parseSelector(token.chi));
|
|
14641
13244
|
}
|
|
14642
13245
|
if (token.val.localeCompare('font-tech', undefined, { sensitivity: 'base' }) == 0) {
|
|
14643
13246
|
const chi = token.chi.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ));
|
|
@@ -14761,6 +13364,9 @@ function validateAtRuleImport(atRule, options, root) {
|
|
|
14761
13364
|
};
|
|
14762
13365
|
}
|
|
14763
13366
|
}
|
|
13367
|
+
tokens.shift();
|
|
13368
|
+
// @ts-ignore
|
|
13369
|
+
consumeWhitespace(tokens);
|
|
14764
13370
|
}
|
|
14765
13371
|
else {
|
|
14766
13372
|
// @ts-ignore
|
|
@@ -14781,86 +13387,85 @@ function validateAtRuleImport(atRule, options, root) {
|
|
|
14781
13387
|
tokens.shift();
|
|
14782
13388
|
// @ts-ignore
|
|
14783
13389
|
if (!consumeWhitespace(tokens)) {
|
|
14784
|
-
// @ts-ignore
|
|
14785
|
-
return {
|
|
14786
|
-
valid: ValidationLevel.Drop,
|
|
14787
|
-
matches: [],
|
|
14788
|
-
node: tokens[0],
|
|
14789
|
-
syntax: '@' + atRule.nam,
|
|
14790
|
-
error: 'expecting whitespace',
|
|
14791
|
-
tokens
|
|
14792
|
-
};
|
|
14793
|
-
}
|
|
14794
|
-
}
|
|
14795
|
-
}
|
|
14796
|
-
// @ts-ignore
|
|
14797
|
-
else if (tokens[0].typ == exports.EnumToken.FunctionTokenType) {
|
|
14798
|
-
// @ts-ignore
|
|
14799
|
-
if ('layer'.localeCompare(tokens[0].val, undefined, { sensitivity: 'base' }) != 0) {
|
|
14800
|
-
// @ts-ignore
|
|
14801
|
-
return {
|
|
14802
|
-
valid: ValidationLevel.Drop,
|
|
14803
|
-
matches: [],
|
|
14804
|
-
node: tokens[0],
|
|
14805
|
-
syntax: '@' + atRule.nam,
|
|
14806
|
-
error: 'expecting layer()',
|
|
14807
|
-
tokens
|
|
14808
|
-
};
|
|
14809
|
-
}
|
|
14810
|
-
// @ts-ignore
|
|
14811
|
-
const result = validateLayerName(tokens[0].chi);
|
|
14812
|
-
if (result.valid == ValidationLevel.Drop) {
|
|
14813
|
-
return result;
|
|
14814
|
-
}
|
|
14815
|
-
tokens.shift();
|
|
14816
|
-
// @ts-ignore
|
|
14817
|
-
if (!consumeWhitespace(tokens)) {
|
|
14818
|
-
// @ts-ignore
|
|
14819
|
-
return {
|
|
14820
|
-
valid: ValidationLevel.Drop,
|
|
14821
|
-
matches: [],
|
|
14822
|
-
node: tokens[0],
|
|
14823
|
-
syntax: '@' + atRule.nam,
|
|
14824
|
-
error: 'expecting whitespace',
|
|
14825
|
-
tokens
|
|
14826
|
-
};
|
|
13390
|
+
// @ts-ignore
|
|
13391
|
+
return {
|
|
13392
|
+
valid: ValidationLevel.Drop,
|
|
13393
|
+
matches: [],
|
|
13394
|
+
node: tokens[0],
|
|
13395
|
+
syntax: '@' + atRule.nam,
|
|
13396
|
+
error: 'expecting whitespace',
|
|
13397
|
+
tokens
|
|
13398
|
+
};
|
|
13399
|
+
}
|
|
14827
13400
|
}
|
|
14828
13401
|
}
|
|
14829
|
-
}
|
|
14830
|
-
if (tokens.length > 0) {
|
|
14831
13402
|
// @ts-ignore
|
|
14832
|
-
if (tokens[0].typ == exports.EnumToken.
|
|
14833
|
-
if (tokens[0].nam != 'supports') {
|
|
14834
|
-
// @ts-ignore
|
|
14835
|
-
return {
|
|
14836
|
-
valid: ValidationLevel.Drop,
|
|
14837
|
-
matches: [],
|
|
14838
|
-
node: tokens[0],
|
|
14839
|
-
syntax: '@' + atRule.nam,
|
|
14840
|
-
error: 'expecting @supports or media query list',
|
|
14841
|
-
tokens
|
|
14842
|
-
};
|
|
14843
|
-
}
|
|
13403
|
+
else if (tokens[0].typ == exports.EnumToken.FunctionTokenType) {
|
|
14844
13404
|
// @ts-ignore
|
|
14845
|
-
|
|
14846
|
-
|
|
14847
|
-
|
|
13405
|
+
if ('layer'.localeCompare(tokens[0].val, undefined, { sensitivity: 'base' }) == 0) {
|
|
13406
|
+
const result = validateLayerName(tokens[0].chi);
|
|
13407
|
+
if (result.valid == ValidationLevel.Drop) {
|
|
13408
|
+
return result;
|
|
13409
|
+
}
|
|
13410
|
+
tokens.shift();
|
|
13411
|
+
// @ts-ignore
|
|
13412
|
+
consumeWhitespace(tokens);
|
|
14848
13413
|
}
|
|
14849
|
-
tokens.shift();
|
|
14850
13414
|
// @ts-ignore
|
|
14851
|
-
if (
|
|
13415
|
+
if ('supports'.localeCompare(tokens[0]?.val, undefined, { sensitivity: 'base' }) == 0) {
|
|
13416
|
+
const result = validateAtRuleSupportsConditions(atRule, tokens[0].chi);
|
|
13417
|
+
if (result.valid == ValidationLevel.Drop) {
|
|
13418
|
+
return result;
|
|
13419
|
+
}
|
|
13420
|
+
tokens.shift();
|
|
14852
13421
|
// @ts-ignore
|
|
14853
|
-
|
|
14854
|
-
valid: ValidationLevel.Drop,
|
|
14855
|
-
matches: [],
|
|
14856
|
-
node: tokens[0],
|
|
14857
|
-
syntax: '@' + atRule.nam,
|
|
14858
|
-
error: 'expecting whitespace',
|
|
14859
|
-
tokens
|
|
14860
|
-
};
|
|
13422
|
+
consumeWhitespace(tokens);
|
|
14861
13423
|
}
|
|
14862
13424
|
}
|
|
14863
13425
|
}
|
|
13426
|
+
// if (tokens.length > 0) {
|
|
13427
|
+
//
|
|
13428
|
+
// // @ts-ignore
|
|
13429
|
+
// if (tokens[0].typ == EnumToken.AtRuleTokenType) {
|
|
13430
|
+
//
|
|
13431
|
+
// if ((tokens[0] as AstAtRule).nam != 'supports') {
|
|
13432
|
+
//
|
|
13433
|
+
// // @ts-ignore
|
|
13434
|
+
// return {
|
|
13435
|
+
// valid: ValidationLevel.Drop,
|
|
13436
|
+
// matches: [],
|
|
13437
|
+
// node: tokens[0],
|
|
13438
|
+
// syntax: '@' + atRule.nam,
|
|
13439
|
+
// error: 'expecting @supports or media query list',
|
|
13440
|
+
// tokens
|
|
13441
|
+
// }
|
|
13442
|
+
// }
|
|
13443
|
+
//
|
|
13444
|
+
// // @ts-ignore
|
|
13445
|
+
// const result: ValidationSyntaxResult = validateAtRuleSupports(tokens[0] as AstAtRule, options, atRule);
|
|
13446
|
+
//
|
|
13447
|
+
// if (result.valid == ValidationLevel.Drop) {
|
|
13448
|
+
//
|
|
13449
|
+
// return result;
|
|
13450
|
+
// }
|
|
13451
|
+
//
|
|
13452
|
+
// tokens.shift();
|
|
13453
|
+
//
|
|
13454
|
+
// // @ts-ignore
|
|
13455
|
+
// if (!consumeWhitespace(tokens)) {
|
|
13456
|
+
//
|
|
13457
|
+
// // @ts-ignore
|
|
13458
|
+
// return {
|
|
13459
|
+
// valid: ValidationLevel.Drop,
|
|
13460
|
+
// matches: [],
|
|
13461
|
+
// node: tokens[0],
|
|
13462
|
+
// syntax: '@' + atRule.nam,
|
|
13463
|
+
// error: 'expecting whitespace',
|
|
13464
|
+
// tokens
|
|
13465
|
+
// }
|
|
13466
|
+
// }
|
|
13467
|
+
// }
|
|
13468
|
+
// }
|
|
14864
13469
|
if (tokens.length > 0) {
|
|
14865
13470
|
return validateAtRuleMediaQueryList(tokens, atRule);
|
|
14866
13471
|
}
|
|
@@ -15029,71 +13634,50 @@ function validateAtRuleDocument(atRule, options, root) {
|
|
|
15029
13634
|
tokens
|
|
15030
13635
|
};
|
|
15031
13636
|
}
|
|
15032
|
-
|
|
13637
|
+
for (const t of splitTokenList(tokens)) {
|
|
13638
|
+
if (t.length != 1) {
|
|
13639
|
+
return {
|
|
13640
|
+
valid: ValidationLevel.Drop,
|
|
13641
|
+
matches: [],
|
|
13642
|
+
node: t[0] ?? atRule,
|
|
13643
|
+
syntax: '@document',
|
|
13644
|
+
error: 'unexpected token',
|
|
13645
|
+
tokens
|
|
13646
|
+
};
|
|
13647
|
+
}
|
|
15033
13648
|
// @ts-ignore
|
|
15034
|
-
|
|
15035
|
-
|
|
15036
|
-
|
|
15037
|
-
|
|
15038
|
-
|
|
15039
|
-
|
|
15040
|
-
|
|
15041
|
-
|
|
15042
|
-
|
|
15043
|
-
while (tokens.length > 0) {
|
|
15044
|
-
if (tokens[0].typ == exports.EnumToken.CommentTokenType) {
|
|
15045
|
-
tokens.shift();
|
|
15046
|
-
consumeWhitespace(tokens);
|
|
13649
|
+
if ((t[0].typ != exports.EnumToken.FunctionTokenType && t[0].typ != exports.EnumToken.UrlFunctionTokenType) || !['url', 'url-prefix', 'domain', 'media-document', 'regexp'].some((f) => f.localeCompare(t[0].val, undefined, { sensitivity: 'base' }) == 0)) {
|
|
13650
|
+
return {
|
|
13651
|
+
valid: ValidationLevel.Drop,
|
|
13652
|
+
matches: [],
|
|
13653
|
+
node: t[0] ?? atRule,
|
|
13654
|
+
syntax: '@document',
|
|
13655
|
+
error: 'expecting any of url-prefix(), domain(), media-document(), regexp() but found ' + t[0].val,
|
|
13656
|
+
tokens
|
|
13657
|
+
};
|
|
15047
13658
|
}
|
|
15048
|
-
|
|
15049
|
-
|
|
15050
|
-
|
|
15051
|
-
|
|
13659
|
+
if (t[0].typ == exports.EnumToken.UrlFunctionTokenType) {
|
|
13660
|
+
result = validateURL(t[0]);
|
|
13661
|
+
if (result.valid == ValidationLevel.Drop) {
|
|
13662
|
+
return result;
|
|
13663
|
+
}
|
|
15052
13664
|
continue;
|
|
15053
13665
|
}
|
|
15054
|
-
|
|
15055
|
-
|
|
15056
|
-
|
|
15057
|
-
|
|
15058
|
-
|
|
15059
|
-
|
|
15060
|
-
|
|
15061
|
-
|
|
15062
|
-
|
|
15063
|
-
|
|
15064
|
-
|
|
15065
|
-
}
|
|
15066
|
-
const children = tokens[0].chi.slice();
|
|
15067
|
-
consumeWhitespace(children);
|
|
15068
|
-
if (children.length == 0) {
|
|
15069
|
-
// @ts-ignore
|
|
15070
|
-
return {
|
|
15071
|
-
valid: ValidationLevel.Drop,
|
|
15072
|
-
matches: [],
|
|
15073
|
-
node: tokens[0],
|
|
15074
|
-
syntax: '@document',
|
|
15075
|
-
error: 'expecting string argument',
|
|
15076
|
-
tokens
|
|
15077
|
-
};
|
|
15078
|
-
}
|
|
15079
|
-
if (children[0].typ == exports.EnumToken.StringTokenType) {
|
|
15080
|
-
children.shift();
|
|
15081
|
-
consumeWhitespace(children);
|
|
15082
|
-
}
|
|
15083
|
-
if (children.length > 0) {
|
|
15084
|
-
// @ts-ignore
|
|
15085
|
-
return {
|
|
15086
|
-
valid: ValidationLevel.Drop,
|
|
15087
|
-
matches: [],
|
|
15088
|
-
node: children[0],
|
|
15089
|
-
syntax: '@document',
|
|
15090
|
-
error: 'unexpected token',
|
|
15091
|
-
tokens
|
|
15092
|
-
};
|
|
15093
|
-
}
|
|
15094
|
-
tokens.shift();
|
|
15095
|
-
consumeWhitespace(tokens);
|
|
13666
|
+
const children = t[0].chi.slice();
|
|
13667
|
+
consumeWhitespace(children);
|
|
13668
|
+
if (children.length != 1 || (children[0].typ != exports.EnumToken.StringTokenType && children[0].typ != exports.EnumToken.UrlTokenTokenType)) {
|
|
13669
|
+
// @ts-ignore
|
|
13670
|
+
return {
|
|
13671
|
+
valid: ValidationLevel.Drop,
|
|
13672
|
+
matches: [],
|
|
13673
|
+
node: tokens[0],
|
|
13674
|
+
syntax: '@document',
|
|
13675
|
+
error: 'expecting string argument',
|
|
13676
|
+
tokens
|
|
13677
|
+
};
|
|
15096
13678
|
}
|
|
13679
|
+
tokens.shift();
|
|
13680
|
+
consumeWhitespace(tokens);
|
|
15097
13681
|
}
|
|
15098
13682
|
// @ts-ignore
|
|
15099
13683
|
return {
|
|
@@ -15909,6 +14493,7 @@ async function doParse(iterator, options = {}) {
|
|
|
15909
14493
|
src: '',
|
|
15910
14494
|
sourcemap: false,
|
|
15911
14495
|
minify: true,
|
|
14496
|
+
pass: 1,
|
|
15912
14497
|
parseColor: true,
|
|
15913
14498
|
nestingRules: false,
|
|
15914
14499
|
resolveImport: false,
|
|
@@ -16028,7 +14613,7 @@ async function doParse(iterator, options = {}) {
|
|
|
16028
14613
|
await parseNode(tokens, context, stats, options, errors, src, map, rawTokens);
|
|
16029
14614
|
rawTokens.length = 0;
|
|
16030
14615
|
if (context != null && context.typ == exports.EnumToken.InvalidRuleTokenType) {
|
|
16031
|
-
const index = context.chi.findIndex(node => node == context);
|
|
14616
|
+
const index = context.chi.findIndex((node) => node == context);
|
|
16032
14617
|
if (index > -1) {
|
|
16033
14618
|
context.chi.splice(index, 1);
|
|
16034
14619
|
}
|
|
@@ -16088,7 +14673,10 @@ async function doParse(iterator, options = {}) {
|
|
|
16088
14673
|
}
|
|
16089
14674
|
if (options.minify) {
|
|
16090
14675
|
if (ast.chi.length > 0) {
|
|
16091
|
-
|
|
14676
|
+
let passes = options.pass ?? 1;
|
|
14677
|
+
while (passes--) {
|
|
14678
|
+
minify(ast, options, true, errors, false);
|
|
14679
|
+
}
|
|
16092
14680
|
}
|
|
16093
14681
|
}
|
|
16094
14682
|
const endTime = performance.now();
|
|
@@ -16189,8 +14777,13 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
16189
14777
|
continue;
|
|
16190
14778
|
}
|
|
16191
14779
|
if (type != exports.EnumToken.AtRuleNodeType) {
|
|
16192
|
-
|
|
16193
|
-
|
|
14780
|
+
// @ts-ignore
|
|
14781
|
+
if (!(type == exports.EnumToken.InvalidAtRuleTokenType &&
|
|
14782
|
+
// @ts-ignore
|
|
14783
|
+
['charset', 'layer', 'import'].includes(context.chi[i].nam))) {
|
|
14784
|
+
errors.push({ action: 'drop', message: 'invalid @import', location: { src, ...position } });
|
|
14785
|
+
return null;
|
|
14786
|
+
}
|
|
16194
14787
|
}
|
|
16195
14788
|
// @ts-ignore
|
|
16196
14789
|
const name = context.chi[i].nam;
|
|
@@ -16225,12 +14818,20 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
16225
14818
|
if (tokens[0].typ == exports.EnumToken.UrlFunctionTokenType) {
|
|
16226
14819
|
if (tokens[1].typ == exports.EnumToken.UrlTokenTokenType || tokens[1].typ == exports.EnumToken.StringTokenType) {
|
|
16227
14820
|
tokens.shift();
|
|
16228
|
-
if (tokens[
|
|
14821
|
+
if (tokens[0]?.typ == exports.EnumToken.UrlTokenTokenType) {
|
|
16229
14822
|
// @ts-ignore
|
|
16230
14823
|
tokens[0].typ = exports.EnumToken.StringTokenType;
|
|
16231
14824
|
// @ts-ignore
|
|
16232
14825
|
tokens[0].val = `"${tokens[0].val}"`;
|
|
16233
14826
|
}
|
|
14827
|
+
// @ts-ignore
|
|
14828
|
+
while (tokens[1]?.typ == exports.EnumToken.WhitespaceTokenType || tokens[1]?.typ == exports.EnumToken.CommentTokenType) {
|
|
14829
|
+
tokens.splice(1, 1);
|
|
14830
|
+
}
|
|
14831
|
+
// @ts-ignore
|
|
14832
|
+
if (tokens[1]?.typ == exports.EnumToken.EndParensTokenType) {
|
|
14833
|
+
tokens.splice(1, 1);
|
|
14834
|
+
}
|
|
16234
14835
|
}
|
|
16235
14836
|
}
|
|
16236
14837
|
// @ts-ignore
|
|
@@ -16314,11 +14915,11 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
16314
14915
|
const node = {
|
|
16315
14916
|
typ: exports.EnumToken.AtRuleNodeType,
|
|
16316
14917
|
nam: renderToken(atRule, { removeComments: true }),
|
|
16317
|
-
tokens: t,
|
|
14918
|
+
// tokens: t,
|
|
16318
14919
|
val: raw.join('')
|
|
16319
14920
|
};
|
|
16320
14921
|
Object.defineProperties(node, {
|
|
16321
|
-
tokens: { ...definedPropertySettings, enumerable:
|
|
14922
|
+
tokens: { ...definedPropertySettings, enumerable: false, value: tokens.slice() },
|
|
16322
14923
|
raw: { ...definedPropertySettings, value: raw }
|
|
16323
14924
|
});
|
|
16324
14925
|
if (delim.typ == exports.EnumToken.BlockStartTokenType) {
|
|
@@ -16443,7 +15044,7 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
16443
15044
|
};
|
|
16444
15045
|
Object.defineProperty(node, 'tokens', {
|
|
16445
15046
|
...definedPropertySettings,
|
|
16446
|
-
enumerable:
|
|
15047
|
+
enumerable: false,
|
|
16447
15048
|
value: tokens.slice()
|
|
16448
15049
|
});
|
|
16449
15050
|
let raw = [...uniq.values()];
|
|
@@ -16544,7 +15145,7 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
16544
15145
|
//
|
|
16545
15146
|
// const valid: ValidationResult = validateDeclaration(result, options, context);
|
|
16546
15147
|
//
|
|
16547
|
-
// console.error({valid});
|
|
15148
|
+
// // console.error({valid});
|
|
16548
15149
|
//
|
|
16549
15150
|
// if (valid.valid == ValidationLevel.Drop) {
|
|
16550
15151
|
//
|
|
@@ -16916,10 +15517,16 @@ function getTokenType(val, hint) {
|
|
|
16916
15517
|
val: val.slice(0, -1),
|
|
16917
15518
|
chi: []
|
|
16918
15519
|
}
|
|
16919
|
-
:
|
|
16920
|
-
|
|
15520
|
+
: (
|
|
15521
|
+
// https://www.w3.org/TR/selectors-4/#single-colon-pseudos
|
|
15522
|
+
val.startsWith('::') || pseudoElements.includes(val) ? {
|
|
15523
|
+
typ: exports.EnumToken.PseudoElementTokenType,
|
|
16921
15524
|
val
|
|
16922
|
-
}
|
|
15525
|
+
} :
|
|
15526
|
+
{
|
|
15527
|
+
typ: exports.EnumToken.PseudoClassTokenType,
|
|
15528
|
+
val
|
|
15529
|
+
});
|
|
16923
15530
|
}
|
|
16924
15531
|
if (isAtKeyword(val)) {
|
|
16925
15532
|
return {
|
|
@@ -17096,25 +15703,25 @@ function parseTokens(tokens, options = {}) {
|
|
|
17096
15703
|
break;
|
|
17097
15704
|
}
|
|
17098
15705
|
}
|
|
17099
|
-
Object.assign(t, {
|
|
15706
|
+
const attr = Object.assign(t, {
|
|
17100
15707
|
typ: inAttr == 0 ? exports.EnumToken.AttrTokenType : exports.EnumToken.InvalidAttrTokenType,
|
|
17101
15708
|
chi: tokens.splice(i + 1, k - i)
|
|
17102
15709
|
});
|
|
17103
15710
|
// @ts-ignore
|
|
17104
|
-
if (
|
|
15711
|
+
if (attr.chi.at(-1).typ == exports.EnumToken.AttrEndTokenType) {
|
|
17105
15712
|
// @ts-ignore
|
|
17106
|
-
|
|
15713
|
+
attr.chi.pop();
|
|
17107
15714
|
}
|
|
17108
15715
|
// @ts-ignore
|
|
17109
|
-
if (
|
|
15716
|
+
if (attr.chi.length > 1) {
|
|
17110
15717
|
/*(<AttrToken>t).chi =*/
|
|
17111
15718
|
// @ts-ignore
|
|
17112
|
-
parseTokens(
|
|
15719
|
+
parseTokens(attr.chi, t.typ);
|
|
17113
15720
|
}
|
|
17114
|
-
let m =
|
|
15721
|
+
let m = attr.chi.length;
|
|
17115
15722
|
let val;
|
|
17116
|
-
for (m = 0; m <
|
|
17117
|
-
val =
|
|
15723
|
+
for (m = 0; m < attr.chi.length; m++) {
|
|
15724
|
+
val = attr.chi[m];
|
|
17118
15725
|
if (val.typ == exports.EnumToken.StringTokenType) {
|
|
17119
15726
|
const slice = val.val.slice(1, -1);
|
|
17120
15727
|
if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
|
|
@@ -17124,55 +15731,55 @@ function parseTokens(tokens, options = {}) {
|
|
|
17124
15731
|
else if (val.typ == exports.EnumToken.LiteralTokenType && val.val == '|') {
|
|
17125
15732
|
let upper = m;
|
|
17126
15733
|
let lower = m;
|
|
17127
|
-
while (++upper <
|
|
17128
|
-
if (
|
|
15734
|
+
while (++upper < attr.chi.length) {
|
|
15735
|
+
if (attr.chi[upper].typ == exports.EnumToken.CommentTokenType) {
|
|
17129
15736
|
continue;
|
|
17130
15737
|
}
|
|
17131
15738
|
break;
|
|
17132
15739
|
}
|
|
17133
15740
|
while (lower-- > 0) {
|
|
17134
|
-
if (
|
|
15741
|
+
if (attr.chi[lower].typ == exports.EnumToken.CommentTokenType) {
|
|
17135
15742
|
continue;
|
|
17136
15743
|
}
|
|
17137
15744
|
break;
|
|
17138
15745
|
}
|
|
17139
15746
|
// @ts-ignore
|
|
17140
|
-
|
|
15747
|
+
attr.chi[m] = {
|
|
17141
15748
|
typ: exports.EnumToken.NameSpaceAttributeTokenType,
|
|
17142
|
-
l:
|
|
17143
|
-
r:
|
|
15749
|
+
l: attr.chi[lower],
|
|
15750
|
+
r: attr.chi[upper]
|
|
17144
15751
|
};
|
|
17145
|
-
|
|
15752
|
+
attr.chi.splice(upper, 1);
|
|
17146
15753
|
if (lower >= 0) {
|
|
17147
|
-
|
|
15754
|
+
attr.chi.splice(lower, 1);
|
|
17148
15755
|
m--;
|
|
17149
15756
|
}
|
|
17150
15757
|
}
|
|
17151
15758
|
else if ([
|
|
17152
15759
|
exports.EnumToken.DashMatchTokenType, exports.EnumToken.StartMatchTokenType, exports.EnumToken.ContainMatchTokenType, exports.EnumToken.EndMatchTokenType, exports.EnumToken.IncludeMatchTokenType, exports.EnumToken.DelimTokenType
|
|
17153
|
-
].includes(
|
|
15760
|
+
].includes(attr.chi[m].typ)) {
|
|
17154
15761
|
let upper = m;
|
|
17155
15762
|
let lower = m;
|
|
17156
|
-
while (++upper <
|
|
17157
|
-
if (
|
|
15763
|
+
while (++upper < attr.chi.length) {
|
|
15764
|
+
if (attr.chi[upper].typ == exports.EnumToken.CommentTokenType) {
|
|
17158
15765
|
continue;
|
|
17159
15766
|
}
|
|
17160
15767
|
break;
|
|
17161
15768
|
}
|
|
17162
15769
|
while (lower-- > 0) {
|
|
17163
|
-
if (
|
|
15770
|
+
if (attr.chi[lower].typ == exports.EnumToken.CommentTokenType) {
|
|
17164
15771
|
continue;
|
|
17165
15772
|
}
|
|
17166
15773
|
break;
|
|
17167
15774
|
}
|
|
17168
|
-
val =
|
|
15775
|
+
val = attr.chi[lower];
|
|
17169
15776
|
if (val.typ == exports.EnumToken.StringTokenType) {
|
|
17170
15777
|
const slice = val.val.slice(1, -1);
|
|
17171
15778
|
if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
|
|
17172
15779
|
Object.assign(val, { typ: exports.EnumToken.IdenTokenType, val: slice });
|
|
17173
15780
|
}
|
|
17174
15781
|
}
|
|
17175
|
-
val =
|
|
15782
|
+
val = attr.chi[upper];
|
|
17176
15783
|
if (val.typ == exports.EnumToken.StringTokenType) {
|
|
17177
15784
|
const slice = val.val.slice(1, -1);
|
|
17178
15785
|
if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
|
|
@@ -17292,7 +15899,9 @@ function parseTokens(tokens, options = {}) {
|
|
|
17292
15899
|
t.typ = exports.EnumToken.ColorTokenType;
|
|
17293
15900
|
// @ts-ignore
|
|
17294
15901
|
t.kin = t.val;
|
|
15902
|
+
// @ts-ignore
|
|
17295
15903
|
if (t.chi[0].typ == exports.EnumToken.IdenTokenType) {
|
|
15904
|
+
// @ts-ignore
|
|
17296
15905
|
if (t.chi[0].val == 'from') {
|
|
17297
15906
|
// @ts-ignore
|
|
17298
15907
|
t.cal = 'rel';
|
|
@@ -17302,10 +15911,11 @@ function parseTokens(tokens, options = {}) {
|
|
|
17302
15911
|
// @ts-ignore
|
|
17303
15912
|
t.cal = 'mix';
|
|
17304
15913
|
}
|
|
17305
|
-
else
|
|
17306
|
-
|
|
17307
|
-
|
|
17308
|
-
|
|
15914
|
+
else { // @ts-ignore
|
|
15915
|
+
if (t.val == 'color') {
|
|
15916
|
+
// @ts-ignore
|
|
15917
|
+
t.cal = 'col';
|
|
15918
|
+
}
|
|
17309
15919
|
}
|
|
17310
15920
|
}
|
|
17311
15921
|
const filter = [exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType];
|
|
@@ -17339,7 +15949,7 @@ function parseTokens(tokens, options = {}) {
|
|
|
17339
15949
|
if (t.chi.length > 0) {
|
|
17340
15950
|
if (t.typ == exports.EnumToken.PseudoClassFuncTokenType && t.val == ':is' && options.minify) {
|
|
17341
15951
|
//
|
|
17342
|
-
const count = t.chi.filter(t => t.typ != exports.EnumToken.CommentTokenType).length;
|
|
15952
|
+
const count = t.chi.filter((t) => t.typ != exports.EnumToken.CommentTokenType).length;
|
|
17343
15953
|
if (count == 1 ||
|
|
17344
15954
|
(i == 0 &&
|
|
17345
15955
|
(tokens[i + 1]?.typ == exports.EnumToken.CommaTokenType || tokens.length == i + 1)) ||
|
|
@@ -17613,7 +16223,14 @@ function expandRule(node) {
|
|
|
17613
16223
|
rule.sel = splitRule(ast.sel).reduce((a, b) => a.concat([b.join('') + r]), []).join(',');
|
|
17614
16224
|
}
|
|
17615
16225
|
else {
|
|
17616
|
-
selRule.
|
|
16226
|
+
// selRule = splitRule(selRule.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.join(''), ''));
|
|
16227
|
+
const arSelf = splitRule(ast.sel).filter((r) => r.every((t) => t != ':before' && t != ':after' && !t.startsWith('::'))).reduce((acc, curr) => acc.concat([curr.join('')]), []).join(',');
|
|
16228
|
+
if (arSelf.length == 0) {
|
|
16229
|
+
ast.chi.splice(i--, 1);
|
|
16230
|
+
continue;
|
|
16231
|
+
}
|
|
16232
|
+
//
|
|
16233
|
+
selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(arSelf) : arr.unshift(arSelf, ' '));
|
|
17617
16234
|
rule.sel = selRule.reduce((acc, curr) => {
|
|
17618
16235
|
acc.push(curr.join(''));
|
|
17619
16236
|
return acc;
|
|
@@ -17624,8 +16241,14 @@ function expandRule(node) {
|
|
|
17624
16241
|
let childSelectorCompound = [];
|
|
17625
16242
|
let withCompound = [];
|
|
17626
16243
|
let withoutCompound = [];
|
|
17627
|
-
|
|
16244
|
+
// pseudo elements cannot be used with '&'
|
|
16245
|
+
// https://www.w3.org/TR/css-nesting-1/#example-7145ff1e
|
|
16246
|
+
const rules = splitRule(ast.sel).filter((r) => r.every((t) => t != ':before' && t != ':after' && !t.startsWith('::')));
|
|
17628
16247
|
const parentSelector = !node.sel.includes('&');
|
|
16248
|
+
if (rules.length == 0) {
|
|
16249
|
+
ast.chi.splice(i--, 1);
|
|
16250
|
+
continue;
|
|
16251
|
+
}
|
|
17629
16252
|
for (const sel of (rule.raw ?? splitRule(rule.sel))) {
|
|
17630
16253
|
const s = sel.join('');
|
|
17631
16254
|
if (s.includes('&') || parentSelector) {
|
|
@@ -19322,7 +17945,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
|
|
|
19322
17945
|
return s.join('');
|
|
19323
17946
|
}).join(',');
|
|
19324
17947
|
// @ts-ignore
|
|
19325
|
-
let sel = wrap ? node.optimized.optimized
|
|
17948
|
+
let sel = wrap ? node.optimized.optimized.join('') + `:is(${rule})` : rule;
|
|
19326
17949
|
if (rule.includes('&')) {
|
|
19327
17950
|
// @ts-ignore
|
|
19328
17951
|
rule = replaceCompound(rule, node.optimized.optimized[0]);
|
|
@@ -20104,106 +18727,6 @@ function reduceRuleSelector(node) {
|
|
|
20104
18727
|
}
|
|
20105
18728
|
}
|
|
20106
18729
|
|
|
20107
|
-
const matchUrl = /^(https?:)?\/\//;
|
|
20108
|
-
function dirname(path) {
|
|
20109
|
-
if (path == '/' || path === '') {
|
|
20110
|
-
return path;
|
|
20111
|
-
}
|
|
20112
|
-
let i = 0;
|
|
20113
|
-
let parts = [''];
|
|
20114
|
-
for (; i < path.length; i++) {
|
|
20115
|
-
const chr = path.charAt(i);
|
|
20116
|
-
if (chr == '/') {
|
|
20117
|
-
parts.push('');
|
|
20118
|
-
}
|
|
20119
|
-
else if (chr == '?' || chr == '#') {
|
|
20120
|
-
break;
|
|
20121
|
-
}
|
|
20122
|
-
else {
|
|
20123
|
-
parts[parts.length - 1] += chr;
|
|
20124
|
-
}
|
|
20125
|
-
}
|
|
20126
|
-
parts.pop();
|
|
20127
|
-
return parts.length == 0 ? '/' : parts.join('/');
|
|
20128
|
-
}
|
|
20129
|
-
function splitPath(result) {
|
|
20130
|
-
const parts = [''];
|
|
20131
|
-
let i = 0;
|
|
20132
|
-
for (; i < result.length; i++) {
|
|
20133
|
-
const chr = result.charAt(i);
|
|
20134
|
-
if (chr == '/') {
|
|
20135
|
-
parts.push('');
|
|
20136
|
-
}
|
|
20137
|
-
else if (chr == '?' || chr == '#') {
|
|
20138
|
-
break;
|
|
20139
|
-
}
|
|
20140
|
-
else {
|
|
20141
|
-
parts[parts.length - 1] += chr;
|
|
20142
|
-
}
|
|
20143
|
-
}
|
|
20144
|
-
let k = -1;
|
|
20145
|
-
while (++k < parts.length) {
|
|
20146
|
-
if (parts[k] == '.') {
|
|
20147
|
-
parts.splice(k--, 1);
|
|
20148
|
-
}
|
|
20149
|
-
else if (parts[k] == '..') {
|
|
20150
|
-
parts.splice(k - 1, 2);
|
|
20151
|
-
k -= 2;
|
|
20152
|
-
}
|
|
20153
|
-
}
|
|
20154
|
-
return { parts, i };
|
|
20155
|
-
}
|
|
20156
|
-
function resolve(url, currentDirectory, cwd) {
|
|
20157
|
-
if (matchUrl.test(url)) {
|
|
20158
|
-
return {
|
|
20159
|
-
absolute: url,
|
|
20160
|
-
relative: url
|
|
20161
|
-
};
|
|
20162
|
-
}
|
|
20163
|
-
if (matchUrl.test(currentDirectory)) {
|
|
20164
|
-
const path = new URL(url, currentDirectory).href;
|
|
20165
|
-
return {
|
|
20166
|
-
absolute: path,
|
|
20167
|
-
relative: path
|
|
20168
|
-
};
|
|
20169
|
-
}
|
|
20170
|
-
let result;
|
|
20171
|
-
if (url.charAt(0) == '/') {
|
|
20172
|
-
result = url;
|
|
20173
|
-
}
|
|
20174
|
-
else if (currentDirectory.charAt(0) == '/') {
|
|
20175
|
-
result = dirname(currentDirectory) + '/' + url;
|
|
20176
|
-
}
|
|
20177
|
-
else if (currentDirectory === '' || dirname(currentDirectory) === '') {
|
|
20178
|
-
result = url;
|
|
20179
|
-
}
|
|
20180
|
-
else {
|
|
20181
|
-
result = dirname(currentDirectory) + '/' + url;
|
|
20182
|
-
}
|
|
20183
|
-
let { parts, i } = splitPath(result);
|
|
20184
|
-
if (parts.length == 0) {
|
|
20185
|
-
const path = result.charAt(0) == '/' ? '/' : '';
|
|
20186
|
-
return {
|
|
20187
|
-
absolute: path,
|
|
20188
|
-
relative: path
|
|
20189
|
-
};
|
|
20190
|
-
}
|
|
20191
|
-
const absolute = parts.join('/');
|
|
20192
|
-
const { parts: dirs } = splitPath(cwd ?? currentDirectory);
|
|
20193
|
-
for (const p of dirs) {
|
|
20194
|
-
if (parts[0] == p) {
|
|
20195
|
-
parts.shift();
|
|
20196
|
-
}
|
|
20197
|
-
else {
|
|
20198
|
-
parts.unshift('..');
|
|
20199
|
-
}
|
|
20200
|
-
}
|
|
20201
|
-
return {
|
|
20202
|
-
absolute,
|
|
20203
|
-
relative: parts.join('/') + (i < result.length ? result.slice(i) : '')
|
|
20204
|
-
};
|
|
20205
|
-
}
|
|
20206
|
-
|
|
20207
18730
|
function parseResponse(response) {
|
|
20208
18731
|
if (!response.ok) {
|
|
20209
18732
|
throw new Error(`${response.status} ${response.statusText} ${response.url}`);
|