@tbela99/css-parser 1.4.2 → 1.4.4

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.
Files changed (122) hide show
  1. package/CHANGELOG.md +354 -4
  2. package/README.md +69 -1077
  3. package/dist/config.json.js +76 -3
  4. package/dist/index-umd-web.js +26838 -18743
  5. package/dist/index.cjs +26819 -18731
  6. package/dist/index.d.ts +2471 -1884
  7. package/dist/lib/ast/clone.js +46 -0
  8. package/dist/lib/ast/expand.js +90 -65
  9. package/dist/lib/ast/features/calc.js +86 -43
  10. package/dist/lib/ast/features/if.js +221 -0
  11. package/dist/lib/ast/features/index.js +1 -0
  12. package/dist/lib/ast/features/inlinecssvariables.js +33 -28
  13. package/dist/lib/ast/features/prefix.js +406 -44
  14. package/dist/lib/ast/features/shorthand.js +6 -9
  15. package/dist/lib/ast/features/transform.js +14 -15
  16. package/dist/lib/ast/find.js +175 -0
  17. package/dist/lib/ast/math/expression.js +145 -99
  18. package/dist/lib/ast/math/math.js +30 -41
  19. package/dist/lib/ast/minify.js +551 -232
  20. package/dist/lib/ast/transform/compute.js +82 -69
  21. package/dist/lib/ast/transform/matrix.js +12 -26
  22. package/dist/lib/ast/transform/minify.js +154 -150
  23. package/dist/lib/ast/transform/perspective.js +1 -1
  24. package/dist/lib/ast/transform/rotate.js +1 -1
  25. package/dist/lib/ast/transform/scale.js +1 -1
  26. package/dist/lib/ast/transform/skew.js +1 -1
  27. package/dist/lib/ast/transform/translate.js +1 -1
  28. package/dist/lib/ast/transform/utils.js +3 -2
  29. package/dist/lib/ast/types.js +345 -30
  30. package/dist/lib/ast/walk.js +119 -64
  31. package/dist/lib/fs/resolve.js +94 -88
  32. package/dist/lib/parser/declaration/list.js +117 -26
  33. package/dist/lib/parser/declaration/map.js +141 -96
  34. package/dist/lib/parser/declaration/set.js +30 -25
  35. package/dist/lib/parser/parse.js +1810 -1739
  36. package/dist/lib/parser/tokenize.js +662 -403
  37. package/dist/lib/parser/utils/angle.js +29 -0
  38. package/dist/lib/parser/utils/at-rule-container.js +486 -0
  39. package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
  40. package/dist/lib/parser/utils/at-rule-generic.js +118 -0
  41. package/dist/lib/parser/utils/at-rule-import.js +393 -0
  42. package/dist/lib/parser/utils/at-rule-media.js +603 -0
  43. package/dist/lib/parser/utils/at-rule-support.js +431 -0
  44. package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
  45. package/dist/lib/parser/utils/at-rule.js +31 -0
  46. package/dist/lib/parser/utils/cache.js +19 -0
  47. package/dist/lib/parser/utils/config.js +1 -0
  48. package/dist/lib/parser/utils/declaration.js +672 -91
  49. package/dist/lib/parser/utils/hash.js +1 -1
  50. package/dist/lib/parser/utils/selector.js +518 -0
  51. package/dist/lib/parser/utils/text.js +17 -1
  52. package/dist/lib/parser/utils/token.js +104 -0
  53. package/dist/lib/parser/utils/type.js +29 -18
  54. package/dist/lib/renderer/render.js +870 -269
  55. package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
  56. package/dist/lib/syntax/color/a98rgb.js +8 -12
  57. package/dist/lib/syntax/color/alpha.js +64 -0
  58. package/dist/lib/syntax/color/cmyk.js +23 -21
  59. package/dist/lib/syntax/color/color-mix.js +311 -237
  60. package/dist/lib/syntax/color/color.js +98 -92
  61. package/dist/lib/syntax/color/hex.js +29 -33
  62. package/dist/lib/syntax/color/hsl.js +7 -14
  63. package/dist/lib/syntax/color/hwb.js +14 -27
  64. package/dist/lib/syntax/color/lab.js +23 -24
  65. package/dist/lib/syntax/color/lch.js +16 -18
  66. package/dist/lib/syntax/color/oklab.js +21 -40
  67. package/dist/lib/syntax/color/oklch.js +16 -18
  68. package/dist/lib/syntax/color/p3.js +0 -8
  69. package/dist/lib/syntax/color/rec2020.js +9 -13
  70. package/dist/lib/syntax/color/relativecolor.js +160 -48
  71. package/dist/lib/syntax/color/rgb.js +14 -18
  72. package/dist/lib/syntax/color/srgb.js +30 -29
  73. package/dist/lib/syntax/color/utils/color-type.js +18 -0
  74. package/dist/lib/syntax/color/utils/colorspace.js +46 -0
  75. package/dist/lib/syntax/color/utils/components.js +36 -16
  76. package/dist/lib/syntax/color/utils/distance.js +21 -11
  77. package/dist/lib/syntax/color/utils/make-color.js +56 -0
  78. package/dist/lib/syntax/color/xyz.js +10 -22
  79. package/dist/lib/syntax/color/xyzd50.js +6 -20
  80. package/dist/lib/syntax/constants.js +464 -0
  81. package/dist/lib/syntax/syntax.js +825 -592
  82. package/dist/lib/validation/config.js +72 -33
  83. package/dist/lib/validation/config.json.js +1185 -85
  84. package/dist/lib/validation/match.js +3120 -0
  85. package/dist/lib/validation/parser/parse.js +683 -935
  86. package/dist/lib/validation/parser/typedef.js +106 -0
  87. package/dist/lib/validation/utils/list.js +4 -11
  88. package/dist/lib/validation/utils/whitespace.js +2 -8
  89. package/dist/node.js +102 -57
  90. package/dist/web.js +100 -48
  91. package/package.json +31 -17
  92. package/dist/lib/syntax/color/utils/constants.js +0 -214
  93. package/dist/lib/syntax/utils.js +0 -70
  94. package/dist/lib/validation/at-rules/container.js +0 -342
  95. package/dist/lib/validation/at-rules/counter-style.js +0 -90
  96. package/dist/lib/validation/at-rules/custom-media.js +0 -50
  97. package/dist/lib/validation/at-rules/document.js +0 -89
  98. package/dist/lib/validation/at-rules/else.js +0 -5
  99. package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
  100. package/dist/lib/validation/at-rules/import.js +0 -150
  101. package/dist/lib/validation/at-rules/keyframes.js +0 -67
  102. package/dist/lib/validation/at-rules/layer.js +0 -41
  103. package/dist/lib/validation/at-rules/media.js +0 -255
  104. package/dist/lib/validation/at-rules/namespace.js +0 -81
  105. package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
  106. package/dist/lib/validation/at-rules/page.js +0 -100
  107. package/dist/lib/validation/at-rules/supports.js +0 -295
  108. package/dist/lib/validation/at-rules/when.js +0 -185
  109. package/dist/lib/validation/atrule.js +0 -184
  110. package/dist/lib/validation/selector.js +0 -36
  111. package/dist/lib/validation/syntax.js +0 -1073
  112. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
  113. package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
  114. package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
  115. package/dist/lib/validation/syntaxes/family-name.js +0 -57
  116. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
  117. package/dist/lib/validation/syntaxes/layer-name.js +0 -57
  118. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
  119. package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
  120. package/dist/lib/validation/syntaxes/selector-list.js +0 -5
  121. package/dist/lib/validation/syntaxes/selector.js +0 -5
  122. package/dist/lib/validation/syntaxes/url.js +0 -40
@@ -1,546 +1,483 @@
1
1
  import { EnumToken, ColorType } from '../ast/types.js';
2
- import '../ast/minify.js';
3
2
  import { walkValues, WalkerOptionEnum } from '../ast/walk.js';
4
- import '../parser/parse.js';
5
- import '../parser/tokenize.js';
6
- import '../parser/utils/config.js';
7
- import { COLORS_NAMES, colorsFunc, funcLike } from './color/utils/constants.js';
8
- import { buildExpression } from '../ast/math/expression.js';
9
- import '../renderer/sourcemap/lib/encode.js';
3
+ import { toDegrees } from '../parser/utils/angle.js';
4
+ import { equalsIgnoreCase } from '../parser/utils/text.js';
5
+ import { getParsedSyntax } from '../validation/config.js';
6
+ import { matchAllSyntaxes, createValidationContext, trimArray } from '../validation/match.js';
7
+ import { ValidationSyntaxGroupEnum } from '../validation/parser/typedef.js';
8
+ import { splitTokenList } from '../validation/utils/list.js';
9
+ import { getColorSpace } from './color/utils/colorspace.js';
10
+ import { getColorComponents } from './color/utils/components.js';
11
+ import { colorsFunc, systemColors, deprecatedSystemColors, nonStandardColors, COLORS_NAMES, colorFuncColorSpace, mathFuncs } from './constants.js';
12
+ import { isOkLabClose } from './color/utils/distance.js';
10
13
 
11
14
  // https://www.w3.org/TR/CSS21/syndata.html#syntax
12
15
  // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token
13
16
  // '\\'
14
17
  const REVERSE_SOLIDUS = 0x5c;
15
18
  const dimensionUnits = new Set([
16
- 'q', 'cap', 'ch', 'cm', 'cqb', 'cqh', 'cqi', 'cqmax', 'cqmin', 'cqw', 'dvb',
17
- 'dvh', 'dvi', 'dvmax', 'dvmin', 'dvw', 'em', 'ex', 'ic', 'in', 'lh', 'lvb',
18
- 'lvh', 'lvi', 'lvmax', 'lvw', 'mm', 'pc', 'pt', 'px', 'rem', 'rlh', 'svb',
19
- 'svh', 'svi', 'svmin', 'svw', 'vb', 'vh', 'vi', 'vmax', 'vmin', 'vw'
19
+ "q",
20
+ "cap",
21
+ "ch",
22
+ "cm",
23
+ "cqb",
24
+ "cqh",
25
+ "cqi",
26
+ "cqmax",
27
+ "cqmin",
28
+ "cqw",
29
+ "dvb",
30
+ "dvh",
31
+ "dvi",
32
+ "dvmax",
33
+ "dvmin",
34
+ "dvw",
35
+ "em",
36
+ "ex",
37
+ "ic",
38
+ "in",
39
+ "lh",
40
+ "lvb",
41
+ "lvh",
42
+ "lvi",
43
+ "lvmax",
44
+ "lvw",
45
+ "mm",
46
+ "pc",
47
+ "pt",
48
+ "px",
49
+ "rem",
50
+ "rlh",
51
+ "svb",
52
+ "svh",
53
+ "svi",
54
+ "svmin",
55
+ "svw",
56
+ "vb",
57
+ "vh",
58
+ "vi",
59
+ "vmax",
60
+ "vmin",
61
+ "vw",
20
62
  ]);
