@tbela99/css-parser 1.6.6 → 1.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -0
- package/README.md +1 -58
- package/architecture.png +0 -0
- package/dist/index-umd-web.js +731 -459
- package/dist/index.cjs +724 -459
- package/dist/index.d.ts +67 -11
- package/dist/package.json.js +10 -0
- package/dist/{data → src/data}/properties.json.js +7 -0
- package/dist/{data → src/data}/validation.json.js +7 -0
- package/dist/{lib → src/lib}/ast/clone.js +7 -0
- package/dist/{lib → src/lib}/ast/expand.js +19 -10
- package/dist/{lib → src/lib}/ast/features/calc.js +7 -0
- package/dist/{lib → src/lib}/ast/features/if.js +7 -0
- package/dist/{lib → src/lib}/ast/features/index.js +7 -0
- package/dist/{lib → src/lib}/ast/features/inlinecssvariables.js +7 -0
- package/dist/{lib → src/lib}/ast/features/prefix.js +8 -3
- package/dist/{lib → src/lib}/ast/features/shorthand.js +7 -0
- package/dist/{lib → src/lib}/ast/features/transform.js +8 -1
- package/dist/{lib → src/lib}/ast/features/type.js +7 -0
- package/dist/{lib → src/lib}/ast/find.js +7 -0
- package/dist/{lib → src/lib}/ast/math/expression.js +7 -0
- package/dist/{lib → src/lib}/ast/math/math.js +7 -0
- package/dist/{lib → src/lib}/ast/minify.js +7 -0
- package/dist/{lib → src/lib}/ast/node.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/compute.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/matrix.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/minify.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/perspective.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/rotate.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/scale.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/skew.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/translate.js +7 -0
- package/dist/{lib → src/lib}/ast/transform/utils.js +7 -0
- package/dist/{lib → src/lib}/ast/types.js +28 -9
- package/dist/{lib → src/lib}/ast/walk.js +16 -0
- package/dist/{lib → src/lib}/fs/resolve.js +7 -0
- package/dist/{lib → src/lib}/parser/declaration/list.js +24 -8
- package/dist/{lib → src/lib}/parser/declaration/map.js +9 -1
- package/dist/{lib → src/lib}/parser/declaration/set.js +7 -0
- package/dist/{lib → src/lib}/parser/linesmap.js +7 -0
- package/dist/{lib → src/lib}/parser/parse.js +93 -49
- package/dist/{lib → src/lib}/parser/source.js +7 -0
- package/dist/{lib → src/lib}/parser/tokenize.js +24 -3
- package/dist/{lib → src/lib}/parser/utils/angle.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule-container.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule-font-feature-values.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule-generic.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule-import.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule-media.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule-support.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule-when-else.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/at-rule.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/base64.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/cache.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/config.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/declaration.js +17 -0
- package/dist/{lib → src/lib}/parser/utils/eq.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/hash.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/selector.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/text.js +7 -0
- package/dist/{lib → src/lib}/parser/utils/token.js +15 -4
- package/dist/{lib → src/lib}/parser/utils/type.js +7 -0
- package/dist/{lib → src/lib}/printer/render.js +20 -9
- package/dist/{lib → src/lib}/printer/sourcemap/lib/codec.js +7 -0
- package/dist/{lib → src/lib}/printer/sourcemap/sourcemap.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/a98rgb.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/alpha.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/cmyk.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/color-mix.js +139 -48
- package/dist/{lib → src/lib}/syntax/color/color.js +7 -1
- package/dist/{lib → src/lib}/syntax/color/hex.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/hsl.js +52 -38
- package/dist/{lib → src/lib}/syntax/color/hwb.js +90 -53
- package/dist/{lib → src/lib}/syntax/color/lab.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/lch.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/oklab.js +8 -1
- package/dist/{lib → src/lib}/syntax/color/oklch.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/p3.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/prophotorgb.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/rec2020.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/relative-color.js +36 -0
- package/dist/{lib → src/lib}/syntax/color/rgb.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/srgb.js +88 -58
- package/dist/{lib → src/lib}/syntax/color/utils/color-type.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/utils/colorspace.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/utils/components.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/utils/distance.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/utils/make-color.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/utils/matrix.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/xyz.js +7 -0
- package/dist/{lib → src/lib}/syntax/color/xyzd50.js +7 -0
- package/dist/{lib → src/lib}/syntax/constants.js +7 -0
- package/dist/{lib → src/lib}/syntax/syntax.js +7 -0
- package/dist/{lib → src/lib}/validation/config.js +7 -0
- package/dist/{lib → src/lib}/validation/match.js +37 -19
- package/dist/{lib → src/lib}/validation/parser/parse.js +7 -0
- package/dist/{lib → src/lib}/validation/parser/typedef.js +7 -0
- package/dist/{lib → src/lib}/validation/utils/list.js +7 -0
- package/dist/{node.js → src/node.js} +8 -0
- package/dist/{types.js → src/types.js} +7 -0
- package/dist/{utils → src/utils}/sync.js +7 -0
- package/dist/{web.js → src/web.js} +8 -0
- package/package.json +7 -6
- package/dist/lib/syntax/color/hsv.js +0 -20
package/dist/index-umd-web.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 1.6.8
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
1
8
|
(function (global, factory) {
|
|
2
9
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
10
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -24,35 +31,43 @@
|
|
|
24
31
|
/**
|
|
25
32
|
* Node passed validation
|
|
26
33
|
*/
|
|
27
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Validated"] =
|
|
34
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Validated"] = 1] = "Validated";
|
|
28
35
|
/**
|
|
29
36
|
* Node is invalid
|
|
30
37
|
*/
|
|
31
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Invalid"] =
|
|
38
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Invalid"] = 2] = "Invalid";
|
|
32
39
|
/**
|
|
33
40
|
* node is not validated
|
|
34
41
|
*/
|
|
35
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Unvalidated"] =
|
|
42
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Unvalidated"] = 4] = "Unvalidated";
|
|
36
43
|
/**
|
|
37
44
|
* Node did not pass validation, but is preserved.
|
|
38
45
|
*/
|
|
39
|
-
EnumAstNodeStatus[EnumAstNodeStatus["ValidationFailed"] =
|
|
46
|
+
EnumAstNodeStatus[EnumAstNodeStatus["ValidationFailed"] = 8] = "ValidationFailed";
|
|
40
47
|
/**
|
|
41
48
|
* Parsing the node is not supported yet or the node syntax definition does not exist.
|
|
42
49
|
*/
|
|
43
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Unknown"] =
|
|
50
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Unknown"] = 16] = "Unknown";
|
|
44
51
|
/**
|
|
45
52
|
* Failed to parse the node.
|
|
46
53
|
*/
|
|
47
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Unparsed"] =
|
|
54
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Unparsed"] = 32] = "Unparsed";
|
|
48
55
|
/**
|
|
49
56
|
* Node is disallowed in the context
|
|
50
57
|
*/
|
|
51
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Disallowed"] =
|
|
58
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Disallowed"] = 64] = "Disallowed";
|
|
52
59
|
/**
|
|
53
60
|
* Node is malformed
|
|
54
61
|
*/
|
|
55
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Malformed"] =
|
|
62
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Malformed"] = 128] = "Malformed";
|
|
63
|
+
/**
|
|
64
|
+
* Important declaration
|
|
65
|
+
*/
|
|
66
|
+
EnumAstNodeStatus[EnumAstNodeStatus["ImportantDeclaration"] = 256] = "ImportantDeclaration";
|
|
67
|
+
/**
|
|
68
|
+
* Color component without unit
|
|
69
|
+
*/
|
|
70
|
+
EnumAstNodeStatus[EnumAstNodeStatus["PowerlessColorComponent"] = 512] = "PowerlessColorComponent";
|
|
56
71
|
})(exports.EnumAstNodeStatus || (exports.EnumAstNodeStatus = {}));
|
|
57
72
|
/**
|
|
58
73
|
* Enum of validation levels
|
|
@@ -539,7 +554,7 @@
|
|
|
539
554
|
/**
|
|
540
555
|
* '|'
|
|
541
556
|
*/
|
|
542
|
-
EnumToken[EnumToken["
|
|
557
|
+
EnumToken[EnumToken["PipeTokenType"] = 109] = "PipeTokenType";
|
|
543
558
|
/**
|
|
544
559
|
* '::'
|
|
545
560
|
*/
|
|
@@ -678,6 +693,10 @@
|
|
|
678
693
|
* negative infinity token
|
|
679
694
|
*/
|
|
680
695
|
EnumToken[EnumToken["NegativeInfinityTokenType"] = 143] = "NegativeInfinityTokenType";
|
|
696
|
+
/**
|
|
697
|
+
* CSS type token
|
|
698
|
+
*/
|
|
699
|
+
EnumToken[EnumToken["CssTypeTokenType"] = 144] = "CssTypeTokenType";
|
|
681
700
|
/* aliases */
|
|
682
701
|
/**
|
|
683
702
|
* alias for time token type
|
|
@@ -7485,7 +7504,7 @@
|
|
|
7485
7504
|
{ typ: exports.EnumToken.NumberTokenType, val: values[1] },
|
|
7486
7505
|
{ typ: exports.EnumToken.NumberTokenType, val: values[2] },
|
|
7487
7506
|
];
|
|
7488
|
-
if (values.length == 4) {
|
|
7507
|
+
if (values.length == 4 && values[3] != 1) {
|
|
7489
7508
|
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
|
|
7490
7509
|
typ: exports.EnumToken.PercentageTokenType,
|
|
7491
7510
|
val: values[3] * 100,
|
|
@@ -7874,6 +7893,222 @@
|
|
|
7874
7893
|
return xyz.map((value, i) => value * D50[i]);
|
|
7875
7894
|
}
|
|
7876
7895
|
|
|
7896
|
+
function rgb2hwbToken(token) {
|
|
7897
|
+
const values = rgb2hwbvalues(token);
|
|
7898
|
+
if (values == null) {
|
|
7899
|
+
return null;
|
|
7900
|
+
}
|
|
7901
|
+
return hwbToken(values);
|
|
7902
|
+
}
|
|
7903
|
+
function hsl2hwbToken(token) {
|
|
7904
|
+
const values = hsl2hwbvalues(token);
|
|
7905
|
+
if (values == null) {
|
|
7906
|
+
return null;
|
|
7907
|
+
}
|
|
7908
|
+
// console.error(new Error("hsl2hwbToken"));
|
|
7909
|
+
return hwbToken(values);
|
|
7910
|
+
}
|
|
7911
|
+
function cmyk2hwbToken(token) {
|
|
7912
|
+
const values = cmyk2hwbvalues(token);
|
|
7913
|
+
if (values == null) {
|
|
7914
|
+
return null;
|
|
7915
|
+
}
|
|
7916
|
+
return hwbToken(values);
|
|
7917
|
+
}
|
|
7918
|
+
function oklab2hwbToken(token) {
|
|
7919
|
+
const values = oklab2hwbvalues(token);
|
|
7920
|
+
if (values == null) {
|
|
7921
|
+
return null;
|
|
7922
|
+
}
|
|
7923
|
+
return hwbToken(values);
|
|
7924
|
+
}
|
|
7925
|
+
function oklch2hwbToken(token) {
|
|
7926
|
+
const values = oklch2hwbvalues(token);
|
|
7927
|
+
if (values == null) {
|
|
7928
|
+
return null;
|
|
7929
|
+
}
|
|
7930
|
+
return hwbToken(values);
|
|
7931
|
+
}
|
|
7932
|
+
function lab2hwbToken(token) {
|
|
7933
|
+
const values = lab2hwbvalues(token);
|
|
7934
|
+
if (values == null) {
|
|
7935
|
+
return null;
|
|
7936
|
+
}
|
|
7937
|
+
return hwbToken(values);
|
|
7938
|
+
}
|
|
7939
|
+
function lch2hwbToken(token) {
|
|
7940
|
+
const values = lch2hwbvalues(token);
|
|
7941
|
+
if (values == null) {
|
|
7942
|
+
return null;
|
|
7943
|
+
}
|
|
7944
|
+
return hwbToken(values);
|
|
7945
|
+
}
|
|
7946
|
+
function color2hwbToken(token) {
|
|
7947
|
+
const values = color2hwbvalues(token);
|
|
7948
|
+
if (values == null) {
|
|
7949
|
+
return null;
|
|
7950
|
+
}
|
|
7951
|
+
return hwbToken(values);
|
|
7952
|
+
}
|
|
7953
|
+
function hwbToken(values) {
|
|
7954
|
+
const chi = [
|
|
7955
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
7956
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[1] },
|
|
7957
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[2] },
|
|
7958
|
+
];
|
|
7959
|
+
if (values.length == 4) {
|
|
7960
|
+
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
|
|
7961
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
7962
|
+
val: values[3] * 100,
|
|
7963
|
+
});
|
|
7964
|
+
}
|
|
7965
|
+
return {
|
|
7966
|
+
typ: exports.EnumToken.ColorTokenType,
|
|
7967
|
+
val: "hwb",
|
|
7968
|
+
chi,
|
|
7969
|
+
kin: exports.ColorType.HWB,
|
|
7970
|
+
};
|
|
7971
|
+
}
|
|
7972
|
+
function rgb2hwbvalues(token) {
|
|
7973
|
+
const values = getColorComponents(token).map((t, index) => {
|
|
7974
|
+
if (index == 3) {
|
|
7975
|
+
return getNumber(t);
|
|
7976
|
+
}
|
|
7977
|
+
return getNumber(t) / 255;
|
|
7978
|
+
});
|
|
7979
|
+
// @ts-ignore
|
|
7980
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
7981
|
+
}
|
|
7982
|
+
function cmyk2hwbvalues(token) {
|
|
7983
|
+
const values = cmyk2srgbvalues(token);
|
|
7984
|
+
return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
7985
|
+
}
|
|
7986
|
+
function hsl2hwbvalues(token) {
|
|
7987
|
+
const values = hslvalues(token);
|
|
7988
|
+
if (values == null) {
|
|
7989
|
+
return null;
|
|
7990
|
+
}
|
|
7991
|
+
// @ts-ignore
|
|
7992
|
+
return hslvalues2hwbvalues(values.h, values.s, values.l, values.a);
|
|
7993
|
+
}
|
|
7994
|
+
function lab2hwbvalues(token) {
|
|
7995
|
+
const values = lab2srgbvalues(token);
|
|
7996
|
+
if (values == null) {
|
|
7997
|
+
return null;
|
|
7998
|
+
}
|
|
7999
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8000
|
+
}
|
|
8001
|
+
function lch2hwbvalues(token) {
|
|
8002
|
+
const values = lch2srgbvalues(token);
|
|
8003
|
+
if (values == null) {
|
|
8004
|
+
return null;
|
|
8005
|
+
}
|
|
8006
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8007
|
+
}
|
|
8008
|
+
function oklab2hwbvalues(token) {
|
|
8009
|
+
const values = oklab2srgbvalues(token);
|
|
8010
|
+
if (values == null) {
|
|
8011
|
+
return null;
|
|
8012
|
+
}
|
|
8013
|
+
// @ts-ignore
|
|
8014
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8015
|
+
}
|
|
8016
|
+
function oklch2hwbvalues(token) {
|
|
8017
|
+
const values = oklch2srgbvalues(token);
|
|
8018
|
+
// @ts-ignore
|
|
8019
|
+
return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8020
|
+
}
|
|
8021
|
+
function color2hwbvalues(token) {
|
|
8022
|
+
const values = color2srgbvalues(token);
|
|
8023
|
+
if (values == null) {
|
|
8024
|
+
return null;
|
|
8025
|
+
}
|
|
8026
|
+
// @ts-ignore
|
|
8027
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8028
|
+
}
|
|
8029
|
+
function hwbvalues(token) {
|
|
8030
|
+
const components = getColorComponents(token);
|
|
8031
|
+
if (components == null) {
|
|
8032
|
+
return null;
|
|
8033
|
+
}
|
|
8034
|
+
let t;
|
|
8035
|
+
// @ts-ignore
|
|
8036
|
+
let h = getAngle(components[0]) * 360;
|
|
8037
|
+
// @ts-ignore
|
|
8038
|
+
t = components[1];
|
|
8039
|
+
// @ts-ignore
|
|
8040
|
+
let w = getNumber(t);
|
|
8041
|
+
// @ts-ignore
|
|
8042
|
+
t = components[2];
|
|
8043
|
+
// @ts-ignore
|
|
8044
|
+
let b = getNumber(t);
|
|
8045
|
+
// if (components[1].typ == EnumToken.NumberTokenType) {
|
|
8046
|
+
w *= 100;
|
|
8047
|
+
// }
|
|
8048
|
+
// if (components[2].typ == EnumToken.NumberTokenType) {
|
|
8049
|
+
b *= 100;
|
|
8050
|
+
// }
|
|
8051
|
+
let a = null;
|
|
8052
|
+
if (components.length == 4) {
|
|
8053
|
+
// @ts-ignore
|
|
8054
|
+
t = components[3];
|
|
8055
|
+
// @ts-ignore
|
|
8056
|
+
a = getNumber(t);
|
|
8057
|
+
}
|
|
8058
|
+
return a == null ? { h, w, b } : { h, w, b, a };
|
|
8059
|
+
}
|
|
8060
|
+
function srgb2hwb(r, g, b, a = null, fallback = 0) {
|
|
8061
|
+
// 1. Clamp inputs to the standard web-safe sRGB gamut [0.0, 1.0]
|
|
8062
|
+
const rClamp = Math.min(1, Math.max(0, r));
|
|
8063
|
+
const gClamp = Math.min(1, Math.max(0, g));
|
|
8064
|
+
const bClamp = Math.min(1, Math.max(0, b));
|
|
8065
|
+
const cMax = Math.max(rClamp, gClamp, bClamp);
|
|
8066
|
+
const cMin = Math.min(rClamp, gClamp, bClamp);
|
|
8067
|
+
const delta = cMax - cMin;
|
|
8068
|
+
// 2. Whiteness and Blackness calculations
|
|
8069
|
+
const w = cMin;
|
|
8070
|
+
const bl = 1 - cMax;
|
|
8071
|
+
// 3. Calculate Hue
|
|
8072
|
+
let h = 0;
|
|
8073
|
+
if (delta !== 0) {
|
|
8074
|
+
if (cMax === rClamp) {
|
|
8075
|
+
h = 60 * (((gClamp - bClamp) / delta) % 6);
|
|
8076
|
+
}
|
|
8077
|
+
else if (cMax === gClamp) {
|
|
8078
|
+
h = 60 * ((bClamp - rClamp) / delta + 2);
|
|
8079
|
+
}
|
|
8080
|
+
else if (cMax === bClamp) {
|
|
8081
|
+
h = 60 * ((rClamp - gClamp) / delta + 4);
|
|
8082
|
+
}
|
|
8083
|
+
if (h < 0) {
|
|
8084
|
+
h += 360;
|
|
8085
|
+
}
|
|
8086
|
+
}
|
|
8087
|
+
const result = [h, w * 100, bl * 100];
|
|
8088
|
+
if (a != null) {
|
|
8089
|
+
result.push(a);
|
|
8090
|
+
}
|
|
8091
|
+
return result;
|
|
8092
|
+
}
|
|
8093
|
+
function hslvalues2hwbvalues(h, s, l, a = null) {
|
|
8094
|
+
const sNorm = s / 100;
|
|
8095
|
+
const lNorm = l / 100;
|
|
8096
|
+
// Keep Hue cleanly bound to standard circle loops
|
|
8097
|
+
const hue = ((h % 360) + 360) % 360;
|
|
8098
|
+
// 1. Compute the intermediate HSV Value component (brightness peak)
|
|
8099
|
+
const v = lNorm + sNorm * Math.min(lNorm, 1 - lNorm);
|
|
8100
|
+
// 2. Compute Chroma
|
|
8101
|
+
const chroma = 2 * (v - lNorm);
|
|
8102
|
+
// 3. Extract Whiteness and Blackness
|
|
8103
|
+
const w = v - chroma;
|
|
8104
|
+
const b = 1 - v;
|
|
8105
|
+
const hwb = [hue, w * 100, b * 100];
|
|
8106
|
+
if (a != null && a != 1) {
|
|
8107
|
+
hwb.push(a);
|
|
8108
|
+
}
|
|
8109
|
+
return hwb;
|
|
8110
|
+
}
|
|
8111
|
+
|
|
7877
8112
|
// from https://www.w3.org/TR/css-color-4/#color-conversion-code
|
|
7878
8113
|
// srgb-linear -> srgb
|
|
7879
8114
|
// 0 <= r, g, b <= 1
|
|
@@ -7947,25 +8182,59 @@
|
|
|
7947
8182
|
return lsrgb2srgbvalues(values[0], values[1], values[2], alpha);
|
|
7948
8183
|
}
|
|
7949
8184
|
function hwb2srgbvalues(token) {
|
|
7950
|
-
const { h
|
|
7951
|
-
if (
|
|
8185
|
+
const { h, w, b, a } = hwbvalues(token) ?? {};
|
|
8186
|
+
if (h == null || w == null || b == null) {
|
|
7952
8187
|
return [];
|
|
7953
8188
|
}
|
|
7954
|
-
const rgb =
|
|
7955
|
-
|
|
7956
|
-
rgb
|
|
7957
|
-
rgb[i] = rgb[i] + white;
|
|
7958
|
-
}
|
|
7959
|
-
if (alpha != null && alpha != 1) {
|
|
7960
|
-
rgb.push(alpha);
|
|
8189
|
+
const rgb = hwb2srgb(h, w, b);
|
|
8190
|
+
if (a != null && a != 1) {
|
|
8191
|
+
rgb.push(a);
|
|
7961
8192
|
}
|
|
7962
8193
|
return rgb;
|
|
7963
8194
|
}
|
|
8195
|
+
/**
|
|
8196
|
+
* convert hwb to sRGB
|
|
8197
|
+
*/
|
|
8198
|
+
function hwb2srgb(h, w, b, alpha) {
|
|
8199
|
+
const wNorm = w / 100;
|
|
8200
|
+
const bNorm = b / 100;
|
|
8201
|
+
if (wNorm + bNorm >= 1) {
|
|
8202
|
+
const gray = wNorm / (wNorm + bNorm);
|
|
8203
|
+
return [Math.round(gray * 10000) / 10000, Math.round(gray * 10000) / 10000, Math.round(gray * 10000) / 10000];
|
|
8204
|
+
}
|
|
8205
|
+
const hPrime = (h % 360) / 60;
|
|
8206
|
+
const x = 1 - Math.abs((hPrime % 2) - 1);
|
|
8207
|
+
let rChroma = 0;
|
|
8208
|
+
let gChroma = 0;
|
|
8209
|
+
let bChroma = 0;
|
|
8210
|
+
if (hPrime >= 0 && hPrime < 1) {
|
|
8211
|
+
[rChroma, gChroma, bChroma] = [1, x, 0];
|
|
8212
|
+
}
|
|
8213
|
+
else if (hPrime >= 1 && hPrime < 2) {
|
|
8214
|
+
[rChroma, gChroma, bChroma] = [x, 1, 0];
|
|
8215
|
+
}
|
|
8216
|
+
else if (hPrime >= 2 && hPrime < 3) {
|
|
8217
|
+
[rChroma, gChroma, bChroma] = [0, 1, x];
|
|
8218
|
+
}
|
|
8219
|
+
else if (hPrime >= 3 && hPrime < 4) {
|
|
8220
|
+
[rChroma, gChroma, bChroma] = [0, x, 1];
|
|
8221
|
+
}
|
|
8222
|
+
else if (hPrime >= 4 && hPrime < 5) {
|
|
8223
|
+
[rChroma, gChroma, bChroma] = [x, 0, 1];
|
|
8224
|
+
}
|
|
8225
|
+
else if (hPrime >= 5 && hPrime <= 6) {
|
|
8226
|
+
[rChroma, gChroma, bChroma] = [1, 0, x];
|
|
8227
|
+
}
|
|
8228
|
+
const factor = 1 - wNorm - bNorm;
|
|
8229
|
+
const srgb = [rChroma * factor + wNorm, gChroma * factor + wNorm, bChroma * factor + wNorm];
|
|
8230
|
+
return srgb;
|
|
8231
|
+
}
|
|
7964
8232
|
function hsl2srgb(token) {
|
|
7965
8233
|
let { h, s, l, a } = hslvalues(token) ?? {};
|
|
7966
8234
|
if (h == null || s == null || l == null) {
|
|
7967
8235
|
return null;
|
|
7968
8236
|
}
|
|
8237
|
+
// hue in degrees
|
|
7969
8238
|
return hslvalues2srgbvalues(h, s, l, a);
|
|
7970
8239
|
}
|
|
7971
8240
|
function cmyk2srgbvalues(token) {
|
|
@@ -8026,7 +8295,7 @@
|
|
|
8026
8295
|
}
|
|
8027
8296
|
let t;
|
|
8028
8297
|
// @ts-ignore
|
|
8029
|
-
let h = getAngle(components[0]);
|
|
8298
|
+
let h = getAngle(components[0]) * 360;
|
|
8030
8299
|
// @ts-ignore
|
|
8031
8300
|
t = components[1];
|
|
8032
8301
|
// @ts-ignore
|
|
@@ -8035,6 +8304,12 @@
|
|
|
8035
8304
|
t = components[2];
|
|
8036
8305
|
// @ts-ignore
|
|
8037
8306
|
let l = getNumber(t);
|
|
8307
|
+
if (components[1].typ == exports.EnumToken.PercentageTokenType) {
|
|
8308
|
+
s *= 100;
|
|
8309
|
+
}
|
|
8310
|
+
if (components[2].typ == exports.EnumToken.PercentageTokenType) {
|
|
8311
|
+
l *= 100;
|
|
8312
|
+
}
|
|
8038
8313
|
let a = null;
|
|
8039
8314
|
if (components.length == 4) {
|
|
8040
8315
|
// @ts-ignore
|
|
@@ -8045,56 +8320,38 @@
|
|
|
8045
8320
|
return a == null ? { h, s, l } : { h, s, l, a };
|
|
8046
8321
|
}
|
|
8047
8322
|
function hslvalues2srgbvalues(h, s, l, a = null) {
|
|
8048
|
-
|
|
8049
|
-
|
|
8050
|
-
|
|
8051
|
-
|
|
8052
|
-
|
|
8053
|
-
|
|
8054
|
-
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
8063
|
-
|
|
8064
|
-
|
|
8065
|
-
|
|
8066
|
-
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
case 3:
|
|
8078
|
-
r = m;
|
|
8079
|
-
g = mid2;
|
|
8080
|
-
b = v;
|
|
8081
|
-
break;
|
|
8082
|
-
case 4:
|
|
8083
|
-
r = mid1;
|
|
8084
|
-
g = m;
|
|
8085
|
-
b = v;
|
|
8086
|
-
break;
|
|
8087
|
-
case 5:
|
|
8088
|
-
r = v;
|
|
8089
|
-
g = m;
|
|
8090
|
-
b = mid2;
|
|
8091
|
-
break;
|
|
8092
|
-
}
|
|
8093
|
-
}
|
|
8094
|
-
const values = [r, g, b];
|
|
8095
|
-
if (a != null && a != 1) {
|
|
8323
|
+
const sNorm = s / 100;
|
|
8324
|
+
const lNorm = l / 100;
|
|
8325
|
+
const chroma = (1 - Math.abs(2 * lNorm - 1)) * sNorm;
|
|
8326
|
+
const hPrime = h / 60;
|
|
8327
|
+
const x = chroma * (1 - Math.abs((hPrime % 2) - 1));
|
|
8328
|
+
let rTmp = 0;
|
|
8329
|
+
let gTmp = 0;
|
|
8330
|
+
let bTmp = 0;
|
|
8331
|
+
if (hPrime >= 0 && hPrime < 1) {
|
|
8332
|
+
[rTmp, gTmp, bTmp] = [chroma, x, 0];
|
|
8333
|
+
}
|
|
8334
|
+
else if (hPrime >= 1 && hPrime < 2) {
|
|
8335
|
+
[rTmp, gTmp, bTmp] = [x, chroma, 0];
|
|
8336
|
+
}
|
|
8337
|
+
else if (hPrime >= 2 && hPrime < 3) {
|
|
8338
|
+
[rTmp, gTmp, bTmp] = [0, chroma, x];
|
|
8339
|
+
}
|
|
8340
|
+
else if (hPrime >= 3 && hPrime < 4) {
|
|
8341
|
+
[rTmp, gTmp, bTmp] = [0, x, chroma];
|
|
8342
|
+
}
|
|
8343
|
+
else if (hPrime >= 4 && hPrime < 5) {
|
|
8344
|
+
[rTmp, gTmp, bTmp] = [x, 0, chroma];
|
|
8345
|
+
}
|
|
8346
|
+
else if (hPrime >= 5 && hPrime <= 6) {
|
|
8347
|
+
[rTmp, gTmp, bTmp] = [chroma, 0, x];
|
|
8348
|
+
}
|
|
8349
|
+
const m = lNorm - chroma / 2;
|
|
8350
|
+
const values = [rTmp + m, gTmp + m, bTmp + m];
|
|
8351
|
+
if (a != null) {
|
|
8096
8352
|
values.push(a);
|
|
8097
8353
|
}
|
|
8354
|
+
// Return exact float decimals instead of multiplying by 255
|
|
8098
8355
|
return values;
|
|
8099
8356
|
}
|
|
8100
8357
|
function lab2srgbvalues(token) {
|
|
@@ -8467,25 +8724,6 @@
|
|
|
8467
8724
|
return lch2srgbvalues(token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
|
|
8468
8725
|
}
|
|
8469
8726
|
|
|
8470
|
-
function hwb2hsv(h, w, b, a) {
|
|
8471
|
-
// @ts-ignore
|
|
8472
|
-
return [h, 1 - w / (1 - b), 1 - b, a];
|
|
8473
|
-
}
|
|
8474
|
-
// https://gist.github.com/defims/0ca2ef8832833186ed396a2f8a204117#file-annotated-js
|
|
8475
|
-
function hsl2hsv(h, s, l, a = null) {
|
|
8476
|
-
s *= l < .5 ? l : 1 - l;
|
|
8477
|
-
const result = [
|
|
8478
|
-
//Range should be between 0 - 1
|
|
8479
|
-
h, //Hue stays the same
|
|
8480
|
-
2 * s / (l + s), //Saturation
|
|
8481
|
-
l + s //Value
|
|
8482
|
-
];
|
|
8483
|
-
if (a != null) {
|
|
8484
|
-
result.push(a);
|
|
8485
|
-
}
|
|
8486
|
-
return result;
|
|
8487
|
-
}
|
|
8488
|
-
|
|
8489
8727
|
function hex2HslToken(token) {
|
|
8490
8728
|
let values = hex2srgbvalues(token);
|
|
8491
8729
|
if (values == null) {
|
|
@@ -8550,11 +8788,17 @@
|
|
|
8550
8788
|
return hslToken(srgb2hslvalues(values[0], values[1], values[2], values[3]));
|
|
8551
8789
|
}
|
|
8552
8790
|
function hslToken(values) {
|
|
8553
|
-
values[
|
|
8791
|
+
if (values[1] == 0) {
|
|
8792
|
+
values[0] = 0;
|
|
8793
|
+
}
|
|
8794
|
+
if (values[2] == 1 || values[2] == 0) {
|
|
8795
|
+
values[0] = 0;
|
|
8796
|
+
values[1] = 0;
|
|
8797
|
+
}
|
|
8554
8798
|
const chi = [
|
|
8555
8799
|
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
8556
|
-
{ typ: exports.EnumToken.PercentageTokenType, val: values[1]
|
|
8557
|
-
{ typ: exports.EnumToken.PercentageTokenType, val: values[2]
|
|
8800
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[1] },
|
|
8801
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[2] },
|
|
8558
8802
|
];
|
|
8559
8803
|
if (values.length == 4 && values[3] != 1) {
|
|
8560
8804
|
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
|
|
@@ -8597,32 +8841,33 @@
|
|
|
8597
8841
|
}
|
|
8598
8842
|
return rgbvalues2hslvalues(values[0], values[1], values[2], values[3]);
|
|
8599
8843
|
}
|
|
8600
|
-
// https://gist.github.com/defims/0ca2ef8832833186ed396a2f8a204117#file-annotated-js
|
|
8601
|
-
function hsv2hsl(h, s, v, a) {
|
|
8602
|
-
const result = [
|
|
8603
|
-
//[hue, saturation, lightness]
|
|
8604
|
-
//Range should be between 0 - 1
|
|
8605
|
-
h, //Hue stays the same
|
|
8606
|
-
//Saturation is very different between the two color spaces
|
|
8607
|
-
//If (2-sat)*val < 1 set it to sat*val/((2-sat)*val)
|
|
8608
|
-
//Otherwise sat*val/(2-(2-sat)*val)
|
|
8609
|
-
//Conditional is not operating with hue, it is reassigned!
|
|
8610
|
-
(s * v) / ((h = (2 - s) * v) < 1 ? h : 2 - h),
|
|
8611
|
-
h / 2, //Lightness is (2-sat)*val/2
|
|
8612
|
-
];
|
|
8613
|
-
if (a != null) {
|
|
8614
|
-
result.push(a);
|
|
8615
|
-
}
|
|
8616
|
-
return result;
|
|
8617
|
-
}
|
|
8618
8844
|
function cmyk2hslvalues(token) {
|
|
8619
8845
|
const values = cmyk2rgbvalues(token);
|
|
8620
8846
|
return values == null ? null : rgbvalues2hslvalues(values[0], values[1], values[2], values[3]);
|
|
8621
8847
|
}
|
|
8622
8848
|
function hwb2hslvalues(token) {
|
|
8623
|
-
const
|
|
8624
|
-
|
|
8625
|
-
|
|
8849
|
+
const { h, w, b, a } = hwbvalues(token) ?? {};
|
|
8850
|
+
if (h == null || w == null || b == null) {
|
|
8851
|
+
return null;
|
|
8852
|
+
}
|
|
8853
|
+
const wNorm = w / 100;
|
|
8854
|
+
const bNorm = b / 100;
|
|
8855
|
+
const hue = ((h % 360) + 360) % 360;
|
|
8856
|
+
if (wNorm + bNorm >= 1) {
|
|
8857
|
+
const grayLightness = wNorm / (wNorm + bNorm);
|
|
8858
|
+
return [hue, 0, grayLightness * 100];
|
|
8859
|
+
}
|
|
8860
|
+
const lightness = (1 - bNorm + wNorm) / 2;
|
|
8861
|
+
let saturation = 0;
|
|
8862
|
+
if (lightness > 0 && lightness < 1) {
|
|
8863
|
+
const chroma = 1 - wNorm - bNorm;
|
|
8864
|
+
saturation = chroma / (1 - Math.abs(2 * lightness - 1));
|
|
8865
|
+
}
|
|
8866
|
+
const hsl = [hue, saturation * 100, lightness * 100];
|
|
8867
|
+
if (a != null && a != 1) {
|
|
8868
|
+
hsl.push(a);
|
|
8869
|
+
}
|
|
8870
|
+
return hsl;
|
|
8626
8871
|
}
|
|
8627
8872
|
function lab2hslvalues(token) {
|
|
8628
8873
|
const values = lab2rgbvalues(token);
|
|
@@ -8653,28 +8898,28 @@
|
|
|
8653
8898
|
return srgb2hslvalues(r / 255, g / 255, b / 255, a);
|
|
8654
8899
|
}
|
|
8655
8900
|
function srgb2hslvalues(r, g, b, a = null) {
|
|
8656
|
-
|
|
8657
|
-
|
|
8901
|
+
const max = Math.max(r, g, b);
|
|
8902
|
+
const min = Math.min(r, g, b);
|
|
8903
|
+
const delta = max - min;
|
|
8904
|
+
const l = (max + min) / 2;
|
|
8658
8905
|
let h = 0;
|
|
8659
8906
|
let s = 0;
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
let d = max - min;
|
|
8663
|
-
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
8907
|
+
if (delta !== 0) {
|
|
8908
|
+
s = delta / (1 - Math.abs(2 * l - 1));
|
|
8664
8909
|
switch (max) {
|
|
8665
8910
|
case r:
|
|
8666
|
-
h = (g - b) /
|
|
8911
|
+
h = 60 * (((g - b) / delta) % 6);
|
|
8667
8912
|
break;
|
|
8668
8913
|
case g:
|
|
8669
|
-
h = (b - r) /
|
|
8914
|
+
h = 60 * ((b - r) / delta + 2);
|
|
8670
8915
|
break;
|
|
8671
8916
|
case b:
|
|
8672
|
-
h = (r - g) /
|
|
8917
|
+
h = 60 * ((r - g) / delta + 4);
|
|
8673
8918
|
break;
|
|
8674
8919
|
}
|
|
8675
|
-
h /= 6;
|
|
8676
8920
|
}
|
|
8677
|
-
|
|
8921
|
+
h = ((h % 360) + 360) % 360;
|
|
8922
|
+
const hsl = [h, s * 100, l * 100];
|
|
8678
8923
|
if (a != null && a < 1) {
|
|
8679
8924
|
// @ts-ignore
|
|
8680
8925
|
return hsl.concat([a]);
|
|
@@ -8683,191 +8928,6 @@
|
|
|
8683
8928
|
return hsl;
|
|
8684
8929
|
}
|
|
8685
8930
|
|
|
8686
|
-
function rgb2hwbToken(token) {
|
|
8687
|
-
const values = rgb2hwbvalues(token);
|
|
8688
|
-
if (values == null) {
|
|
8689
|
-
return null;
|
|
8690
|
-
}
|
|
8691
|
-
return hwbToken(values);
|
|
8692
|
-
}
|
|
8693
|
-
function hsl2hwbToken(token) {
|
|
8694
|
-
const values = hsl2hwbvalues(token);
|
|
8695
|
-
if (values == null) {
|
|
8696
|
-
return null;
|
|
8697
|
-
}
|
|
8698
|
-
return hwbToken(values);
|
|
8699
|
-
}
|
|
8700
|
-
function cmyk2hwbToken(token) {
|
|
8701
|
-
const values = cmyk2hwbvalues(token);
|
|
8702
|
-
if (values == null) {
|
|
8703
|
-
return null;
|
|
8704
|
-
}
|
|
8705
|
-
return hwbToken(values);
|
|
8706
|
-
}
|
|
8707
|
-
function oklab2hwbToken(token) {
|
|
8708
|
-
const values = oklab2hwbvalues(token);
|
|
8709
|
-
if (values == null) {
|
|
8710
|
-
return null;
|
|
8711
|
-
}
|
|
8712
|
-
return hwbToken(values);
|
|
8713
|
-
}
|
|
8714
|
-
function oklch2hwbToken(token) {
|
|
8715
|
-
const values = oklch2hwbvalues(token);
|
|
8716
|
-
if (values == null) {
|
|
8717
|
-
return null;
|
|
8718
|
-
}
|
|
8719
|
-
return hwbToken(values);
|
|
8720
|
-
}
|
|
8721
|
-
function lab2hwbToken(token) {
|
|
8722
|
-
const values = lab2hwbvalues(token);
|
|
8723
|
-
if (values == null) {
|
|
8724
|
-
return null;
|
|
8725
|
-
}
|
|
8726
|
-
return hwbToken(values);
|
|
8727
|
-
}
|
|
8728
|
-
function lch2hwbToken(token) {
|
|
8729
|
-
const values = lch2hwbvalues(token);
|
|
8730
|
-
if (values == null) {
|
|
8731
|
-
return null;
|
|
8732
|
-
}
|
|
8733
|
-
return hwbToken(values);
|
|
8734
|
-
}
|
|
8735
|
-
function color2hwbToken(token) {
|
|
8736
|
-
const values = color2hwbvalues(token);
|
|
8737
|
-
if (values == null) {
|
|
8738
|
-
return null;
|
|
8739
|
-
}
|
|
8740
|
-
return hwbToken(values);
|
|
8741
|
-
}
|
|
8742
|
-
function hwbToken(values) {
|
|
8743
|
-
values[0] = values[0] * 360;
|
|
8744
|
-
const chi = [
|
|
8745
|
-
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
8746
|
-
{ typ: exports.EnumToken.PercentageTokenType, val: values[1] * 100 },
|
|
8747
|
-
{ typ: exports.EnumToken.PercentageTokenType, val: values[2] * 100 },
|
|
8748
|
-
];
|
|
8749
|
-
if (values.length == 4) {
|
|
8750
|
-
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
|
|
8751
|
-
typ: exports.EnumToken.PercentageTokenType,
|
|
8752
|
-
val: values[3] * 100,
|
|
8753
|
-
});
|
|
8754
|
-
}
|
|
8755
|
-
return {
|
|
8756
|
-
typ: exports.EnumToken.ColorTokenType,
|
|
8757
|
-
val: "hwb",
|
|
8758
|
-
chi,
|
|
8759
|
-
kin: exports.ColorType.HWB,
|
|
8760
|
-
};
|
|
8761
|
-
}
|
|
8762
|
-
function rgb2hwbvalues(token) {
|
|
8763
|
-
const values = getColorComponents(token).map((t, index) => {
|
|
8764
|
-
if (index == 3) {
|
|
8765
|
-
return getNumber(t);
|
|
8766
|
-
}
|
|
8767
|
-
return getNumber(t) / 255;
|
|
8768
|
-
});
|
|
8769
|
-
// @ts-ignore
|
|
8770
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8771
|
-
}
|
|
8772
|
-
function cmyk2hwbvalues(token) {
|
|
8773
|
-
const values = cmyk2srgbvalues(token);
|
|
8774
|
-
return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8775
|
-
}
|
|
8776
|
-
function hsl2hwbvalues(token) {
|
|
8777
|
-
const values = getColorComponents(token).map((t, index) => {
|
|
8778
|
-
if (index == 3 && t.typ == exports.EnumToken.IdenTokenType && t.val == "none") {
|
|
8779
|
-
return 1;
|
|
8780
|
-
}
|
|
8781
|
-
if (index == 0) {
|
|
8782
|
-
return getAngle(t);
|
|
8783
|
-
}
|
|
8784
|
-
return getNumber(t);
|
|
8785
|
-
});
|
|
8786
|
-
// @ts-ignore
|
|
8787
|
-
return hslvalues2hwbvalues(values[0], values[1], values[2], values[3]);
|
|
8788
|
-
}
|
|
8789
|
-
function lab2hwbvalues(token) {
|
|
8790
|
-
const values = lab2srgbvalues(token);
|
|
8791
|
-
if (values == null) {
|
|
8792
|
-
return null;
|
|
8793
|
-
}
|
|
8794
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8795
|
-
}
|
|
8796
|
-
function lch2hwbvalues(token) {
|
|
8797
|
-
const values = lch2srgbvalues(token);
|
|
8798
|
-
if (values == null) {
|
|
8799
|
-
return null;
|
|
8800
|
-
}
|
|
8801
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8802
|
-
}
|
|
8803
|
-
function oklab2hwbvalues(token) {
|
|
8804
|
-
const values = oklab2srgbvalues(token);
|
|
8805
|
-
if (values == null) {
|
|
8806
|
-
return null;
|
|
8807
|
-
}
|
|
8808
|
-
// @ts-ignore
|
|
8809
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8810
|
-
}
|
|
8811
|
-
function oklch2hwbvalues(token) {
|
|
8812
|
-
const values = oklch2srgbvalues(token);
|
|
8813
|
-
// @ts-ignore
|
|
8814
|
-
return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8815
|
-
}
|
|
8816
|
-
function rgb2hue(r, g, b, fallback = 0) {
|
|
8817
|
-
let value = rgb2value(r, g, b);
|
|
8818
|
-
let whiteness = rgb2whiteness(r, g, b);
|
|
8819
|
-
let delta = value - whiteness;
|
|
8820
|
-
if (delta > 0) {
|
|
8821
|
-
// calculate segment
|
|
8822
|
-
let segment = value === r ? (g - b) / delta : value === g ? (b - r) / delta : (r - g) / delta;
|
|
8823
|
-
// calculate shift
|
|
8824
|
-
let shift = value === r ? (segment < 0 ? 360 / 60 : 0 / 60) : value === g ? 120 / 60 : 240 / 60;
|
|
8825
|
-
// calculate hue
|
|
8826
|
-
return (segment + shift) * 60;
|
|
8827
|
-
}
|
|
8828
|
-
return fallback;
|
|
8829
|
-
}
|
|
8830
|
-
function rgb2value(r, g, b) {
|
|
8831
|
-
return Math.max(r, g, b);
|
|
8832
|
-
}
|
|
8833
|
-
function rgb2whiteness(r, g, b) {
|
|
8834
|
-
return Math.min(r, g, b);
|
|
8835
|
-
}
|
|
8836
|
-
function color2hwbvalues(token) {
|
|
8837
|
-
const values = color2srgbvalues(token);
|
|
8838
|
-
if (values == null) {
|
|
8839
|
-
return null;
|
|
8840
|
-
}
|
|
8841
|
-
// @ts-ignore
|
|
8842
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8843
|
-
}
|
|
8844
|
-
function srgb2hwb(r, g, b, a = null, fallback = 0) {
|
|
8845
|
-
r *= 100;
|
|
8846
|
-
g *= 100;
|
|
8847
|
-
b *= 100;
|
|
8848
|
-
let hue = rgb2hue(r, g, b, fallback);
|
|
8849
|
-
let whiteness = rgb2whiteness(r, g, b);
|
|
8850
|
-
let value = Math.round(rgb2value(r, g, b));
|
|
8851
|
-
let blackness = 100 - value;
|
|
8852
|
-
const result = [hue / 360, whiteness / 100, blackness / 100];
|
|
8853
|
-
if (a != null) {
|
|
8854
|
-
result.push(a);
|
|
8855
|
-
}
|
|
8856
|
-
return result;
|
|
8857
|
-
}
|
|
8858
|
-
function hsv2hwb(h, s, v, a = null) {
|
|
8859
|
-
const result = [h, (1 - s) * v, 1 - v];
|
|
8860
|
-
if (a != null) {
|
|
8861
|
-
result.push(a);
|
|
8862
|
-
}
|
|
8863
|
-
return result;
|
|
8864
|
-
}
|
|
8865
|
-
function hslvalues2hwbvalues(h, s, l, a = null) {
|
|
8866
|
-
let values = hsl2hsv(h, s, l);
|
|
8867
|
-
// @ts-ignore
|
|
8868
|
-
return hsv2hwb(values[0], values[1], values[2], a);
|
|
8869
|
-
}
|
|
8870
|
-
|
|
8871
8931
|
function prophotorgb2srgbvalues(r, g, b, a = null) {
|
|
8872
8932
|
let values = prophotorgb2xyz50(r, g, b);
|
|
8873
8933
|
// @ts-ignore
|
|
@@ -9169,6 +9229,7 @@
|
|
|
9169
9229
|
const percentages = [];
|
|
9170
9230
|
const srgbComponentValues = [];
|
|
9171
9231
|
const colorComponents = [];
|
|
9232
|
+
const colors = [];
|
|
9172
9233
|
if (args[i]?.typ === exports.EnumToken.IdenTokenType) {
|
|
9173
9234
|
if (!equalsIgnoreCase(args[i++].val, "in")) {
|
|
9174
9235
|
return null;
|
|
@@ -9218,9 +9279,10 @@
|
|
|
9218
9279
|
if (values == null) {
|
|
9219
9280
|
return null;
|
|
9220
9281
|
}
|
|
9221
|
-
if (colorSpace == "hwb") {
|
|
9222
|
-
|
|
9223
|
-
}
|
|
9282
|
+
// if (colorSpace == "hwb") {
|
|
9283
|
+
// colorSpace = "srgb";
|
|
9284
|
+
// }
|
|
9285
|
+
colors.push(processPowerlessComponents(args[i]));
|
|
9224
9286
|
switch (colorSpace) {
|
|
9225
9287
|
case "srgb":
|
|
9226
9288
|
break;
|
|
@@ -9250,17 +9312,12 @@
|
|
|
9250
9312
|
values = srgb2xyz_d65(values[0], values[1], values[2], values[3]);
|
|
9251
9313
|
values = XYZ_D65_to_D50(values[0], values[1], values[2], values[3]);
|
|
9252
9314
|
break;
|
|
9253
|
-
// case "rgb":
|
|
9254
|
-
// for (let j = 0; j < values.length; j++) {
|
|
9255
|
-
// values[j] = j == 3 ? values[j] : srgb2rgb(values[j]);
|
|
9256
|
-
// }
|
|
9257
|
-
// break;
|
|
9258
9315
|
case "hsl":
|
|
9259
9316
|
values = srgb2hslvalues(values[0], values[1], values[2], values[3]);
|
|
9260
9317
|
break;
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
|
|
9318
|
+
case "hwb":
|
|
9319
|
+
values = srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
9320
|
+
break;
|
|
9264
9321
|
case "lab":
|
|
9265
9322
|
values = srgb2labvalues(values[0], values[1], values[2], values[3]);
|
|
9266
9323
|
break;
|
|
@@ -9322,7 +9379,8 @@
|
|
|
9322
9379
|
}
|
|
9323
9380
|
}
|
|
9324
9381
|
const stack = [];
|
|
9325
|
-
const lchSpaces = ["lch", "oklch"];
|
|
9382
|
+
// const lchSpaces: string[] = ["lch", "oklch"];
|
|
9383
|
+
const isLCHOrOKLCH = colorSpace === "lch" || colorSpace == "oklch";
|
|
9326
9384
|
i = srgbComponentValues.length;
|
|
9327
9385
|
while (i--) {
|
|
9328
9386
|
stack.push({
|
|
@@ -9340,46 +9398,73 @@
|
|
|
9340
9398
|
let premult1;
|
|
9341
9399
|
let premult2;
|
|
9342
9400
|
let mixedPremult;
|
|
9343
|
-
let
|
|
9344
|
-
|
|
9345
|
-
|
|
9346
|
-
|
|
9347
|
-
|
|
9348
|
-
if (colorComponents[0][3] != null &&
|
|
9349
|
-
colorComponents[0][3].typ == exports.EnumToken.IdenTokenType &&
|
|
9350
|
-
colorComponents[0][3].val == "none" &&
|
|
9351
|
-
colorComponents[1].length == 4) {
|
|
9401
|
+
let offset1 = colors[0].kin == exports.ColorType.COLOR ? 1 : 0;
|
|
9402
|
+
if (colorComponents[0][offset1 + 3] != null &&
|
|
9403
|
+
colorComponents[0][offset1 + 3].typ == exports.EnumToken.IdenTokenType &&
|
|
9404
|
+
colorComponents[0][offset1 + 3].val == "none" &&
|
|
9405
|
+
colorComponents[1].length == offset1 + 4) {
|
|
9352
9406
|
// fix powerless alpha for last color if previous color has alpha
|
|
9353
9407
|
stack[stack.length - 1].color[3] = stack[stack.length - 2].color[3];
|
|
9354
9408
|
}
|
|
9355
|
-
//
|
|
9356
|
-
if (
|
|
9357
|
-
|
|
9358
|
-
|
|
9359
|
-
|
|
9360
|
-
|
|
9409
|
+
// console.error(stack);
|
|
9410
|
+
if (stack.length > 1) {
|
|
9411
|
+
// powerless hue for lch spaces
|
|
9412
|
+
// if (lchSpaces.includes(colorSpace)) {
|
|
9413
|
+
// console.error(JSON.stringify({colorSpace1, colorSpace, stack, colorComponents}, null, 1));
|
|
9414
|
+
if ((stack[stack.length - 1].color[0] == 0 && colorComponents[0][offset1].typ == exports.EnumToken.IdenTokenType &&
|
|
9415
|
+
colorComponents[0][offset1].val == "none") ||
|
|
9416
|
+
colorComponents[0][0][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
|
|
9417
|
+
stack[stack.length - 1].color[0] = stack[stack.length - 2].color[0];
|
|
9418
|
+
}
|
|
9419
|
+
if ((stack[stack.length - 1].color[1] == 0 && colorComponents[0][offset1 + 1].typ == exports.EnumToken.IdenTokenType &&
|
|
9420
|
+
colorComponents[0][offset1 + 1].val == "none") ||
|
|
9421
|
+
colorComponents[0][1][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
|
|
9422
|
+
stack[stack.length - 1].color[1] = stack[stack.length - 2].color[1];
|
|
9423
|
+
}
|
|
9424
|
+
if ((stack[stack.length - 1].color[2] == 0 && colorComponents[0][offset1 + 2].typ == exports.EnumToken.IdenTokenType &&
|
|
9425
|
+
colorComponents[0][offset1 + 2].val == "none") ||
|
|
9426
|
+
colorComponents[0][2][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent ||
|
|
9427
|
+
(isLCHOrOKLCH &&
|
|
9428
|
+
(stack[stack.length - 1].color[1] == 0 ||
|
|
9429
|
+
stack[stack.length - 1].color[0] == 0 ||
|
|
9430
|
+
stack[stack.length - 1].color[0] ==
|
|
9431
|
+
colorRange[colors[0].kin == exports.ColorType.LCH ? "lch" : "oklch"].l[1]))) {
|
|
9361
9432
|
stack[stack.length - 1].color[2] = stack[stack.length - 2].color[2];
|
|
9362
9433
|
}
|
|
9434
|
+
// }
|
|
9363
9435
|
}
|
|
9436
|
+
// console.error([colorComponents[0][offset1].typ == EnumToken.IdenTokenType, (colorComponents[0][offset1] as IdentToken).val == "none"]);
|
|
9437
|
+
// console.error(isLCHOrOKLCH, colorComponents, stack);
|
|
9364
9438
|
while (stack.length > 1) {
|
|
9365
9439
|
r1 = stack.pop();
|
|
9366
9440
|
r2 = stack.pop();
|
|
9441
|
+
offset1 = colors[++currentIndex].kin == exports.ColorType.COLOR ? 1 : 0;
|
|
9367
9442
|
// r2 powerless alpha
|
|
9368
|
-
if (colorComponents[
|
|
9369
|
-
colorComponents[currentIndex][3].typ == exports.EnumToken.IdenTokenType &&
|
|
9370
|
-
colorComponents[currentIndex][3].val == "none") {
|
|
9443
|
+
if (colorComponents[currentIndex][offset1 + 3] != null &&
|
|
9444
|
+
colorComponents[currentIndex][offset1 + 3].typ == exports.EnumToken.IdenTokenType &&
|
|
9445
|
+
colorComponents[currentIndex][offset1 + 3].val == "none") {
|
|
9371
9446
|
// fix powerless alpha for last color if previous color has alpha
|
|
9372
9447
|
r2.color[3] = r1.color[3];
|
|
9373
9448
|
}
|
|
9374
|
-
// @ts-expect-error
|
|
9375
|
-
colorSpace1 = exports.ColorType[colorComponents[currentIndex].kin]?.toLowerCase?.();
|
|
9376
9449
|
// powerless hue for lch spaces
|
|
9377
|
-
if (
|
|
9378
|
-
|
|
9379
|
-
|
|
9380
|
-
|
|
9381
|
-
|
|
9382
|
-
|
|
9450
|
+
if ((r2.color[0] == 0 && colorComponents[currentIndex][offset1].typ == exports.EnumToken.IdenTokenType &&
|
|
9451
|
+
colorComponents[currentIndex][offset1].val == "none") ||
|
|
9452
|
+
colorComponents[currentIndex][offset1][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
|
|
9453
|
+
r2.color[0] = r1.color[0];
|
|
9454
|
+
}
|
|
9455
|
+
if ((r2.color[1] == 0 && colorComponents[currentIndex][offset1 + 1].typ == exports.EnumToken.IdenTokenType &&
|
|
9456
|
+
colorComponents[currentIndex][offset1 + 1].val == "none") ||
|
|
9457
|
+
colorComponents[currentIndex][offset1 + 1][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
|
|
9458
|
+
r2.color[1] = r1.color[1];
|
|
9459
|
+
}
|
|
9460
|
+
if ((r2.color[2] == 0 && colorComponents[currentIndex][offset1 + 2].typ == exports.EnumToken.IdenTokenType &&
|
|
9461
|
+
colorComponents[currentIndex][offset1 + 2].val == "none") ||
|
|
9462
|
+
colorComponents[currentIndex][offset1 + 2][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent ||
|
|
9463
|
+
(isLCHOrOKLCH &&
|
|
9464
|
+
(r2.color[1] == 0 ||
|
|
9465
|
+
r2.color[0] == 0 ||
|
|
9466
|
+
r2.color[0] == colorRange[colors[currentIndex].kin == exports.ColorType.LCH ? "lch" : "oklch"].l[1]))) {
|
|
9467
|
+
r2.color[2] = r1.color[2];
|
|
9383
9468
|
}
|
|
9384
9469
|
if (hueInterpolationMethod != null) {
|
|
9385
9470
|
let hueIndex = 2;
|
|
@@ -9407,6 +9492,7 @@
|
|
|
9407
9492
|
alpha: mult,
|
|
9408
9493
|
};
|
|
9409
9494
|
}
|
|
9495
|
+
// console.error({ r1, r2, r, premult1, mult1, premult2, mult2, mixedPremult, mult });
|
|
9410
9496
|
stack.push(r);
|
|
9411
9497
|
}
|
|
9412
9498
|
const result = stack.pop();
|
|
@@ -9461,16 +9547,16 @@
|
|
|
9461
9547
|
};
|
|
9462
9548
|
// case "rgb":
|
|
9463
9549
|
case "hsl":
|
|
9464
|
-
|
|
9550
|
+
case "hwb":
|
|
9465
9551
|
case "lab":
|
|
9466
9552
|
case "lch":
|
|
9467
9553
|
case "oklab":
|
|
9468
9554
|
case "oklch":
|
|
9469
|
-
if (colorSpace == "hsl") {
|
|
9555
|
+
if (colorSpace == "hsl" || colorSpace == "hwb") {
|
|
9470
9556
|
// @ts-ignore
|
|
9471
9557
|
if (values[2] < 0) {
|
|
9472
9558
|
// @ts-ignore
|
|
9473
|
-
values[2] +=
|
|
9559
|
+
values[2] += 360;
|
|
9474
9560
|
}
|
|
9475
9561
|
}
|
|
9476
9562
|
else if (colorSpace == "lch" || colorSpace == "oklch") {
|
|
@@ -9498,16 +9584,72 @@
|
|
|
9498
9584
|
};
|
|
9499
9585
|
if (colorSpace == "hsl") {
|
|
9500
9586
|
// @ts-ignore
|
|
9501
|
-
result.chi[0] = { typ: exports.EnumToken.AngleTokenType, val: result.chi[0].val
|
|
9587
|
+
result.chi[0] = { typ: exports.EnumToken.AngleTokenType, val: result.chi[0].val };
|
|
9502
9588
|
// @ts-ignore
|
|
9503
|
-
result.chi[1] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[1].val
|
|
9589
|
+
result.chi[1] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[1].val };
|
|
9504
9590
|
// @ts-ignore
|
|
9505
|
-
result.chi[2] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[2].val
|
|
9591
|
+
result.chi[2] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[2].val };
|
|
9506
9592
|
}
|
|
9507
9593
|
return result;
|
|
9508
9594
|
}
|
|
9509
9595
|
return null;
|
|
9510
9596
|
}
|
|
9597
|
+
function processPowerlessComponents(color) {
|
|
9598
|
+
let components;
|
|
9599
|
+
let values;
|
|
9600
|
+
switch (color.kin) {
|
|
9601
|
+
case exports.ColorType.LCH:
|
|
9602
|
+
case exports.ColorType.OKLCH:
|
|
9603
|
+
values = color.kin == exports.ColorType.LCH ? getLCHComponents(color) : getOKLCHComponents(color);
|
|
9604
|
+
components = getColorComponents(color);
|
|
9605
|
+
if (values == null || values.length < 3 || components == null) {
|
|
9606
|
+
break;
|
|
9607
|
+
}
|
|
9608
|
+
const max = color.kin == exports.ColorType.LCH ? colorRange.lch.l[1] : colorRange.oklch.l[1];
|
|
9609
|
+
// https://www.w3.org/TR/css-color-4/#specifying-lab-lch
|
|
9610
|
+
// https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch
|
|
9611
|
+
const epsilon = color.kin == exports.ColorType.LCH ? 0.0015 : 0.000004;
|
|
9612
|
+
if (values[0] < epsilon || Math.abs(values[0] - max) < epsilon) {
|
|
9613
|
+
Object.assign(components[0], { val: values[0] < epsilon ? 0 : max, typ: exports.EnumToken.NumberTokenType });
|
|
9614
|
+
Object.assign(components[1], { val: "none", typ: exports.EnumToken.IdenTokenType });
|
|
9615
|
+
Object.assign(components[2], { val: "none", typ: exports.EnumToken.IdenTokenType });
|
|
9616
|
+
setColorFlag(components[1], exports.EnumAstNodeStatus.PowerlessColorComponent);
|
|
9617
|
+
setColorFlag(components[2], exports.EnumAstNodeStatus.PowerlessColorComponent);
|
|
9618
|
+
}
|
|
9619
|
+
else if (values[1] < epsilon) {
|
|
9620
|
+
values[1] = 0;
|
|
9621
|
+
Object.assign(components[1], { val: 0, typ: exports.EnumToken.NumberTokenType });
|
|
9622
|
+
Object.assign(components[2], { val: "none", typ: exports.EnumToken.IdenTokenType });
|
|
9623
|
+
setColorFlag(components[2], exports.EnumAstNodeStatus.PowerlessColorComponent);
|
|
9624
|
+
}
|
|
9625
|
+
break;
|
|
9626
|
+
case exports.ColorType.HSL:
|
|
9627
|
+
case exports.ColorType.HWB:
|
|
9628
|
+
values = Object.values((color.kin == exports.ColorType.HSL ? hslvalues(color) : hwbvalues(color)) ?? {});
|
|
9629
|
+
components = getColorComponents(color);
|
|
9630
|
+
if (values == null || values.length < 3 || components == null) {
|
|
9631
|
+
break;
|
|
9632
|
+
}
|
|
9633
|
+
// https://www.w3.org/TR/css-color-4/#the-hsl-notation
|
|
9634
|
+
// https://www.w3.org/TR/css-color-4/#the-hwb-notation
|
|
9635
|
+
if ((color.kin == exports.ColorType.HSL && values[1] <= 0.001) ||
|
|
9636
|
+
(color.kin == exports.ColorType.HWB && values[1] + values[2] >= 99.999)) {
|
|
9637
|
+
Object.assign(components[0], { val: "none", typ: exports.EnumToken.IdenTokenType });
|
|
9638
|
+
setColorFlag(components[0], exports.EnumAstNodeStatus.PowerlessColorComponent);
|
|
9639
|
+
}
|
|
9640
|
+
break;
|
|
9641
|
+
}
|
|
9642
|
+
// console.error({ color: color.chi ?? color, values });
|
|
9643
|
+
return color;
|
|
9644
|
+
}
|
|
9645
|
+
function setColorFlag(token, flag) {
|
|
9646
|
+
if (token[STATE] == null) {
|
|
9647
|
+
token[STATE] = flag;
|
|
9648
|
+
}
|
|
9649
|
+
else {
|
|
9650
|
+
token[STATE] |= flag;
|
|
9651
|
+
}
|
|
9652
|
+
}
|
|
9511
9653
|
|
|
9512
9654
|
/**
|
|
9513
9655
|
* Options for the walk function
|
|
@@ -9545,6 +9687,7 @@
|
|
|
9545
9687
|
*/
|
|
9546
9688
|
WalkerEvent[WalkerEvent["Leave"] = 2] = "Leave";
|
|
9547
9689
|
})(exports.WalkerEvent || (exports.WalkerEvent = {}));
|
|
9690
|
+
const maxQueueLength = 25000;
|
|
9548
9691
|
/**
|
|
9549
9692
|
* Walk ast nodes
|
|
9550
9693
|
* @param node initial node
|
|
@@ -9648,6 +9791,10 @@
|
|
|
9648
9791
|
},
|
|
9649
9792
|
};
|
|
9650
9793
|
while ((node = parents[i++])) {
|
|
9794
|
+
if (i > maxQueueLength) {
|
|
9795
|
+
parents.splice(0, maxQueueLength);
|
|
9796
|
+
i -= maxQueueLength;
|
|
9797
|
+
}
|
|
9651
9798
|
let option = null;
|
|
9652
9799
|
if (filter != null) {
|
|
9653
9800
|
// @ts-expect-error
|
|
@@ -9791,6 +9938,10 @@
|
|
|
9791
9938
|
while (++i < stack.length) {
|
|
9792
9939
|
value = stack[i];
|
|
9793
9940
|
option = null;
|
|
9941
|
+
if (i > maxQueueLength) {
|
|
9942
|
+
stack.splice(0, maxQueueLength);
|
|
9943
|
+
i -= maxQueueLength;
|
|
9944
|
+
}
|
|
9794
9945
|
if (filter.fn != null && eventType & exports.WalkerEvent.Enter) {
|
|
9795
9946
|
const isValid = filter.type == null ||
|
|
9796
9947
|
value.typ == filter.type ||
|
|
@@ -11023,7 +11174,36 @@
|
|
|
11023
11174
|
: aExp),
|
|
11024
11175
|
};
|
|
11025
11176
|
const result = computeComponentValue(keys, values);
|
|
11177
|
+
if (result != null) {
|
|
11178
|
+
if ("hsl" == relativeKeys) {
|
|
11179
|
+
Object.assign(result.s, {
|
|
11180
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
11181
|
+
// @ts-ignore
|
|
11182
|
+
val: result.s.val * 100,
|
|
11183
|
+
});
|
|
11184
|
+
Object.assign(result.l, {
|
|
11185
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
11186
|
+
// @ts-ignore
|
|
11187
|
+
val: result.l.val * 100,
|
|
11188
|
+
});
|
|
11189
|
+
}
|
|
11190
|
+
else if ("hwb" == relativeKeys) {
|
|
11191
|
+
// @ts
|
|
11192
|
+
Object.assign(result.w, {
|
|
11193
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
11194
|
+
// @ts-ignore
|
|
11195
|
+
val: result.w.val * 100,
|
|
11196
|
+
});
|
|
11197
|
+
Object.assign(result.b, {
|
|
11198
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
11199
|
+
// @ts-ignore
|
|
11200
|
+
val: result.b.val * 100,
|
|
11201
|
+
});
|
|
11202
|
+
}
|
|
11203
|
+
}
|
|
11204
|
+
// @ts-ignore
|
|
11026
11205
|
if (result?.alpha?.typ == exports.EnumToken.NumberTokenType && result.alpha.val === 1) {
|
|
11206
|
+
// @ts-ignore
|
|
11027
11207
|
const { alpha, ...components } = result;
|
|
11028
11208
|
return components;
|
|
11029
11209
|
}
|
|
@@ -12316,8 +12496,7 @@
|
|
|
12316
12496
|
case MediaFeatureType.RatioType:
|
|
12317
12497
|
return {
|
|
12318
12498
|
valid: true,
|
|
12319
|
-
success: (tokens.length == 1 &&
|
|
12320
|
-
tokens[0].typ == exports.EnumToken.NumberTokenType) ||
|
|
12499
|
+
success: (tokens.length == 1 && tokens[0].typ == exports.EnumToken.NumberTokenType) ||
|
|
12321
12500
|
(tokens.length === 3 &&
|
|
12322
12501
|
tokens[0].typ == exports.EnumToken.NumberTokenType &&
|
|
12323
12502
|
typeof tokens[0].val === "number" &&
|
|
@@ -12624,7 +12803,7 @@
|
|
|
12624
12803
|
}
|
|
12625
12804
|
stack.push(token);
|
|
12626
12805
|
break;
|
|
12627
|
-
case exports.EnumToken.
|
|
12806
|
+
case exports.EnumToken.PipeTokenType:
|
|
12628
12807
|
case exports.EnumToken.DelimTokenType:
|
|
12629
12808
|
case exports.EnumToken.StringTokenType:
|
|
12630
12809
|
case exports.EnumToken.IncludeMatchTokenType:
|
|
@@ -12672,10 +12851,10 @@
|
|
|
12672
12851
|
}
|
|
12673
12852
|
slice.push(tokens[n]);
|
|
12674
12853
|
}
|
|
12675
|
-
if (slice[1]?.typ === exports.EnumToken.
|
|
12854
|
+
if (slice[1]?.typ === exports.EnumToken.PipeTokenType) {
|
|
12676
12855
|
slice.shift();
|
|
12677
12856
|
}
|
|
12678
|
-
if (slice[0].typ === exports.EnumToken.
|
|
12857
|
+
if (slice[0].typ === exports.EnumToken.PipeTokenType) {
|
|
12679
12858
|
slice.shift();
|
|
12680
12859
|
}
|
|
12681
12860
|
if (slice.length === 1) {
|
|
@@ -13037,8 +13216,8 @@
|
|
|
13037
13216
|
// custom function token
|
|
13038
13217
|
if (token.typ === exports.EnumToken.CustomFunctionTokenDefType) {
|
|
13039
13218
|
if (syntaxes[i].typ != ValidationTokenEnum.PropertyType ||
|
|
13040
|
-
syntaxes[i + 1]
|
|
13041
|
-
syntaxes[i + 2]
|
|
13219
|
+
syntaxes[i + 1]?.typ != ValidationTokenEnum.OpenParenthesis ||
|
|
13220
|
+
syntaxes[i + 2]?.typ == null) {
|
|
13042
13221
|
if (!isOptional) {
|
|
13043
13222
|
return {
|
|
13044
13223
|
success: false,
|
|
@@ -13885,17 +14064,15 @@
|
|
|
13885
14064
|
case "display-internal":
|
|
13886
14065
|
case "display-outside":
|
|
13887
14066
|
case "display-legacy":
|
|
13888
|
-
case "content-position":
|
|
13889
|
-
|
|
13890
|
-
|
|
13891
|
-
|
|
13892
|
-
|
|
13893
|
-
propertyKeywordValues.set(property.val, values);
|
|
13894
|
-
}
|
|
13895
|
-
success =
|
|
13896
|
-
token?.typ == exports.EnumToken.IdenTokenType && values.has(token.val.toLowerCase());
|
|
13897
|
-
break;
|
|
14067
|
+
case "content-position": {
|
|
14068
|
+
let values = propertyKeywordValues.get(property.val);
|
|
14069
|
+
if (values == null) {
|
|
14070
|
+
values = new Set(config$3.syntaxes[property.val].syntax.split(/[\s|]+/));
|
|
14071
|
+
propertyKeywordValues.set(property.val, values);
|
|
13898
14072
|
}
|
|
14073
|
+
success = token?.typ == exports.EnumToken.IdenTokenType && values.has(token.val.toLowerCase());
|
|
14074
|
+
break;
|
|
14075
|
+
}
|
|
13899
14076
|
case "mf-name":
|
|
13900
14077
|
{
|
|
13901
14078
|
const token = context.peek();
|
|
@@ -13915,8 +14092,7 @@
|
|
|
13915
14092
|
case "custom-ident":
|
|
13916
14093
|
case "counter-name":
|
|
13917
14094
|
case "counter-style-name":
|
|
13918
|
-
success =
|
|
13919
|
-
token?.typ == exports.EnumToken.IdenTokenType || token?.typ == exports.EnumToken.DashedIdenTokenType;
|
|
14095
|
+
success = token?.typ == exports.EnumToken.IdenTokenType || token?.typ == exports.EnumToken.DashedIdenTokenType;
|
|
13920
14096
|
if (success && token?.typ === exports.EnumToken.IdenTokenType) {
|
|
13921
14097
|
const val = token.val.toLowerCase();
|
|
13922
14098
|
success = "none" !== val && !allValues.includes(val);
|
|
@@ -14387,6 +14563,21 @@
|
|
|
14387
14563
|
}
|
|
14388
14564
|
break;
|
|
14389
14565
|
}
|
|
14566
|
+
case "css-type": {
|
|
14567
|
+
success = context.peek()?.typ == exports.EnumToken.CssTypeTokenType;
|
|
14568
|
+
if (success) {
|
|
14569
|
+
context.next();
|
|
14570
|
+
return {
|
|
14571
|
+
success: true,
|
|
14572
|
+
valid: true,
|
|
14573
|
+
token: null,
|
|
14574
|
+
context,
|
|
14575
|
+
syntaxToken: null,
|
|
14576
|
+
errors: [],
|
|
14577
|
+
};
|
|
14578
|
+
}
|
|
14579
|
+
break;
|
|
14580
|
+
}
|
|
14390
14581
|
default:
|
|
14391
14582
|
if (!(property.val in config$3.syntaxes)) {
|
|
14392
14583
|
console.debug("Unknown syntax", context.peek(), property);
|
|
@@ -15165,7 +15356,6 @@
|
|
|
15165
15356
|
return +token.val;
|
|
15166
15357
|
}
|
|
15167
15358
|
}
|
|
15168
|
-
// @ts-ignore
|
|
15169
15359
|
return token.val / 360;
|
|
15170
15360
|
}
|
|
15171
15361
|
|
|
@@ -17023,9 +17213,7 @@
|
|
|
17023
17213
|
}
|
|
17024
17214
|
}
|
|
17025
17215
|
run(node) {
|
|
17026
|
-
if (node[STATE]
|
|
17027
|
-
node[STATE] == exports.EnumAstNodeStatus.Invalid ||
|
|
17028
|
-
node[STATE] == exports.EnumAstNodeStatus.Malformed) {
|
|
17216
|
+
if (node[STATE] & (exports.EnumAstNodeStatus.Disallowed | exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.Malformed)) {
|
|
17029
17217
|
return null;
|
|
17030
17218
|
}
|
|
17031
17219
|
if (node.typ == exports.EnumToken.RuleNodeType) {
|
|
@@ -19740,7 +19928,8 @@
|
|
|
19740
19928
|
const tokens = {};
|
|
19741
19929
|
const values = [];
|
|
19742
19930
|
const val = [[]];
|
|
19743
|
-
for (const curr of this.declarations.get(this.config.shorthand).val) {
|
|
19931
|
+
for (const curr of this.declarations.get(this.config.shorthand).val) {
|
|
19932
|
+
// @ts-ignore
|
|
19744
19933
|
// @ts-ignore
|
|
19745
19934
|
if (separator != null && separator.typ == curr.typ && separator.val == curr.val) {
|
|
19746
19935
|
val.push([]);
|
|
@@ -20684,9 +20873,8 @@
|
|
|
20684
20873
|
let result;
|
|
20685
20874
|
for (const declaration of declarations) {
|
|
20686
20875
|
name = declaration.typ != exports.EnumToken.DeclarationNodeType ? null : declaration.nam;
|
|
20687
|
-
if (declaration[STATE]
|
|
20688
|
-
|
|
20689
|
-
declaration[STATE] == exports.EnumAstNodeStatus.ValidationFailed ||
|
|
20876
|
+
if (declaration[STATE] &
|
|
20877
|
+
(exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.Unknown | exports.EnumAstNodeStatus.ValidationFailed) ||
|
|
20690
20878
|
declaration.typ != exports.EnumToken.DeclarationNodeType ||
|
|
20691
20879
|
equalsIgnoreCase("composes", name) ||
|
|
20692
20880
|
(typeof this.options.removeDuplicateDeclarations === "string" &&
|
|
@@ -20705,17 +20893,17 @@
|
|
|
20705
20893
|
this.declarations.set(declaration.nam, declaration);
|
|
20706
20894
|
continue;
|
|
20707
20895
|
}
|
|
20708
|
-
if (declaration[STATE]
|
|
20896
|
+
if (declaration[STATE] & exports.EnumAstNodeStatus.Unvalidated) {
|
|
20709
20897
|
syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, declaration.nam.toLowerCase());
|
|
20710
20898
|
if (syntaxRules != null) {
|
|
20711
20899
|
result = matchAllSyntaxes(syntaxRules, createValidationContext(declaration.val), this.options);
|
|
20712
|
-
declaration[STATE]
|
|
20713
|
-
? exports.EnumAstNodeStatus.Validated
|
|
20714
|
-
|
|
20900
|
+
declaration[STATE] |=
|
|
20901
|
+
(result.success ? exports.EnumAstNodeStatus.Validated : exports.EnumAstNodeStatus.ValidationFailed) &
|
|
20902
|
+
~exports.EnumAstNodeStatus.Unvalidated;
|
|
20715
20903
|
}
|
|
20716
20904
|
}
|
|
20717
20905
|
// do not compute shorthand for invalid declarations
|
|
20718
|
-
if (declaration[STATE]
|
|
20906
|
+
if (!(declaration[STATE] & exports.EnumAstNodeStatus.Validated)) {
|
|
20719
20907
|
this.declarations.set(objectHash(declaration), declaration);
|
|
20720
20908
|
continue;
|
|
20721
20909
|
}
|
|
@@ -20745,6 +20933,16 @@
|
|
|
20745
20933
|
// @ts-ignore
|
|
20746
20934
|
shorthand = config.property[propertyName];
|
|
20747
20935
|
}
|
|
20936
|
+
if (this.declarations.has(shorthand)) {
|
|
20937
|
+
let existing = this.declarations.get(shorthand);
|
|
20938
|
+
if (existing instanceof PropertySet || existing instanceof PropertyMap) {
|
|
20939
|
+
existing = existing.declarations.get(declaration.nam);
|
|
20940
|
+
}
|
|
20941
|
+
if (existing?.[STATE] & exports.EnumAstNodeStatus.ImportantDeclaration &&
|
|
20942
|
+
declaration[STATE] & ~exports.EnumAstNodeStatus.ImportantDeclaration) {
|
|
20943
|
+
continue;
|
|
20944
|
+
}
|
|
20945
|
+
}
|
|
20748
20946
|
// @ts-ignore
|
|
20749
20947
|
if (shortHandType == "map") {
|
|
20750
20948
|
let owner = this;
|
|
@@ -20956,12 +21154,15 @@
|
|
|
20956
21154
|
exports.EnumToken.LtTokenType,
|
|
20957
21155
|
exports.EnumToken.LteTokenType,
|
|
20958
21156
|
exports.EnumToken.ChildCombinatorTokenType,
|
|
21157
|
+
exports.EnumToken.PipeTokenType,
|
|
20959
21158
|
]);
|
|
20960
21159
|
const trimSpaceAfter = new Set([
|
|
20961
21160
|
...tokensfuncSet.values(),
|
|
20962
21161
|
exports.EnumToken.ChildCombinatorTokenType,
|
|
20963
21162
|
exports.EnumToken.SupportsQueryConditionTokenType,
|
|
20964
21163
|
exports.EnumToken.SupportsQueryUnaryConditionTokenType,
|
|
21164
|
+
exports.EnumToken.CommaTokenType,
|
|
21165
|
+
exports.EnumToken.PipeTokenType,
|
|
20965
21166
|
]);
|
|
20966
21167
|
/**
|
|
20967
21168
|
* Replace token in its parent node
|
|
@@ -21031,17 +21232,18 @@
|
|
|
21031
21232
|
return tokens;
|
|
21032
21233
|
}
|
|
21033
21234
|
for (; i < tokens.length; i++) {
|
|
21034
|
-
if (
|
|
21035
|
-
tokens.splice(i + 1, 1);
|
|
21036
|
-
}
|
|
21037
|
-
else if (trimTokenSpace.has(tokens[i].typ)) {
|
|
21235
|
+
if (trimTokenSpace.has(tokens[i].typ)) {
|
|
21038
21236
|
if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
|
|
21039
21237
|
tokens.splice(i + 1, 1);
|
|
21040
21238
|
}
|
|
21041
21239
|
if (i > 0 && tokens[i - 1].typ === exports.EnumToken.Whitespace) {
|
|
21042
21240
|
tokens.splice(--i, 1);
|
|
21241
|
+
continue;
|
|
21043
21242
|
}
|
|
21044
21243
|
}
|
|
21244
|
+
if (trimSpaceAfter.has(tokens[i].typ) && tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
|
|
21245
|
+
tokens.splice(i + 1, 1);
|
|
21246
|
+
}
|
|
21045
21247
|
}
|
|
21046
21248
|
return tokens;
|
|
21047
21249
|
}
|
|
@@ -22386,7 +22588,7 @@
|
|
|
22386
22588
|
for (; i < ast.chi.length; i++) {
|
|
22387
22589
|
// @ts-ignore
|
|
22388
22590
|
node = ast.chi[i];
|
|
22389
|
-
if (node[STATE]
|
|
22591
|
+
if (node[STATE] & (exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.ValidationFailed)) {
|
|
22390
22592
|
continue;
|
|
22391
22593
|
}
|
|
22392
22594
|
if (node.typ != exports.EnumToken.DeclarationNodeType ||
|
|
@@ -24329,11 +24531,12 @@
|
|
|
24329
24531
|
* @private
|
|
24330
24532
|
*/
|
|
24331
24533
|
function expand(ast) {
|
|
24332
|
-
if (ast[STATE]
|
|
24333
|
-
|
|
24334
|
-
|
|
24335
|
-
|
|
24336
|
-
|
|
24534
|
+
if (ast[STATE] &
|
|
24535
|
+
(exports.EnumAstNodeStatus.Invalid |
|
|
24536
|
+
exports.EnumAstNodeStatus.Disallowed |
|
|
24537
|
+
exports.EnumAstNodeStatus.Unknown |
|
|
24538
|
+
exports.EnumAstNodeStatus.Unparsed |
|
|
24539
|
+
exports.EnumAstNodeStatus.Malformed)) {
|
|
24337
24540
|
return ast;
|
|
24338
24541
|
}
|
|
24339
24542
|
const result = Object.assign(cloneNode(ast), { chi: [] });
|
|
@@ -24381,11 +24584,12 @@
|
|
|
24381
24584
|
return result;
|
|
24382
24585
|
}
|
|
24383
24586
|
function expandRule(node) {
|
|
24384
|
-
if (node[STATE]
|
|
24385
|
-
|
|
24386
|
-
|
|
24387
|
-
|
|
24388
|
-
|
|
24587
|
+
if (node[STATE] &
|
|
24588
|
+
(exports.EnumAstNodeStatus.Invalid |
|
|
24589
|
+
exports.EnumAstNodeStatus.Disallowed |
|
|
24590
|
+
exports.EnumAstNodeStatus.Unknown |
|
|
24591
|
+
exports.EnumAstNodeStatus.Unparsed |
|
|
24592
|
+
exports.EnumAstNodeStatus.Malformed)) {
|
|
24389
24593
|
return [node];
|
|
24390
24594
|
}
|
|
24391
24595
|
const ast = Object.assign(cloneNode(node), { chi: node.chi.slice() });
|
|
@@ -26489,7 +26693,7 @@
|
|
|
26489
26693
|
return ",";
|
|
26490
26694
|
case exports.EnumToken.ImportantTokenType:
|
|
26491
26695
|
return "!important";
|
|
26492
|
-
case exports.EnumToken.
|
|
26696
|
+
case exports.EnumToken.PipeTokenType:
|
|
26493
26697
|
return "|";
|
|
26494
26698
|
case exports.EnumToken.AttrTokenType:
|
|
26495
26699
|
case exports.EnumToken.IdenListTokenType:
|
|
@@ -26612,6 +26816,7 @@
|
|
|
26612
26816
|
pseudoElements.includes(token.val.slice(1))) {
|
|
26613
26817
|
return token.val.slice(1);
|
|
26614
26818
|
}
|
|
26819
|
+
case exports.EnumToken.CssTypeTokenType:
|
|
26615
26820
|
case exports.EnumToken.UrlTokenTokenType:
|
|
26616
26821
|
case exports.EnumToken.HashTokenType:
|
|
26617
26822
|
case exports.EnumToken.IdenTokenType:
|
|
@@ -26645,17 +26850,20 @@
|
|
|
26645
26850
|
? ""
|
|
26646
26851
|
: token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
|
|
26647
26852
|
":" +
|
|
26853
|
+
(options.indent ?? "") +
|
|
26648
26854
|
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "");
|
|
26649
26855
|
case exports.EnumToken.IfElseConditionTokenType:
|
|
26650
|
-
return renderValue(token.l) +
|
|
26856
|
+
return (renderValue(token.l, options, cache, reducer) +
|
|
26857
|
+
(options.indent ?? "") +
|
|
26858
|
+
renderValue(token.r, options, cache, reducer));
|
|
26651
26859
|
case exports.EnumToken.DeclarationNodeType:
|
|
26652
26860
|
return (token.nam +
|
|
26653
26861
|
":" +
|
|
26654
|
-
(options.minifyValues ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
|
|
26862
|
+
(options.minifyValues ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
|
|
26655
26863
|
case exports.EnumToken.MediaQueryUnaryFeatureTokenType:
|
|
26656
26864
|
return (renderValue(token.l, options, cache, reducer) +
|
|
26657
26865
|
" " +
|
|
26658
|
-
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
|
|
26866
|
+
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
|
|
26659
26867
|
case exports.EnumToken.MediaQueryConditionTokenType: {
|
|
26660
26868
|
const indent = token.op.typ == exports.EnumToken.LtTokenType ||
|
|
26661
26869
|
token.op.typ == exports.EnumToken.GtTokenType ||
|
|
@@ -26669,14 +26877,14 @@
|
|
|
26669
26877
|
indent +
|
|
26670
26878
|
renderValue(token.op, options, cache, reducer) +
|
|
26671
26879
|
indent +
|
|
26672
|
-
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
|
|
26880
|
+
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
|
|
26673
26881
|
}
|
|
26674
26882
|
case exports.EnumToken.MediaRangeQueryTokenType:
|
|
26675
|
-
return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache), "") +
|
|
26676
|
-
renderValue(token.op1) +
|
|
26883
|
+
return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
|
|
26884
|
+
renderValue(token.op1, options, cache, reducer) +
|
|
26677
26885
|
token.val.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
|
|
26678
|
-
renderValue(token.op2) +
|
|
26679
|
-
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
|
|
26886
|
+
renderValue(token.op2, options, cache, reducer) +
|
|
26887
|
+
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
|
|
26680
26888
|
case exports.EnumToken.MediaFeatureTokenType:
|
|
26681
26889
|
return token.val;
|
|
26682
26890
|
case exports.EnumToken.NotTokenType:
|
|
@@ -26762,7 +26970,7 @@
|
|
|
26762
26970
|
SymbolsMapTokens[""] = exports.EnumToken.DelimTokenType;
|
|
26763
26971
|
SymbolsMapTokens["+"] = exports.EnumToken.Plus;
|
|
26764
26972
|
SymbolsMapTokens["="] = exports.EnumToken.DelimTokenType;
|
|
26765
|
-
SymbolsMapTokens["|"] = exports.EnumToken.
|
|
26973
|
+
SymbolsMapTokens["|"] = exports.EnumToken.PipeTokenType;
|
|
26766
26974
|
SymbolsMapTokens["||"] = exports.EnumToken.ColumnCombinatorTokenType;
|
|
26767
26975
|
SymbolsMapTokens["|="] = exports.EnumToken.DashMatchTokenType;
|
|
26768
26976
|
SymbolsMapTokens["&"] = exports.EnumToken.NestingSelectorTokenType;
|
|
@@ -27421,7 +27629,6 @@
|
|
|
27421
27629
|
if (codepoint == 92 /* TokenMap.REVERSE_SOLIDUS */) {
|
|
27422
27630
|
// eof
|
|
27423
27631
|
if ((codepoint = parseInfo.stream.charCodeAt(position + 1)) != codepoint) {
|
|
27424
|
-
// this.next(parseInfo, position);
|
|
27425
27632
|
return 0;
|
|
27426
27633
|
}
|
|
27427
27634
|
// \n \r \f \v
|
|
@@ -28194,7 +28401,7 @@
|
|
|
28194
28401
|
return this.makeToken(parseInfo, exports.EnumToken.DashMatchTokenType);
|
|
28195
28402
|
}
|
|
28196
28403
|
this.advance(parseInfo);
|
|
28197
|
-
return this.makeToken(parseInfo, exports.EnumToken.
|
|
28404
|
+
return this.makeToken(parseInfo, exports.EnumToken.PipeTokenType);
|
|
28198
28405
|
case 33 /* TokenMap.EXCLAMATION */:
|
|
28199
28406
|
if (parseInfo.position < parseInfo.currentPosition) {
|
|
28200
28407
|
return this.makeToken(parseInfo);
|
|
@@ -28260,6 +28467,21 @@
|
|
|
28260
28467
|
return this.makeToken(parseInfo, exports.EnumToken.CDOCOMMTokenType);
|
|
28261
28468
|
}
|
|
28262
28469
|
}
|
|
28470
|
+
{
|
|
28471
|
+
const startPosition = parseInfo.position - parseInfo.offset;
|
|
28472
|
+
let offset = 1;
|
|
28473
|
+
let charCode = parseInfo.stream.charCodeAt(startPosition + offset);
|
|
28474
|
+
if (isLetter(charCode)) {
|
|
28475
|
+
charCode = parseInfo.stream.charCodeAt(++offset + startPosition);
|
|
28476
|
+
while (offset < endPosition && (charCode == 45 /* TokenMap.MINUS */ || isLetter(charCode))) {
|
|
28477
|
+
charCode = parseInfo.stream.charCodeAt(++offset + startPosition);
|
|
28478
|
+
}
|
|
28479
|
+
if (offset > 1 && charCode == 62 /* TokenMap.GREATERTHAN */) {
|
|
28480
|
+
this.advance(parseInfo, offset);
|
|
28481
|
+
return this.makeToken(parseInfo, exports.EnumToken.CssTypeTokenType);
|
|
28482
|
+
}
|
|
28483
|
+
}
|
|
28484
|
+
}
|
|
28263
28485
|
break;
|
|
28264
28486
|
case 35 /* TokenMap.HASH */:
|
|
28265
28487
|
if (parseInfo.position < parseInfo.currentPosition) {
|
|
@@ -28880,6 +29102,7 @@
|
|
|
28880
29102
|
let rules = null;
|
|
28881
29103
|
let syntaxRules = null;
|
|
28882
29104
|
let success = true;
|
|
29105
|
+
let hasImportantFlag = false;
|
|
28883
29106
|
let validate = typeof options.validation === "boolean" ? options.validation : !!options.validation;
|
|
28884
29107
|
if (renamedStandardProperties.has(name.val)) {
|
|
28885
29108
|
name.val = renamedStandardProperties.get(name.val);
|
|
@@ -29181,6 +29404,9 @@
|
|
|
29181
29404
|
}
|
|
29182
29405
|
}
|
|
29183
29406
|
break;
|
|
29407
|
+
case exports.EnumToken.ImportantTokenType:
|
|
29408
|
+
hasImportantFlag = true;
|
|
29409
|
+
break;
|
|
29184
29410
|
}
|
|
29185
29411
|
if (trimTokenSpace$1.has(token.typ)) {
|
|
29186
29412
|
if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
|
|
@@ -29247,6 +29473,9 @@
|
|
|
29247
29473
|
}
|
|
29248
29474
|
name[STATE] = exports.EnumAstNodeStatus.Unknown;
|
|
29249
29475
|
name[ERRORS] = result?.errors ?? [];
|
|
29476
|
+
if (hasImportantFlag) {
|
|
29477
|
+
name[STATE] |= exports.EnumAstNodeStatus.ImportantDeclaration;
|
|
29478
|
+
}
|
|
29250
29479
|
// @ts-expect-error
|
|
29251
29480
|
return Object.assign(name, {
|
|
29252
29481
|
typ: exports.EnumToken.DeclarationNodeType,
|
|
@@ -29284,6 +29513,9 @@
|
|
|
29284
29513
|
: exports.EnumAstNodeStatus.Validated
|
|
29285
29514
|
: exports.EnumAstNodeStatus.ValidationFailed;
|
|
29286
29515
|
name[ERRORS] = result?.errors ?? [];
|
|
29516
|
+
if (hasImportantFlag) {
|
|
29517
|
+
name[STATE] |= exports.EnumAstNodeStatus.ImportantDeclaration;
|
|
29518
|
+
}
|
|
29287
29519
|
// @ts-expect-error
|
|
29288
29520
|
return Object.assign(name, {
|
|
29289
29521
|
typ: exports.EnumToken.DeclarationNodeType,
|
|
@@ -30979,6 +31211,9 @@
|
|
|
30979
31211
|
let key;
|
|
30980
31212
|
let value;
|
|
30981
31213
|
let i;
|
|
31214
|
+
const allVisitorsHandlers = new Set();
|
|
31215
|
+
const preAllVisitorsHandlers = new Set();
|
|
31216
|
+
const postAllVisitorsHandlers = new Set();
|
|
30982
31217
|
const valuesHandlers = new Map();
|
|
30983
31218
|
const preValuesHandlers = new Map();
|
|
30984
31219
|
const postValuesHandlers = new Map();
|
|
@@ -31079,6 +31314,21 @@
|
|
|
31079
31314
|
errors.push({ action: "ignore", message: `doParse: visitor.${key} is not a valid key name` });
|
|
31080
31315
|
}
|
|
31081
31316
|
}
|
|
31317
|
+
else if (key == "All" || key == "visitor") {
|
|
31318
|
+
if (typeof value == "function") {
|
|
31319
|
+
allVisitorsHandlers.add(value);
|
|
31320
|
+
}
|
|
31321
|
+
else if (typeof value == "object") {
|
|
31322
|
+
if ("type" in value && "handler" in value && value.type in exports.WalkerEvent) {
|
|
31323
|
+
if (value.type == exports.WalkerEvent.Enter) {
|
|
31324
|
+
preAllVisitorsHandlers.add(value.handler);
|
|
31325
|
+
}
|
|
31326
|
+
else if (value.type == exports.WalkerEvent.Leave) {
|
|
31327
|
+
postAllVisitorsHandlers.add(value.handler);
|
|
31328
|
+
}
|
|
31329
|
+
}
|
|
31330
|
+
}
|
|
31331
|
+
}
|
|
31082
31332
|
else {
|
|
31083
31333
|
errors.push({ action: "ignore", message: `doParse: visitor.${key} is not a valid key name` });
|
|
31084
31334
|
}
|
|
@@ -31102,10 +31352,25 @@
|
|
|
31102
31352
|
if (postValuesHandlers.size > 0) {
|
|
31103
31353
|
allHandlers.push(postValuesHandlers);
|
|
31104
31354
|
}
|
|
31105
|
-
|
|
31355
|
+
const result = {
|
|
31106
31356
|
allHandlers,
|
|
31107
|
-
includeTokens: preValuesHandlers.size > 0 ||
|
|
31357
|
+
includeTokens: preValuesHandlers.size > 0 ||
|
|
31358
|
+
valuesHandlers.size > 0 ||
|
|
31359
|
+
postValuesHandlers.size > 0 ||
|
|
31360
|
+
allVisitorsHandlers.size > 0 ||
|
|
31361
|
+
preAllVisitorsHandlers.size > 0 ||
|
|
31362
|
+
postAllVisitorsHandlers.size > 0,
|
|
31108
31363
|
};
|
|
31364
|
+
if (allVisitorsHandlers.size > 0) {
|
|
31365
|
+
result.allVisitorsHandlers = allVisitorsHandlers;
|
|
31366
|
+
}
|
|
31367
|
+
if (preAllVisitorsHandlers.size > 0) {
|
|
31368
|
+
result.preAllVisitorsHandlers = preAllVisitorsHandlers;
|
|
31369
|
+
}
|
|
31370
|
+
if (postAllVisitorsHandlers.size > 0) {
|
|
31371
|
+
result.postAllVisitorsHandlers = postAllVisitorsHandlers;
|
|
31372
|
+
}
|
|
31373
|
+
return result;
|
|
31109
31374
|
}
|
|
31110
31375
|
/**
|
|
31111
31376
|
* Parse css string
|
|
@@ -31178,12 +31443,10 @@
|
|
|
31178
31443
|
// @ts-ignore ignore error
|
|
31179
31444
|
let parensMatch = 0;
|
|
31180
31445
|
let curlyBracketMatch = 0;
|
|
31181
|
-
// let currentItemIndex: number;
|
|
31182
31446
|
ast[LOCSRCID] = options.source.id;
|
|
31183
31447
|
ast[LOCSTA] = 0;
|
|
31184
31448
|
while (!tokenizer.done()) {
|
|
31185
31449
|
tokenizer.next();
|
|
31186
|
-
// item = (iter as Array<TokenizeResult>)[currentItemIndex];
|
|
31187
31450
|
if (tokenizer.unit != null) {
|
|
31188
31451
|
item = {
|
|
31189
31452
|
typ: tokenizer.typ,
|
|
@@ -31329,7 +31592,6 @@
|
|
|
31329
31592
|
parensMatch = 0;
|
|
31330
31593
|
curlyBracketMatch = 0;
|
|
31331
31594
|
}
|
|
31332
|
-
// }
|
|
31333
31595
|
}
|
|
31334
31596
|
if (tokens.length > 0) {
|
|
31335
31597
|
node = parseNode(tokens, context, options, errors, stats, invalidNodes);
|
|
@@ -31399,6 +31661,9 @@
|
|
|
31399
31661
|
}
|
|
31400
31662
|
parens = null;
|
|
31401
31663
|
handlers.length = 0;
|
|
31664
|
+
if (visitors.preAllVisitorsHandlers?.size > 0) {
|
|
31665
|
+
handlers.push(...visitors.preAllVisitorsHandlers);
|
|
31666
|
+
}
|
|
31402
31667
|
genericKey =
|
|
31403
31668
|
nodes[i].typ == exports.EnumToken.DeclarationNodeType
|
|
31404
31669
|
? "Declaration"
|
|
@@ -31418,6 +31683,9 @@
|
|
|
31418
31683
|
: nodes[i].typ == exports.EnumToken.KeyframesAtRuleNodeType
|
|
31419
31684
|
? camelize(nodes[i].val)
|
|
31420
31685
|
: null;
|
|
31686
|
+
if (visitors.allVisitorsHandlers?.size > 0) {
|
|
31687
|
+
handlers.push(...visitors.allVisitorsHandlers);
|
|
31688
|
+
}
|
|
31421
31689
|
for (const map of visitors.allHandlers) {
|
|
31422
31690
|
// @ts-ignore
|
|
31423
31691
|
if (genericKey != null && map.has(genericKey)) {
|
|
@@ -31426,20 +31694,6 @@
|
|
|
31426
31694
|
if (typeof handler == "function") {
|
|
31427
31695
|
handlers.push(handler);
|
|
31428
31696
|
}
|
|
31429
|
-
// else if (Array.isArray(handler)) {
|
|
31430
|
-
// for (const h of handler) {
|
|
31431
|
-
// if (typeof h == "function") {
|
|
31432
|
-
// handlers.push(h);
|
|
31433
|
-
// }
|
|
31434
|
-
// // @ts-ignore
|
|
31435
|
-
// else if (h[keyName] != null) {
|
|
31436
|
-
// // @ts-ignore
|
|
31437
|
-
// handlers.push(h[keyName]);
|
|
31438
|
-
// }
|
|
31439
|
-
// }
|
|
31440
|
-
// } else if (typeof handler.handler! == "function") {
|
|
31441
|
-
// handlers.push(handler.handler);
|
|
31442
|
-
// }
|
|
31443
31697
|
// @ts-ignore
|
|
31444
31698
|
else if (typeof handler[keyName] == "function") {
|
|
31445
31699
|
// @ts-ignore
|
|
@@ -31472,6 +31726,9 @@
|
|
|
31472
31726
|
}
|
|
31473
31727
|
}
|
|
31474
31728
|
}
|
|
31729
|
+
if (visitors.postAllVisitorsHandlers?.size > 0) {
|
|
31730
|
+
handlers.push(...visitors.postAllVisitorsHandlers);
|
|
31731
|
+
}
|
|
31475
31732
|
if (handlers.length == 0) {
|
|
31476
31733
|
continue;
|
|
31477
31734
|
}
|
|
@@ -31511,14 +31768,14 @@
|
|
|
31511
31768
|
if (invalidNodes.length > 0) {
|
|
31512
31769
|
let count = invalidNodes.length;
|
|
31513
31770
|
for (const { node, parent } of walk(ast)) {
|
|
31514
|
-
if (options.lenient && node[STATE]
|
|
31771
|
+
if (options.lenient && node[STATE] & exports.EnumAstNodeStatus.Unknown) {
|
|
31515
31772
|
continue;
|
|
31516
31773
|
}
|
|
31517
|
-
if (node[STATE]
|
|
31518
|
-
node[STATE]
|
|
31519
|
-
node[STATE]
|
|
31520
|
-
node[STATE]
|
|
31521
|
-
node[STATE]
|
|
31774
|
+
if (node[STATE] & exports.EnumAstNodeStatus.Invalid ||
|
|
31775
|
+
node[STATE] & exports.EnumAstNodeStatus.Unknown ||
|
|
31776
|
+
node[STATE] & exports.EnumAstNodeStatus.Unparsed ||
|
|
31777
|
+
node[STATE] & exports.EnumAstNodeStatus.Malformed ||
|
|
31778
|
+
node[STATE] & exports.EnumAstNodeStatus.Disallowed) {
|
|
31522
31779
|
// @ts-ignore
|
|
31523
31780
|
parent.chi.splice(parent.chi.indexOf(node), 1);
|
|
31524
31781
|
node[PARENT] = null;
|
|
@@ -32391,6 +32648,9 @@
|
|
|
32391
32648
|
}
|
|
32392
32649
|
parens = null;
|
|
32393
32650
|
handlers.length = 0;
|
|
32651
|
+
if (visitors.preAllVisitorsHandlers?.size > 0) {
|
|
32652
|
+
handlers.push(...visitors.preAllVisitorsHandlers);
|
|
32653
|
+
}
|
|
32394
32654
|
genericKey =
|
|
32395
32655
|
nodes[i].typ == exports.EnumToken.DeclarationNodeType
|
|
32396
32656
|
? "Declaration"
|
|
@@ -32410,6 +32670,9 @@
|
|
|
32410
32670
|
: nodes[i].typ == exports.EnumToken.KeyframesAtRuleNodeType
|
|
32411
32671
|
? camelize(nodes[i].val)
|
|
32412
32672
|
: null;
|
|
32673
|
+
if (visitors.allVisitorsHandlers?.size > 0) {
|
|
32674
|
+
handlers.push(...visitors.allVisitorsHandlers);
|
|
32675
|
+
}
|
|
32413
32676
|
for (const map of visitors.allHandlers) {
|
|
32414
32677
|
// @ts-ignore
|
|
32415
32678
|
if (genericKey != null && map.has(genericKey)) {
|
|
@@ -32464,6 +32727,9 @@
|
|
|
32464
32727
|
}
|
|
32465
32728
|
}
|
|
32466
32729
|
}
|
|
32730
|
+
if (visitors.postAllVisitorsHandlers?.size > 0) {
|
|
32731
|
+
handlers.push(...visitors.postAllVisitorsHandlers);
|
|
32732
|
+
}
|
|
32467
32733
|
if (handlers.length == 0) {
|
|
32468
32734
|
continue;
|
|
32469
32735
|
}
|
|
@@ -32506,14 +32772,14 @@
|
|
|
32506
32772
|
if (invalidNodes.length > 0) {
|
|
32507
32773
|
let count = invalidNodes.length;
|
|
32508
32774
|
for (const { node, parent } of walk(ast)) {
|
|
32509
|
-
if (options.lenient && node[STATE]
|
|
32775
|
+
if (options.lenient && node[STATE] & exports.EnumAstNodeStatus.Unknown) {
|
|
32510
32776
|
continue;
|
|
32511
32777
|
}
|
|
32512
|
-
if (node[STATE]
|
|
32513
|
-
node[STATE]
|
|
32514
|
-
node[STATE]
|
|
32515
|
-
node[STATE]
|
|
32516
|
-
node[STATE]
|
|
32778
|
+
if (node[STATE] & exports.EnumAstNodeStatus.Invalid ||
|
|
32779
|
+
node[STATE] & exports.EnumAstNodeStatus.Unknown ||
|
|
32780
|
+
node[STATE] & exports.EnumAstNodeStatus.Unparsed ||
|
|
32781
|
+
node[STATE] & exports.EnumAstNodeStatus.Malformed ||
|
|
32782
|
+
node[STATE] & exports.EnumAstNodeStatus.Disallowed) {
|
|
32517
32783
|
// @ts-ignore
|
|
32518
32784
|
parent.chi.splice(parent.chi.indexOf(node), 1);
|
|
32519
32785
|
node[PARENT] = null;
|
|
@@ -33244,11 +33510,12 @@
|
|
|
33244
33510
|
if (node == null) {
|
|
33245
33511
|
return null;
|
|
33246
33512
|
}
|
|
33247
|
-
if (node[STATE]
|
|
33248
|
-
|
|
33249
|
-
|
|
33250
|
-
|
|
33251
|
-
|
|
33513
|
+
if (node[STATE] &
|
|
33514
|
+
(exports.EnumAstNodeStatus.Invalid |
|
|
33515
|
+
exports.EnumAstNodeStatus.Disallowed |
|
|
33516
|
+
exports.EnumAstNodeStatus.Unknown |
|
|
33517
|
+
exports.EnumAstNodeStatus.Unparsed |
|
|
33518
|
+
exports.EnumAstNodeStatus.Malformed)) {
|
|
33252
33519
|
invalidNodes.push(node);
|
|
33253
33520
|
}
|
|
33254
33521
|
stats.nodesCount++;
|
|
@@ -33266,11 +33533,11 @@
|
|
|
33266
33533
|
context.chi.push(node);
|
|
33267
33534
|
node[PARENT] = context;
|
|
33268
33535
|
node[ROOT] = context[ROOT];
|
|
33269
|
-
if (node[STATE]
|
|
33270
|
-
node[STATE]
|
|
33271
|
-
node[STATE]
|
|
33272
|
-
node[STATE]
|
|
33273
|
-
node[STATE]
|
|
33536
|
+
if (node[STATE] & exports.EnumAstNodeStatus.Invalid ||
|
|
33537
|
+
node[STATE] & exports.EnumAstNodeStatus.Disallowed ||
|
|
33538
|
+
node[STATE] & exports.EnumAstNodeStatus.Unknown ||
|
|
33539
|
+
node[STATE] & exports.EnumAstNodeStatus.Unparsed ||
|
|
33540
|
+
node[STATE] & exports.EnumAstNodeStatus.Malformed) {
|
|
33274
33541
|
invalidNodes.push(node);
|
|
33275
33542
|
}
|
|
33276
33543
|
return node;
|
|
@@ -33280,7 +33547,9 @@
|
|
|
33280
33547
|
node[PARENT] = context;
|
|
33281
33548
|
node[ROOT] = context[ROOT];
|
|
33282
33549
|
if (context.typ === exports.EnumToken.StyleSheetNodeType && node.typ === exports.EnumToken.DeclarationNodeType) {
|
|
33283
|
-
node[STATE]
|
|
33550
|
+
node[STATE] |=
|
|
33551
|
+
exports.EnumAstNodeStatus.Invalid &
|
|
33552
|
+
~(exports.EnumAstNodeStatus.Validated | exports.EnumAstNodeStatus.Unvalidated | exports.EnumAstNodeStatus.Unparsed);
|
|
33284
33553
|
errors.push({
|
|
33285
33554
|
message: "<declaration> not allowed in <stylesheet>",
|
|
33286
33555
|
action: "drop",
|
|
@@ -33291,11 +33560,12 @@
|
|
|
33291
33560
|
else if (options.lenient || node.typ === exports.EnumToken.DeclarationNodeType) {
|
|
33292
33561
|
context.chi.push(node);
|
|
33293
33562
|
}
|
|
33294
|
-
if (node[STATE]
|
|
33295
|
-
|
|
33296
|
-
|
|
33297
|
-
|
|
33298
|
-
|
|
33563
|
+
if (node[STATE] &
|
|
33564
|
+
(exports.EnumAstNodeStatus.Invalid |
|
|
33565
|
+
exports.EnumAstNodeStatus.Disallowed |
|
|
33566
|
+
exports.EnumAstNodeStatus.Unknown |
|
|
33567
|
+
exports.EnumAstNodeStatus.Unparsed |
|
|
33568
|
+
exports.EnumAstNodeStatus.Malformed)) {
|
|
33299
33569
|
invalidNodes.push(node);
|
|
33300
33570
|
}
|
|
33301
33571
|
}
|
|
@@ -33320,7 +33590,6 @@
|
|
|
33320
33590
|
const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
|
|
33321
33591
|
const blockAllowed = syntaxRules?.getBlockRules() != null;
|
|
33322
33592
|
if (syntaxRules == null) {
|
|
33323
|
-
// if (!options.lenient) {
|
|
33324
33593
|
errors.push({
|
|
33325
33594
|
action: "drop",
|
|
33326
33595
|
node: atRule,
|
|
@@ -34037,7 +34306,7 @@
|
|
|
34037
34306
|
stream[index][LOCEND] = stream[i][LOCEND];
|
|
34038
34307
|
Object.assign(stream[index], {
|
|
34039
34308
|
typ: tokensfuncDefMap.get(stream[index].typ),
|
|
34040
|
-
chi: stream.splice(index + 1, i - index - 1),
|
|
34309
|
+
chi: trimWhiteSpaceTokens(stream.splice(index + 1, i - index - 1)),
|
|
34041
34310
|
});
|
|
34042
34311
|
i = index;
|
|
34043
34312
|
stream.splice(index + 1, 1);
|
|
@@ -34509,6 +34778,8 @@
|
|
|
34509
34778
|
}
|
|
34510
34779
|
}
|
|
34511
34780
|
|
|
34781
|
+
var version = "1.6.8";
|
|
34782
|
+
|
|
34512
34783
|
/**
|
|
34513
34784
|
* Load file or url
|
|
34514
34785
|
* @param url
|
|
@@ -34942,6 +35213,7 @@
|
|
|
34942
35213
|
exports.transform = transform;
|
|
34943
35214
|
exports.transformFile = transformFile;
|
|
34944
35215
|
exports.transformSync = transformSync;
|
|
35216
|
+
exports.version = version;
|
|
34945
35217
|
exports.walk = walk;
|
|
34946
35218
|
exports.walkValues = walkValues;
|
|
34947
35219
|
|