@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,184 +0,0 @@
1
- import { SyntaxValidationResult, EnumToken } from '../ast/types.js';
2
- import '../ast/minify.js';
3
- import '../ast/walk.js';
4
- import '../parser/parse.js';
5
- import '../parser/tokenize.js';
6
- import '../parser/utils/config.js';
7
- import '../syntax/color/utils/constants.js';
8
- import '../renderer/sourcemap/lib/encode.js';
9
- import { getSyntaxConfig, getParsedSyntax } from './config.js';
10
- import { validateAtRuleMedia } from './at-rules/media.js';
11
- import { validateAtRuleCounterStyle } from './at-rules/counter-style.js';
12
- import { validateAtRulePage } from './at-rules/page.js';
13
- import { validateAtRulePageMarginBox } from './at-rules/page-margin-box.js';
14
- import { validateAtRuleSupports } from './at-rules/supports.js';
15
- import { validateAtRuleImport } from './at-rules/import.js';
16
- import { validateAtRuleLayer } from './at-rules/layer.js';
17
- import { validateAtRuleFontFeatureValues } from './at-rules/font-feature-values.js';
18
- import { validateAtRuleNamespace } from './at-rules/namespace.js';
19
- import { validateAtRuleDocument } from './at-rules/document.js';
20
- import { validateAtRuleWhen } from './at-rules/when.js';
21
- import { validateAtRuleElse } from './at-rules/else.js';
22
- import { validateAtRuleContainer } from './at-rules/container.js';
23
- import { validateAtRuleCustomMedia } from './at-rules/custom-media.js';
24
-
25
- function validateAtRule(atRule, options, root) {
26
- if (atRule.nam == 'charset') {
27
- const valid = atRule.val.match(/^"[a-zA-Z][a-zA-Z0-9_-]+"$/i) != null;
28
- return {
29
- valid: valid ? SyntaxValidationResult.Valid : SyntaxValidationResult.Drop,
30
- node: atRule,
31
- syntax: null,
32
- error: ''
33
- };
34
- }
35
- if (['font-face', 'view-transition', 'starting-style'].includes(atRule.nam)) {
36
- return {
37
- valid: SyntaxValidationResult.Valid,
38
- node: atRule,
39
- syntax: '@' + atRule.nam,
40
- error: ''
41
- };
42
- }
43
- if (atRule.nam == 'media') {
44
- return validateAtRuleMedia(atRule);
45
- }
46
- if (atRule.nam == 'import') {
47
- return validateAtRuleImport(atRule);
48
- }
49
- if (atRule.nam == 'supports') {
50
- return validateAtRuleSupports(atRule);
51
- }
52
- if (atRule.nam == 'counter-style') {
53
- return validateAtRuleCounterStyle(atRule);
54
- }
55
- if (atRule.nam == 'layer') {
56
- return validateAtRuleLayer(atRule);
57
- }
58
- if (atRule.nam == 'font-feature-values') {
59
- return validateAtRuleFontFeatureValues(atRule);
60
- }
61
- if (atRule.nam == 'namespace') {
62
- return validateAtRuleNamespace(atRule);
63
- }
64
- if (atRule.nam == 'when') {
65
- return validateAtRuleWhen(atRule);
66
- }
67
- if (atRule.nam == 'else') {
68
- return validateAtRuleElse(atRule);
69
- }
70
- if (atRule.nam == 'container') {
71
- return validateAtRuleContainer(atRule);
72
- }
73
- if (atRule.nam == 'document') {
74
- return validateAtRuleDocument(atRule);
75
- }
76
- if (atRule.nam == 'custom-media') {
77
- return validateAtRuleCustomMedia(atRule);
78
- }
79
- if (['position-try', 'property', 'font-palette-values'].includes(atRule.nam)) {
80
- if (!Array.isArray(atRule.tokens) || atRule.tokens.length == 0) {
81
- return {
82
- valid: SyntaxValidationResult.Drop,
83
- node: atRule,
84
- syntax: '@' + atRule.nam,
85
- error: 'expected prelude'
86
- };
87
- }
88
- if (!('chi' in atRule)) {
89
- return {
90
- valid: SyntaxValidationResult.Drop,
91
- node: atRule,
92
- syntax: '@' + atRule.nam,
93
- error: 'expected body'
94
- };
95
- }
96
- const chi = atRule.tokens.filter((t) => t.typ != EnumToken.WhitespaceTokenType && t.typ != EnumToken.CommentTokenType);
97
- if (chi.length != 1) {
98
- return {
99
- valid: SyntaxValidationResult.Drop,
100
- node: atRule,
101
- syntax: '@' + atRule.nam,
102
- error: 'expected ' + (atRule.nam == 'property' ? 'custom-property-name' : 'dashed-ident')
103
- };
104
- }
105
- if (chi[0].typ != EnumToken.DashedIdenTokenType) {
106
- // @ts-ignore
107
- return {
108
- valid: SyntaxValidationResult.Drop,
109
- node: atRule,
110
- syntax: '@' + atRule.nam,
111
- error: 'expected ' + (atRule.nam == 'property' ? 'custom-property-name' : 'dashed-ident')
112
- };
113
- }
114
- // @ts-ignore
115
- return {
116
- valid: SyntaxValidationResult.Valid,
117
- node: atRule,
118
- syntax: '@' + atRule.nam,
119
- error: ''
120
- };
121
- }
122
- // scope
123
- if (atRule.nam == 'page') {
124
- return validateAtRulePage(atRule);
125
- }
126
- if (['top-left-corner', 'top-left', 'top-center', 'top-right', 'top-right-corner', 'bottom-left-corner', 'bottom-left', 'bottom-center', 'bottom-right', 'bottom-right-corner', 'left-top', 'left-middle', 'left-bottom', 'right-top', 'right-middle', 'right-bottom'].includes(atRule.nam)) {
127
- if (!(root == null || (root.typ == EnumToken.AtRuleNodeType && root.nam == 'page'))) {
128
- // @ts-ignore
129
- return {
130
- valid: SyntaxValidationResult.Drop,
131
- node: atRule,
132
- syntax: '@page',
133
- error: 'not allowed here'
134
- };
135
- }
136
- return validateAtRulePageMarginBox(atRule);
137
- }
138
- // handle keyframe as special case
139
- // check if the node exists
140
- const config = getSyntaxConfig();
141
- let name = '@' + atRule.nam;
142
- if (!(name in config.atRules)) {
143
- if (name.charAt(1) == '-') {
144
- name = name.replace(/@-[a-zA-Z]+-([a-zA-Z][a-zA-Z0-9_-]*)/, '@$1');
145
- }
146
- }
147
- if (!(name in config.atRules)) {
148
- if (options.lenient) {
149
- return {
150
- valid: SyntaxValidationResult.Lenient,
151
- node: atRule,
152
- syntax: null,
153
- error: ''
154
- };
155
- }
156
- return {
157
- valid: SyntaxValidationResult.Drop,
158
- node: atRule,
159
- syntax: null,
160
- error: 'unknown at-rule'
161
- };
162
- }
163
- const syntax = getParsedSyntax("atRules" /* ValidationSyntaxGroupEnum.AtRules */, name)?.[0];
164
- if ('chi' in syntax && !('chi' in atRule)) {
165
- return {
166
- valid: SyntaxValidationResult.Drop,
167
- node: atRule,
168
- syntax,
169
- error: 'missing at-rule body'
170
- };
171
- }
172
- // if ('prelude' in syntax) {
173
- //
174
- // return validateSyntax(syntax.prelude as ValidationToken[], atRule.tokens as Token[], root, options);
175
- // }
176
- return {
177
- valid: SyntaxValidationResult.Valid,
178
- node: null,
179
- syntax,
180
- error: ''
181
- };
182
- }
183
-
184
- export { validateAtRule };
@@ -1,36 +0,0 @@
1
- import { EnumToken } from '../ast/types.js';
2
- import '../ast/minify.js';
3
- import '../ast/walk.js';
4
- import '../parser/parse.js';
5
- import '../parser/tokenize.js';
6
- import '../parser/utils/config.js';
7
- import '../syntax/color/utils/constants.js';
8
- import '../renderer/sourcemap/lib/encode.js';
9
- import { validateRelativeSelectorList } from './syntaxes/relative-selector-list.js';
10
- import './syntaxes/complex-selector.js';
11
- import './syntax.js';
12
- import './config.js';
13
- import { validateSelectorList } from './syntaxes/selector-list.js';
14
-
15
- function validateSelector(selector, options, root) {
16
- let isNested = root.typ == EnumToken.RuleNodeType ? 1 : 0;
17
- let currentRoot = root.parent;
18
- while (currentRoot != null && isNested == 0) {
19
- if (currentRoot.typ == EnumToken.RuleNodeType) {
20
- isNested++;
21
- if (isNested > 0) {
22
- // @ts-ignore
23
- return validateRelativeSelectorList(selector, root, { ...(options ?? {}), nestedSelector: true });
24
- }
25
- }
26
- currentRoot = currentRoot.parent;
27
- }
28
- const nestedSelector = isNested > 0;
29
- // @ts-ignore
30
- return nestedSelector ? validateRelativeSelectorList(selector, root, {
31
- ...(options ?? {}),
32
- nestedSelector
33
- }) : validateSelectorList(selector, root, { ...(options ?? {}), nestedSelector });
34
- }
35
-
36
- export { validateSelector };