21
- const fontFormat = ['collection', 'embedded-opentype', 'opentype', 'svg', 'truetype', 'woff', 'woff2'];
22
- const colorFontTech = ['color-colrv0', 'color-colrv1', 'color-svg', 'color-sbix', 'color-cbdt'];
23
- const fontFeaturesTech = ['features-opentype', 'features-aat', 'features-graphite', 'incremental-patch', 'incremental-range', 'incremental-auto', 'variations', 'palettes'];
24
- /**
25
- * supported transform functions
26
- *
27
- * @internal
28
- */
29
- const transformFunctions = [
30
- 'translate', 'scale', 'rotate', 'skew', 'perspective',
31
- 'translateX', 'translateY', 'translateZ',
32
- 'scaleX', 'scaleY', 'scaleZ',
33
- 'rotateX', 'rotateY', 'rotateZ',
34
- 'skewX', 'skewY',
35
- 'rotate3d', 'translate3d', 'scale3d', 'matrix', 'matrix3d'
36
- ];
37
- // https://drafts.csswg.org/mediaqueries/#media-types
38
- const mediaTypes = ['all', 'print', 'screen',
39
- /* deprecated */
40
- 'aural', 'braille', 'embossed', 'handheld', 'projection', 'tty', 'tv', 'speech'];
41
63
  // https://www.w3.org/TR/css-values-4/#math-function
42
- /**
43
- * supported math functions
44
- *
45
- * @internal
46
- */
47
- const mathFuncs = ['minmax', 'repeat', 'fit-content', 'calc', 'clamp', 'min', 'max', 'round', 'mod', 'rem', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2', 'pow', 'sqrt', 'hypot', 'log', 'exp', 'abs', 'sign'];
48
- const wildCardFuncs = ['var', 'env'];
49
- const pseudoElements = [':before', ':after', ':first-line', ':first-letter'];
64
+ const pseudoElements = [":before", ":after", ":first-line", ":first-letter"];
50
65
  // https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions
51
66
  // https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions
52
67
  const pseudoAliasMap = {
53
- '-moz-center': 'center',
54
- '-webkit-center': 'center',
55
- '-ms-grid-columns': 'grid-template-columns',
56
- '-ms-grid-rows': 'grid-template-rows',
57
- '-ms-grid-row': 'grid-row-start',
58
- '-ms-grid-column': 'grid-column-start',
59
- '-ms-grid-row-align': 'align-self',
60
- '-ms-grid-row-span': 'grid-row-end',
61
- '-ms-grid-column-span': 'grid-column-end',
62
- '-ms-grid-column-align': 'justify-self',
63
- ':-ms-input-placeholder': '::placeholder',
64
- '::-ms-input-placeholder': '::placeholder',
65
- ':-moz-any()': ':is',
66
- '-moz-user-modify': 'user-modify',
67
- '-webkit-match-parent': 'match-parent',
68
- '-moz-background-clip': 'background-clip',
69
- '-moz-background-origin': 'background-origin',
70
- '-ms-input-placeholder': 'placeholder',
71
- ':-webkit-autofill': ':autofill',
72
- ':-webkit-any()': ':is',
73
- '::-webkit-input-placeholder': '::placeholder',
74
- '::-webkit-file-upload-button': '::file-selector-button',
75
- '::-moz-placeholder': '::placeholder',
76
- ':-webkit-any-link': ':any-link',
77
- '-webkit-border-after': 'border-block-end',
78
- '-webkit-border-after-color': 'border-block-end-color',
79
- '-webkit-border-after-style': 'border-block-end-style',
80
- '-webkit-border-after-width': 'border-block-end-width',
81
- '-webkit-border-before': 'border-block-start',
82
- '-webkit-border-before-color': 'border-block-start-color',
83
- '-webkit-border-before-style': 'border-block-start-style',
84
- '-webkit-border-before-width': 'border-block-start-width',
85
- '-webkit-border-end': 'border-inline-end',
86
- '-webkit-border-end-color': 'border-inline-end-color',
87
- '-webkit-border-end-style': 'border-inline-end-style',
88
- '-webkit-border-end-width': 'border-inline-end-width',
89
- '-webkit-border-start': 'border-inline-start',
90
- '-webkit-border-start-color': 'border-inline-start-color',
91
- '-webkit-border-start-style': 'border-inline-start-style',
92
- '-webkit-border-start-width': 'border-inline-start-width',
93
- '-webkit-box-align': 'align-items',
94
- '-webkit-box-direction': 'flex-direction',
95
- '-webkit-box-flex': 'flex-grow',
96
- '-webkit-box-lines': 'flex-flow',
97
- '-webkit-box-ordinal-group': 'order',
98
- '-webkit-box-orient': 'flex-direction',
99
- '-webkit-box-pack': 'justify-content',
100
- '-webkit-column-break-after': 'break-after',
101
- '-webkit-column-break-before': 'break-before',
102
- '-webkit-column-break-inside': 'break-inside',
103
- '-webkit-font-feature-settings': 'font-feature-settings',
104
- '-webkit-hyphenate-character': 'hyphenate-character',
105
- '-webkit-initial-letter': 'initial-letter',
106
- '-webkit-margin-end': 'margin-block-end',
107
- '-webkit-margin-start': 'margin-block-start',
108
- '-webkit-padding-after': 'padding-block-end',
109
- '-webkit-padding-before': 'padding-block-start',
110
- '-webkit-padding-end': 'padding-inline-end',
111
- '-webkit-padding-start': 'padding-inline-start',
112
- '-webkit-min-device-pixel-ratio': 'min-resolution',
113
- '-webkit-max-device-pixel-ratio': 'max-resolution',
114
- '-webkit-font-smoothing': 'font-smooth',
115
- '-webkit-line-clamp': 'line-clamp',
116
- ':-webkit-autofill-strong-password': ':autofill',
117
- ':-webkit-full-page-media': ':fullscreen',
118
- ':-webkit-full-screen': ':fullscreen',
119
- ':-webkit-full-screen-ancestor': ':fullscreen',
120
- ':-webkit-full-screen-document': ':fullscreen',
121
- ':-webkit-full-screen-controls-hidden': ':fullscreen',
122
- '-moz-background-inline-policy': 'box-decoration-break',
123
- '-moz-background-size': 'background-size',
124
- '-moz-border-end': 'border-inline-end',
125
- '-moz-border-end-color': 'border-inline-end-color',
126
- '-moz-border-end-style': 'border-inline-end-style',
127
- '-moz-border-end-width': 'border-inline-end-width',
128
- '-moz-border-image': 'border-inline-end-width',
129
- '-moz-border-start': 'border-inline-start',
130
- '-moz-border-start-color': 'border-inline-start-color',
131
- '-moz-border-start-style': 'border-inline-start-style',
132
- '-moz-border-start-width': 'border-inline-start-width',
133
- '-moz-column-count': 'column-count',
134
- '-moz-column-fill': 'column-fill',
135
- '-moz-column-gap': 'column-gap',
136
- '-moz-column-width': 'column-width',
137
- '-moz-column-rule': 'column-rule',
138
- '-moz-column-rule-width': 'column-rule-width',
139
- '-moz-column-rule-style': 'column-rule-style',
140
- '-moz-column-rule-color': 'column-rule-color',
141
- '-moz-margin-end': 'margin-inline-end',
142
- '-moz-margin-start': 'margin-inline-start',
143
- '-moz-opacity': 'opacity',
144
- '-moz-outline': 'outline',
145
- '-moz-outline-color': 'outline-color',
146
- '-moz-outline-offset': 'outline-offset',
147
- '-moz-outline-style': 'outline-style',
148
- '-moz-outline-width': 'outline-width',
149
- '-moz-padding-end': 'padding-inline-end',
150
- '-moz-padding-start': 'padding-inline-start',
151
- '-moz-tab-size': 'tab-size',
152
- '-moz-text-align-last': 'text-align-last',
153
- '-moz-text-decoration-color': 'text-decoration-color',
154
- '-moz-text-decoration-line': 'text-decoration-line',
155
- '-moz-text-decoration-style': 'text-decoration-style',
156
- '-moz-transition': 'transition',
157
- '-moz-transition-delay': 'transition-delay',
158
- '-moz-transition-duration': 'transition-duration',
159
- '-moz-transition-property': 'transition-property',
160
- '-moz-transition-timing-function': 'transition-timing-function',
161
- '-moz-user-select': 'user-select',
162
- '-moz-initial': 'initial',
163
- '-moz-linear-gradient()': 'linear-gradient',
164
- '-moz-radial-gradient()': 'radial-gradient',
165
- '-moz-element()': 'element',
166
- '-moz-crisp-edges': 'crisp-edges',
167
- '-moz-calc()': 'calc',
168
- '-moz-min-content': 'min-content',
169
- '-moz-fit-content': 'fit-content',
170
- '-moz-max-content': 'max-content',
171
- '-moz-available': 'stretch',
172
- ':-moz-any-link': ':any-link',
173
- ':-moz-full-screen': ':fullscreen',
174
- ':-moz-full-screen-ancestor': ':fullscreen',
175
- ':-moz-placeholder': ':placeholder-shown',
176
- ':-moz-read-only': ':read-only',
177
- ':-moz-read-write': ':read-write',
178
- ':-moz-submit-invalid': ':invalid',
179
- ':-moz-ui-invalid': ':user-invalid',
180
- ':-moz-ui-valid': ':user-valid',
181
- '::-moz-selection': '::selection',
68
+ "-moz-center": "center",
69
+ "-webkit-center": "center",
70
+ "-ms-grid-columns": "grid-template-columns",
71
+ "-ms-grid-rows": "grid-template-rows",
72
+ "-ms-grid-row": "grid-row-start",
73
+ "-ms-grid-column": "grid-column-start",
74
+ "-ms-grid-row-align": "align-self",
75
+ "-ms-grid-row-span": "grid-row-end",
76
+ "-ms-grid-column-span": "grid-column-end",
77
+ "-ms-grid-column-align": "justify-self",
78
+ ":-ms-input-placeholder": "::placeholder",
79
+ "::-ms-input-placeholder": "::placeholder",
80
+ ":-moz-any()": ":is",
81
+ "-moz-user-modify": "user-modify",
82
+ "-webkit-match-parent": "match-parent",
83
+ "-moz-background-clip": "background-clip",
84
+ "-moz-background-origin": "background-origin",
85
+ "-ms-input-placeholder": "placeholder",
86
+ ":-webkit-autofill": ":autofill",
87
+ ":-webkit-any()": ":is",
88
+ "::-webkit-input-placeholder": "::placeholder",
89
+ "::-webkit-file-upload-button": "::file-selector-button",
90
+ "::-moz-placeholder": "::placeholder",
91
+ ":-webkit-any-link": ":any-link",
92
+ "-webkit-border-after": "border-block-end",
93
+ "-webkit-border-after-color": "border-block-end-color",
94
+ "-webkit-border-after-style": "border-block-end-style",
95
+ "-webkit-border-after-width": "border-block-end-width",
96
+ "-webkit-border-before": "border-block-start",
97
+ "-webkit-border-before-color": "border-block-start-color",
98
+ "-webkit-border-before-style": "border-block-start-style",
99
+ "-webkit-border-before-width": "border-block-start-width",
100
+ "-webkit-border-end": "border-inline-end",
101
+ "-webkit-border-end-color": "border-inline-end-color",
102
+ "-webkit-border-end-style": "border-inline-end-style",
103
+ "-webkit-border-end-width": "border-inline-end-width",
104
+ "-webkit-border-start": "border-inline-start",
105
+ "-webkit-border-start-color": "border-inline-start-color",
106
+ "-webkit-border-start-style": "border-inline-start-style",
107
+ "-webkit-border-start-width": "border-inline-start-width",
108
+ "-webkit-box-align": "align-items",
109
+ "-webkit-box-direction": "flex-direction",
110
+ "-webkit-box-flex": "flex-grow",
111
+ "-webkit-box-lines": "flex-flow",
112
+ "-webkit-box-ordinal-group": "order",
113
+ "-webkit-box-orient": "flex-direction",
114
+ "-webkit-box-pack": "justify-content",
115
+ "-webkit-column-break-after": "break-after",
116
+ "-webkit-column-break-before": "break-before",
117
+ "-webkit-column-break-inside": "break-inside",
118
+ "-webkit-font-feature-settings": "font-feature-settings",
119
+ "-webkit-hyphenate-character": "hyphenate-character",
120
+ "-webkit-initial-letter": "initial-letter",
121
+ "-webkit-margin-end": "margin-block-end",
122
+ "-webkit-margin-start": "margin-block-start",
123
+ "-webkit-padding-after": "padding-block-end",
124
+ "-webkit-padding-before": "padding-block-start",
125
+ "-webkit-padding-end": "padding-inline-end",
126
+ "-webkit-padding-start": "padding-inline-start",
127
+ "-webkit-min-device-pixel-ratio": "min-resolution",
128
+ "-webkit-max-device-pixel-ratio": "max-resolution",
129
+ "-webkit-font-smoothing": "font-smooth",
130
+ "-webkit-line-clamp": "line-clamp",
131
+ ":-webkit-autofill-strong-password": ":autofill",
132
+ ":-webkit-full-page-media": ":fullscreen",
133
+ ":-webkit-full-screen": ":fullscreen",
134
+ ":-webkit-full-screen-ancestor": ":fullscreen",
135
+ ":-webkit-full-screen-document": ":fullscreen",
136
+ ":-webkit-full-screen-controls-hidden": ":fullscreen",
137
+ "-moz-background-inline-policy": "box-decoration-break",
138
+ "-moz-background-size": "background-size",
139
+ "-moz-border-end": "border-inline-end",
140
+ "-moz-border-end-color": "border-inline-end-color",
141
+ "-moz-border-end-style": "border-inline-end-style",
142
+ "-moz-border-end-width": "border-inline-end-width",
143
+ "-moz-border-image": "border-inline-end-width",
144
+ "-moz-border-start": "border-inline-start",
145
+ "-moz-border-start-color": "border-inline-start-color",
146
+ "-moz-border-start-style": "border-inline-start-style",
147
+ "-moz-border-start-width": "border-inline-start-width",
148
+ "-moz-column-count": "column-count",
149
+ "-moz-column-fill": "column-fill",
150
+ "-moz-column-gap": "column-gap",
151
+ "-moz-column-width": "column-width",
152
+ "-moz-column-rule": "column-rule",
153
+ "-moz-column-rule-width": "column-rule-width",
154
+ "-moz-column-rule-style": "column-rule-style",
155
+ "-moz-column-rule-color": "column-rule-color",
156
+ "-moz-margin-end": "margin-inline-end",
157
+ "-moz-margin-start": "margin-inline-start",
158
+ "-moz-opacity": "opacity",
159
+ "-moz-outline": "outline",
160
+ "-moz-outline-color": "outline-color",
161
+ "-moz-outline-offset": "outline-offset",
162
+ "-moz-outline-style": "outline-style",
163
+ "-moz-outline-width": "outline-width",
164
+ "-moz-padding-end": "padding-inline-end",
165
+ "-moz-padding-start": "padding-inline-start",
166
+ "-moz-tab-size": "tab-size",
167
+ "-moz-text-align-last": "text-align-last",
168
+ "-moz-text-decoration-color": "text-decoration-color",
169
+ "-moz-text-decoration-line": "text-decoration-line",
170
+ "-moz-text-decoration-style": "text-decoration-style",
171
+ "-moz-transition": "transition",
172
+ "-moz-transition-delay": "transition-delay",
173
+ "-moz-transition-duration": "transition-duration",
174
+ "-moz-transition-property": "transition-property",
175
+ "-moz-transition-timing-function": "transition-timing-function",
176
+ "-moz-user-select": "user-select",
177
+ "-moz-initial": "initial",
178
+ "-moz-linear-gradient()": "linear-gradient",
179
+ "-moz-radial-gradient()": "radial-gradient",
180
+ "-moz-element()": "element",
181
+ "-moz-crisp-edges": "crisp-edges",
182
+ "-moz-calc()": "calc",
183
+ "-moz-min-content": "min-content",
184
+ "-moz-fit-content": "fit-content",
185
+ "-moz-max-content": "max-content",
186
+ "-moz-available": "stretch",
187
+ ":-moz-any-link": ":any-link",
188
+ ":-moz-full-screen": ":fullscreen",
189
+ ":-moz-full-screen-ancestor": ":fullscreen",
190
+ ":-moz-placeholder": ":placeholder-shown",
191
+ ":-moz-read-only": ":read-only",
192
+ ":-moz-read-write": ":read-write",
193
+ ":-moz-submit-invalid": ":invalid",
194
+ ":-moz-ui-invalid": ":user-invalid",
195
+ ":-moz-ui-valid": ":user-valid",
196
+ "::-moz-selection": "::selection",
182
197
  };
183
- // https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions
184
- // https://developer.mozilla.org/en-US/docs/Web/CSS/::-webkit-scrollbar
185
- const webkitExtensions = new Set([
186
- '-webkit-app-region',
187
- '-webkit-border-horizontal-spacing',
188
- '-webkit-border-vertical-spacing',
189
- '-webkit-box-reflect',
190
- '-webkit-column-axis',
191
- '-webkit-column-progression',
192
- '-webkit-cursor-visibility',
193
- '-webkit-font-smoothing',
194
- '-webkit-hyphenate-limit-after',
195
- '-webkit-hyphenate-limit-before',
196
- '-webkit-hyphenate-limit-lines',
197
- '-webkit-line-align',
198
- '-webkit-line-box-contain',
199
- '-webkit-line-clamp',
200
- '-webkit-line-grid',
201
- '-webkit-line-snap',
202
- '-webkit-locale',
203
- '-webkit-logical-height',
204
- '-webkit-logical-width',
205
- '-webkit-margin-after',
206
- '-webkit-margin-before',
207
- '-webkit-mask-box-image-outset',
208
- '-webkit-mask-box-image-repeat',
209
- '-webkit-mask-box-image-slice',
210
- '-webkit-mask-box-image-source',
211
- '-webkit-mask-box-image-width',
212
- '-webkit-mask-box-image',
213
- '-webkit-mask-composite',
214
- '-webkit-mask-position-x',
215
- '-webkit-mask-position-y',
216
- '-webkit-mask-repeat-x',
217
- '-webkit-mask-repeat-y',
218
- '-webkit-mask-source-type',
219
- '-webkit-max-logical-height',
220
- '-webkit-max-logical-width',
221
- '-webkit-min-logical-height',
222
- '-webkit-min-logical-width',
223
- '-webkit-nbsp-mode',
224
- '-webkit-match-parent',
225
- '-webkit-perspective-origin-x',
226
- '-webkit-perspective-origin-y',
227
- '-webkit-rtl-ordering',
228
- '-webkit-tap-highlight-color',
229
- '-webkit-text-decoration-skip',
230
- '-webkit-text-decorations-in-effect',
231
- '-webkit-text-fill-color',
232
- '-webkit-text-security',
233
- '-webkit-text-stroke-color',
234
- '-webkit-text-stroke-width',
235
- '-webkit-text-stroke',
236
- '-webkit-text-zoom',
237
- '-webkit-touch-callout',
238
- '-webkit-transform-origin-x',
239
- '-webkit-transform-origin-y',
240
- '-webkit-transform-origin-z',
241
- '-webkit-user-drag',
242
- '-webkit-user-modify',
243
- '-webkit-border-after',
244
- '-webkit-border-after-color',
245
- '-webkit-border-after-style',
246
- '-webkit-border-after-width',
247
- '-webkit-border-before',
248
- '-webkit-border-before-color',
249
- '-webkit-border-before-style',
250
- '-webkit-border-before-width',
251
- '-webkit-border-end',
252
- '-webkit-border-end-color',
253
- '-webkit-border-end-style',
254
- '-webkit-border-end-width',
255
- '-webkit-border-start',
256
- '-webkit-border-start-color',
257
- '-webkit-border-start-style',
258
- '-webkit-border-start-width',
259
- '-webkit-box-align',
260
- '-webkit-box-direction',
261
- '-webkit-box-flex-group',
262
- '-webkit-box-flex',
263
- '-webkit-box-lines',
264
- '-webkit-box-ordinal-group',
265
- '-webkit-box-orient',
266
- '-webkit-box-pack',
267
- '-webkit-column-break-after',
268
- '-webkit-column-break-before',
269
- '-webkit-column-break-inside',
270
- '-webkit-font-feature-settings',
271
- '-webkit-hyphenate-character',
272
- '-webkit-initial-letter',
273
- '-webkit-margin-end',
274
- '-webkit-margin-start',
275
- '-webkit-padding-after',
276
- '-webkit-padding-before',
277
- '-webkit-padding-end',
278
- '-webkit-padding-start',
279
- '-webkit-fill-available',
280
- ':-webkit-animating-full-screen-transition',
281
- ':-webkit-any',
282
- ':-webkit-any-link',
283
- ':-webkit-autofill',
284
- ':-webkit-autofill-strong-password',
285
- ':-webkit-drag',
286
- ':-webkit-full-page-media',
287
- ':-webkit-full-screen*',
288
- ':-webkit-full-screen-ancestor',
289
- ':-webkit-full-screen-document',
290
- ':-webkit-full-screen-controls-hidden',
291
- '::-webkit-file-upload-button*',
292
- '::-webkit-inner-spin-button',
293
- '::-webkit-input-placeholder',
294
- '::-webkit-meter-bar',
295
- '::-webkit-meter-even-less-good-value',
296
- '::-webkit-meter-inner-element',
297
- '::-webkit-meter-optimum-value',
298
- '::-webkit-meter-suboptimum-value',
299
- '::-webkit-progress-bar',
300
- '::-webkit-progress-inner-element',
301
- '::-webkit-progress-value',
302
- '::-webkit-search-cancel-button',
303
- '::-webkit-search-results-button',
304
- '::-webkit-slider-runnable-track',
305
- '::-webkit-slider-thumb',
306
- '-webkit-animation',
307
- '-webkit-device-pixel-ratio',
308
- '-webkit-transform-2d',
309
- '-webkit-transform-3d',
310
- '-webkit-transition',
311
- '::-webkit-scrollbar',
312
- '::-webkit-scrollbar-button',
313
- '::-webkit-scrollbar',
314
- '::-webkit-scrollbar-thumb',
315
- '::-webkit-scrollbar-track',
316
- '::-webkit-scrollbar-track-piece',
317
- '::-webkit-scrollbar:vertical',
318
- '::-webkit-scrollbar-corner ',
319
- '::-webkit-resizer',
320
- ':vertical',
321
- ':horizontal',
322
- ]);
323
- // https://developer.mozilla.org/en-US/docs/Web/CSS/Mozilla_Extensions
324
- const mozExtensions = new Set([
325
- '-moz-box-align',
326
- '-moz-box-direction',
327
- '-moz-box-flex',
328
- '-moz-box-ordinal-group',
329
- '-moz-box-orient',
330
- '-moz-box-pack',
331
- '-moz-float-edge',
332
- '-moz-force-broken-image-icon',
333
- '-moz-image-region',
334
- '-moz-orient',
335
- '-moz-osx-font-smoothing',
336
- '-moz-user-focus',
337
- '-moz-user-input',
338
- '-moz-user-modify',
339
- '-moz-animation',
340
- '-moz-animation-delay',
341
- '-moz-animation-direction',
342
- '-moz-animation-duration',
343
- '-moz-animation-fill-mode',
344
- '-moz-animation-iteration-count',
345
- '-moz-animation-name',
346
- '-moz-animation-play-state',
347
- '-moz-animation-timing-function',
348
- '-moz-appearance',
349
- '-moz-backface-visibility',
350
- '-moz-background-clip',
351
- '-moz-background-origin',
352
- '-moz-background-inline-policy',
353
- '-moz-background-size',
354
- '-moz-border-end',
355
- '-moz-border-end-color',
356
- '-moz-border-end-style',
357
- '-moz-border-end-width',
358
- '-moz-border-image',
359
- '-moz-border-start',
360
- '-moz-border-start-color',
361
- '-moz-border-start-style',
362
- '-moz-border-start-width',
363
- '-moz-box-sizing',
364
- 'clip-path',
365
- '-moz-column-count',
366
- '-moz-column-fill',
367
- '-moz-column-gap',
368
- '-moz-column-width',
369
- '-moz-column-rule',
370
- '-moz-column-rule-width',
371
- '-moz-column-rule-style',
372
- '-moz-column-rule-color',
373
- 'filter',
374
- '-moz-font-feature-settings',
375
- '-moz-font-language-override',
376
- '-moz-hyphens',
377
- '-moz-margin-end',
378
- '-moz-margin-start',
379
- 'mask',
380
- '-moz-opacity',
381
- '-moz-outline',
382
- '-moz-outline-color',
383
- '-moz-outline-offset',
384
- '-moz-outline-style',
385
- '-moz-outline-width',
386
- '-moz-padding-end',
387
- '-moz-padding-start',
388
- '-moz-perspective',
389
- '-moz-perspective-origin',
390
- 'pointer-events',
391
- '-moz-tab-size',
392
- '-moz-text-align-last',
393
- '-moz-text-decoration-color',
394
- '-moz-text-decoration-line',
395
- '-moz-text-decoration-style',
396
- '-moz-text-size-adjust',
397
- '-moz-transform',
398
- '-moz-transform-origin',
399
- '-moz-transform-style',
400
- '-moz-transition',
401
- '-moz-transition-delay',
402
- '-moz-transition-duration',
403
- '-moz-transition-property',
404
- '-moz-transition-timing-function',
405
- '-moz-user-select',
406
- '-moz-initial',
407
- '-moz-appearance',
408
- '-moz-linear-gradient',
409
- '-moz-radial-gradient',
410
- '-moz-element',
411
- '-moz-image-rect',
412
- '::-moz-anonymous-block',
413
- '::-moz-anonymous-positioned-block',
414
- ':-moz-any',
415
- ':-moz-any-link',
416
- ':-moz-broken',
417
- '::-moz-canvas',
418
- '::-moz-color-swatch',
419
- '::-moz-cell-content',
420
- ':-moz-drag-over',
421
- ':-moz-first-node',
422
- '::-moz-focus-inner',
423
- '::-moz-focus-outer',
424
- ':-moz-full-screen',
425
- ':-moz-full-screen-ancestor',
426
- ':-moz-handler-blocked',
427
- ':-moz-handler-crashed',
428
- ':-moz-handler-disabled',
429
- '::-moz-inline-table',
430
- ':-moz-last-node',
431
- '::-moz-list-bullet',
432
- '::-moz-list-number',
433
- ':-moz-loading',
434
- ':-moz-locale-dir',
435
- ':-moz-locale-dir',
436
- ':-moz-lwtheme',
437
- ':-moz-lwtheme-brighttext',
438
- ':-moz-lwtheme-darktext',
439
- '::-moz-meter-bar',
440
- ':-moz-native-anonymous',
441
- ':-moz-only-whitespace',
442
- '::-moz-pagebreak',
443
- '::-moz-pagecontent',
444
- ':-moz-placeholder',
445
- '::-moz-placeholder',
446
- '::-moz-progress-bar',
447
- '::-moz-range-progress',
448
- '::-moz-range-thumb',
449
- '::-moz-range-track',
450
- ':-moz-read-only',
451
- ':-moz-read-write',
452
- '::-moz-scrolled-canvas',
453
- '::-moz-scrolled-content',
454
- '::-moz-selection',
455
- ':-moz-submit-invalid',
456
- ':-moz-suppressed',
457
- '::-moz-svg-foreign-content',
458
- '::-moz-table',
459
- '::-moz-table-cell',
460
- '::-moz-table-column',
461
- '::-moz-table-column-group',
462
- '::-moz-table-outer',
463
- '::-moz-table-row',
464
- '::-moz-table-row-group',
465
- ':-moz-ui-invalid',
466
- ':-moz-ui-valid',
467
- ':-moz-user-disabled',
468
- '::-moz-viewport',
469
- '::-moz-viewport-scroll',
470
- ':-moz-window-inactive',
471
- '-moz-device-pixel-ratio',
472
- '-moz-os-version',
473
- '-moz-touch-enabled',
474
- '-moz-windows-glass',
475
- '-moz-alt-content'
476
- ]);
198
+ // renamed standard properties
199
+ const renamedStandardProperties = new Map([["color-adjust", "print-color-adjust"]]);
477
200
  function isLength(dimension) {
478
- return 'unit' in dimension && dimensionUnits.has(dimension.unit.toLowerCase());
201
+ return "unit" in dimension && dimensionUnits.has(dimension.unit.toLowerCase());
479
202
  }
480
203
  function isResolution(dimension) {
481
- return 'unit' in dimension && ['dpi', 'dpcm', 'dppx', 'x'].includes(dimension.unit.toLowerCase());
204
+ return "unit" in dimension && ["dpi", "dpcm", "dppx", "x"].includes(dimension.unit.toLowerCase());
482
205
  }
483
206
  function isAngle(dimension) {
484
- return 'unit' in dimension && ['rad', 'turn', 'deg', 'grad'].includes(dimension.unit.toLowerCase());
207
+ return "unit" in dimension && ["rad", "turn", "deg", "grad"].includes(dimension.unit.toLowerCase());
485
208
  }
486
209
  function isTime(dimension) {
487
- return 'unit' in dimension && ['ms', 's'].includes(dimension.unit.toLowerCase());
210
+ return "unit" in dimension && ["ms", "s"].includes(dimension.unit.toLowerCase());
488
211
  }
489
212
  function isFrequency(dimension) {
490
- return 'unit' in dimension && ['hz', 'khz'].includes(dimension.unit.toLowerCase());
213
+ return "unit" in dimension && ["hz", "khz"].includes(dimension.unit.toLowerCase());
491
214
  }
492
215
  function isColorspace(token) {
216
+ if (token.typ === EnumToken.WildCardFunctionTokenType && token.val === "var") {
217
+ return true;
218
+ }
493
219
  if (token.typ != EnumToken.IdenTokenType) {
494
220
  return false;
495
221
  }
496
- return ['srgb', 'srgb-linear', 'lab', 'oklab', 'lch', 'oklch', 'xyz', 'xyz-d50', 'xyz-d65', 'display-p3', 'a98-rgb', 'prophoto-rgb', 'rec2020', 'rgb', 'hsl', 'hwb'].includes(token.val.toLowerCase());
222
+ return [
223
+ "srgb",
224
+ "srgb-linear",
225
+ "lab",
226
+ "oklab",
227
+ "lch",
228
+ "oklch",
229
+ "xyz",
230
+ "xyz-d50",
231
+ "xyz-d65",
232
+ "display-p3",
233
+ "a98-rgb",
234
+ "prophoto-rgb",
235
+ "rec2020",
236
+ "rgb",
237
+ "hsl",
238
+ "hwb",
239
+ ].includes(token.val.toLowerCase());
240
+ }
241
+ function reduceColorStops(stops) {
242
+ const parts = splitTokenList(stops);
243
+ const n = parts.length == 1 ? 1 : parts.length - 1;
244
+ let j;
245
+ let i;
246
+ let k = -1;
247
+ let updated = false;
248
+ for (i = 0; i < parts.length; i++) {
249
+ k++;
250
+ if (parts[i].length != 3) {
251
+ continue;
252
+ }
253
+ if (i > 0 && isOkLabClose(parts[i - 1][0], parts[i][0])) {
254
+ if (parts[i - 1].length == 1) {
255
+ parts[i - 1].push({ typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.PercentageTokenType, val: ((k - 1) * 100) / n });
256
+ }
257
+ parts[i - 1].push(...parts[i].slice(1));
258
+ parts.splice(i--, 1);
259
+ updated = true;
260
+ continue;
261
+ }
262
+ for (j = 0; j < parts[i].length; j++) {
263
+ if ((parts[i][j].typ == EnumToken.LengthTokenType && 0 == parts[i][j].val) ||
264
+ parts[i][j].typ == EnumToken.NumberTokenType ||
265
+ parts[i][j].typ == EnumToken.PercentageTokenType) {
266
+ if (parts[i][j].val === (k * 100) / n) {
267
+ parts[i].length = j;
268
+ trimArray(parts[i]);
269
+ updated = true;
270
+ break;
271
+ }
272
+ }
273
+ }
274
+ }
275
+ if (updated) {
276
+ stops.length = 0;
277
+ for (j = 0; j < parts.length; j++) {
278
+ if (stops.length > 0) {
279
+ stops.push({ typ: EnumToken.CommaTokenType });
280
+ }
281
+ stops.push(...parts[j]);
282
+ }
283
+ }
284
+ return stops;
285
+ }
286
+ /**
287
+ * Reduce background-position values.
288
+ * @param positions
289
+ * @param position
290
+ */
291
+ function reducegradientBackgroundPosition(positions, position) {
292
+ switch (position) {
293
+ case "50%":
294
+ case "50% 50%":
295
+ case "center":
296
+ case "center center":
297
+ positions.length = 0;
298
+ break;
299
+ case "0 50%":
300
+ case "0% 50%":
301
+ case "left":
302
+ case "left center":
303
+ case "center left":
304
+ positions.length = 2;
305
+ positions.push({ typ: EnumToken.PercentageTokenType, val: 0 });
306
+ break;
307
+ case "50% 0":
308
+ case "50% 0%":
309
+ case "top center":
310
+ case "center top":
311
+ positions.length = 2;
312
+ positions.push({ typ: EnumToken.IdenTokenType, val: "top" });
313
+ break;
314
+ case "bottom":
315
+ case "50% 100%":
316
+ case "bottom center":
317
+ case "center bottom":
318
+ positions.length = 2;
319
+ positions.push({ typ: EnumToken.IdenTokenType, val: "bottom" });
320
+ break;
321
+ case "left":
322
+ case "0 50%":
323
+ case "0% 50%":
324
+ case "left center":
325
+ case "center left":
326
+ positions.length = 2;
327
+ positions.push({ typ: EnumToken.PercentageTokenType, val: 0 });
328
+ break;
329
+ case "100% 50%":
330
+ case "right":
331
+ case "right center":
332
+ case "center right":
333
+ positions.length = 2;
334
+ positions.push({ typ: EnumToken.PercentageTokenType, val: 100 });
335
+ break;
336
+ case "bottom left":
337
+ case "left bottom":
338
+ positions.length = 2;
339
+ positions.push({ typ: EnumToken.PercentageTokenType, val: 0 }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.PercentageTokenType, val: 100 });
340
+ break;
341
+ case "bottom right":
342
+ case "right bottom":
343
+ positions.length = 2;
344
+ positions.push({ typ: EnumToken.PercentageTokenType, val: 100 }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.PercentageTokenType, val: 100 });
345
+ break;
346
+ case "top left":
347
+ case "left top":
348
+ positions.length = 2;
349
+ positions.push({ typ: EnumToken.PercentageTokenType, val: 0 }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.PercentageTokenType, val: 0 });
350
+ break;
351
+ case "top right":
352
+ case "right top":
353
+ positions.length = 2;
354
+ positions.push({ typ: EnumToken.PercentageTokenType, val: 100 }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.PercentageTokenType, val: 0 });
355
+ break;
356
+ }
357
+ }
358
+ function reduceConicColorStops(stops) {
359
+ const parts = splitTokenList(stops);
360
+ const n = parts.length == 1 ? 1 : parts.length - 1;
361
+ let j;
362
+ let i;
363
+ let k = -1;
364
+ let updated = false;
365
+ for (i = 0; i < parts.length; i++) {
366
+ k++;
367
+ if (parts[i].length != 3) {
368
+ continue;
369
+ }
370
+ if (i > 0 && isOkLabClose(parts[i - 1][0], parts[i][0])) {
371
+ if (parts[i - 1].length == 1) {
372
+ parts[i - 1].push({ typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.AngleTokenType, val: ((k - 1) * 100) / n, unit: "deg" });
373
+ }
374
+ parts[i - 1].push(...parts[i].slice(1));
375
+ parts.splice(i--, 1);
376
+ updated = true;
377
+ continue;
378
+ }
379
+ for (j = 0; j < parts[i].length; j++) {
380
+ if ((parts[i][j].typ == EnumToken.NumberTokenType && 0 == parts[i][j].val) ||
381
+ parts[i][j].typ == EnumToken.AngleTokenType) {
382
+ if (toDegrees(parts[i][j]).val === (k * 360) / n) {
383
+ parts[i].length = j;
384
+ trimArray(parts[i]);
385
+ updated = true;
386
+ break;
387
+ }
388
+ }
389
+ }
390
+ }
391
+ if (updated) {
392
+ stops.length = 0;
393
+ for (j = 0; j < parts.length; j++) {
394
+ if (stops.length > 0) {
395
+ stops.push({ typ: EnumToken.CommaTokenType });
396
+ }
397
+ stops.push(...parts[j]);
398
+ }
399
+ }
400
+ return stops;
497
401
  }
498
402
  function isRectangularOrthogonalColorspace(token) {
499
403
  if (token.typ != EnumToken.IdenTokenType) {
500
404
  return false;
501
405
  }
502
- return ['srgb', 'srgb-linear', 'display-p3', 'a98-rgb', 'prophoto-rgb', 'rec2020', 'lab', 'oklab', 'xyz', 'xyz-d50', 'xyz-d65'].includes(token.val.toLowerCase());
406
+ return [
407
+ "srgb",
408
+ "srgb-linear",
409
+ "display-p3",
410
+ "a98-rgb",
411
+ "prophoto-rgb",
412
+ "rec2020",
413
+ "lab",
414
+ "oklab",
415
+ "xyz",
416
+ "xyz-d50",
417
+ "xyz-d65",
418
+ ].some((t) => equalsIgnoreCase(t, token.val));
503
419
  }
504
420
  function isPolarColorspace(token) {
505
421
  if (token.typ != EnumToken.IdenTokenType) {
506
422
  return false;
507
423
  }
508
- return ['hsl', 'hwb', 'lch', 'oklch'].includes(token.val);
509
- }
510
- function isHueInterpolationMethod(token) {
511
- if (!Array.isArray(token)) {
512
- return token.typ == EnumToken.IdenTokenType && 'hue' === token.val?.toLowerCase?.();
513
- }
514
- if (token.length != 2 || token[0].typ != EnumToken.IdenTokenType || token[1].typ != EnumToken.IdenTokenType) {
515
- return false;
516
- }
517
- return ['shorter', 'longer', 'increasing', 'decreasing'].includes(token[0].val?.toLowerCase?.()) && 'hue' === token[1].val?.toLowerCase?.();
424
+ return ["hsl", "hwb", "lch", "oklch"].some((t) => equalsIgnoreCase(t, token.val));
518
425
  }
519
426
  function isIdentColor(token) {
520
- return token.typ == EnumToken.ColorTokenType && [ColorType.SYS, ColorType.DPSYS, ColorType.LIT].includes(token.kin) && isIdent(token.val);
427
+ return (token.typ == EnumToken.ColorTokenType &&
428
+ [ColorType.SYS, ColorType.DPSYS, ColorType.LIT].includes(token.kin) &&
429
+ isIdent(token.val));
521
430
  }
522
431
  function isPercentageToken(token) {
523
- return token.typ == EnumToken.PercentageTokenType || (token.typ == EnumToken.NumberTokenType && token.val == 0);
432
+ return (token.typ == EnumToken.PercentageTokenType ||
433
+ (token.typ == EnumToken.NumberTokenType && token.val == 0));
524
434
  }
525
- function isColor(token) {
526
- if (token.typ == EnumToken.ColorTokenType) {
435
+ function isColor(token, errors) {
436
+ if (token.typ == EnumToken.WildCardFunctionTokenType) {
527
437
  return true;
528
438
  }
439
+ if (token.typ == EnumToken.FunctionTokenType) {
440
+ if (!colorsFunc.includes(token.val.toLowerCase())) {
441
+ return false;
442
+ }
443
+ }
444
+ if (token.typ == EnumToken.ColorTokenType) {
445
+ if ("kin" in token && !("chi" in token)) {
446
+ return true;
447
+ }
448
+ }
529
449
  if (token.typ == EnumToken.IdenTokenType) {
450
+ const val = token.val.toLowerCase();
451
+ if (systemColors.has(val) || deprecatedSystemColors.has(val) || nonStandardColors.has(val)) {
452
+ return true;
453
+ }
530
454
  // named color
531
- return token.val.toLowerCase() in COLORS_NAMES || 'currentcolor' === token.val.toLowerCase() || 'transparent' === token.val.toLowerCase();
455
+ return val in COLORS_NAMES || "currentcolor" === val || "transparent" === val;
532
456
  }
533
457
  let isLegacySyntax = false;
534
- if (token.typ == EnumToken.FunctionTokenType) {
458
+ if (token.typ === EnumToken.FunctionTokenType || token.typ === EnumToken.ColorTokenType) {
535
459
  if (!colorsFunc.includes(token.val.toLowerCase())) {
536
460
  return false;
537
461
  }
538
462
  if (token.chi.length > 0) {
539
463
  // @ts-ignore
540
- if (token.val == 'light-dark') {
464
+ if (token.val === "light-dark") {
541
465
  // @ts-ignore
542
- const children = token.chi.filter((t) => [EnumToken.IdenTokenType, EnumToken.NumberTokenType, EnumToken.LiteralTokenType, EnumToken.ColorTokenType, EnumToken.FunctionTokenType, EnumToken.PercentageTokenType].includes(t.typ));
466
+ const children = token.chi.filter((t) => [
467
+ EnumToken.IdenTokenType,
468
+ EnumToken.NumberTokenType,
469
+ EnumToken.LiteralTokenType,
470
+ EnumToken.ColorTokenType,
471
+ EnumToken.FunctionTokenType,
472
+ EnumToken.PercentageTokenType,
473
+ EnumToken.WildCardFunctionTokenType,
474
+ ].includes(t.typ));
543
475
  if (children.length != 2) {
476
+ errors?.push({
477
+ message: "light-dark function must have 2 arguments",
478
+ node: token,
479
+ action: "drop",
480
+ });
544
481
  return false;
545
482
  }
546
483
  if (isColor(children[0]) && isColor(children[1])) {
@@ -548,26 +485,156 @@ function isColor(token) {
548
485
  }
549
486
  }
550
487
  // adding numbers and percentages is disallowed
551
- // https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/lch#defining_relative_color_output_channel_components
488
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/color_value/lch#defining_relative_color_output_channel_components:~:text=Adding%20a%20%3Cpercentage%3E%20to%20a%20%3Cnumber%3E%2C%20for%20example%2C%20doesn%27t%20work
489
+ const components = getColorComponents(token);
490
+ if (components !== null) {
491
+ const colorSpace = getColorSpace(token)?.split?.("");
492
+ if (colorSpace != null) {
493
+ for (const value of components) {
494
+ if (value.typ === EnumToken.IdenTokenType) {
495
+ const val = value.val.toLowerCase();
496
+ if (
497
+ // @ts-expect-error
498
+ typeof Math[val.toUpperCase()] !== "number" &&
499
+ val != "in" &&
500
+ val != "hue" &&
501
+ val != "from" &&
502
+ val != "alpha" &&
503
+ val != "none" &&
504
+ val != "shorter" &&
505
+ val != "longer" &&
506
+ val != "increasing" &&
507
+ val != "decreasing" &&
508
+ !colorsFunc.includes(val) &&
509
+ !colorSpace.includes(val) &&
510
+ !colorFuncColorSpace.includes(val)) {
511
+ errors?.push({
512
+ action: "drop",
513
+ message: `Unexpected constant '${val}'`,
514
+ node: value,
515
+ location: value.loc,
516
+ });
517
+ return false;
518
+ }
519
+ }
520
+ else if (value.typ === EnumToken.MathFunctionTokenType &&
521
+ equalsIgnoreCase("calc", value.val)) {
522
+ let val;
523
+ for (const v of walkValues(value.chi)) {
524
+ if (v.value.typ === EnumToken.IdenTokenType) {
525
+ val = v.value.val.toLowerCase();
526
+ if (
527
+ // @ts-expect-error
528
+ typeof Math[val.toUpperCase()] !== "number" &&
529
+ val != "in" &&
530
+ val != "hue" &&
531
+ val != "from" &&
532
+ val != "alpha" &&
533
+ val != "none" &&
534
+ val != "shorter" &&
535
+ val != "longer" &&
536
+ val != "increasing" &&
537
+ val != "decreasing" &&
538
+ !colorsFunc.includes(val) &&
539
+ !colorSpace.includes(val) &&
540
+ !colorFuncColorSpace.includes(val)) {
541
+ // console.debug({ val });
542
+ errors?.push({
543
+ action: "drop",
544
+ message: `Unexpected constant '${val}'`,
545
+ node: v.value,
546
+ location: v.value.loc,
547
+ });
548
+ return false;
549
+ }
550
+ }
551
+ }
552
+ }
553
+ }
554
+ }
555
+ }
552
556
  // @ts-ignore
553
- for (const { value } of walkValues(token.chi, null, (node) => funcLike.includes(node.typ) ? WalkerOptionEnum.IgnoreChildren : null)) {
554
- if (funcLike.includes(value.typ)) {
555
- for (const { value: val } of walkValues([buildExpression(value.chi)])) {
556
- if (val.typ == EnumToken.BinaryExpressionTokenType &&
557
- (val.l.typ == EnumToken.PercentageTokenType || val.r.typ == EnumToken.PercentageTokenType) &&
558
- ((val.r.typ == EnumToken.PercentageTokenType && val.op == EnumToken.Div) ||
559
- ((val.op == EnumToken.Add || val.op == EnumToken.Sub) &&
560
- val.l.typ != val.r.typ))) {
561
- return false;
557
+ for (const { value, parent } of walkValues(token.chi, token, (value) => value.typ === EnumToken.WildCardFunctionTokenType
558
+ ? WalkerOptionEnum.Ignore | WalkerOptionEnum.IgnoreChildren
559
+ : null)) {
560
+ let k = 0;
561
+ let l;
562
+ let tk = null;
563
+ let tl = null;
564
+ if (value.typ === EnumToken.BinaryExpressionTokenType) {
565
+ tk = value.l;
566
+ tl = value.r;
567
+ }
568
+ else if (parent?.typ === EnumToken.MathFunctionTokenType &&
569
+ parent.val === "calc") {
570
+ l = k + 1;
571
+ while (l + 1 < parent.chi.length) {
572
+ const tk = parent.chi[l];
573
+ if (tk.typ === EnumToken.WhitespaceTokenType ||
574
+ tk.typ === EnumToken.CommentTokenType ||
575
+ tk.typ === EnumToken.Add ||
576
+ tk.typ === EnumToken.Sub ||
577
+ tk.typ === EnumToken.Div ||
578
+ tk.typ === EnumToken.Mul) {
579
+ l++;
580
+ continue;
562
581
  }
582
+ break;
583
+ }
584
+ tk = parent.chi[k];
585
+ tl = parent.chi[l];
586
+ }
587
+ if (tk != null && tl != null) {
588
+ if ((tk.typ === EnumToken.PercentageTokenType || tl.typ === EnumToken.PercentageTokenType) &&
589
+ tk.typ !== tl.typ) {
590
+ errors?.push({
591
+ action: "drop",
592
+ message: "adding percentage and number is not allowed",
593
+ node: token,
594
+ location: token.loc,
595
+ });
596
+ return false;
563
597
  }
564
598
  }
565
599
  }
566
600
  // @ts-ignore
567
- if (token.val == 'color') {
601
+ if (token.val == "color") {
568
602
  // @ts-ignore
569
- const children = token.chi.filter((t) => [EnumToken.IdenTokenType, EnumToken.NumberTokenType, EnumToken.LiteralTokenType, EnumToken.ColorTokenType, EnumToken.FunctionTokenType, EnumToken.PercentageTokenType].includes(t.typ));
570
- const isRelative = children[0].typ == EnumToken.IdenTokenType && children[0].val == 'from';
603
+ const children = token.chi.filter((t) => [
604
+ EnumToken.DashedIdenTokenType,
605
+ EnumToken.IdenTokenType,
606
+ EnumToken.NumberTokenType,
607
+ EnumToken.LiteralTokenType,
608
+ EnumToken.ColorTokenType,
609
+ EnumToken.FunctionTokenType,
610
+ EnumToken.MathFunctionTokenType,
611
+ EnumToken.PercentageTokenType,
612
+ ].includes(t.typ));
613
+ const isRelative = children[0].typ == EnumToken.IdenTokenType && children[0].val == "from";
614
+ let offset = 0;
615
+ if (isRelative) {
616
+ offset = 2;
617
+ }
618
+ if (children[offset]?.typ == EnumToken.DashedIdenTokenType) {
619
+ if (children.length < offset + 1) {
620
+ return false;
621
+ }
622
+ for (let i = offset + 1; i < children.length; i++) {
623
+ if (children[i].typ == EnumToken.NumberTokenType ||
624
+ children[i].typ == EnumToken.LiteralTokenType ||
625
+ children[i].typ == EnumToken.ColorTokenType ||
626
+ children[i].typ == EnumToken.FunctionTokenType ||
627
+ children[i].typ == EnumToken.MathFunctionTokenType ||
628
+ children[i].typ == EnumToken.PercentageTokenType ||
629
+ isColor(children[i]) ||
630
+ (children[i].typ == EnumToken.IdenTokenType &&
631
+ equalsIgnoreCase("none", children[i].val))) {
632
+ continue;
633
+ }
634
+ return false;
635
+ }
636
+ return true;
637
+ }
571
638
  if (children.length < 4 || children.length > 8) {
572
639
  return false;
573
640
  }
@@ -576,15 +643,21 @@ function isColor(token) {
576
643
  }
577
644
  for (let i = 1; i < children.length - 2; i++) {
578
645
  if (children[i].typ == EnumToken.IdenTokenType) {
579
- if (children[i].val != 'none' &&
580
- !(isRelative && ['alpha', 'r', 'g', 'b', 'x', 'y', 'z'].includes(children[i].val) || isColorspace(children[i]))) {
646
+ if (isColor(children[i])) {
647
+ continue;
648
+ }
649
+ if (children[i].val != "none" &&
650
+ !((isRelative &&
651
+ ["alpha", "r", "g", "b", "x", "y", "z"].includes(children[i].val)) ||
652
+ isColorspace(children[i]))) {
581
653
  return false;
582
654
  }
583
655
  }
584
- if (children[i].typ == EnumToken.FunctionTokenType) {
585
- if ('var' == children[i].val.toLowerCase()) {
586
- continue;
587
- }
656
+ if (children[i].typ === EnumToken.WildCardFunctionTokenType) {
657
+ continue;
658
+ }
659
+ if (children[i].typ === EnumToken.FunctionTokenType ||
660
+ children[i].typ === EnumToken.MathFunctionTokenType) {
588
661
  if (!mathFuncs.includes(children[i].val)) {
589
662
  return false;
590
663
  }
@@ -597,10 +670,11 @@ function isColor(token) {
597
670
  const sep = children.at(-2);
598
671
  const alpha = children.at(-1);
599
672
  // @ts-ignore
600
- if ((children.length > 6 || !isRelative) && sep.typ != EnumToken.LiteralTokenType || sep.val != '/') {
673
+ if (((children.length > 6 || !isRelative) && sep.typ != EnumToken.LiteralTokenType) ||
674
+ sep.val != "/") {
601
675
  return false;
602
676
  }
603
- if (alpha.typ == EnumToken.IdenTokenType && alpha.val != 'none') {
677
+ if (alpha.typ == EnumToken.IdenTokenType && alpha.val != "none") {
604
678
  return false;
605
679
  }
606
680
  else {
@@ -620,7 +694,7 @@ function isColor(token) {
620
694
  return true;
621
695
  }
622
696
  // @ts-ignore
623
- else if (token.val == 'color-mix') {
697
+ else if (token.val == "color-mix") {
624
698
  // @ts-ignore
625
699
  const children = token.chi.reduce((acc, t) => {
626
700
  if (t.typ == EnumToken.CommaTokenType) {
@@ -633,40 +707,86 @@ function isColor(token) {
633
707
  }
634
708
  return acc;
635
709
  }, [[]]);
636
- if (children.length == 3) {
637
- if (children[0].length > 4 ||
638
- children[0][0].typ != EnumToken.IdenTokenType ||
639
- 'in' !== children[0][0].val?.toLowerCase?.() ||
640
- !isColorspace(children[0][1]) ||
641
- (children[0].length >= 3 && !isHueInterpolationMethod(children[0].slice(2))) ||
642
- children[1].length > 2 ||
643
- !isColor(children[1][0]) ||
644
- (children[1].length == 2 && !isPercentageToken(children[1][1])) ||
645
- children[2].length > 2 ||
646
- (children[2].length == 2 && !isPercentageToken(children[2][1])) ||
647
- !isColor(children[2][0])) {
710
+ if (children.length === 0 || children[0].length === 0) {
711
+ return false;
712
+ }
713
+ let j = 0;
714
+ let k = 0;
715
+ if (children[j][0].typ === EnumToken.IdenTokenType &&
716
+ equalsIgnoreCase("in", children[j][k].val)) {
717
+ k++;
718
+ if (children[j][k]?.typ === EnumToken.IdenTokenType) {
719
+ if (!isRectangularOrthogonalColorspace(children[j][k])) {
720
+ if (isPolarColorspace(children[j][k++])) {
721
+ if (k == children[j].length) ;
722
+ else if (children[j][k].typ !== EnumToken.IdenTokenType) {
723
+ return false;
724
+ }
725
+ else if (equalsIgnoreCase("hue", children[j][k].val)) {
726
+ k++;
727
+ }
728
+ else {
729
+ switch (children[j][k].val) {
730
+ case "increasing":
731
+ case "decreasing":
732
+ case "longer":
733
+ case "shorter":
734
+ k++;
735
+ break;
736
+ default:
737
+ return false;
738
+ }
739
+ if (children[j][k]?.typ !== EnumToken.IdenTokenType ||
740
+ !equalsIgnoreCase("hue", children[j][k].val)) {
741
+ return false;
742
+ }
743
+ k++;
744
+ }
745
+ }
746
+ else {
747
+ return false;
748
+ }
749
+ }
750
+ else {
751
+ k++;
752
+ }
753
+ }
754
+ else {
648
755
  return false;
649
756
  }
650
- if (children[1].length == 2) {
651
- if (!(children[1][1].typ == EnumToken.PercentageTokenType || (children[1][1].typ == EnumToken.NumberTokenType && children[1][1].val == 0))) {
652
- return false;
653
- }
757
+ if (k != children[j].length) {
758
+ return false;
654
759
  }
655
- if (children[2].length == 2) {
656
- if (!(children[2][1].typ == EnumToken.PercentageTokenType || (children[2][1].typ == EnumToken.NumberTokenType && children[2][1].val == 0))) {
760
+ j++;
761
+ }
762
+ while (j < children.length) {
763
+ if (children[j].length > 2) {
764
+ return false;
765
+ }
766
+ if (!isColor(children[j][0]) &&
767
+ !(children[j][0].typ == EnumToken.WildCardFunctionTokenType &&
768
+ equalsIgnoreCase("calc", children[j][0].val))) {
769
+ return false;
770
+ }
771
+ if (children[j][0].typ == EnumToken.WildCardFunctionTokenType) {
772
+ const result = matchAllSyntaxes(getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, "calc()"), createValidationContext([children[j][0]]), {});
773
+ if (!result.success) {
657
774
  return false;
658
775
  }
659
776
  }
660
- return true;
777
+ if (children[j].length > 1 && !isPercentageToken(children[j][1])) {
778
+ return false;
779
+ }
780
+ j++;
661
781
  }
662
- return false;
782
+ return true;
663
783
  }
664
784
  else {
665
- const keywords = ['from', 'none'];
785
+ const keywords = ["from", "none"];
666
786
  // @ts-ignore
667
- if (['rgb', 'hsl', 'hwb', 'lab', 'lch', 'oklab', 'oklch'].includes(token.val)) {
787
+ if (["rgb", "hsl", "hwb", "lab", "lch", "oklab", "oklch"].some((t) => equalsIgnoreCase(t, token.val))) {
668
788
  // @ts-ignore
669
- keywords.push('alpha', ...token.val.slice(-3).split(''));
789
+ keywords.push("alpha", ...token.val.slice(-3).split(""));
670
790
  }
671
791
  // @ts-ignore
672
792
  for (const v of token.chi) {
@@ -674,6 +794,9 @@ function isColor(token) {
674
794
  isLegacySyntax = true;
675
795
  }
676
796
  if (v.typ == EnumToken.IdenTokenType) {
797
+ if (isColor(v)) {
798
+ continue;
799
+ }
677
800
  if (!(keywords.includes(v.val) || v.val.toLowerCase() in COLORS_NAMES)) {
678
801
  return false;
679
802
  }
@@ -682,16 +805,27 @@ function isColor(token) {
682
805
  return false;
683
806
  }
684
807
  // @ts-ignore
685
- if (v.val == 'from' && ['rgba', 'hsla'].includes(token.val)) {
808
+ if (v.val == "from" && ["rgba", "hsla"].includes(token.val)) {
686
809
  return false;
687
810
  }
688
811
  }
689
812
  continue;
690
813
  }
691
- if (v.typ == EnumToken.FunctionTokenType && (mathFuncs.includes(v.val) || v.val == 'var' || colorsFunc.includes(v.val))) {
814
+ if (v.typ === EnumToken.MathFunctionTokenType ||
815
+ v.typ === EnumToken.WildCardFunctionTokenType ||
816
+ colorsFunc.includes(v.val)) {
692
817
  continue;
693
818
  }
694
- if (![EnumToken.ColorTokenType, EnumToken.IdenTokenType, EnumToken.NumberTokenType, EnumToken.AngleTokenType, EnumToken.PercentageTokenType, EnumToken.CommaTokenType, EnumToken.WhitespaceTokenType, EnumToken.LiteralTokenType].includes(v.typ)) {
819
+ if (![
820
+ EnumToken.ColorTokenType,
821
+ EnumToken.IdenTokenType,
822
+ EnumToken.NumberTokenType,
823
+ EnumToken.AngleTokenType,
824
+ EnumToken.PercentageTokenType,
825
+ EnumToken.CommaTokenType,
826
+ EnumToken.WhitespaceTokenType,
827
+ EnumToken.LiteralTokenType,
828
+ ].includes(v.typ)) {
695
829
  return false;
696
830
  }
697
831
  }
@@ -702,26 +836,109 @@ function isColor(token) {
702
836
  return false;
703
837
  }
704
838
  function parseColor(token) {
839
+ if (token.typ === EnumToken.IdenTokenType) {
840
+ const val = token.val.toLowerCase();
841
+ if (nonStandardColors.has(val)) {
842
+ Object.assign(token, {
843
+ typ: EnumToken.ColorTokenType,
844
+ kin: ColorType.NON_STD,
845
+ });
846
+ return token;
847
+ }
848
+ if (systemColors.has(val)) {
849
+ Object.assign(token, {
850
+ typ: EnumToken.ColorTokenType,
851
+ kin: ColorType.SYS,
852
+ });
853
+ return token;
854
+ }
855
+ if (deprecatedSystemColors.has(val)) {
856
+ Object.assign(token, {
857
+ typ: EnumToken.ColorTokenType,
858
+ kin: ColorType.DPSYS,
859
+ });
860
+ return token;
861
+ }
862
+ if (val in COLORS_NAMES || val === "currentcolor") {
863
+ Object.assign(token, {
864
+ typ: EnumToken.ColorTokenType,
865
+ val,
866
+ kin: ColorType.LIT,
867
+ });
868
+ return token;
869
+ }
870
+ }
871
+ if (token.typ === EnumToken.ColorTokenType) {
872
+ if (!("kin" in token) && "val" in token) {
873
+ // @ts-expect-error
874
+ token.kin = ColorType[token.val.replaceAll("-", "_").toUpperCase()];
875
+ }
876
+ if ("chi" in token) {
877
+ const tk = token.chi?.find((t) => t.typ !== EnumToken.WhitespaceTokenType && t.typ !== EnumToken.CommentTokenType);
878
+ if (tk?.typ === EnumToken.IdenTokenType && tk.val === "from") {
879
+ token.cal = "rel";
880
+ }
881
+ else if (token.val == "color-mix" && tk.val == "in") {
882
+ token.cal = "mix";
883
+ }
884
+ if (token.val == "color") {
885
+ let index = token.chi.indexOf(tk);
886
+ if (token.cal == "rel") {
887
+ for (let k = 0; k < token.chi.length; k++) {
888
+ if (EnumToken.DashedIdenTokenType == token.chi[k].typ) {
889
+ index = k;
890
+ break;
891
+ }
892
+ }
893
+ }
894
+ if (EnumToken.DashedIdenTokenType == token?.chi?.[index]?.typ) {
895
+ token.kin = ColorType.CUSTOM_COLOR;
896
+ }
897
+ }
898
+ }
899
+ return token;
900
+ }
705
901
  // @ts-ignore
706
902
  token.typ = EnumToken.ColorTokenType;
707
903
  // @ts-ignore
708
- token.kin = ColorType[token.val.replaceAll('-', '_').toUpperCase()];
904
+ token.kin = ColorType[token.val.replaceAll("-", "_").toUpperCase()];
905
+ if (!("chi" in token)) {
906
+ const val = token.val.toLowerCase();
907
+ if (val == "currentcolor" || val == "transparent" || val in COLORS_NAMES) {
908
+ token.kin = ColorType.LIT;
909
+ }
910
+ else if (isHexColor(val)) {
911
+ token.kin = ColorType.HEX;
912
+ }
913
+ const tk = token.chi?.find((t) => t.typ !== EnumToken.WhitespaceTokenType && t.typ !== EnumToken.CommentTokenType);
914
+ if (tk?.typ === EnumToken.IdenTokenType && tk.val === "from") {
915
+ token.cal = "rel";
916
+ }
917
+ else if (token.val == "color-mix" && tk.val == "in") {
918
+ token.cal = "mix";
919
+ }
920
+ else if (token.val == "color") {
921
+ token.cal = "col";
922
+ }
923
+ return token;
924
+ }
709
925
  // @ts-ignore
710
926
  if (token.chi[0].typ == EnumToken.IdenTokenType) {
711
927
  // @ts-ignore
712
- if (token.chi[0].val == 'from') {
928
+ if (token.chi[0].val == "from") {
713
929
  // @ts-ignore
714
- token.cal = 'rel';
930
+ token.cal = "rel";
715
931
  }
716
932
  // @ts-ignore
717
- else if (token.val == 'color-mix' && token.chi[0].val == 'in') {
933
+ else if (token.val == "color-mix" && token.chi[0].val == "in") {
718
934
  // @ts-ignore
719
- token.cal = 'mix';
935
+ token.cal = "mix";
720
936
  }
721
- else { // @ts-ignore
722
- if (token.val == 'color') {
937
+ else {
938
+ // @ts-ignore
939
+ if (token.val == "color") {
723
940
  // @ts-ignore
724
- token.cal = 'col';
941
+ token.cal = "col";
725
942
  }
726
943
  }
727
944
  }
@@ -729,9 +946,9 @@ function parseColor(token) {
729
946
  }
730
947
  function isLetter(codepoint) {
731
948
  // lowercase
732
- return (codepoint >= 0x61 && codepoint <= 0x7a) ||
949
+ return ((codepoint >= 0x61 && codepoint <= 0x7a) ||
733
950
  // uppercase
734
- (codepoint >= 0x41 && codepoint <= 0x5a);
951
+ (codepoint >= 0x41 && codepoint <= 0x5a));
735
952
  }
736
953
  function isNonAscii(codepoint) {
737
954
  return codepoint >= 0x80;
@@ -757,26 +974,26 @@ function isIdent(name) {
757
974
  if (Number.isNaN(nextCodepoint)) {
758
975
  return false;
759
976
  }
760
- // -
761
- if (nextCodepoint == 0x2d) {
762
- return true;
763
- }
764
977
  if (nextCodepoint == REVERSE_SOLIDUS) {
765
978
  return name.length > 2 && !isNewLine(name.charCodeAt(2));
766
979
  }
767
- return true;
980
+ if (isDigit(nextCodepoint)) {
981
+ return false;
982
+ }
983
+ codepoint = nextCodepoint;
984
+ i = 1;
768
985
  }
769
- if (!isIdentStart(codepoint)) {
986
+ if (codepoint !== 0x2d && !isIdentStart(codepoint)) {
770
987
  return false;
771
988
  }
772
989
  if (codepoint == REVERSE_SOLIDUS) {
773
- codepoint = name.codePointAt(i + 1);
990
+ codepoint = name.charCodeAt(i + 1);
774
991
  if (!isIdentCodepoint(codepoint)) {
775
992
  return false;
776
993
  }
777
994
  i += String.fromCodePoint(codepoint).length;
778
995
  if (i < j) {
779
- codepoint = name.codePointAt(i);
996
+ codepoint = name.charCodeAt(i);
780
997
  if (!isIdentCodepoint(codepoint)) {
781
998
  return false;
782
999
  }
@@ -791,19 +1008,19 @@ function isIdent(name) {
791
1008
  i += codepoint < 0x80 ? 1 : String.fromCodePoint(codepoint).length;
792
1009
  continue;
793
1010
  }
794
- if (!isIdentCodepoint(codepoint)) {
1011
+ if (codepoint !== 0x2d && !isIdentCodepoint(codepoint)) {
795
1012
  return false;
796
1013
  }
797
1014
  }
798
1015
  return true;
799
1016
  }
800
1017
  function isPseudo(name) {
801
- return name.charAt(0) == ':' &&
802
- ((name.endsWith('(') && isIdent(name.charAt(1) == ':' ? name.slice(2, -1) : name.slice(1, -1))) ||
803
- isIdent(name.charAt(1) == ':' ? name.slice(2) : name.slice(1)));
1018
+ return (name.charAt(0) == ":" &&
1019
+ ((name.endsWith("(") && isIdent(name.charAt(1) == ":" ? name.slice(2, -1) : name.slice(1, -1))) ||
1020
+ isIdent(name.charAt(1) == ":" ? name.slice(2) : name.slice(1))));
804
1021
  }
805
1022
  function isHash(name) {
806
- return name.charAt(0) == '#' && isIdent(name.charAt(1));
1023
+ return name.charAt(0) == "#" && isIdent(name.charAt(1));
807
1024
  }
808
1025
  function isNumber(name) {
809
1026
  if (name.length == 0) {
@@ -874,29 +1091,11 @@ function isNumber(name) {
874
1091
  }
875
1092
  return true;
876
1093
  }
877
- // export function isDimension(name: string) {
878
- //
879
- // let index: number = name.length;
880
- //
881
- // while (index--) {
882
- //
883
- // if (isLetter(<number>name.charCodeAt(index))) {
884
- //
885
- // continue
886
- // }
887
- //
888
- // index++;
889
- // break;
890
- // }
891
- //
892
- // const number: string = name.slice(0, index);
893
- // return number.length > 0 && isIdentStart(name.charCodeAt(index)) && isNumber(number);
894
- // }
895
1094
  function isPercentage(name) {
896
- return name.endsWith('%') && isNumber(name.slice(0, -1));
1095
+ return name.endsWith("%") && isNumber(name.slice(0, -1));
897
1096
  }
898
1097
  function isFlex(dimension) {
899
- return 'unit' in dimension && 'fr' == dimension.unit.toLowerCase();
1098
+ return "unit" in dimension && "fr" == dimension.unit.toLowerCase();
900
1099
  }
901
1100
  function parseDimension(name) {
902
1101
  let index = name.length;
@@ -907,12 +1106,15 @@ function parseDimension(name) {
907
1106
  index++;
908
1107
  break;
909
1108
  }
1109
+ if (index < 0) {
1110
+ return null;
1111
+ }
910
1112
  const dimension = {
911
1113
  typ: EnumToken.DimensionTokenType,
912
1114
  val: +name.slice(0, index),
913
- unit: name.slice(index)
1115
+ unit: name.slice(index),
914
1116
  };
915
- if (index < 0 || Number.isNaN(dimension.val)) {
1117
+ if (Number.isNaN(dimension.val)) {
916
1118
  return null;
917
1119
  }
918
1120
  if (isAngle(dimension)) {
@@ -930,8 +1132,8 @@ function parseDimension(name) {
930
1132
  else if (isResolution(dimension)) {
931
1133
  // @ts-ignore
932
1134
  dimension.typ = EnumToken.ResolutionTokenType;
933
- if (dimension.unit == 'dppx') {
934
- dimension.unit = 'x';
1135
+ if (dimension.unit == "dppx") {
1136
+ dimension.unit = "x";
935
1137
  }
936
1138
  }
937
1139
  else if (isFrequency(dimension)) {
@@ -945,7 +1147,7 @@ function parseDimension(name) {
945
1147
  return dimension;
946
1148
  }
947
1149
  function isHexColor(name) {
948
- if (name.charAt(0) != '#' || ![4, 5, 7, 9].includes(name.length)) {
1150
+ if (name.charAt(0) != "#" || ![4, 5, 7, 9].includes(name.length)) {
949
1151
  return false;
950
1152
  }
951
1153
  for (let chr of name.slice(1)) {
@@ -961,19 +1163,50 @@ function isHexColor(name) {
961
1163
  return true;
962
1164
  }
963
1165
  function isFunction(name) {
964
- return name.endsWith('(') && isIdent(name.slice(0, -1));
965
- }
966
- function isAtKeyword(name) {
967
- return name.charCodeAt(0) == 0x40 && isIdent(name.slice(1));
1166
+ return name.endsWith("(") && isIdent(name.slice(0, -1));
968
1167
  }
969
1168
  function isNewLine(codepoint) {
970
- // \n \r \f
971
- return codepoint == 0xa || codepoint == 0xc || codepoint == 0xd;
1169
+ // \n \r \f \v
1170
+ return (codepoint == 0xa ||
1171
+ codepoint == 0xb ||
1172
+ codepoint == 0xc ||
1173
+ codepoint == 0xd ||
1174
+ codepoint == 0x2028 ||
1175
+ codepoint == 0x2029);
972
1176
  }
973
1177
  function isWhiteSpace(codepoint) {
974
- return codepoint == 0x9 || codepoint == 0x20 ||
1178
+ return (codepoint == 0x9 ||
1179
+ codepoint == 0x20 ||
975
1180
  // isNewLine
976
- codepoint == 0xa || codepoint == 0xc || codepoint == 0xd;
1181
+ codepoint == 0xa ||
1182
+ codepoint == 0xb ||
1183
+ codepoint == 0xc ||
1184
+ codepoint == 0xd ||
1185
+ codepoint == 0x2028 ||
1186
+ codepoint == 0x2029);
1187
+ }
1188
+ function isValue(token) {
1189
+ if (token == null) {
1190
+ return false;
1191
+ }
1192
+ return (token.typ === EnumToken.IdenTokenType ||
1193
+ token.typ === EnumToken.DimensionTokenType ||
1194
+ token.typ === EnumToken.LengthTokenType ||
1195
+ token.typ === EnumToken.AngleTokenType ||
1196
+ token.typ === EnumToken.FlexTokenType ||
1197
+ token.typ === EnumToken.TimeTokenType ||
1198
+ token.typ === EnumToken.ResolutionTokenType ||
1199
+ token.typ === EnumToken.FrequencyTokenType ||
1200
+ token.typ === EnumToken.NumberTokenType ||
1201
+ token.typ === EnumToken.ColorTokenType ||
1202
+ token.typ === EnumToken.FunctionTokenType ||
1203
+ token.typ === EnumToken.UrlFunctionTokenType ||
1204
+ token.typ === EnumToken.GridTemplateFuncTokenType ||
1205
+ token.typ === EnumToken.ImageFunctionTokenType ||
1206
+ token.typ === EnumToken.TimelineFunctionTokenType ||
1207
+ token.typ === EnumToken.TimingFunctionTokenType ||
1208
+ token.typ === EnumToken.MathFunctionTokenType ||
1209
+ token.typ === EnumToken.TransformFunctionTokenType);
977
1210
  }
978
1211
 
979
- export { colorFontTech, fontFeaturesTech, fontFormat, isAngle, isAtKeyword, isColor, isColorspace, isDigit, isFlex, isFrequency, isFunction, isHash, isHexColor, isHueInterpolationMethod, isIdent, isIdentCodepoint, isIdentColor, isIdentStart, isLength, isNewLine, isNumber, isPercentage, isPercentageToken, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolution, isTime, isWhiteSpace, mathFuncs, mediaTypes, mozExtensions, parseColor, parseDimension, pseudoAliasMap, pseudoElements, transformFunctions, webkitExtensions, wildCardFuncs };
1212
+ export { dimensionUnits, isAngle, isColor, isColorspace, isDigit, isFlex, isFrequency, isFunction, isHash, isHexColor, isIdent, isIdentCodepoint, isIdentColor, isIdentStart, isLength, isLetter, isNewLine, isNumber, isPercentage, isPercentageToken, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolution, isTime, isValue, isWhiteSpace, parseColor, parseDimension, pseudoAliasMap, pseudoElements, reduceColorStops, reduceConicColorStops, reducegradientBackgroundPosition, renamedStandardProperties };